8 Replies Latest reply on Dec 13, 2005 2:35 PM by toby saville

    pass from one task-node to the following task-node

    pedro costa Apprentice

      If i have to task-nodes, which one follows the other, what method should i use to say for my program pass from one task-node to the following task-node?

      I used token.submit() and processInstance.submit(), and the token remains in the first task-node.

      Thanks

        • 1. Re: pass from one task-node to the following task-node
          ch praveen Newbie

          Hi pedrosacosta

          Did you tried token.singnal() method.

          • 2. Re: pass from one task-node to the following task-node
            pedro costa Apprentice

            Yes, tried the signal() method, but nothing happened.
            Here is the example that i'm trying to put to work.

            package com.sample.jbpm.taskmgmt;
            
            import junit.framework.TestCase;
            
            import org.jbpm.graph.def.ProcessDefinition;
            import org.jbpm.graph.exe.ProcessInstance;
            import org.jbpm.graph.exe.Token;
            import org.jbpm.taskmgmt.exe.TaskInstance;
            
            public class TaskAssignmentTest extends TestCase {
            
             public void testTaskAssignment() {
             ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
             "<process-definition name='the baby process'>" +
             " <start-state>" +
             " <transition name='baby cries' to='t' />" +
             " </start-state>" +
            
             " <task-node name='t'>" +
             " <task name='change nappy'>" +
             " <assignment class='com.sample.jbpm.taskmgmt.NappyAssignmentHandler' />" +
             " </task>" +
             " <transition to='t2' />" +
             " </task-node>" +
            
             " <task-node name='t2'>" +
             " <task name='change nappy2'>" +
             " <assignment class='com.sample.jbpm.taskmgmt.NappyAssignmentHandler' />" +
             " </task>" +
             " <transition to='t3' />" +
             " </task-node>" +
            
             " <task-node name='t3'>" +
             " <task name='change nappy3'>" +
             " <assignment class='com.sample.jbpm.taskmgmt.NappyAssignmentHandler' />" +
             " </task>" +
             " <transition to='end' />" +
             " </task-node>" +
            
             " <end-state name='end' />" +
             "</process-definition>"
             );
            
            
             ProcessInstance processInstance =
             new ProcessInstance(processDefinition);
             Token token = processInstance.getRootToken();
            
            
             token.signal();
            
             assertSame(processDefinition.getNode("t"), token.getNode());
            
             // When execution arrived in the task-node, a task 'change nappy'
             // was created and the NappyAssignmentHandler was called to determine
             // to whom the task should be assigned. The NappyAssignmentHandler
             // returned 'papa'.
            
             // In a real environment, the tasks would be fetched from the
             // database with the methods in the org.jbpm.db.TaskMgmtSession.
             // Since we don't want to include the persistence complexity in
             // this example, we just take the first task-instance of this
             // process instance (we know there is only one in this test
             // scenario.
             TaskInstance taskInstance = (TaskInstance)processInstance.getTaskMgmtInstance().getTaskInstances().iterator().next();
            
             // Now, we check if the taskInstance was actually assigned to 'papa'.
             assertEquals("papa", taskInstance.getActorId() );
            
             // Now suppose that 'papa' has done his duties and marks the task
             // as done.
             taskInstance.end();
            
             token.signal();
            
             taskInstance = (TaskInstance)processInstance.getTaskMgmtInstance().getTaskInstances().iterator().next();
            
             // Now, we check if the taskInstance was actually assigned to 'papa'.
             assertEquals("papa", taskInstance.getActorId() );
            
             // Now suppose that 'papa' has done his duties and marks the task
             // as done.
             taskInstance.end();
            
            
            /*
             taskInstance = (TaskInstance)processInstance.getTaskMgmtInstance().getTaskInstances().iterator().next();
            
             // Now, we check if the taskInstance was actually assigned to 'papa'.
             assertEquals("papa", taskInstance.getActorId() );
            
             // Now suppose that 'papa' has done his duties and marks the task
             // as done.
             taskInstance.end();
            */
            
            
             // Since this was the last (only) task to do, the completion of this
             // task triggered the continuation of the process instance execution.
            
             assertSame(processDefinition.getNode("end"), token.getNode());
             }
            
            }
            
            



            • 3. Re: pass from one task-node to the following task-node
              pedro costa Apprentice

              The snippet below doesn't have the comments tags. The right snippet is without the comments.

              /*
               taskInstance = (TaskInstance)processInstance.getTaskMgmtInstance().getTaskInstances().iterator()
              .next();
              
               // Now, we check if the taskInstance was actually assigned to 'papa'.
               assertEquals("papa", taskInstance.getActorId() );
              
               // Now suppose that 'papa' has done his duties and marks the task
               // as done.
               taskInstance.end();
              */
              



              • 4. Re: pass from one task-node to the following task-node
                pedro costa Apprentice

                Ok. To avoid any misunderstanding, here is the right code.

                package com.sample.jbpm.taskmgmt;
                
                import junit.framework.TestCase;
                
                import org.jbpm.graph.def.ProcessDefinition;
                import org.jbpm.graph.exe.ProcessInstance;
                import org.jbpm.graph.exe.Token;
                import org.jbpm.taskmgmt.exe.TaskInstance;
                
                public class TaskAssignmentTest extends TestCase {
                
                 public void testTaskAssignment() {
                 ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
                 "<process-definition name='the baby process'>" +
                 " <start-state>" +
                 " <transition name='baby cries' to='t' />" +
                 " </start-state>" +
                
                 " <task-node name='t'>" +
                 " <task name='change nappy'>" +
                 " <assignment class='com.sample.jbpm.taskmgmt.NappyAssignmentHandler' />" +
                 " </task>" +
                 " <transition to='t2' />" +
                 " </task-node>" +
                
                 " <task-node name='t2'>" +
                 " <task name='change nappy2'>" +
                 " <assignment class='com.sample.jbpm.taskmgmt.NappyAssignmentHandler' />" +
                 " </task>" +
                 " <transition to='end' />" +
                 " </task-node>" +
                
                 " <task-node name='t3'>" +
                 " <task name='change nappy3'>" +
                 " <assignment class='com.sample.jbpm.taskmgmt.NappyAssignmentHandler' />" +
                 " </task>" +
                 " <transition to='end' />" +
                 " </task-node>" +
                
                 " <end-state name='end' />" +
                 "</process-definition>"
                 );
                
                
                 ProcessInstance processInstance =
                 new ProcessInstance(processDefinition);
                 Token token = processInstance.getRootToken();
                
                
                 token.signal();
                
                 assertSame(processDefinition.getNode("t"), token.getNode());
                
                 // When execution arrived in the task-node, a task 'change nappy'
                 // was created and the NappyAssignmentHandler was called to determine
                 // to whom the task should be assigned. The NappyAssignmentHandler
                 // returned 'papa'.
                
                 // In a real environment, the tasks would be fetched from the
                 // database with the methods in the org.jbpm.db.TaskMgmtSession.
                 // Since we don't want to include the persistence complexity in
                 // this example, we just take the first task-instance of this
                 // process instance (we know there is only one in this test
                 // scenario.
                 TaskInstance taskInstance = (TaskInstance)processInstance.getTaskMgmtInstance().getTaskInstances().iterator().next();
                
                 // Now, we check if the taskInstance was actually assigned to 'papa'.
                 assertEquals("papa", taskInstance.getActorId() );
                
                 // Now suppose that 'papa' has done his duties and marks the task
                 // as done.
                 taskInstance.end();
                
                 token.signal();
                
                 taskInstance = (TaskInstance)processInstance.getTaskMgmtInstance().getTaskInstances().iterator().next();
                
                 // Now, we check if the taskInstance was actually assigned to 'papa'.
                 assertEquals("papa", taskInstance.getActorId() );
                
                 // Now suppose that 'papa' has done his duties and marks the task
                 // as done.
                 taskInstance.end();
                
                
                
                 taskInstance = (TaskInstance)processInstance.getTaskMgmtInstance().getTaskInstances().iterator().next();
                
                 // Now, we check if the taskInstance was actually assigned to 'papa'.
                 assertEquals("papa", taskInstance.getActorId() );
                
                 // Now suppose that 'papa' has done his duties and marks the task
                 // as done.
                 taskInstance.end();
                
                
                
                 // Since this was the last (only) task to do, the completion of this
                 // task triggered the continuation of the process instance execution.
                
                 assertSame(processDefinition.getNode("end"), token.getNode());
                 }
                
                }
                
                


                • 5. Re: pass from one task-node to the following task-node
                  pedro costa Apprentice

                  This is weird. Now i can work with 3 task-nodes, but not with 4 task-nodes.

                  Does anyone know what is happenning?

                  Here is the code again.

                  package com.sample.jbpm.taskmgmt;
                  
                  import junit.framework.TestCase;
                  
                  import org.jbpm.graph.def.ProcessDefinition;
                  import org.jbpm.graph.exe.ProcessInstance;
                  import org.jbpm.graph.exe.Token;
                  import org.jbpm.taskmgmt.exe.TaskInstance;
                  
                  public class TaskAssignmentTest extends TestCase {
                  
                   public void testTaskAssignment() {
                   ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
                   "<process-definition name='the baby process'>" +
                   " <start-state>" +
                   " <transition name='baby cries' to='t' />" +
                   " </start-state>" +
                  
                   " <task-node name='t'>" +
                   " <task name='change nappy'>" +
                   // " <assignment class='com.sample.jbpm.taskmgmt.NappyAssignmentHandler' />" +
                   " </task>" +
                   " <transition to='t2' />" +
                   " </task-node>" +
                  
                   " <task-node name='t2'>" +
                   " <task name='change nappy2'>" +
                  // " <assignment class='com.sample.jbpm.taskmgmt.NappyAssignmentHandler' />" +
                   " </task>" +
                   " <transition to='t3' />" +
                   " </task-node>" +
                  
                   " <task-node name='t3'>" +
                   " <task name='change nappy3'>" +
                  // " <assignment class='com.sample.jbpm.taskmgmt.NappyAssignmentHandler' />" +
                   " </task>" +
                   " <transition to='t4' />" +
                   " </task-node>" +
                  
                   " <task-node name='t4'>" +
                   " <task name='change nappy4'>" +
                  // " <assignment class='com.sample.jbpm.taskmgmt.NappyAssignmentHandler' />" +
                   " </task>" +
                   " <transition to='end' />" +
                   " </task-node>" +
                  
                   " <end-state name='end' />" +
                   "</process-definition>"
                   );
                  
                  
                   ProcessInstance processInstance =
                   new ProcessInstance(processDefinition);
                   Token token = processInstance.getRootToken();
                  
                  
                   token.signal();
                   System.out.println("---> " + token.getNode().getName());
                   assertSame(processDefinition.getNode("t"), token.getNode());
                  
                   TaskInstance taskInstance = (TaskInstance)processInstance.getTaskMgmtInstance().getTaskInstances().iterator().next();
                  
                   // assertEquals("papa", taskInstance.getActorId() );
                  
                   taskInstance.end();
                   System.out.println("---> " + token.getNode().getName());
                  
                  
                   taskInstance = (TaskInstance)processInstance.getTaskMgmtInstance().getTaskInstances().iterator().next();
                  
                   // assertEquals("papa", taskInstance.getActorId() );
                  
                   taskInstance.end();
                   System.out.println("---> " + token.getNode().getName());
                  
                  
                   taskInstance = (TaskInstance)processInstance.getTaskMgmtInstance().getTaskInstances().iterator().next();
                  
                  // assertEquals("papa", taskInstance.getActorId() );
                  
                   taskInstance.end();
                   System.out.println("---> " + token.getNode().getName());
                  
                  
                   taskInstance = (TaskInstance)processInstance.getTaskMgmtInstance().getTaskInstances().iterator().next();
                  
                  // assertEquals("papa", taskInstance.getActorId() );
                  
                   taskInstance.end();
                   System.out.println("---> " + token.getNode().getName());
                  
                   assertSame(processDefinition.getNode("end"), token.getNode());
                   }
                  
                  }
                  
                  


                  • 6. Re: pass from one task-node to the following task-node
                    pedro costa Apprentice

                    This is a hint. This problem occurs because it's related to the deployment of my process definition in a database? Well, if it really occurs. I don't know if it's what must happen for my xml run correctly.

                    • 7. Re: pass from one task-node to the following task-node
                      pedro costa Apprentice

                      Adding my previous questions, what this error means?

                      java.lang.IllegalStateException: task instance '0'is already started
                       at org.jbpm.taskmgmt.exe.TaskInstance.end(TaskInstance.java:306)
                       at org.jbpm.taskmgmt.exe.TaskInstance.end(TaskInstance.java:272)
                       at com.sample.jbpm.taskmgmt.TaskAssignmentTest.testTaskAssignment(TaskAssignmentTest.java:89)
                       at com.sample.jbpm.taskmgmt.TaskAssignmentTest.main(TaskAssignmentTest.java:96)
                      Exception in thread "main"
                      


                      • 8. Re: pass from one task-node to the following task-node
                        toby saville Novice

                        In TaskInstance.end() it tests if the end time is not null, and if thats true, throws the error that your getting.

                        This seems to be a contradiction to me. Basically, it says if the end date has been set already, report that this task has already started. In other words, if the task has already been ended, and you try to end it again, it reports that it has already been started. This confuses me. Perhaps its just a bad error message, raised when you try to stop a task that is already stopped.

                        Sorry i dont have an answer, but thought i would contribute all the same.