Is it possible to show .bpmn diagram in front end?

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Established Member

Is it possible to show .bpmn diagram in front end?

Jump to solution

Hi,

I am using activiti in my spring web application. I would like to show to the end user, where current status of process in process. Is any other way to show like this?

1 Solution

Accepted Solutions
Highlighted
Established Member II

Re: Is it possible to show .bpmn diagram in front end?

Jump to solution

You can generating diagram for process or diagram por instance in process, in my case I have a test unit to generate a image of instance process diagram:

@Test
@Deployment(resources = {"org/activiti/test/BoundaryTimerTest.bpmn20.xml"})
public void testGetProcessInstanceDiagram() throws IOException {
   logger.info("Test of instance diagram process...");
   RuntimeService runtimeService = activitiRule.getRuntimeService();
   RepositoryService repositoryService = activitiRule.getRepositoryService();
   ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("BoundaryTimerTest");
   assertNotNull(processInstance);

   String processInstanceId = processInstance.getId();
   logger.info("Process Id = " + processInstanceId);

   ExecutionEntity pi = (ExecutionEntity)    runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();

   ProcessDefinitionEntity pde = (ProcessDefinitionEntity) ((RepositoryServiceImpl)    repositoryService).getDeployedProcessDefinition(pi.getProcessDefinitionId());

   if (pde != null && pde.isGraphicalNotationDefined()) {
      BpmnModel bpmnModel = repositoryService.getBpmnModel(pde.getId());
      ProcessDiagramGenerator processDiagramGenerator = new DefaultProcessDiagramGenerator();
      InputStream is = processDiagramGenerator.generateDiagram(bpmnModel, "png",       runtimeService.getActiveActivityIds(processInstanceId));
      byte[] buffer = new byte[is.available()];
      is.read(buffer);

      File imageFile = new File("D:/diagram-" + processInstanceId + ".png");
      FileOutputStream fileOutputStream = new FileOutputStream(imageFile);
      fileOutputStream.write(buffer);
      fileOutputStream.close();

   }

   assertNotNull(processInstance.getProcessInstanceId());
}

You can need this dependency:

<dependency>
   <groupId>org.activiti</groupId>
   <artifactId>activiti-image-generator</artifactId>
   <version>5.16.1</version>
</dependency>

Regards.

View solution in original post

9 Replies
Highlighted
Senior Member

Re: Is it possible to show .bpmn diagram in front end?

Jump to solution

Hi there, which version of Activiti are you using? without that is very difficult to help you. This is a very common requirement, so it is definitely possible, but you need to find what is the best way based on which version are you using. 

Highlighted
Established Member

Re: Is it possible to show .bpmn diagram in front end?

Jump to solution

I am using 5.17.0

Highlighted
Senior Member

Re: Is it possible to show .bpmn diagram in front end?

Jump to solution

I'm sure that there is a way in 5.22 but not sure if that was present in 5.17, is there any chance for you to upgrade to 5.22? 

Highlighted
Established Member

Re: Is it possible to show .bpmn diagram in front end?

Jump to solution

ya.. but how can i display it?

Highlighted
Established Member II

Re: Is it possible to show .bpmn diagram in front end?

Jump to solution

You can generating diagram for process or diagram por instance in process, in my case I have a test unit to generate a image of instance process diagram:

@Test
@Deployment(resources = {"org/activiti/test/BoundaryTimerTest.bpmn20.xml"})
public void testGetProcessInstanceDiagram() throws IOException {
   logger.info("Test of instance diagram process...");
   RuntimeService runtimeService = activitiRule.getRuntimeService();
   RepositoryService repositoryService = activitiRule.getRepositoryService();
   ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("BoundaryTimerTest");
   assertNotNull(processInstance);

   String processInstanceId = processInstance.getId();
   logger.info("Process Id = " + processInstanceId);

   ExecutionEntity pi = (ExecutionEntity)    runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();

   ProcessDefinitionEntity pde = (ProcessDefinitionEntity) ((RepositoryServiceImpl)    repositoryService).getDeployedProcessDefinition(pi.getProcessDefinitionId());

   if (pde != null && pde.isGraphicalNotationDefined()) {
      BpmnModel bpmnModel = repositoryService.getBpmnModel(pde.getId());
      ProcessDiagramGenerator processDiagramGenerator = new DefaultProcessDiagramGenerator();
      InputStream is = processDiagramGenerator.generateDiagram(bpmnModel, "png",       runtimeService.getActiveActivityIds(processInstanceId));
      byte[] buffer = new byte[is.available()];
      is.read(buffer);

      File imageFile = new File("D:/diagram-" + processInstanceId + ".png");
      FileOutputStream fileOutputStream = new FileOutputStream(imageFile);
      fileOutputStream.write(buffer);
      fileOutputStream.close();

   }

   assertNotNull(processInstance.getProcessInstanceId());
}

You can need this dependency:

<dependency>
   <groupId>org.activiti</groupId>
   <artifactId>activiti-image-generator</artifactId>
   <version>5.16.1</version>
</dependency>

Regards.

View solution in original post

Established Member

Re: Is it possible to show .bpmn diagram in front end?

Jump to solution

In my execution, repositoryService not have method like getDeployedProcessDefinition 

How can i resolve it?

Highlighted
Established Member II

Re: Is it possible to show .bpmn diagram in front end?

Jump to solution

Hi!

How has initialize your getFormService(), getRepository() and getRuntime()?

In my case I create a ActivitiRule, for example:

@Rule
public ActivitiRule activitiRule = new ActivitiRule();

And now in my method testListFields():

RuntimeService runtimeService = activitiRule.getRuntimeService();
RepositoryService repositoryService = activitiRule.getRepositoryService();
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("BoundaryTimerTest");

Regards.

Highlighted
Established Member

Re: Is it possible to show .bpmn diagram in front end?

Jump to solution

Ya. those are not an issue. It is showing error at RepositoryServiceImpl. How can i import that file?

Highlighted
Established Member II

Re: Is it possible to show .bpmn diagram in front end?

Jump to solution

This class is included in org.activiti.engine.impl:

import org.activiti.engine.impl.RepositoryServiceImpl;

Regards.