5 Replies Latest reply on Jul 22, 2008 3:31 AM by minam97531

    how to use Decision nodes??????

    minam97531

      I am newbie. i want to use decision node but i have some problems. first i tried one of the process definition examples (../jbpm-web/WEB-INF/definitions/websale_defintion) to see how it works but when i make new instance of websale, in "check-for-another-web-order" task, if i select either "yes" or "no",i get the following error:

      Entering node evaluate-another-web-order
      ERROR [com.liferay.jbpm.WorkflowComponentImpl] Task has already ended

      i thought maybe other ways could help me. so i tried this process definition:

      <?xml version="1.0" encoding="UTF-8"?>
      <process-definition
      xmlns="urn:jbpm.org:jpdl-3.1"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="urn:jbpm.org:jpdl-3.1 urn:jbpm.org/xsd/jpdl-3.1.xsd" name="mytest">
      <!-- Event Logging -->

      System.out.println("Entering node " + node.getName());


      System.out.println("Leaving node " + node.getName());

      <!-- Swimlane -->

      <start-state name="start">






      </start-state>



      <variable name="aName" mapped-name="mappedName"/>
      executionContext.setVariable("mappedName", 7);












      <task-node name="task1">







      </task-node>
      <task-node name="task2">






      </task-node>
      <end-state name="end"></end-state>
      </process-definition>

      i searched and i saw that someone use this definition. i made some changes and i tried it but i get:

      Leaving node start
      Entering node decision1
      Leaving node decision1
      Entering node task2

      and then nothing. there isn't any task2 to be managed by swimlane "buyer"!
      i don't know what is the problem!

      could anyone help me and tell me how to use decision nodes??
      i just wanted to see if i could use decision nodes in my definition process but now i am not sure that if it works properly.

        • 1. Re: how to use Decision nodes??????
          minam97531

          oops, sorry! here's the code:

          <?xml version="1.0" encoding="UTF-8"?>
          <process-definition
           xmlns="urn:jbpm.org:jpdl-3.1"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="urn:jbpm.org:jpdl-3.1 urn:jbpm.org/xsd/jpdl-3.1.xsd" name="mytest">
          <!-- Event Logging -->
          <event type="node-enter">
          <script>System.out.println("Entering node " + node.getName());</script>
          </event>
          <event type="node-leave">
          <script>System.out.println("Leaving node " + node.getName());</script>
           </event>
          <!--Swimlane-->
          <swimlane name="buyer" />
          <start-state name="start">
          <task swimlane="user">
          <controller>
          <variable name="textarea:comments" />
          </controller>
          </task>
          <transition name="ok" to="state1"></transition>
          </start-state>
          <state name="state1">
          <event type="node-leave">
          <script>
          <variable name="aName" mapped-name="mappedName"/>
          <expression>executionContext.setVariable("mappedName", 7);</expression>
          </script>
          </event>
          <transition name="" to="decision1"></transition>
          </state>
          <decision name="decision1">
          <transition name="tr1" to="task1">
          <condition expression="#{contextInstance.variables.mappedName le 5}"/>
          </transition>
          <transition name="tr2" to="task2">
          <condition expression="#{contextInstance.variables.mappedName ge 5}"/>
          </transition>
          </decision>
          <task-node name="task1">
          <task swimlane="buyer">
          <controller>
          <variable name="text:name" access="read,write,required" />
          <variable name="number:tel" access="read,write,required" />
          </controller>
          </task>
          <transition name="finish" to="end" />
          </task-node>
          <task-node name="task2">
          <task swimlane="buyer">
          <controller>
          <variable name="textarea:address" access="read,write,required" />
          </controller>
          </task>
          <transition name="submit" to="end" />
          </task-node>
          <end-state name="end"></end-state>
          </process-definition>
          


          and i forgot to say i appreciate any help!
          thanks!

          • 2. Re: how to use Decision nodes??????
            minam97531

            could anyone help me, PLEASE?
            i must use decision nodes in my process definition and i have above problems. :(

            • 3. Re: how to use Decision nodes??????
              villatore

              Upssssssssss, I have problems with Decision too. But I'm using JBPM 3.2.3, it's a little different. Sorry, but If somebody can, help ussssssss..........

              • 4. Re: how to use Decision nodes??????
                kukeltje

                write a full unit test that demonstrates the problem... the code signalling you process can be a cause of the problem. How such a unittest should look like can be seen in this example

                • 5. Re: how to use Decision nodes??????
                  minam97531

                  i could make the process definition work. (the one that i put above with name "mytest"). it's problem was swimlanes that i assigned!
                  but i still have the same problem, using handler class in decision nodes! :(
                  when i make new instance of websale process definition, in "check-for-another-web-order" task, if i select either "yes" or "no",i get the following error:

                  Entering node evaluate-another-web-order
                  ERROR [com.liferay.jbpm.WorkflowComponentImpl] Task has already ended

                  i made some changes to the original websale example to make it easier to check.
                  this is the first time i write a unit test, so i hope it's correct.
                  here's the unit test:

                  import java.util.Collection;
                  
                  import junit.framework.TestCase;
                  
                  import org.jbpm.graph.def.ProcessDefinition;
                  import org.jbpm.graph.exe.ProcessInstance;
                  import org.jbpm.taskmgmt.exe.TaskInstance;
                  
                  public class DecisionTest {
                  
                   private static final String TEST_PROCESS =
                   "<?xml version=\"1.0\" >"
                   +"<process-definition name=\"websale\">"
                   +"<!-- Event Logging -->"
                   +"<event type=\"node-enter\">"
                   +"<script>System.out.println(\"Entering node \" + node.getName());</script>"
                   +" </event>"
                   +"<event type=\"node-leave\">"
                   +"<script>System.out.println(\"Leaving node \" + node.getName());</script>"
                   +"</event>"
                   +"<!-- Swimlanes -->"
                   +"<swimlane name=\"user\" />"
                   +"<!-- Nodes -->"
                   +"<start-state name=\"initiate-process\">"
                   +"<task swimlane=\"user\">"
                   +"<controller>"
                   +"<variable name=\"textarea:description\" />"
                   +"</controller>"
                   +"</task>"
                   +"<transition name=\"save\" to=\"create-new-web-sale-order\" />"
                   +"</start-state>"
                   +"<task-node name=\"create-new-web-sale-order\">"
                   +"<task swimlane=\"user\">"
                   +"<controller>"
                   +"<variable name=\"text:item\" access=\"read,write,required\" />"
                   +"</controller>"
                   +"</task>"
                   +"<transition name=\"submit\" to=\"check-for-another-web-order\" />"
                   +"</task-node>"
                   +"<task-node name=\"check-for-another-web-order\">"
                   +"<task swimlane=\"user\">"
                   +"<controller>"
                   +"<variable name=\"radio:perform-another-order:yes,no\" />"
                   +"</controller>"
                   +"</task>"
                   +"<transition name=\"submit\" to=\"decision\">"
                   +"</transition>"
                   +"</task-node>"
                   +"<decision name=\"decision\">"
                   +"<handler class=\"com.liferay.jbpm.handler.WebOrderDecisionHandler\" />"
                   +"<transition name=\"finished\" to=\"disagree\" />"
                   +"<transition name=\"another\" to=\"agree\" />"
                   +"</decision>"
                   +"<task-node name=\"agree\">"
                   +"<task swimlane=\"user\">"
                   +"<controller>"
                   +"<variable name=\"text:hello\" />"
                   +"</controller>"
                   +"</task>"
                   +"<transition name=\"submit\" to=\"end\">"
                   +"</transition>"
                   +"</task-node>"
                   +"<task-node name=\"disagree\">"
                   +"<task swimlane=\"user\">"
                   +"<controller>"
                   +"<variable name=\"text:goodbye\" />"
                   +"</controller>"
                   +"</task>"
                   +"<transition name=\"submit\" to=\"end\">"
                   +"</transition>"
                   +"</task-node>"
                   +"<end-state name=\"end\" />"
                   +"</process-definition>";
                  
                   public void testExpression() {
                   ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(TEST_PROCESS);
                   ProcessInstance processInstance = processDefinition.createProcessInstance();
                   processInstance.getContextInstance().setVariable("textarea:description", "something");
                   processInstance.signal();
                   processInstance.getContextInstance().setVariable("text:item", "book");
                   processInstance.signal();
                   processInstance.getContextInstance().setVariable("radio:perform-another-order:yes,no", "yes");
                   processInstance.signal();
                   assertEquals(processDefinition.getNode("agree"), processInstance.getRootToken().getNode());
                   }
                  
                  }
                  


                  and this is WebOrderDecisionHandler.java:

                  import org.jbpm.context.exe.ContextInstance;
                  import org.jbpm.graph.exe.ExecutionContext;
                  import org.jbpm.graph.node.DecisionHandler;
                  
                  /**
                   * <a href="WebOrderDecisionHandler.java.html"><b><i>View Source</i></b></a>
                   *
                   * @author Charles May
                   *
                   */
                  public class WebOrderDecisionHandler implements DecisionHandler {
                  
                   public String decide(ExecutionContext executionContext) throws Exception {
                   ContextInstance contextInstance = executionContext.getContextInstance();
                  
                   String decision = null;
                  
                   String buyerResponse = (String)contextInstance.getVariable(
                   "radio:perform-another-order:yes,no");
                  
                   if (buyerResponse.equals("yes")) {
                   decision = "another";
                   }
                   else {
                   decision = "finished";
                   }
                  
                   return decision;
                   }
                  
                  }
                  


                  one another question: where should i put WebOrderDecisionHandler.class?? maybe i put it in wrong path.

                  thanks again.