Drawing progress line on process instance Activiti 6.x

cancel
Showing results for 
Search instead for 
Did you mean: 
quint
Member II

Drawing progress line on process instance Activiti 6.x

Jump to solution

In version 5.21, we followed this path using PVM Transitions to show the progress and flow the process has taken:

Easy way to visualize a process instance history? 

Now in version 6.0.0, the PVM Transition & Activity classes have been removed.  Can anyone help as to how we can approach this problem?

In this migration doc (seems outdated), it eludes to the fact that these objects have been removed and we can now use the BpmnModel, but I'm not sure what to use. 

thanks!

Mike

1 Solution

Accepted Solutions
quint
Member II

Re: Drawing progress line on process instance Activiti 6.x

Jump to solution

Figured it out for those who care.  Here's the code:

Since there are no longer transitions available, I simply built a collection of Active and Historic Activity Id's. I then iterate through the list of FlowElement's for each Process and single out the SequenceFlow elements.  Next, grab the sourceRef and targetRef values so you know what connected a given pair of Activity objects.  If the Activity Id's exist in the list of active and historic Id's, then go ahead and draw the line.

I'm sure there is a more elegant solution out there, but this works fairly well.

diagramGenerator.generateDiagram(
                    bpmnModel, "png", activeActivityIds, highlightedFlows, scaleFactor);

//go out and get the highlighted flows that are eventually passed to the diagram generator above:

highLightedFLows = getHighLightedFlows(processDefinition, instanceId);

...

        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());
            }

            highLightedFlows.addAll(historicActivityInstanceList);
            
            // add current activities to list
            List<String> highLightedActivities = runtimeService.getActiveActivityIds(processInstanceId);
            highLightedFlows.addAll(highLightedActivities);

            BpmnModel model = repositoryService.getBpmnModel(processDefinition.getId());
            
            if(model.getProcesses()!=null && model.getProcesses().size()>0) {
                for(Process process : model.getProcesses()) {
                    getHighLightedFlows(process);
                }
            }
            return highLightedFlows;
        }

//Here I iterate through the flow elements of the Process(es):

        private void getHighLightedFlows(FlowElementsContainer process) {
            List<String> sequenceFlows = new ArrayList<String>();
                if(process.getFlowElements()!=null && process.getFlowElements().size()>0) {
                    for(FlowElement element : process.getFlowElements()) {
                        if(element!=null && element instanceof SequenceFlow) {
                            String sourceRef = ((SequenceFlow) element).getSourceRef();
                            String targetRef = ((SequenceFlow) element).getTargetRef();
                            
                            FlowElement srcElement = process.getFlowElement(sourceRef);
                            FlowElement targetElement = process.getFlowElement(targetRef);
                            
                            if(drawLine(srcElement, targetElement)) {
                                sequenceFlows.add(element.getId());
                            }
                        } else if (element instanceof SubProcess) {
                            getHighLightedFlows((SubProcess)element);
                        }
                    }
                }
            highLightedFlows.addAll(sequenceFlows);
        }
        
        private boolean drawLine(FlowElement srcElement, FlowElement targetElement) {
            if(srcElement !=null && targetElement!=null) {
                if(highLightedFlows.contains(srcElement.getId())
                        && highLightedFlows.contains(targetElement.getId())) {
                    return true;
                }
            }
            return false;
        }

View solution in original post

2 Replies
quint
Member II

Re: Drawing progress line on process instance Activiti 6.x

Jump to solution

Figured it out for those who care.  Here's the code:

Since there are no longer transitions available, I simply built a collection of Active and Historic Activity Id's. I then iterate through the list of FlowElement's for each Process and single out the SequenceFlow elements.  Next, grab the sourceRef and targetRef values so you know what connected a given pair of Activity objects.  If the Activity Id's exist in the list of active and historic Id's, then go ahead and draw the line.

I'm sure there is a more elegant solution out there, but this works fairly well.

diagramGenerator.generateDiagram(
                    bpmnModel, "png", activeActivityIds, highlightedFlows, scaleFactor);

//go out and get the highlighted flows that are eventually passed to the diagram generator above:

highLightedFLows = getHighLightedFlows(processDefinition, instanceId);

...

        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());
            }

            highLightedFlows.addAll(historicActivityInstanceList);
            
            // add current activities to list
            List<String> highLightedActivities = runtimeService.getActiveActivityIds(processInstanceId);
            highLightedFlows.addAll(highLightedActivities);

            BpmnModel model = repositoryService.getBpmnModel(processDefinition.getId());
            
            if(model.getProcesses()!=null && model.getProcesses().size()>0) {
                for(Process process : model.getProcesses()) {
                    getHighLightedFlows(process);
                }
            }
            return highLightedFlows;
        }

//Here I iterate through the flow elements of the Process(es):

        private void getHighLightedFlows(FlowElementsContainer process) {
            List<String> sequenceFlows = new ArrayList<String>();
                if(process.getFlowElements()!=null && process.getFlowElements().size()>0) {
                    for(FlowElement element : process.getFlowElements()) {
                        if(element!=null && element instanceof SequenceFlow) {
                            String sourceRef = ((SequenceFlow) element).getSourceRef();
                            String targetRef = ((SequenceFlow) element).getTargetRef();
                            
                            FlowElement srcElement = process.getFlowElement(sourceRef);
                            FlowElement targetElement = process.getFlowElement(targetRef);
                            
                            if(drawLine(srcElement, targetElement)) {
                                sequenceFlows.add(element.getId());
                            }
                        } else if (element instanceof SubProcess) {
                            getHighLightedFlows((SubProcess)element);
                        }
                    }
                }
            highLightedFlows.addAll(sequenceFlows);
        }
        
        private boolean drawLine(FlowElement srcElement, FlowElement targetElement) {
            if(srcElement !=null && targetElement!=null) {
                if(highLightedFlows.contains(srcElement.getId())
                        && highLightedFlows.contains(targetElement.getId())) {
                    return true;
                }
            }
            return false;
        }

toajayks
Member II

Re: Drawing progress line on process instance Activiti 6.x

Jump to solution

Hi, I'm new to Activiti and working on existing project that is based on 5.22. We had used PVMActiviti, Now we wanted to migrate Activiti 6.x, 

Can any one please guide me to convert the below code to BPMN Module. or to work in 6.x

public synchronized void execute(DelegateExecution exe) {
   logger.debug("TaskTransition - execute - START");
   PvmActivity activity = exe.getActivity();
   PvmTransition transition = activity.findOutgoingTransition("task-subState-remainder");
   int newsubstateid = (Integer) exe
      .getVariable(WorkflowContants.WKFL_NEW_SUB_STATE_ID);
   logger.debug("TaskTransition - execute - newsubstateid - "+ newsubstateid);
switch (newsubstateid) {
   case 9:
   transition = activity.findOutgoingTransition("subState-9");
   break;

   case 11:
   transition = activity.findOutgoingTransition("subState-11");
   break;

   default:
   transition = activity
      .findOutgoingTransition("task-subState-remainder");
   break;
   }
   logger.debug("TaskTransition - execute - END");
   exe.take(transition);
}

 

Thanks in Advance,

Ajay