AnsweredAssumed Answered

ActivityExectuion take issue

Question asked by chrishe on Jul 11, 2011
Latest reply on Jul 16, 2011 by ronald.van.kuijk
Hi there:
   In the API doc, the take method in ActivityExcution has described as this:leaves the current activity by taking the given transition.
   I wrote a unit test as following, try to leave the current activity to the next manually:


public class TransitionTest {

   private static RuntimeService runtimeService;
   private static RepositoryService repositoryService;
   private static Deployment deployment;
   
   
   @BeforeClass
   public static void init() {
      ProcessEngine processEngine = ProcessEngineConfiguration
            .createStandaloneProcessEngineConfiguration()
             .buildProcessEngine();
      
      repositoryService = processEngine.getRepositoryService();
      deployment = repositoryService.createDeployment()
         .addClasspathResource("zfsoft/Transition.bpmn20.xml")
         .deploy();
      
      runtimeService = processEngine.getRuntimeService();
   }
   
   @Test
   public void transitionTest(){
      ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Transition");   
      String processDefinitionId = processInstance.getProcessDefinitionId();      
      
      ExecutionEntity executionEntity = (ExecutionEntity) runtimeService.createExecutionQuery()
            .executionId(processInstance.getProcessInstanceId()).singleResult();
      
      ProcessDefinitionEntity processDef = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService)
            .getDeployedProcessDefinition(processDefinitionId);
      
      ActivityImpl currentActiviti = processDef.findActivity("ApplicationTask");
            
      String activitiId = currentActiviti.getId();
      System.out.println("current activitiId:" + activitiId);

      TransitionImpl outgoingTran = currentActiviti.findOutgoingTransition("flow2");
      System.out.println(outgoingTran);

      try {
         executionEntity.take(outgoingTran);
      } catch (Exception e1) {
         e1.printStackTrace();
      }
   }
   
   @AfterClass
   public static void destory(){
      repositoryService.deleteDeployment(deployment.getId(), true);
   }
}
And the BPMN as following:

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
  <process id="Transition" name="Transition">
    <documentation>Place documentation for the 'Transition' process here.</documentation>
    <startEvent id="startevent1" name="Start"></startEvent>
    <userTask id="ApplicationTask" name="Application Task" activiti:assignee="kermit"></userTask>
    <userTask id="ApproveTask" name="Approve Task" activiti:assignee="kermit"></userTask>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow1" name="" sourceRef="startevent1" targetRef="ApplicationTask"></sequenceFlow>
    <sequenceFlow id="flow2" name="" sourceRef="ApplicationTask" targetRef="ApproveTask"></sequenceFlow>
    <sequenceFlow id="flow3" name="" sourceRef="ApproveTask" targetRef="endevent1"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_Transition">
    <bpmndi:BPMNPlane bpmnElement="Transition" id="BPMNPlane_Transition">
      <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
        <omgdc:Bounds height="35" width="35" x="147" y="215"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="ApplicationTask" id="BPMNShape_ApplicationTask">
        <omgdc:Bounds height="55" width="105" x="267" y="209"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="ApproveTask" id="BPMNShape_ApproveTask">
        <omgdc:Bounds height="55" width="105" x="460" y="205"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
        <omgdc:Bounds height="35" width="35" x="700" y="215"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
        <omgdi:waypoint x="182" y="232"></omgdi:waypoint>
        <omgdi:waypoint x="267" y="236"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
        <omgdi:waypoint x="372" y="236"></omgdi:waypoint>
        <omgdi:waypoint x="460" y="232"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
        <omgdi:waypoint x="565" y="232"></omgdi:waypoint>
        <omgdi:waypoint x="671" y="232"></omgdi:waypoint>
        <omgdi:waypoint x="700" y="232"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

When run the test, we got the error message:
java.lang.NullPointerException at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:481)

Ok, it seems the  Context.getCommandContext() has a null result.

I have read the source code, but got no idea.

So the question is why the 'take' does not work? And what is Context used for?

Could someone give a hand?

Outcomes