cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with XOR gateway

activiti-admin
Champ in-the-making
Champ in-the-making
There is a process model of the shape
    startEvent - userTask - exclusiveGateway - 3 userTasks - endEvent

The problem is, when the first userTask has been completed, the process does not have active tasks.

(In contrast, the process works as expected when the first userTask is removed.)

XorTest.testXorFunctionality.bpmn20.xml:
<?xml version="1.0" encoding="UTF-8"?>
<definitions id="propertyTest" xmlns="http://schema.omg.org/spec/BPMN/2.0"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn-extensions"
   typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath"
   targetNamespace="http://www.activiti.org/bpmn2.0">

   <process id="xorTest">
      <startEvent id="startEvent" />

      <sequenceFlow targetRef="chooseRecipeTask" sourceRef="startEvent" />

      <userTask id="chooseRecipeTask" name="Choose Recipe" />
      <exclusiveGateway id="recipeChosenXorGateway" />

      <sequenceFlow sourceRef="recipeChosenXorGateway"
         targetRef="cookPastaTask">
         <conditionExpression xsi:type="tFormalExpression">${recipe == 0}</conditionExpression>
      </sequenceFlow>
      <sequenceFlow sourceRef="recipeChosenXorGateway"
         targetRef="roastSteakTask">
         <conditionExpression xsi:type="tFormalExpression">${recipe == 1}</conditionExpression>
      </sequenceFlow>
      <sequenceFlow sourceRef="recipeChosenXorGateway"
         targetRef="prepareSaladTask">
         <conditionExpression xsi:type="tFormalExpression">${recipe == 2}</conditionExpression>
      </sequenceFlow>

      <userTask id="cookPastaTask" name="Cook Pasta" />
      <userTask id="roastSteakTask" name="Roast Steak" />
      <userTask id="prepareSaladTask" name="Prepare Salad" />

      <sequenceFlow targetRef="endEvent" sourceRef="cookPastaTask" />
      <sequenceFlow targetRef="endEvent" sourceRef="roastSteakTask" />
      <sequenceFlow targetRef="endEvent" sourceRef="prepareSaladTask" />

      <endEvent id="endEvent" />
   </process>
</definitions>

XorTest.java:
public class XorTest extends ActivitiTestCase {
   public void testXorFunctionality() {
      deployProcessForThisTestMethod();

      Map<String, Object> variables = new HashMap<String, Object>();
      variables.put("recipe", 2);
      ProcessInstance processInstance = processService
            .startProcessInstanceById("xorTest:1", variables);

      Task task = taskService.createTaskQuery().processInstance(
            processInstance.getId()).singleResult();
      assertEquals("Choose Recipe", task.getName());

      taskService.complete(task.getId());

      task = taskService.createTaskQuery().processInstance(
            processInstance.getId()).singleResult();
      // task is null at this place (but shouldn't be)
      assertEquals("Prepare Salad", task.getName());
   }
}



BTW, the variable named "result" in ExpressionCondition#evaluate(..) should be trimmed in order to remove potential XML whitespace.

Thanks
2 REPLIES 2

jbarrez
Star Contributor
Star Contributor
It looks like there is no sequence flow going from your first task to the exclusive gateway.
In that case, the process execution will be ended, since that is the required semantics according to the BPMN 2.0 spec (ie an 'invisible' end event following the task)


if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("No outgoing sequence flow found for " + execution.getActivity().getId() + ". Ending execution.");
      }
      execution.end();

activiti-admin
Champ in-the-making
Champ in-the-making
It looks like there is no sequence flow going from your first task to the exclusive gateway.
Oh, that's correct. - Sorry, and thank you for getting into this.