cancel
Showing results for 
Search instead for 
Did you mean: 

ProcessDiagramGenerator.generateDiagram not working

felipe1
Champ in-the-making
Champ in-the-making
I'm trying to generate a diagram for a running process.

My method receives the process instance Id as an argument. The code is shown bellow:


   public InputStream createInstanceDiagram(String processInstanceId) {
      ProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();

      ProcessDefinitionEntity pde = (ProcessDefinitionEntity) repositoryService.createProcessDefinitionQuery()
            .processDefinitionId(pi.getProcessDefinitionId()).singleResult();

      System.out.println("******* isGraphicalNotationDefined? " + pde.isGraphicalNotationDefined()); // always false
      System.out.println("******* diagramResourceName:  " + pde.getDiagramResourceName()); // returns resource name from database
      
      List<String> activities = runtimeService.getActiveActivityIds(idInstanciaProcesso);

      InputStream is = ProcessDiagramGenerator.generateDiagram(pde, "png", activities);
      
      return is;
   }


I have re-used code from other posts, and from the book-explorer-form project, which is part of the Activiti in Action book.

So, for debugging purposes, I wrote the InputStream object to a file, and when I open the file I see an empty image. Please notice that the isGraphicalNotationDefined method returns 'false', despite of the fact that there is a Diagram Resource associated with that process definition in the database, I can query the ACT_GE_BYTEARRAY table to prove that, and the getDiagramResourceName returns the value from the NAME column.

I have created a similar method that generates a diagram for the process instance, and this one is working perfectly:


   public InputStream createDefinitionDiagram(String processDefinitionId) {
      ProcessDefinitionEntity pde = (ProcessDefinitionEntity) repositoryService.createProcessDefinitionQuery()
            .processDefinitionId(processDefinitionId).singleResult();
      
      repositoryService.getResourceAsStream(pde.getDeploymentId(), pde.getDiagramResourceName());

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


The code I'm using to publish the process is the following:


   public String publishProcess(File file) throws IOException {
      try (ZipInputStream inputStream = new ZipInputStream(new FileInputStream(file))) {
         return repositoryService.createDeployment().name(arquivoPublicacao.getName()).addZipInputStream(inputStream).deploy().getId();
      }
   }


Here is my processDefinition


<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.bpmnwithactiviti.org">
  <process id="admissao" name="admissao" isExecutable="true">
    <startEvent id="inicioAdmissao" name="Start" activiti:formKey="tarefa_novaAdmissao.xhtml"></startEvent>
    <sequenceFlow id="indoParaDigitacao" sourceRef="inicioAdmissao" targetRef="digitaAdmissao"></sequenceFlow>
    <userTask id="digitaAdmissao" name="Digita Admissao" activiti:assignee="consultor" activiti:formKey="tarefa_digitaAdmissao.xhtml">
      <documentation>Digitar admissão para cargo: ${funAdmissaoWF.cargo}</documentation>
    </userTask>
    <sequenceFlow id="indoParaEfetivacao" sourceRef="digitaAdmissao" targetRef="efetivaAdmissao"></sequenceFlow>
    <serviceTask id="efetivaAdmissao" name="Efetiva Admissao" activiti:expression="#{servicoAdmissao.admiteFuncionario()}"></serviceTask>
    <sequenceFlow id="indoParaFim" sourceRef="efetivaAdmissao" targetRef="fim"></sequenceFlow>
    <endEvent id="fim" name="End"></endEvent>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_admissao">
    <bpmndi:BPMNPlane bpmnElement="admissao" id="BPMNPlane_admissao">
      <bpmndi:BPMNShape bpmnElement="inicioAdmissao" id="BPMNShape_inicioAdmissao">
        <omgdc:Bounds height="49.0" width="51.0" x="10.0" y="22.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="fim" id="BPMNShape_fim">
        <omgdc:Bounds height="49.0" width="61.0" x="420.0" y="22.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="digitaAdmissao" id="BPMNShape_digitaAdmissao">
        <omgdc:Bounds height="66.0" width="121.0" x="110.0" y="15.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="efetivaAdmissao" id="BPMNShape_efetivaAdmissao">
        <omgdc:Bounds height="65.0" width="134.0" x="267.0" y="16.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="indoParaDigitacao" id="BPMNEdge_indoParaDigitacao">
        <omgdi:waypoint x="61.0" y="46.0"></omgdi:waypoint>
        <omgdi:waypoint x="80.0" y="39.0"></omgdi:waypoint>
        <omgdi:waypoint x="110.0" y="48.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="indoParaEfetivacao" id="BPMNEdge_indoParaEfetivacao">
        <omgdi:waypoint x="231.0" y="48.0"></omgdi:waypoint>
        <omgdi:waypoint x="249.0" y="39.0"></omgdi:waypoint>
        <omgdi:waypoint x="234.0" y="39.0"></omgdi:waypoint>
        <omgdi:waypoint x="249.0" y="39.0"></omgdi:waypoint>
        <omgdi:waypoint x="267.0" y="48.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="indoParaFim" id="BPMNEdge_indoParaFim">
        <omgdi:waypoint x="401.0" y="48.0"></omgdi:waypoint>
        <omgdi:waypoint x="397.0" y="39.0"></omgdi:waypoint>
        <omgdi:waypoint x="420.0" y="46.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

I'm using Activit 3.11
1 REPLY 1

felipe1
Champ in-the-making
Champ in-the-making
My solution was upgrading to version 5.14.

The following code works perfectly in this version:


  BpmnModel model = repositoryService.getBpmnModel(pde.getProcessDefinition().getId());
  InputStream is = ProcessDiagramGenerator.generateDiagram(model, "png", activities);