cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot find activity in ProcessDefinition

kikyou1986
Champ in-the-making
Champ in-the-making
Hi,

I want to find a certain activity in a ProcessDefinitionImpl object using method #findActivity(activityId), but it returns null every time.

Below is the process picture. It is a simple Manager approval process. the applicant fills the application form first, then the manager approves it or reject it (send a message event which is caught by the boundary event handler).
I am aware that there is more sensible way to accomplish my purpose. However, I'm just using this way to do some study about activiti.
[IMG]http://i1066.photobucket.com/albums/u420/kikyou1986/rejectionTest_zps6ottqrra.png[/IMG]

Then, the main part of the bpmn.xml

<!– message that asking for transition –>
   <message id="transitionMsg" name="transitionMsg"></message>
   
   <process id="rejectionTest" isExecutable="true">
      <!– start event –>
      <startEvent id="sid-3CB181D7-6454-4191-8C64-6913830F0080"></startEvent>
      <!– fill the form –>
      <userTask id="formDocumentation" name="Form documentation"></userTask>
      
      <!– sub process for manager approval –>
      <subProcess id="subProcess" name="subProcess">
         <startEvent id="sid-F8C6AEE8-38BD-4756-97B4-B3F41D1C9888"></startEvent>
         <userTask id="managerApproval" name="Manager approval"></userTask>
         <endEvent id="sid-BD446E60-3C91-4F92-88DB-FC52B65CF0C0"></endEvent>
         <sequenceFlow id="sid-4D793033-8D63-4719-B21F-B749E86ED395"
            sourceRef="sid-F8C6AEE8-38BD-4756-97B4-B3F41D1C9888" targetRef="managerApproval"></sequenceFlow>
         <sequenceFlow id="sid-1305E9CA-3531-49AC-9AB3-6369FD898CE3"
            sourceRef="managerApproval" targetRef="sid-BD446E60-3C91-4F92-88DB-FC52B65CF0C0"></sequenceFlow>
      </subProcess>
      <endEvent id="sid-36FFF592-1898-4D99-8697-29B61CBA76EF"></endEvent>
      
      <!– boundary event –>
      <boundaryEvent id="sid-F1583981-7F79-4242-B396-9FAE066D8B56"
         attachedToRef="subProcess" cancelActivity="true">
         <messageEventDefinition messageRef="transitionMsg"></messageEventDefinition>
      </boundaryEvent>
      
      <!– transition handler –>
      <serviceTask id="sid-BDD36229-21A6-4D6A-A639-58EDADC29D4C"
         activiti:delegateExpression="${transitionHandleTask}"></serviceTask>
      <endEvent id="sid-A5BEB0D2-B629-4333-AE47-32AB08817F86"></endEvent>
      
      <sequenceFlow id="sid-1CF9CD35-52CB-457C-97C1-0BC8393D391C"
         sourceRef="subProcess" targetRef="sid-36FFF592-1898-4D99-8697-29B61CBA76EF"></sequenceFlow>      
      <sequenceFlow id="sid-71B6C7DC-52B7-4553-84B0-470CD0319562"
         sourceRef="sid-3CB181D7-6454-4191-8C64-6913830F0080" targetRef="formDocumentation"></sequenceFlow>
      <sequenceFlow id="sid-D6C9CE38-D763-4BEC-8EB0-22862957235D"
         sourceRef="formDocumentation" targetRef="subProcess"></sequenceFlow>
      <sequenceFlow id="sid-BBFCA741-55EC-4BB1-BAE9-12131512CC3F"
         sourceRef="sid-F1583981-7F79-4242-B396-9FAE066D8B56" targetRef="sid-BDD36229-21A6-4D6A-A639-58EDADC29D4C"></sequenceFlow>
      <sequenceFlow id="sid-EDEC210F-7292-4BA3-ACD8-15238DC4A7C9"
         sourceRef="sid-BDD36229-21A6-4D6A-A639-58EDADC29D4C" targetRef="sid-A5BEB0D2-B629-4333-AE47-32AB08817F86"></sequenceFlow>
   </process>


Below is the main part of TransitionHandleTask which is an implementation of ActivityBehavior using as the ServiceTask.

/**
    * handle Task Jump
    *
    * @param execution
    */
   private void handleJump(ActivityExecution execution) {

      String activityId = execution.getVariable("toActivity_").toString();
      String processDefinitionId = execution.getProcessDefinitionId();
      ProcessDefinitionImpl pd = (ProcessDefinitionImpl) repositoryService
            .createProcessDefinitionQuery()
            .processDefinitionId(processDefinitionId).singleResult();
      // the destination activity
      ActivityImpl pointActivity = pd.findActivity(activityId);
      // the current activity
      ActivityImpl currActivity = (ActivityImpl) execution.getActivity();
      // build a temporary outgoing transition for current activity
      PvmTransition tempTransition = (currActivity)
            .createOutgoingTransition();
      ((TransitionImpl) tempTransition).setDestination(pointActivity);
      // take the transition
      execution.take(tempTransition);
      // remove the temporary transition
      pointActivity.getIncomingTransitions().remove(tempTransition);
      currActivity.getOutgoingTransitions().remove(tempTransition);
   }


I traced down the code. Everytime I get a null pointActivity. the activity id I used is `formDocumentation` matching the first activity in the xml. I also found in the ProcessDefinitionImpl object, the activity map(list) properties like activities and namedActivities are all empty map(list). Am I doing anything wrong here? Any help would be appriciated!
4 REPLIES 4

jbarrez
Star Contributor
Star Contributor
Try using the method on the repositoryService.getBpmnModel() to get the BpmnModel, which you can then use to get information about your activity

kikyou1986
Champ in-the-making
Champ in-the-making
Hi jbarrez, how can I get the ActivityImpl ojbect with certain activityId from the BpmnModel object?

kikyou1986
Champ in-the-making
Champ in-the-making
ok. I solved this by getting ProcessDefinitionImpl object with the following code:
<java>
ProcessDefinitionImpl pd = (ProcessDefinitionImpl) ((RepositoryServiceImpl) repositoryService)
    .getDeployedProcessDefinition(processDefinitionId);
</java>
This ProcessDefinitionImpl object will have all activity infomation in it.

I reckon that with the former approach, it is designed to have no activity infomation in it. The former approach I was using is:
<java>
ProcessDefinitionImpl pd = (ProcessDefinitionImpl) repositoryService
   .createProcessDefinitionQuery()
   .processDefinitionId(processDefinitionId).singleResult();
</java>

jbarrez
Star Contributor
Star Contributor
Correct.  RepositoryService.getProcessDefinition() would do the same, and does not need the cast.
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.