AnsweredAssumed Answered

Visualize a process instance history

Question asked by nhhao1996 on Feb 25, 2019

Hi everyone!

I'm using Activiti 5.22.0.

After my process is completed. I tried to re-draw my process diagram with highlighted tasks from start to end.

I followed this post Easy way to visualize a process instance history? but the code is so complex for me.

Can you give me an example class or tell me step by step to write a class to draw process diagram with history highlighted tasks (look like this: Imgur: The magic of the Internet )

Thank you very much!

 

UPDATE:

I tried a few hours with this code in my class:

 

public class redrawProcess implements JavaDelegate {

private List<String> historicActivityInstanceList = new ArrayList<String>();
private static List<String> highLightedFlows = new ArrayList<String>();
private static List<String> highLightedActivities;

private RuntimeService runtimeService;
private HistoryService historyService;

//get highlight flows
private List<String> getHighlightedFlows (ProcessDefinitionEntity processDefinition, String processInstanceId) {

List<HistoricActivityInstance> historicActivityInstances = historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstanceId)
.orderByHistoricActivityInstanceStartTime().asc().list();

for (HistoricActivityInstance hai : historicActivityInstances) {
historicActivityInstanceList.add(hai.getActivityId());
}

highLightedActivities = runtimeService.getActiveActivityIds(processInstanceId);
historicActivityInstanceList.addAll(highLightedActivities);

getHighLightedFlows(processDefinition.getActivities());

return highLightedFlows;
}

private void getHighLightedFlows(List<ActivityImpl> activityList) {
for (ActivityImpl activity : activityList) {
if (activity.getProperty("type").equals("subProcess")) {
// get flows for the subProcess
getHighLightedFlows(activity.getActivities());
}

if (historicActivityInstanceList.contains(activity.getId())) {
List<PvmTransition> pvmTransitionList = activity.getOutgoingTransitions();
for (PvmTransition pvmTransition: pvmTransitionList) {
String destinationFlowId = pvmTransition.getDestination().getId();

if (historicActivityInstanceList.contains(destinationFlowId)) {
highLightedFlows.add(pvmTransition.getId());
}
}
}
}
}

public static InputStream drawProcess(String processInstanceId) {
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();

RuntimeService runtimeService = processEngine.getRuntimeService();

RepositoryService repositoryService = processEngine.getRepositoryService();

ProcessInstance processInstance = runtimeService.createProcessInstanceQuery()
.processInstanceId(processInstanceId).singleResult();

BpmnModel processDefinitionEntity = repositoryService.getBpmnModel(processInstance.getProcessDefinitionId());

ProcessDiagramGenerator processDiagramGenerator = new DefaultProcessDiagramGenerator();

return processDiagramGenerator.generateDiagram(processDefinitionEntity, "png", highLightedActivities, highLightedFlows);
}

@Override
public void execute(DelegateExecution execution) throws Exception {
drawProcess(execution.getProcessInstanceId());

FileOutputStream outputStream = new FileOutputStream(new File("d:\\test.png"));

IOUtils.copy(drawProcess(execution.getProcessInstanceId()), outputStream);
outputStream.close();
}

}

But when I deploy to Activiti Explorer, it appear warning: null. What's wrong with my code?

Outcomes