cancel
Showing results for 
Search instead for 
Did you mean: 

How to generate the diagram of a Deployed Workflow

vire7777
Champ in-the-making
Champ in-the-making
Hi Dear Activiti Community

Maybe someone could tell me how it could be possible to have the diagram of a deployed Workflow (after the Bpmn deployment) without any instance of it.
I would love to show my users the different diagram before they launch an instance of the specified workflow.

I use this to bring the diagram of my launched instances :

"ProcessEngine processEngine = UserSession.getProcessEngine(session);

// get the diagram image
ProcessDefinitionEntity pde = (ProcessDefinitionEntity) ((RepositoryServiceImpl) processEngine.getRepositoryService()).getDeployedProcessDefinition(defintionId);
InputStream diagStream = ProcessDiagramGenerator.generatePngDiagram(pde);"


I would love something similar but for not launched (instanced) Process, just deployed ones.
Could you help me ?
9 REPLIES 9

felipe1
Champ in-the-making
Champ in-the-making
To get a process diagram use repositoryService#getResourceAsStream:


  ProcessDefinitionEntity pde = (ProcessDefinitionEntity) repositoryService.createProcessDefinitionQuery().processDefinitionId(processDefId)
    .singleResult();

  repositoryService.getResourceAsStream(pde.getDeploymentId(), pde.getDiagramResourceName());

  InputStream is = repositoryService.getResourceAsStream(pde.getDeploymentId(), pde.getDiagramResourceName());

  return is;

this will give you an InputStream containing the image data.

vire7777
Champ in-the-making
Champ in-the-making
In fact, i don't see the difference between your code and mine ?

trademak
Star Contributor
Star Contributor
Are you sure your process definition contains the necessary BPMN DI information?

Best regards,

felipe1
Champ in-the-making
Champ in-the-making
Sorry Vire7777, I didn't read your code carefully, I just read the thread title and copied and pasted a working code I use to get a process diagram.

In your understanding what is the difference between a launched and a deployed process?

I'm asking that because your code does not reference a process instance at any point. It just passes the process definition Id as an argument to the getDeployedProcessDefinition method. So the result is a diagram which does not highlights the active tasks.

vire7777
Champ in-the-making
Champ in-the-making
That s exactly what i want !
I want the diagram of the process BEFORE any instance was launched, just after deployment

So there s no active task as there is no instance launched.

It's just to show a list of all deployed workflow to the user, then they can choose which one they want to launch (seeing the diagram) then they click on : "create an instance" button and it launch an instance.

Here for me the cycle of a workflow :
1) BPMN DEFINITION
2) Workflow deployed in BDD (you took your BPMN and deployed it
3) Launch an instance of the workflow (manually or automatically)

I want the diagram at point 2 !

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi,

the only think needed is process definition.
Possibilities:
    * java API for getting process diagram - http://www.activiti.org/userguide/#generatingProcessDiagram
    * REST api provides interface to get diagram from process instance.

    @Get
      public InputRepresentation getProcessInstanceDiagram() {
        ProcessInstance processInstance = getProcessInstanceFromRequest();
       
        ProcessDefinitionEntity pde = (ProcessDefinitionEntity) ((RepositoryServiceImpl)
                ActivitiUtil.getRepositoryService()).getDeployedProcessDefinition(processInstance.getProcessDefinitionId());

        if (pde != null && pde.isGraphicalNotationDefined()) {
          BpmnModel bpmnModel = ActivitiUtil.getRepositoryService().getBpmnModel(pde.getId());
          InputStream resource = ProcessDiagramGenerator.generateDiagram(bpmnModel, "png", ActivitiUtil.getRuntimeService().getActiveActivityIds(processInstance.getId()));

          InputRepresentation output = new InputRepresentation(resource, MediaType.IMAGE_PNG);
          return output;
         
        } else {
          throw new ActivitiIllegalArgumentException("Process instance with id '" + processInstance.getId() + "' has no graphical notation defined.");
        }
      }
    if you have ProcessDefinition Id you do not need process instance.
Regards
Martin

vire7777
Champ in-the-making
Champ in-the-making
Thanks for your answers Smiley Happy

minhquankq
Champ in-the-making
Champ in-the-making
Hi @martin.grofcik,
I'm using DefaultProcessDiagramGenerator class (in activiti-image-generator module) to generate diagram of current process instance (with highlight activiti and highlight sequenceflow), but the result image is not included sequence name, when I'm debugging, the map labelLocationMap allway empty, so it can not draw the sequence name.

Can I draw sequence flow name with DefaultProcessDiagramGenerator class?

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi,

Technically it should be possible. If flow name is not drawn, there is a bug in DiagramGenerator.

Regards
Martin