cancel
Showing results for 
Search instead for 
Did you mean: 

Is this correct way to get outgoing transitions?

sberardelli
Champ in-the-making
Champ in-the-making
So, we're taking Activiti for a test ride…
We need a way in our web app to present a list of outgoing transitions from whatever task they are on…
Digging around the docs didn't really shed any light.

So….stumbled onto this in my testing.
Is this a reasonable/correct way to go about this?
Seems like there should be a better way…

ProcessInstance instanceA = runtimeService.startProcessInstanceByKey("K12-Workflow-Master", map);
ExecutionEntity entity = (ExecutionEntity)instanceA;
List<PvmTransition> transitions = entity.getActivity().getOutgoingTransitions();

Thanks for any advice!
7 REPLIES 7

thodte
Champ in-the-making
Champ in-the-making
Hello,

I have the same problem. I want to know from on state the outgoing transitions and the the destination state of the transition.

I try following:

final Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
 
  ExecutionEntity exe = (ExecutionEntity)runtimeService.createExecutionQuery().executionId(task.getExecutionId()).singleResult();
  List<PvmTransition> result = exe.getActivity().getOutgoingTransitions();

But I get this exception:

java.lang.NullPointerException
at org.activiti.engine.impl.runtime.ExecutionEntity.ensureProcessDefinitionInitialized(ExecutionEntity.java:603)
at org.activiti.engine.impl.runtime.ExecutionEntity.getProcessDefinition(ExecutionEntity.java:588)
at org.activiti.engine.impl.runtime.ExecutionEntity.ensureActivityInitialized(ExecutionEntity.java:655)
at org.activiti.engine.impl.runtime.ExecutionEntity.getActivity(ExecutionEntity.java:648)
at de.htsolutions.foerderwesen.intern.server.service.WorkflowServiceImpl.getNextTasks(WorkflowServiceImpl.java:164)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)

Is there a solution for our problems?

Regards,
Christoph

mproch
Champ in-the-making
Champ in-the-making
Hello guys,
please try sth like:

ExecutionEntity exe = … //the code you already have
ProcessDefinitionEntity pde = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService)
            .getDeployedProcessDefinition("your_process_definition_id"); //this can be cached
List<PvmTransition> out = pde.findActivity(exe.getActivityId()).getOutgoingTransitions();
(tried it with Activiti 5.3)
why so complex (at least I don't know simpler way Smiley Wink)? The point is that ExecutionEntity which is returned by executionQuery is not fully initialized - basically it contains only stuff that can be read directly from DB - which does not include process definition information. Hope it helps.

Please also bear in mind, that the code above (and all PVM stuff) is not in 'official' API - so it can change without much warning Smiley Wink

jbarrez
Star Contributor
Star Contributor
Note that what youa re asking is avery bad BPMN 2.0 style.
In BPMN, all outgoing sequence flow are to be taken in parallel, unless you define conditions on each of them.

The right way to do it, is using a  combination of task + exclusive gateway based on data you've set while handling the task.

thodte
Champ in-the-making
Champ in-the-making
Hello,

yes I understand this but to set the condition I want to show the next task. The user should see the next task which will be created.
The user is not stupid and the process is clear. I want to display the next states so that he can decide which transition should used.

Other solutions or ideas?

Regards,
Christoph

sberardelli
Champ in-the-making
Champ in-the-making
So, I don't understand how this is bad bpmn20 style?

Let's say I have a workflow where I've saved a document and set a "ReadyToPublish" state.
(Don't get distracted by the document, it really doesn't matter)

What I need is for an editor to decide to a)publish the doc, or b) reject the document.

Basically, I want to be able to have the user choose the next sequence.

How else can I offer the user a choice of the available sequence flows?
I don't want to offer the user a hardcoded set of choices that I have to update every time I decide to add another outgoing sequenceFlow….

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
So, I don't understand how this is bad bpmn20 style?

That is menioned before. Explicit taking of a sequenceflow is not specificed in BPMN. Which sequenceflow should be taken is to be decided by conditions ON the sequenceflows. If there are multiple sequenceflows without conditions they ALL should be taken. So if you take an explicit flow that is against behaviour.

The issue regarding conditions ON sequenceflows leaving the activity (task) is maybe even weirder. On the one hand it seems not to be allowed not allowed to have conditions on sequenceflows having it's source in a task.  As mentioned in the BPMN spec on page 5
  • ConditionExpression, allowed only for Sequence Flow out of Gateways, MAY be null.

  • Default is an attribute of a sourceRef (exclusive or inclusive) Gateway.

and page 7
  • Multiple outgoing connections are only allowed for converging Gateways.
  •   
  • Multiple outgoing connections are only allowed for diverging Gateways.
  •   
  • ConditionExpression, allowed only for Sequence Flow out of Gateways, MAY be null.
  •   
  • Default is an attribute of a sourceRef (exclusive or inclusive) Gateway.

This is in line with what is mentioned on page 153:

An Activity MAY be a source for Sequence Flows; it can have multiple outgoing Sequence Flows. If there
are multiple outgoing Sequence Flows, then this means that a separate parallel path is being created for each
Sequence Flow (i.e., tokens will be generated for each outgoing Sequence Flow from the Activity).
(no mention of conditions here)

But it contradicts what is on page 427

…Multiple outgoing Sequence Flows with conditions behaves as an inclusive split. A mix of multiple outgoing Sequence
Flows with and without conditions is considered as a combination of a parallel and an inclusive split as shown in the Figure 13.1.

Now back to the questions:

Basically, I want to be able to have the user choose the next sequence.

How else can I offer the user a choice of the available sequence flows?

Joram described how to do this… Set a process variable with the value a use chooses (might be the NAME of the sequenceflow) and use that on a condition on a gateway. Just do *not* use it to take an explicit sequenceflow on an activity

I don't want to offer the user a hardcoded set of choices that I have to update every time I decide to add another outgoing sequenceFlow….

This way it is *not* 'hardcoded'

sberardelli
Champ in-the-making
Champ in-the-making
Thanks for the help!

I have it setup with a userTask that will set the process variable, which then flows into the gateway, and takes a sequence out based on that variable.