3 Replies Latest reply on Sep 12, 2006 7:31 AM by earniedyke

    Help getting a condition to work

    earniedyke

      Greetings all!!!!

      I have been trying all day to get, what I think, is a simple process to work. I can never get it to think the account is NOT locked. No matter what value I set the locked variable to it always takes the default transition. I have tried every style of condition I could find referenced in this forum all to no avail.

      Any and all help would be appreciated.

      Earnie!

      processdefinition.xml

      <?xml version="1.0" encoding="UTF-8"?>
      
      <process-definition
       xmlns="urn:jbpm.org:jpdl-3.1" name="test2">
       <start-state name="BeginLogin">
       <transition name="toCheckForLock" to="CheckForLockedAccount"></transition>
       </start-state>
       <end-state name="End"></end-state>
       <decision name="CheckForLockedAccount">
       <transition name="Account is locked" to="AccountIsLocked"></transition>
       <transition name="Account is not locked" to="AccountIsNotLocked">
       <condition expression="#{contextInstance.variables['locked'] == 'N'}"/>
       </transition>
       </decision>
       <node name="AccountIsLocked">
       <controller>
       <variable name="message">Is</variable>
       </controller>
       <transition name="toEnd" to="End"></transition>
       </node>
       <node name="AccountIsNotLocked">
       <controller>
       <variable name="message">Is NOT</variable>
       </controller>
       <transition name="toEnd" to="End"></transition>
       </node>
      </process-definition>


      test case:
      package com.sample;
      
      import java.io.FileInputStream;
      
      import junit.framework.TestCase;
      
      import org.jbpm.*;
      import org.jbpm.graph.def.ProcessDefinition;
      import org.jbpm.graph.exe.ProcessInstance;
      
      public class SimpleProcessTest extends TestCase {
       public void testSimpleProcess() throws Exception {
       JbpmConfiguration cfg = JbpmConfiguration.getInstance();
       JbpmContext ctx = cfg.createJbpmContext();
       try {
       FileInputStream fis = new FileInputStream("processes/test2/processdefinition.xml");
       ProcessDefinition processDefinition = ProcessDefinition.parseXmlInputStream(fis);
       ctx.deployProcessDefinition(processDefinition);
      
       ProcessInstance instance = ctx.getGraphSession().findLatestProcessDefinition("test2").createProcessInstance();
      
       instance.getContextInstance().setVariable("locked","N");
      
       instance.signal();
       System.out.println(instance.getContextInstance().getVariable("message") + " Locked? " + instance.getContextInstance().getVariable("locked"));
       } finally {
       ctx.close();
       cfg.close();
       }
       }
      
      }
      


        • 1. Re: Help getting a condition to work
          jbpmndc

          try this:

          <condition expression="#{locked == 'N'}"/>
          




          • 2. Re: Help getting a condition to work
            jits_1998

            Heyi earnie,

            Is this allowed ?

             <controller>
             <variable name="message">Is</variable>
             </controller>
            


            I think variable tag can only declare the variable.

            If you can post the exception that will be helpful to us.

            cheers!

            • 3. Re: Help getting a condition to work
              earniedyke

              Thanks for the help. You are correct the variable in the controller was not valid. This is what I have now that works:

              <?xml version="1.0" encoding="UTF-8"?>
              
              <process-definition
               xmlns="urn:jbpm.org:jpdl-3.1" name="test2">
               <start-state name="BeginLogin">
               <transition name="toCheckForLock" to="CheckForLockedAccount"></transition>
               </start-state>
               <end-state name="End"></end-state>
               <decision name="CheckForLockedAccount">
               <transition name="Account is locked" to="AccountIsLocked"></transition>
               <transition name="Account is not locked" to="CheckPassword">
               <condition expression="#{contextInstance.variables['locked'] == 'N'}"/>
               </transition>
               </decision>
               <node name="AccountIsLocked">
               <script>executionContext.getContextInstance().setVariable("message","Is");</script>
               <transition name="toEnd" to="End"></transition>
               </node>
               <node name="CheckPassword">
               <script>executionContext.getContextInstance().setVariable("message","Is NOT");</script>
               <transition name="toEnd" to="End"></transition>
               </node>
              </process-definition>


              Earnie!