4 Replies Latest reply on Jul 8, 2009 10:23 AM by kukeltje

    jBPM4: Manually created task can't block the execution

      I have a process definition as shown below:

      [img]http://scude.co.cc/pub_img/fork-process.png[/img]

      Process definition:

      <process name="EventListener" xmlns="http://jbpm.org/4.0/jpdl">
      
       <start g="100,16,48,48">
       <transition to="wait"/>
       </start>
      
       <state g="84,424,80,52" name="park"/>
       <fork g="100,180,48,48" name="fork1">
       <on event="start">
       <event-listener class="cc.scude.PlaceHomeworkListener"/>
       </on>
       <transition name="to submit" to="task1" g="-59,-21"/>
       <transition to="task2"/>
       </fork>
       <task assignee="stu" g="16,260,92,52" name="task1">
       <transition name="next" to="join1" g="-30,-21"/>
       </task>
       <task assignee="stu" g="140,260,92,52" name="task2">
       <transition to="join1"/>
       </task>
       <join g="100,344,48,48" name="join1">
       <transition to="park"/>
       </join>
       <state g="78,96,92,52" name="wait">
       <transition to="fork1"/>
       </state>
      </process>
      


      There are 2 tasks for user 'stu' after the fork node. And I have a EventListener attached to the fork node, which is used to create a task manually.

      public class PlaceHomeworkListener implements EventListener {
       @Override
       public void notify(EventListenerExecution execution) throws Exception {
       Environment env = Environment.getCurrent();
       Context ctx = env.getContext(Context.CONTEXTNAME_PROCESS_ENGINE);
       if (ctx instanceof WireContext) {
       WireContext context = (WireContext) ctx;
       TaskService taskService = context.get(TaskService.class);
      
       Task task = taskService.newTask();
       task.setAssignee("stu");
       task.setName("submit your homework");
       taskService.saveTask(task);
       }
       }
      }
      


      The task was created successfully by the listener and it's appeared in stu's personal task list. But it can't block the execution as tasks should be. When I completed the 2 tasks defined in xml, the execution goes to the next state 'park' whether I complete the task created in listener or not. Unit test code looks as below:
       ProcessInstance processInstance = executionService.startProcessInstanceByKey("EventListener");
       String pid = processInstance.getId();
      
       List<Task> tasks = taskService.findPersonalTasks("stu");
       assertEquals(0, tasks.size());
       Execution execution = processInstance.findActiveExecutionIn("wait");
       executionService.signalExecutionById(execution.getId());
      
       tasks = taskService.findPersonalTasks("stu");
       assertEquals(3, tasks.size()); // SUCCESS
      
       //Complete the first two tasks that were defined xml
       for (int i=0;i<2;i++) {
       Task t = tasks.get(i);
       taskService.completeTask(t.getDbid());
       }
       processInstance = executionService.findProcessInstanceById(pid);
      
       assertFalse(processInstance.isActive("park")); //FAILED
      
       tasks = taskService.findPersonalTasks("stu");
       debug("tasks after task completed:"+tasks.size());
       assertEquals(1, tasks.size());
      


      If I complete only one task, the last assertFalse line will success. It means that the task defined in xml will stop the execution while the task created in listener not.

      How to make the task created in code behaviour the same as that in xml?

        • 1. Re: jBPM4: Manually created task can't block the execution
          shekharv

          At first look, I would think that this is expected.

          From what I can remember there is a lot more happening around taskCreation that just the simple:

          Task task = taskService.newTask();
          task.setAssignee("stu");
          task.setName("submit your homework");
          taskService.saveTask(task);
          

          The execution is not being set, the signalling property is not being set etc.
          I will look a little deeper and let you know if I find more details,

          • 2. Re: jBPM4: Manually created task can't block the execution
            shekharv

            There is no execution associated with the Task you created, if there is no execution, then we cannot expect it to block.

            Again, v4 is fairly new, so as I said before, will dig deeper and see if there is another way to do this,

            • 3. Re: jBPM4: Manually created task can't block the execution

              Any progress?

              I'm confusing about the relationship of task, activity and execution. Anybody know how to relat a task with a activity or execution in jBPM4?

              • 4. Re: jBPM4: Manually created task can't block the execution
                kukeltje

                wow... please... a little patience ;-). This is all free (as in beer) time of others. You ask for progress in less than 9 hours from Shekarv's posting AND a little over 9 hours from your original posting. In between you already had two replies. Most would be jealous.

                You could also have a look at the foreach forkhandler in jBPM 3 that is in the wiki. Yes it is for jBPM 3, but some concepts are the same. And maybe the implementation of the taskactivity in th source of jBPM 4.