cancel
Showing results for 
Search instead for 
Did you mean: 

Create and display diagram in Netbeans RCP application

jph
Champ in-the-making
Champ in-the-making
Hello,

I am developing a NetBeans RCP application to provide static representations of exisitng processes.
I would like to be able to read existing .bpmn20.xml files and display the diagrams in a NB RCP top component.

Could you point me to existing example or show me which libraries / API can be used.

Thank you in advance,

JP
5 REPLIES 5

jbarrez
Star Contributor
Star Contributor
How do you want to display it? Is an image enough? If so, the engine can autogenerate them for you.

jph
Champ in-the-making
Champ in-the-making
Yes.  An image is good enough.
Can you provide some additional info on which APIs / classes would need to be used, which libraries loaded in NB, a small example would be great also 🙂

Thanks
JP

frederikherema1
Star Contributor
Star Contributor
You only need the activiti-engine and it's dependencies. To fetch the diagram, see extract of our javadocs for RepositoryService:

InputStream getProcessDiagram(String processDefinitionId)
Gives access to a deployed process diagram, e.g., a PNG image, through a stream of bytes.
Parameters:
processDefinitionId - id of a ProcessDefinition, cannot be null.
Returns:
null when the diagram resource name of a ProcessDefinition is null.
Throws:
ActivitiObjectNotFoundException - when the process diagram doesn't exist.

jph
Champ in-the-making
Champ in-the-making
Thank you for following up on my question.  I followed your advice in trying to get the diagram but the return value of is (see below) is null.

Is there anything else I should do during initialization?  I see for instance that "isGraphicalNotationDefined" is false for the processDefinition?

Thank you

package org.ncia.npc.ProcessViewerActiviti;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.DeploymentBuilder;
import org.activiti.engine.repository.ProcessDefinition;

/**
*
* @author JPH
*/
public class ProcessDiagramActiviti {

    private RepositoryService repositoryService;
    private String pdID;

    public void deploy() {
        ProcessEngine processEngine = ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration()
                .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE)
                .setJdbcUrl("jdbc:h2:mem:my-own-db;DB_CLOSE_DELAY=1000")
                .setJobExecutorActivate(true)
                .buildProcessEngine();
        repositoryService = processEngine.getRepositoryService();
        DeploymentBuilder deployBuilder = repositoryService.createDeployment()
                .name("userWorkflow.bar")
                .addClasspathResource("resources/userWorkflow.bpmn20.xml");
        Deployment deployment = deployBuilder.deploy();
    }

    public void getDiagram() throws FileNotFoundException, IOException {
        ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
        pdID = processDefinition.getId();
        try{
        InputStream is = repositoryService.getProcessDiagram(pdID);
        OutputStream os = new FileOutputStream("images\\userWorkflow.png");
        byte[] buffer = new byte[1024];
        int bytesRead;
        //read from is to buffer
        while ((bytesRead = is.read(buffer)) != -1) {
            os.write(buffer, 0, bytesRead);
        }
        is.close();
        os.flush();
        os.close();
        }
        catch(IOException e) {
        }
    }
}

jph
Champ in-the-making
Champ in-the-making
Thank you for your patience Joram and Frederik.  I spent some more time on the week-end learning about activiti and found an answer to my questions.