cancel
Showing results for 
Search instead for 
Did you mean: 

Process instance state image generator access via API

lossril
Champ in-the-making
Champ in-the-making
Hello!
In Activiti-explorer webapp in Manage/Administration/Running process instances we can see a diagram of a process instance with current state markup. Can anyone please tell me how to get it or point me to some tutorials/javadocs on this case? I cannot find anything about it in userguide, only the info on how to get process definition diagram.
5 REPLIES 5

iam
Champ in-the-making
Champ in-the-making
Do you have installed activiti-rest web application?
WIth activiti-rest you can get process instance diagram:
http://localhost:8080/activiti-rest/service/runtime/process-instances/{processInstanceId}/diagram
Change {processInstanceId} to your process instance id.

lossril
Champ in-the-making
Champ in-the-making
Yes, I know about this option. I've searched through Activiti sources and found the code for it. Here it is:

<java>
public @ResponseBody byte[] getProcessInstanceDiagram(@PathVariable String processInstanceId, HttpServletResponse response) {
    ProcessInstance processInstance = getProcessInstanceFromRequest(processInstanceId);
   
    ProcessDefinitionEntity pde = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService)
        .getDeployedProcessDefinition(processInstance.getProcessDefinitionId());

    if (pde != null && pde.isGraphicalNotationDefined()) {
      BpmnModel bpmnModel = repositoryService.getBpmnModel(pde.getId());
      ProcessDiagramGenerator diagramGenerator = processEngineConfiguration.getProcessDiagramGenerator();
      InputStream resource = diagramGenerator.generateDiagram(bpmnModel, "png", runtimeService.getActiveActivityIds(processInstance.getId()),
          Collections.<String>emptyList(), processEngineConfiguration.getActivityFontName(), processEngineConfiguration.getLabelFontName(),
          processEngineConfiguration.getClassLoader(), 1.0);

      try {
        byte[] responseBytes = IOUtils.toByteArray(resource);
        response.setContentType("image/png");
        return responseBytes;
       
      } catch(Exception e) {
        response.setContentType("application/json");
        throw new ActivitiIllegalArgumentException("Error exporting diagram", e);
      }
     
    } else {
      response.setContentType("application/json");
      throw new ActivitiIllegalArgumentException("Process instance with id '" + processInstance.getId() + "' has no graphical notation defined.");
    }
  }
</java>

lossril
Champ in-the-making
Champ in-the-making
But I find lack of the javadocs or any documentation at all for ProcessDiagramGenerator (or other non-engine class) quite disturbing.

jbarrez
Star Contributor
Star Contributor
The cheesy answer would be that if you find it disturbing, we always accept pull requests that fix the disturbing situation 😉

The ProcessDiagramGenerator is mostly an internal class … hence why it's not directly documented in the userguide.

lossril
Champ in-the-making
Champ in-the-making
The problem about pull requests is I cannot work with github from work - our firewalls are set up for full tinfoil hat mode. I will try to fix it but no promises.