2 Replies Latest reply on Nov 26, 2008 10:18 AM by ardavan

    Does AssignmentHandler work within the start node??

    ardavan

      Hi,
      I can't assign the actorid that I want for a simple start node:
      As a test case I am using a simple processdefinition:

      <?xml version="1.0" encoding="UTF-8"?>
      <process-definition xmlns="urn:jbpm.org:jpdl-3.2" name="test">
      
       <start-state name="Submission">
       <task name="taskSubmission">
       <assignment class="jbpm.taskmgmt.EmiliAssignmentHandler"></assignment>
       </task>
       <transition to="Evaluate" name="trEvaluate"></transition>
       </start-state>
      
       <task-node name="Evaluate">
       <task name="evaluateTask">
       <assignment class="jbpm.taskmgmt.ManagerAssignmentHandler"></assignment>
       <controller></controller>
       </task>
       <transition to="end" name="trAbort"></transition>
       </task-node>
      
       <end-state name="end">
       <event type=""></event>
       </end-state>
      </process-definition>
      


      My issue is within the task: "taskSubmission" f the start node and the class "EmiliAssignmentHandler":

      package jbpm.taskmgmt;
      import org.jbpm.graph.exe.*;
      import org.jbpm.taskmgmt.def.*;
      import org.jbpm.taskmgmt.exe.Assignable;
      
      public class EmiliAssignmentHandler implements AssignmentHandler {
      
       private static final long serialVersionUID = 1L;
       public void assign(Assignable assignable, ExecutionContext executionContext) {
       assignable.setActorId("emili");
       }
      }
      


      I run the JUNIT test:
      + the correct imports...
      
      public class TestCase2 extends junit.framework.TestCase {
      
       static JbpmConfiguration jbpmConfiguration =
       JbpmConfiguration.parseResource("jbpm.cfg.xml");
      
       ... variables ...
       public void setUp() {
       ... same as in jbpm examples
       }
      
       public void tearDown() {
       ... same as in jbpm examples
       }
      
       private void newTransaction() {
       ... same as in jbpm examples
       }
      
       private void deployProcess() {
       ... same as in jbpm examples
       }
      
       private TaskInstance createNewProcessInstance() {
       GraphSession graphSession = jbpmContext.getGraphSession();
       ProcessDefinition processDefinition =
       graphSession.findLatestProcessDefinition("test");
       processInstance =
       new ProcessInstance(processDefinition);
       processInstanceId = processInstance.getId();
       contextInstance = processInstance.getContextInstance();
       taskMgmtInstance = processInstance.getTaskMgmtInstance();
       return processInstance.getTaskMgmtInstance().createStartTaskInstance();
       }
      
       public void testStartSubmissionParameters() {
       TaskInstance taskInstance = createNewProcessInstance();
       assertEquals("taskSubmission", taskInstance.getName());
       assertEquals(0, taskInstance.getVariables().size());
       }
      
       public void testSubmissionTask(){
       TaskInstance taskInstance = createNewProcessInstance();
       taskInstance.setActorId("emili");
       taskInstance.end();
       assertEquals("emili", taskInstance.getActorId()); <----WORKS
       List emiliTasks = jbpmContext.getTaskMgmtSession().findTaskInstances("emili");
       assertEquals(0, emiliTasks.size()); <----WORKS
       }
      
       public void testSubmissionNotWorking(){
       // create a task to start the test process
       TaskInstance taskInstance = createNewProcessInstance();
       assertEquals("emili", taskInstance.getActorId()); <----PROBLEM
       taskInstance.end();
       }
      }
      


      Why does taskInstance.getActorId() in method testSubmissionTask() equal null where it should be equal to "emili" because of the EmiliAssignmentHandler class in the "taskSubmission" start node ????

      thank you for your help
      Ardavan

        • 1. Re: Does AssignmentHandler work within the start node??
          mputz

           

          Why does taskInstance.getActorId() in method testSubmissionTask() equal null


          Your assignment handler will never be called when the TaskMgmtInstance.createStartTaskInstance() is used, have a look at the javadocs:

           /**
           * creates a task instance on the rootToken, and assigns it
           * to the currently authenticated user.
           */
           public TaskInstance createStartTaskInstance() {
          


          • 2. Re: Does AssignmentHandler work within the start node??
            ardavan

            Thank you for your reply Martin.

            I checked the javadoc - I believed that at the creation of my TaskInstance object, the actorID parameter would be null
            but that because this assertion is true:

            TaskInstance taskInstance = createNewProcessInstance();
             assertEquals("taskSubmission", taskInstance.getName());
            

            which shows that I am in the "taskSubmission" node
            <task name="taskSubmission">
             <assignment class="jbpm.taskmgmt.EmiliAssignmentHandler"></assignment>
            </task>
            

            my jbpm.taskmgmt.EmiliAssignmentHandler would set the null actorId to "emili".

            Nevertheless now this is the way that I am doing it:
            public void testSubmissionTask3(){
             GraphSession graphSession = jbpmContext.getGraphSession();
             ProcessDefinition processDefinition =
             graphSession.findLatestProcessDefinition("test");
             processInstance =
             new ProcessInstance(processDefinition);
             contextInstance = processInstance.getContextInstance();
             Task t = processInstance.getTaskMgmtInstance().getTaskMgmtDefinition().getTask("taskSubmission");
             TaskInstance ti = processInstance.getTaskMgmtInstance().createTaskInstance(t,processInstance.getRootToken());
             assertEquals("emili", ti.getActorId());
             }
            

            I hope it is correct

            Danke schoen
            Ardavan