cancel
Showing results for 
Search instead for 
Did you mean: 

Process diagram highlighting current process

dm22
Champ in-the-making
Champ in-the-making
Hi,

I am currently a student using Activiti as part of a project. I have noticed from other forum posts that there is definitely a way to show a process diagram that highlights the current process. Activiti Explorer also contains this feature.

Most of the other answers seem to just say "Look at the source code", however due to my inexperience I am struggling to grasp how it works. I was wondering if anyone could point me in the right direction? I am currently using the call:

InputStream image= repo.getProcessDiagram(processInstanceId);

which returns a process diagram, is there any way I can update this so it highlights the current process?

Many thanks
4 REPLIES 4

frederikherema1
Star Contributor
Star Contributor

  String processInstanceId = (String) getRequest().getAttributes().get("processInstanceId");
   
    if(processInstanceId == null) {
      throw new ActivitiIllegalArgumentException("No process instance id provided");
    }

    ExecutionEntity pi = (ExecutionEntity) ActivitiUtil.getRuntimeService().createProcessInstanceQuery()
        .processInstanceId(processInstanceId).singleResult();

    if (pi == null) {
      throw new ActivitiObjectNotFoundException("Process instance with id" + processInstanceId + " could not be found", ProcessInstance.class);
    }

    ProcessDefinitionEntity pde = (ProcessDefinitionEntity) ((RepositoryServiceImpl)
        ActivitiUtil.getRepositoryService()).getDeployedProcessDefinition(pi.getProcessDefinitionId());

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

      InputRepresentation output = new InputRepresentation(resource, MediaType.IMAGE_PNG);
      return output;
     
    } else {
      throw new ActivitiException("Process instance with id " + processInstanceId + " has no graphic description");
    }

Extract from the REST-resource (org.activiti.rest.api.legacy.process.ProcessInstanceDiagramResource). The main idea is that you fetch the model, pass it to the diagram-generator together with the activities that need to be highlighted.

dm22
Champ in-the-making
Champ in-the-making
Hi Frederik,

Thanks for the quick reply. I have been trying to implement this for a few hours. My first point which could be a problem is I don't have the method "getDeployedProcessDefinition" for repository service. I am instead using "getProcessDefinition" which is available to select in my IDE. Could I be using an old version?

The main problem I am is having is that while debugging i noticed that "ExecutionEntity pi" is always null even though the process instanceId is valid. I have a very similar method that just returns the process diagram without highlighting the current process which works fine. I am unsure where I am going wrong here.

Many thanks!

jbarrez
Star Contributor
Star Contributor
- Correct. You need to cast to (RepositoryServiceImpl) to get that method.

- It could very well be a case of lazy loading. It could be you need to explicitely fetch the data or execute the code within a custom command in Activiti.

pravin1
Champ in-the-making
Champ in-the-making
Hi

I have read through many forms. please clarify the below query. I am practicing activiti workflow mgnt. Both the wars activiti rest and activiti explorer deployed in jboss pointing to same port of H2 DB. i trying to fetch the records via activiti rest for the vacation request task (demo process)  created via activiti explorer. I am able to retrieve the process without any issues.
http://localhost:8080/activiti-rest/service/query/process-instances - POST

request
——–

{
  "processDefinitionKey":"vacationRequest",
"variables": [
        {
          "name": "employeeName",
          "type": "string",
          "value": "kermit",
          "operation" : "equals"
        }
      ]
}

response
——–
{
  "data": [
    {
      "id": "4143",
      "url": "http://localhost:8080/activiti-rest/service/runtime/process-instances/4143",
      "businessKey": null,
      "suspended": false,
      "ended": false,
      "processDefinitionId": "vacationRequest:1:31",
      "processDefinitionUrl": "http://localhost:8080/activiti-rest/service/repository/process-definitions/vacationRequest:1:31",
      "activityId": "handleRequest",
      "variables": [],
      "tenantId": "",
      "completed": false
    }
  ],
  "total": 1,
  "start": 0,
  "sort": "id",
  "order": "asc",
  "size": 1
}.


When i tried to generate the Process diagram highlighting current process using below api.
http://localhost:8080/activiti-rest/service/runtime/process-instances/4143/diagram

{
  "message": "Bad request",
  "exception": "Process instance with id '4143' has no graphical notation defined."
}

When i analyse the sample code, will get the exception when pde.isGraphicalNotationDefined() returns false.

if (pde != null && pde.isGraphicalNotationDefined()) {
..
}else {
      throw new ActivitiException("Process instance with id " + processInstanceId + " has no graphic description");
    }

Not sure how and where to set this variable to true in order to retrieve the Process diagram highlighting current process



Thanks in advance.

-
Pravin