12 Replies Latest reply on Jun 27, 2007 6:07 AM by kukeltje

    Why my condtion doesn't get evaluated?

    ghezzi

      I have this snippet process definition

      <decision name="CheckState">
       <transition name="tr2" to="node2">
       <condition>#{JBpmService.status=='DELETED'}</condition>
       </transition>
       <transition name="tr3" to="node3">
       <condition>#{JBpmService.status=='READY'}</condition>
       </transition>
       <transition name="tr0" to="node0">
       <condition>#{JBpmService.status=='UNDEF'}</condition>
       </transition>
       <transition name="tr1" to="node1">
       <condition>#{JBpmService.status=='NOT_LOGGED'}</condition>
       </transition>
      </decision>
      


      I've set in contextinstance the object JBpmService in an action prior to the decision ( which has a status property ) with this code

      ContextInstance contextInstance = processInstance.getContextInstance();
      contextInstance.setVariable("JBpmService",jbpms);
      processInstance.signal();
      


      What 's wrong?
      I get always the first (default) transition.
      Is there a simple way to debug this?


      I've tried to change the expression in several ways with always the same result: default transition taken. for example

      <condition>#{contextInstance.variables['JBpmService'].status=='READY'}</condition>
      or
      <condition>#{contextInstance.variables.JBpmService.status=='READY'}</condition>
      

      i've tried also to set a simple String var status to simplify : always default transition
      <condition>#{status=='READY'}</condition>
      or
      <condition>#{contextInstance.variables.status=='READY'}</condition>
      


        • 1. Re: Why my condtion doesn't get evaluated?
          kukeltje

          did you search the forum (e.g. with google or the search above on the left, small blue text))

          Has been discussed lots of times... first see if there is some info in there.

          Besides that ALWAYS report you jboss version, db used, jdk etc...etc...etc...

          • 2. Re: Why my condtion doesn't get evaluated?
            ghezzi

             

            "kukeltje" wrote:
            did you search the forum (e.g. with google or the search above on the left, small blue text))

            Has been discussed lots of times... first see if there is some info in there.

            Besides that ALWAYS report you jboss version, db used, jdk etc...etc...etc...



            i'm a seasoned programmed

            i loose my finger googleing on jbpm

            anyway thankyou for the usefull support



            • 3. Re: Why my condtion doesn't get evaluated?
              ghezzi

              I've tried without luck also a simplified scenario with all possible conditon syntax

               <decision name="CheckState">
               <transition name="tr2" to="node2">
               <condition>status=='DO NOT GO HERE'</condition>
               </transition>
               <transition name="tr3" to="node3">
               <condition>status=='UNDEF'</condition>
               </transition>
               <transition name="tr0" to="node0">
               <condition>status eq 'UNDEF'</condition>
               </transition>
               <transition name="tr1" to="node1">
               <condition>#{status == 'UNDEF'}</condition>
               </transition>
               <transition name="tr4" to="node4">
               <condition>#{contextInstance.variables['status'] == 'UNDEF'}</condition>
               </transition>
               <transition name="tr5" to="node5">
               <condition>#{contextInstance.variable.status == 'UNDEF'}</condition>
               </transition>
               <transition name="tr6" to="node6">
               <condition>#{contextInstance.variable.status eq 'UNDEF'}</condition>
               </transition>
               <transition name="tr7" to="node7">
               <condition>status -ùà-è+òl0'''00ì' 'UNDEF'</condition>
               </transition>
              
               </decision>
              


              having set a status var to UNDEF

              The jbpm log says


              2007-06-26 09:59:08,649 DEBUG [] update variable 'status' in 'TokenVariableMap159640d' to value 'UNDEF'

              2007-06-26 09:59:08,667 DEBUG [] event 'before-signal' on 'State(RequestedState)' for 'Token(/)'
              2007-06-26 09:59:08,710 DEBUG [] event 'node-leave' on 'State(RequestedState)' for 'Token(/)'
              2007-06-26 09:59:08,710 DEBUG [] event 'transition' on 'Transition()' for 'Token(/)'
              2007-06-26 09:59:08,732 DEBUG [] event 'node-enter' on 'Decision(CheckState)' for 'Token(/)'
              2007-06-26 09:59:08,813 DEBUG [] decision didn't select transition, taking default Transition(tr2)
              2007-06-26 09:59:08,813 DEBUG [] decision CheckState is taking 'Transition(tr2)'

              So it seems that my variable status is set to undef
              But i always get transition 2

              Is there a way to debug the condition code that decide to get the default
              transition?

              thanks in advance

              • 4. Re: Why my condtion doesn't get evaluated?
                kukeltje

                Please, can anyone tell me what version of jBPM he is using, what appserver, db, jdk, if he did upgrades etc?

                Or tell him to e.g. look at the unittests where there are examples, or look in the jira... (but watch out, he might loose a finger)

                • 5. Re: Why my condtion doesn't get evaluated?
                  ghezzi

                  jboss 4.0.5.GA
                  JBPM 3.2.GA
                  JDK 1.5

                  thanks


                  • 6. Re: Why my condtion doesn't get evaluated?
                    kukeltje

                    Remaining question: did you upgrade from a 3.1 version:

                    http://jira.jboss.com/jira/browse/JBPM-854?

                    Or use mysql 5.0?

                    debugging the decisioncode requires adding a debug statement in the source to see what gets evaluated.

                    • 7. Re: Why my condtion doesn't get evaluated?
                      kukeltje

                      Unittests are great to reproduce issues instead of snippets (should be well known to.... ahhh never mind). The following unittest runs fine in the cvs head of 21-06-2007




                      package org.jbpm.jpdl.el;
                      
                      import junit.framework.TestCase;
                      
                      import org.jbpm.JbpmException;
                      import org.jbpm.graph.def.ProcessDefinition;
                      import org.jbpm.graph.exe.ProcessInstance;
                      
                      public class DecisionExpressionTest extends TestCase {
                      
                       public static class Customer {
                       String priority;
                       int number;
                       public Customer(String priority) {
                       this.priority = priority;
                       }
                       public Customer(int number) {
                       this.number = number;
                       }
                       public String getPriority() {
                       return priority;
                       }
                       public int getNumber() {
                       return number;
                       }
                       }
                      
                       public ProcessDefinition createCustomerPriorityProcess() {
                       return ProcessDefinition.parseXmlString(
                       "<process-definition>" +
                       " <start-state>" +
                       " <transition to='d'/>" +
                       " </start-state>" +
                       " <decision name='d'>" +
                       " <transition to='l' >" +
                       " <condition expression='#{customer.priority == \"LOW\"}' />" +
                       " </transition>" +
                       " <transition to='m'>" +
                       " <condition expression='#{customer.priority == \"MEDIUM\"}' />" +
                       " </transition>" +
                       " <transition to='h'>" +
                       " <condition expression='#{customer.priority == \"HIGH\"}' />" +
                       " </transition>" +
                       " </decision>" +
                       " <state name='l' />" +
                       " <state name='m' />" +
                       " <state name='h' />" +
                       "</process-definition>"
                       );
                       }
                      
                       public void testCustomerPriorityLow() {
                       ProcessDefinition processDefinition = createCustomerPriorityProcess();
                       ProcessInstance processInstance = new ProcessInstance(processDefinition);
                       processInstance.getContextInstance().setVariable("customer", new Customer("LOW"));
                       processInstance.signal();
                       assertEquals("l", processInstance.getRootToken().getNode().getName());
                      
                       }
                      
                       public void testCustomerPriorityMedium() {
                       ProcessDefinition processDefinition = createCustomerPriorityProcess();
                       ProcessInstance processInstance = new ProcessInstance(processDefinition);
                       processInstance.getContextInstance().setVariable("customer", new Customer("MEDIUM"));
                       processInstance.signal();
                       assertEquals("m", processInstance.getRootToken().getNode().getName());
                       }
                      
                       public void testCustomerPriorityHigh() {
                       ProcessDefinition processDefinition = createCustomerPriorityProcess();
                       ProcessInstance processInstance = new ProcessInstance(processDefinition);
                       processInstance.getContextInstance().setVariable("customer", new Customer("HIGH"));
                       processInstance.signal();
                       assertEquals("h", processInstance.getRootToken().getNode().getName());
                       }
                      
                       public void testCustomerPriorityUndefined() {
                       ProcessDefinition processDefinition = createCustomerPriorityProcess();
                       ProcessInstance processInstance = new ProcessInstance(processDefinition);
                       processInstance.getContextInstance().setVariable("customer", new Customer("UNDEFINED"));
                       processInstance.signal();
                       // 'Default' transition
                       assertEquals("l", processInstance.getRootToken().getNode().getName());
                       }
                      
                       public void testCustomerPriorityNull() {
                       ProcessDefinition processDefinition = createCustomerPriorityProcess();
                       ProcessInstance processInstance = new ProcessInstance(processDefinition);
                       processInstance.getContextInstance().setVariable("customer", new Customer(null));
                       processInstance.signal();
                       // 'Default' transition
                       assertEquals("l", processInstance.getRootToken().getNode().getName()); }
                      }
                      


                      So find the differences

                      • 8. Re: Why my condtion doesn't get evaluated?
                        kukeltje

                        oh and btw, this one does as well. (no expression)

                        package org.jbpm.jpdl.el;
                        
                        import junit.framework.TestCase;
                        
                        import org.jbpm.JbpmException;
                        import org.jbpm.graph.def.ProcessDefinition;
                        import org.jbpm.graph.exe.ProcessInstance;
                        
                        public class DecisionExpressionTest extends TestCase {
                        
                         public static class Customer {
                         String priority;
                         int number;
                         public Customer(String priority) {
                         this.priority = priority;
                         }
                         public Customer(int number) {
                         this.number = number;
                         }
                         public String getPriority() {
                         return priority;
                         }
                         public int getNumber() {
                         return number;
                         }
                         }
                        
                         public ProcessDefinition createCustomerPriorityProcess() {
                         return ProcessDefinition.parseXmlString(
                         "<process-definition>" +
                         " <start-state>" +
                         " <transition to='d'/>" +
                         " </start-state>" +
                         " <decision name='d'>" +
                         " <transition to='l' >" +
                         " <condition>#{customer.priority == 'LOW'}</condition>" +
                         " </transition>" +
                         " <transition to='m'>" +
                         " <condition>#{customer.priority == 'MEDIUM'}</condition>" +
                         " </transition>" +
                         " <transition to='h'>" +
                         " <condition>#{customer.priority == 'HIGH'}</condition>" +
                         " </transition>" +
                         " </decision>" +
                         " <state name='l' />" +
                         " <state name='m' />" +
                         " <state name='h' />" +
                         "</process-definition>"
                         );
                         }
                        
                         public void testCustomerPriorityLow() {
                         ProcessDefinition processDefinition = createCustomerPriorityProcess();
                         ProcessInstance processInstance = new ProcessInstance(processDefinition);
                         processInstance.getContextInstance().setVariable("customer", new Customer("LOW"));
                         processInstance.signal();
                         assertEquals("l", processInstance.getRootToken().getNode().getName());
                         }
                        
                         public void testCustomerPriorityMedium() {
                         ProcessDefinition processDefinition = createCustomerPriorityProcess();
                         ProcessInstance processInstance = new ProcessInstance(processDefinition);
                         processInstance.getContextInstance().setVariable("customer", new Customer("MEDIUM"));
                         processInstance.signal();
                         assertEquals("m", processInstance.getRootToken().getNode().getName());
                         }
                        
                         public void testCustomerPriorityHigh() {
                         ProcessDefinition processDefinition = createCustomerPriorityProcess();
                         ProcessInstance processInstance = new ProcessInstance(processDefinition);
                         processInstance.getContextInstance().setVariable("customer", new Customer("HIGH"));
                         processInstance.signal();
                         assertEquals("h", processInstance.getRootToken().getNode().getName());
                         }
                        
                         public void testCustomerPriorityUndefined() {
                         ProcessDefinition processDefinition = createCustomerPriorityProcess();
                         ProcessInstance processInstance = new ProcessInstance(processDefinition);
                         processInstance.getContextInstance().setVariable("customer", new Customer("UNDEFINED"));
                         processInstance.signal();
                         // 'Default' transition
                         assertEquals("l", processInstance.getRootToken().getNode().getName());
                         }
                        
                         public void testCustomerPriorityNull() {
                         ProcessDefinition processDefinition = createCustomerPriorityProcess();
                         ProcessInstance processInstance = new ProcessInstance(processDefinition);
                         processInstance.getContextInstance().setVariable("customer", new Customer(null));
                         processInstance.signal();
                         // 'Default' transition
                         assertEquals("l", processInstance.getRootToken().getNode().getName()); }
                        }
                        
                        


                        • 9. Re: Why my condtion doesn't get evaluated?
                          ghezzi

                           

                          "kukeltje" wrote:
                          Remaining question: did you upgrade from a 3.1 version:

                          http://jira.jboss.com/jira/browse/JBPM-854?

                          Or use mysql 5.0?

                          debugging the decisioncode requires adding a debug statement in the source to see what gets evaluated.


                          no upgrade, just fresh install of all the stuff
                          but i'm using mysql 5.0

                          i've also tried to change, even if i don't see any error,
                          every bit(1) in the mysql schema to tinyint(1)
                          ...same result

                          i will try the unit test you suggest and let you know

                          thanks




                          • 10. Re: Why my condtion doesn't get evaluated?
                            kukeltje

                             

                            "sparklehorse" wrote:

                            no upgrade, just fresh install of all the stuff
                            but i'm using mysql 5.0


                            i've also tried to change, even if i don't see any error,
                            every bit(1) in the mysql schema to tinyint(1)
                            ...same result


                            ok, thanks for letting me know

                            "sparklehorse" wrote:

                            i will try the unit test you suggest and let you know


                            I'm curious...

                            • 11. Re: Why my condtion doesn't get evaluated?
                              ghezzi

                               

                              "sparklehorse" wrote:
                              "kukeltje" wrote:
                              Remaining question: did you upgrade from a 3.1 version:

                              http://jira.jboss.com/jira/browse/JBPM-854?

                              Or use mysql 5.0?

                              debugging the decisioncode requires adding a debug statement in the source to see what gets evaluated.


                              no upgrade, just fresh install of all the stuff
                              but i'm using mysql 5.0

                              i've also tried to change, even if i don't see any error,
                              every bit(1) in the mysql schema to tinyint(1)
                              ...same result

                              i will try the unit test you suggest and let you know

                              thanks




                              i've tried some test suite and they don't work with conditions

                              i've upgraded to 3.2.1 and now condition works

                              I think this two patches are important

                              # [JBPM-853] - Attribute 'expression' not taken from Condition element
                              # [JBPM-854] - Condition in transition not retrieved from database JBPM_TRANSITIONS#DECISION_


                              bye


                              • 12. Re: Why my condtion doesn't get evaluated?
                                kukeltje

                                strange... these two bugs are ONLY (as in the report) when deployed against a previous version. That is not the case here as you reported. That is why I did not mention these to you. So probably these two reports are incomplete.

                                Thanks for letting me/us know....