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

cancel
Showing results for 
Search instead for 
Did you mean: 
vamsinipun
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
fegor
Senior Member

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
salaboy
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. 

vamsinipun
Established Member

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

Jump to solution

I am using 5.17.0

salaboy
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? 

vamsinipun
Established Member

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

Jump to solution

ya.. but how can i display it?

fegor
Senior Member

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.

vamsinipun
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?

fegor
Senior Member

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.

vamsinipun
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?

fegor
Senior Member

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.