How to get all possible flows from current activity?


#1

I used code to get all flows from current activity described here https://community.alfresco.com/thread/220347-how-to-get-all-possible-flows-from-current-activity
In Flowable v6.3.1 interface changed and I don’t know how to get it.

I know that:

Process process = ...?...
Activity activity = (Activity) process.getFlowElement(activityId, true);
List<SequenceFlow> outgoingFlows = activity.getOutgoingFlows();

but how can I get Process object?


#2
public class GetOutgoingFlowsCommand implements Command<List<String>>, Serializable {

private String processDefinitionId;
private String activityId;

public GetOutgoingFlowsCommand(String processDefinitionId, String activityId) {
    this.processDefinitionId = processDefinitionId;
    this.activityId = activityId;
}

public List<String> execute(CommandContext commandContext) {
    List<String> possibleSequenceFlowIds = new ArrayList<String>();
    Process process = ProcessDefinitionUtil.getProcess(processDefinitionId);
    Activity activity = (Activity) process.getFlowElement(activityId, true);

    for (SequenceFlow sequenceFlow : activity.getOutgoingFlows()) {
        possibleSequenceFlowIds.add(sequenceFlow.getId());
    }

    return possibleSequenceFlowIds;
}

}


#3

@Jakub_Ferschmann this looks quite complex.

Have you looked at RepositoryService#getBpmnModel(String)? This returns you back BpmnModel and then you can do BpmnModel#getMainProcess()


#4

How to fetch Extension elements on TaskListener.notify()

public class MyTaskCreateListener implements TaskListener {

@Override
public void notify(DelegateTask delegateTask) {
	
	Map<String, List<ExtensionElement>> exelements  = ProcessDefinitionUtil.getBpmnModel(delegateTask.getProcessDefinitionId()).getFlowElement(delegateTask.getTaskDefinitionKey()).getExtensionElements();
	
	
	
	System.out.println(exelements.size());
	
	
}

}

Is this the way or do we have any better way


#5

I would not use the ProcessDefinitionUtil that’s an internal API. You can use the RepositoryService#getBpmnModel from the API package to get the BpmnModel

Cheers,
Filip


#6

Hi
I believe we need to give the class names of the listener at extensionElements. In my case MyTaskCreateListener does not have any access to Repository Service. From the context of MyTaskCreateListener how can we get access to RepositoryServerObject,


#7

@ksv have a look at the CommandContextUtil from the flowable-engine, you can get access to the RepositoryService through it