3 Replies Latest reply on Oct 4, 2005 3:44 AM by iburth

    ActionHandler: executionContext.getTaskInstance()=null

    iburth

      Hello everyone,

      first of all I'm embarking on jBPM - so this could all base on a misconception for my part.

      I try to integrate some applications with jBPM;
      For steps without user-interaction I use Nodes including an action.
      For steps with user-interaction I intend/try to use task-nodes. The idea is to have the user select one of the tasks to be performed and automatically bring up the user interface.
      I came up with starting the target-application on the 'task-start'-event using the following definition within a pointless testcase:

      0 <task-node name="first" swimlane="buyer" createTasks="true">
      1 <task name="fold cardboard box">
      3 <controller>
      4 <variable name="comment" mappedName="commentX" access="read"/>
      5 <variable name="itemCount" access="read,write"/>
      6 </controller>
      7 <event type ="task-start">
      8 <action class="com.sample.action.StartFoldingTaskHandler"/>
      9 </event>
      10 </task>
      11 <transition name="to_end" to="end">
      12 </transition>
      13</task-node>
      


      In the StartFoldingTaskHandler I try to access the TaskFormParameters via the TaskInstance
      The problem: I can't obtain the TaskInstance via the executionContext: l_ti (line5) is always null

      0 public class StartFoldingTaskHandler implements ActionHandler {
      1 public void execute(ExecutionContext executionContext) throws Exception {
      2 //get TaskInstance:
      3 TaskInstance l_ti=executionContext.getTaskInstance();
      4 //Params:
      5 List taskFormParameters = l_ti.getTaskFormParameters();
      6
      7 //extracting those params an start the external app.
      8 ..
      9 }


      0 public void testSimpleProcess() throws Exception {
      1 ProcessDefinition definition =
      2 ProcessDefinition.parseXmlResource("simple.par/processdefinition.xml");
      3 instance.signal();
      4
      5 //just for testing purposes: start all Tasks
      6 Collection l_coll=instance.getTaskMgmtInstance().getTaskInstances();
      7 for (Iterator l_it=l_coll.iterator();l_it.hasNext();){
      8 TaskInstance x= (TaskInstance) l_it.next();
      9 x.start();
      10
      11 }
      12 }
      

      Env: jBPM starter-kit with unmodified environment.

      Grateful for any hints
      Ingo









        • 1. Re: ActionHandler: executionContext.getTaskInstance()=null
          iburth

          Hy,

          finally I found the time to investigate this issue. Delving into the codebase I found out, that the executionContext IMHO isn't set up properly.

          While TaskInstance&Task are set up correctly in TaskInstance.create(..)/TaskInstance.assign(..)
          they aren't set in TaskInstance.start() at all;

          I suggest to extend the TaskEventExecutionTestCase to check whether the executionContext is set up correctly by changing the implementation of the inner PlusPlus-class similarly to

          public static class PlusPlus implements ActionHandler {
           private static final long serialVersionUID = 1L;
           public void execute(ExecutionContext executionContext) throws Exception {
           counter++;
           TaskInstance l_ti=executionContext.getTaskInstance();
           Task l_task=executionContext.getTask();
           if(l_ti==null || l_task==null){
           fail("execution Context within "+executionContext.getEvent().toString()+" not properly setUp");
           }
           }
           }
          


          and to fix TaskInstance.start() with two additional lines:

          public void start(){
           if (start!=null) {
           throw new IllegalStateException("task instance '"+id+"' is already started");
           }
          
           start = new Date();
           if ( (task!=null)
           && (token!=null)
           ) {
           ExecutionContext executionContext = new ExecutionContext(token);
          //------ additional lines -----
           executionContext.setTaskInstance(this);
           executionContext.setTask(task);
          //-----------------------------
           task.fireEvent(Event.EVENTTYPE_TASK_START, executionContext);
           }
           }
          


          As said I regard this as a fix :-)


          It would be great if someone could tell me whether/when this'll be fixed in the codebase :-)

          • 2. Re: ActionHandler: executionContext.getTaskInstance()=null
            icyjamie

            Well, if you create an entry in JIRA, with a link to this topic, it's ready to be followed up.

            • 3. Re: ActionHandler: executionContext.getTaskInstance()=null
              iburth

              Done.

              Added as JIRA-Issue: JBPM-394