7 Replies Latest reply on Aug 5, 2009 1:32 AM by prajatna

    How to design a Task Node with two Transition?

      I have a task node (Ex. PM_Approval) in the process definition. There are two transitions associated with this node called "Accepted" & "Denied" . The Accepted transition connects to another Task Node "HOD_Approval" .And the Denied ends up with end-state....... The selection of transition should base on the decision , given by user in the action class.(ProcessAction in my design...given below.)

      Now how to design this .. I tried with the following , but problem is that, when ever it goes to end state by selecting Reject transition, it is again begins from the current Node.

      Please suggest....what is going wrong.. with my design..


      Processdefinition.xml

       <start-state name="start">
       <transition to="PM_Approval" name="Test"></transition>
       </start-state>
      
      
       <task-node name="PM_Approval" >
       <event type="node-enter">
       <action class="com.sample.action.ProcessAction">
       </action>
       </event>
       <transition to="HOD_Approval"></transition>
       <transition to="end-state" name="Denied"></transition>
       </task-node>




      ProcessAction.java

      public class ProcessAction implements ActionHandler {
      
       /**
       *
       */
       private static final long serialVersionUID = 1L;
      
       public void execute(ExecutionContext executionContext) throws Exception {
       System.out.println("######################---------ProcessAction------------1-----------------###################### .");
       System.out.println("This Node is---"+executionContext.getNode().getName());
      
       String decission = null;
      
       System.out.print("Enter your decission: ");
       BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      
      
       try {
       decission = br.readLine();
       } catch (IOException ioe) {
       System.out.println("IO error trying to read your decission!");
       }
      
       //}
      
       System.out.println("Thanks for the desission, " + decission);
       System.out.println("######################---------ProcessAction------------2-----------------###################### .");
       if(decission != null && decission.equalsIgnoreCase("a")){
      
       System.out.println("######################---------ProcessAction----a--------3-----------------###################### .");
      
       executionContext.leaveNode("Accepted");
       }
       else if(decission != null && decission.equalsIgnoreCase("d")){
      
       System.out.println("######################---------ProcessAction-----d-------3-----------------###################### .");
       executionContext.leaveNode("Denied");
       }
       else if(decission != null && decission.equalsIgnoreCase("c")){
       System.out.println("######################---------ProcessAction-----c-------3-----------------###################### .");
      
       executionContext.leaveNode("checkBudget");
       }
       else{
       System.out.println("Error trying to read your decission!..Enter only a/d ");
       }
      
       }
      }
      



      Java class I am using to invoke the process...( TravelProcessTest.java)


      public class TravelProcessTest extends TestCase {
      
       public static void main(String args[])throws Exception {
       new TravelProcessTest().execute();
       }
       public void execute() throws Exception {
      
      
      
       // Extract a process definition from the processdefinition.xml file.
       ProcessDefinition processDefinition = ProcessDefinition.parseXmlResource("simple/processdefinition.xml");
      
       ProcessInstance(processDefinition,map);
       ProcessInstance instance = new ProcessInstance(processDefinition);
      
       System.out.println("Hi............");
      
       System.out.println("######################---------------------1-----------------###################### .");
      
      
      
       instance.signal();
      
       System.out.println("######################---------------------3-----------------###################### .");
       displayStatus(instance);
       System.out.println("######################---------------------4-----------------###################### .");
       );
      
      
       }
      
       private void displayStatus(ProcessInstance instance) {
       String nodeName = instance.getRootToken().getNode().getName();
       System.out.println("You are now in node: "+nodeName);
       }
      
       }
      }


      Console O/P

      10:37:23,038 [main] INFO JbpmConfiguration : using jbpm configuration resource 'jbpm.cfg.xml'
      10:37:23,038 [main] DEBUG JbpmConfiguration : loading defaults in jbpm configuration
      10:37:23,128 [main] DEBUG ObjectFactoryImpl : adding object info 'default.jbpm.context'
      10:37:23,128 [main] DEBUG ObjectFactoryImpl : adding object info 'resource.hibernate.cfg.xml'
      10:37:23,128 [main] DEBUG ObjectFactoryImpl : adding object info 'resource.business.calendar'
      10:37:23,128 [main] DEBUG ObjectFactoryImpl : adding object info 'resource.default.modules'
      10:37:23,128 [main] DEBUG ObjectFactoryImpl : adding object info 'resource.converter'
      10:37:23,128 [main] DEBUG ObjectFactoryImpl : adding object info 'resource.action.types'
      10:37:23,128 [main] DEBUG ObjectFactoryImpl : adding object info 'resource.node.types'
      10:37:23,149 [main] DEBUG ObjectFactoryImpl : adding object info 'resource.parsers'
      10:37:23,149 [main] DEBUG ObjectFactoryImpl : adding object info 'resource.varmapping'
      10:37:23,149 [main] DEBUG ObjectFactoryImpl : adding object info 'resource.mail.templates'
      10:37:23,159 [main] DEBUG ObjectFactoryImpl : adding object info 'jbpm.byte.block.size'
      10:37:23,159 [main] DEBUG ObjectFactoryImpl : adding object info 'jbpm.task.instance.factory'
      10:37:23,159 [main] DEBUG ObjectFactoryImpl : adding object info 'jbpm.variable.resolver'
      10:37:23,159 [main] DEBUG ObjectFactoryImpl : adding object info 'jbpm.mail.smtp.host'
      10:37:23,159 [main] DEBUG ObjectFactoryImpl : adding object info 'jbpm.mail.address.resolver'
      10:37:23,159 [main] DEBUG ObjectFactoryImpl : adding object info 'jbpm.mail.from.address'
      10:37:23,169 [main] DEBUG ObjectFactoryImpl : adding object info 'jbpm.job.executor'
      10:37:23,169 [main] DEBUG JbpmConfiguration : loading specific configuration...
      10:37:23,179 [main] DEBUG ObjectFactoryImpl : adding object info 'jbpmConfiguration'
      10:37:23,179 [main] INFO StaleObjectLogConfigurer : stale object exceptions will be hidden from logging
      10:37:23,289 [main] DEBUG JpdlParser$JpdlEntityResolver : resolving schema reference publicId(null) systemId(http://jbpm.org/jpdl-3.2.xsd)
      10:37:23,289 [main] DEBUG JpdlParser$JpdlEntityResolver : providing input source to local 'jpdl-3.2.xsd' resource
      10:37:23,460 [main] DEBUG NodeTypes : node 'page' will not be available. class 'org.jboss.seam.pageflow.Page' couldn't be loaded
      10:37:23,460 [main] DEBUG NodeTypes : node 'start-page' will not be available. class 'org.jboss.seam.pageflow.Page' couldn't be loaded
      10:37:23,520 [main] DEBUG GraphElement : event 'process-start' on 'ProcessDefinition(processdefinition)' for 'Token(/)'
      Hi............
      ######################---------------------1-----------------###################### .
      ######################---------------------2-----------------###################### .
      10:37:23,530 [main] DEBUG GraphElement : event 'before-signal' on 'StartState(start)' for 'Token(/)'
      10:37:23,530 [main] DEBUG GraphElement : event 'node-leave' on 'StartState(start)' for 'Token(/)'
      10:37:23,530 [main] DEBUG GraphElement : event 'transition' on 'Transition(Test)' for 'Token(/)'
      10:37:23,530 [main] DEBUG GraphElement : event 'node-enter' on 'TaskNode(PM_Approval)' for 'Token(/)'
      10:37:23,530 [main] DEBUG GraphElement : executing action 'Action(1efb836)'
      10:37:23,530 [main] DEBUG Token : token[0] is locked by token[0]
      ######################---------ProcessAction------------1-----------------###################### .
      This Node is---PM_Approval
      Enter your decission: d
      Thanks for the desission, d
      ######################---------ProcessAction------------2-----------------###################### .
      ######################---------ProcessAction-----d-------3-----------------###################### .
      10:37:34,071 [main] DEBUG GraphElement : event 'node-leave' on 'TaskNode(PM_Approval)' for 'Token(/)'
      10:37:34,071 [main] DEBUG GraphElement : event 'transition' on 'Transition(Denied)' for 'Token(/)'
      10:37:34,071 [main] DEBUG GraphElement : event 'node-enter' on 'EndState(end-state)' for 'Token(/)'
      10:37:34,071 [main] DEBUG GraphElement : event 'process-end' on 'ProcessDefinition(processdefinition)' for 'Token(/)'
      10:37:34,071 [main] DEBUG Token : token[0] is unlocked by token[0]
      10:37:34,071 [main] DEBUG GraphElement : event 'node-leave' on 'TaskNode(PM_Approval)' for 'Token(/)'
      10:37:34,071 [main] DEBUG GraphElement : event 'transition' on 'Transition(cec0c5)' for 'Token(/)'
      10:37:34,071 [main] DEBUG GraphElement : event 'node-enter' on 'TaskNode(HOD_Approval)' for 'Token(/)'
      10:37:34,071 [main] DEBUG GraphElement : executing action 'Action(116ab4e)'
      
      


      As you can see, even when decision is denied , it is going to end state.. but again coming to next node...

      Thanks in advance for your suggestion..

        • 1. Re: How to design a Task Node with two Transition?
          kukeltje
          • 2. Re: How to design a Task Node with two Transition?
            kukeltje

            Sorry, pressed submit instead of preview.... and this link does not belong here

            You cannot leave a task-node on a node-enter. You can only do this on generic nodes. The usage of a tasknode is completely superfluous here.

            • 3. Re: How to design a Task Node with two Transition?

               

              "kukeltje" wrote:
              Sorry, pressed submit instead of preview.... and this link does not belong here

              You cannot leave a task-node on a node-enter. You can only do this on generic nodes. The usage of a tasknode is completely superfluous here.



              Thanks for your comments...
              Then, what we should use in my scenario, where we have two transition with a Task node.

              I also tried with task assignment like....

              <task-node name="PM_Approval" >
               <task>
               <assignment class="com.sample.nodeAction.PMAssignAction"></assignment>
               </task>
               <transition to="HOD_Approval" name="Accepted"></transition>
               <transition to="end" name="Denied"></transition>
               </task-node>
              



              and from inside my PMAssignAction class i am trying to switch to required transition as follows.

              public class PMAssignAction implements AssignmentHandler {
              
              
               private static final long serialVersionUID = 1L;
              
               public void assign(Assignable assignable, ExecutionContext executionContext)
               throws Exception {
              
               System.out.println("--------PMAssignAction------------1-------");
               System.out.println("This Node is---"+executionContext.getNode().getName());
              
               System.out.print("Enter your decission: ");
               BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
               String decision = null;
              
               try {
               decision = br.readLine();
               } catch (IOException ioe) {
               System.out.println("IO error trying to read your decission!");
               }
              
               System.out.println("Thanks for the desission, " + decision);
               System.out.println("---------PMAssignAction------------2-------");
              
               if(decision != null && decision.equalsIgnoreCase("a")){
              
               executionContext.getContextInstance().setVariable("decision", decision);
               System.out.println("---------PMAssignAction----a--------3---");
               executionContext.getProcessInstance().signal("Accepted");
               //leaveNode("Accepted");
               }
               else if(decision != null && decision.equalsIgnoreCase("d")){
              
               executionContext.getContextInstance().setVariable("decision", decision);
               System.out.println("---------PMAssignAction-----d-------3----");
               executionContext.getProcessInstance().signal("Denied");
              
               }
               else{
               System.out.println("Error trying to read your decission!..Enter only a/d ");
               }
               }
              }



              But unfortunately , this is also not working..... The problem is that once flow reaches the end state by giving denied decision.... it is again coming back to the previous node....

              Please find the log below and help me out resolving this.....Thanks..

              
              16:49:51,530 [main] DEBUG Converters : adding converter 'R', 'org.jbpm.context.exe.converter.SerializableToByteArrayConverter'
              16:49:51,530 [main] DEBUG Converters : adding converter 'I', 'org.jbpm.context.exe.converter.IntegerToLongConverter'
              16:49:51,530 [main] DEBUG Converters : adding converter 'H', 'org.jbpm.context.exe.converter.ShortToLongConverter'
              16:49:51,530 [main] DEBUG Converters : adding converter 'G', 'org.jbpm.context.exe.converter.FloatToDoubleConverter'
              16:49:51,540 [main] DEBUG Converters : adding converter 'F', 'org.jbpm.context.exe.converter.FloatToStringConverter'
              16:49:51,540 [main] DEBUG Converters : adding converter 'E', 'org.jbpm.context.exe.converter.ByteToLongConverter'
              Hi............
              ---------------------1-----------------
              You are now in node: start
              ---------------------2-----------------
              16:49:51,570 [main] DEBUG GraphElement : event 'before-signal' on 'StartState(start)' for 'Token(/)'
              16:49:51,570 [main] DEBUG GraphElement : event 'node-leave' on 'StartState(start)' for 'Token(/)'
              16:49:51,570 [main] DEBUG GraphElement : event 'transition' on 'Transition(Test)' for 'Token(/)'
              16:49:51,570 [main] DEBUG GraphElement : event 'node-enter' on 'TaskNode(PM_Approval)' for 'Token(/)'
              16:49:51,580 [main] DEBUG GraphElement : event 'task-create' on 'Task(PM_Approval)' for 'Token(/)'
              --------PMAssignAction------------1-------
              This Node is---PM_Approval
              Enter your decission: d
              Thanks for the desission, d
              ---------PMAssignAction------------2-------
              16:49:55,435 [main] DEBUG VariableContainer : update variable 'decision' in 'TokenVariableMap1193779' to value 'd'
              ---------PMAssignAction-----d-------3----
              16:49:55,445 [main] DEBUG GraphElement : event 'before-signal' on 'TaskNode(PM_Approval)' for 'Token(/)'
              16:49:55,445 [main] DEBUG GraphElement : event 'node-leave' on 'TaskNode(PM_Approval)' for 'Token(/)'
              16:49:55,445 [main] DEBUG GraphElement : event 'transition' on 'Transition(Denied)' for 'Token(/)'
              16:49:55,445 [main] DEBUG GraphElement : event 'node-enter' on 'EndState(end)' for 'Token(/)'
              16:49:55,445 [main] DEBUG GraphElement : event 'process-end' on 'ProcessDefinition(processdefinition)' for 'Token(/)'
              16:49:55,465 [main] DEBUG GraphElement : event 'after-signal' on 'TaskNode(PM_Approval)' for 'Token(/)'
              16:49:55,465 [main] DEBUG GraphElement : event 'node-leave' on 'TaskNode(PM_Approval)' for 'Token(/)'
              16:49:55,465 [main] DEBUG GraphElement : event 'transition' on 'Transition(Accepted)' for 'Token(/)'
              16:49:55,465 [main] DEBUG GraphElement : event 'node-enter' on 'TaskNode(HOD_Approval)' for 'Token(/)'
              16:49:55,465 [main] DEBUG GraphElement : event 'task-create' on 'Task(HOD_Approval)' for 'Token(/)'
              --------HODAssignAction------------1-------
              This Node is---HOD_Approval
              Enter your decission:


              • 4. Re: How to design a Task Node with two Transition?
                kukeltje

                also not possible to leave a task on an assignment. Why would you? I miss the usecase. Normally you create a task, assign it to someone and than wait till it is acted upon externallly. e.g. via a web ui, an external command etc... and that should end the task which in turn will make it leave the tasknode. Just search the web a little, or look in the jBPM testcases.

                • 5. Re: How to design a Task Node with two Transition?

                   

                  "kukeltje" wrote:
                  also not possible to leave a task on an assignment. Why would you? I miss the usecase. Normally you create a task, assign it to someone and than wait till it is acted upon externallly. e.g. via a web ui, an external command etc... and that should end the task which in turn will make it leave the tasknode. Just search the web a little, or look in the jBPM testcases.



                  Thanks for your valuable response..

                  Can I have some urls.. where it is described clearly..Thanks again...

                  • 6. Re: How to design a Task Node with two Transition?
                    kukeltje

                    The last line of my previous comment refers to testcases. Testcases are normally in the source, source can normally be found in either cvs or svn. In case of jBPM this is svn. On the jBPM homepage is a link to the source.... Simple deduction ;-)

                    But since I am in a good mood: http://fisheye.jboss.org/browse/JbpmSvn/jbpm3/trunk/modules/core/src/test/java/org/jbpm

                    • 7. Re: How to design a Task Node with two Transition?

                       

                      "kukeltje" wrote:
                      The last line of my previous comment refers to testcases. Testcases are normally in the source, source can normally be found in either cvs or svn. In case of jBPM this is svn. On the jBPM homepage is a link to the source.... Simple deduction ;-)

                      But since I am in a good mood: http://fisheye.jboss.org/browse/JbpmSvn/jbpm3/trunk/modules/core/src/test/java/org/jbpm



                      Thanks a Lot..