10 Replies Latest reply on Apr 26, 2007 4:25 PM by dario.oliveros

    conditional trans in 3.2 - deprecated syntax doesn't work at

    cristim1979

      Hi,

      I had this problem: some process definition using decisions worked well on JBPM 3.1.4, but when I tried upgrading to 3.2GA, decision nodes didn't work correctly anymore: they always chose the default transition.
      After some work, I've seen that the conditions simply do not work in that syntax - using the 'expression' as ATTRIBUTE of the condition tag - but work in the alternate one: using expression as child element.

      From the 3.2 userguide (section 18.4.29. condition):
      "{content} For backwards compatibility, the condition can also be entered with the 'expression' attribute, but that attribute is deprecated since 3.2"

      If it's still allowed (even deprecated), I was expecting it to still work, somehow (to keep backward compatibility) - or else the schema to be changed to give clear error on this.

      Is this a real problem / should it be fixed somehow ?!..

      JUnit for this:

      import junit.framework.TestCase;
      import org.jbpm.graph.def.ProcessDefinition;
      import org.jbpm.graph.exe.ProcessInstance;
      /**
       * JUnit test of JBPM to check issues regarding the sintax of conditional transitions.<br>
       * In 3.2 it seems that using the 'expression' ATTRIBUTE of the <condition> tag does not
       * work! (but only the alternative, where the expression is passed as a child element of the tag!)
       */
      public class TestDecisionAndConditionalTransitions extends TestCase
      {
       public void testDecision( )
       {
       String def1 = "<process-definition>" + " <start-state>" + " <transition to='d' />"
       + " </start-state>" + " <decision name='d'>"
       + " <transition name='t1' to='a'>"
       + " <condition>#{a == '1'}</condition>" + " </transition>"
       + " <transition name='t2' to='b'>"
       + " <condition>#{a == '2'}</condition>" + " </transition>"
       + " <transition name='t3' to='c'>"
       + " <condition>#{a == '3'}</condition>" + " </transition>"
       + " </decision>" + " <state name='a' />" + " <state name='b' />"
       + " <state name='c' />" + "</process-definition>";
      
       String def2 = "<process-definition>" + " <start-state>" + " <transition to='d' />"
       + " </start-state>" + " <decision name='d'>"
       + " <transition name='t1' to='a'>"
       + " <condition expression=\"#{a == '1'\"/>" + " </transition>"
       + " <transition name='t2' to='b'>"
       + " <condition expression=\"#{a == '2'\"/>" + " </transition>"
       + " <transition name='t3' to='c'>"
       + " <condition expression=\"#{a == '3'\"/>" + " </transition>"
       + " </decision>" + " <state name='a' />" + " <state name='b' />"
       + " <state name='c' />" + "</process-definition>";
      
       ProcessDefinition processDefinition1 = ProcessDefinition.parseXmlString( def1 );
       ProcessDefinition processDefinition2 = ProcessDefinition.parseXmlString( def2 );
      
       //test def 1 - should work
       ProcessInstance processInstance = new ProcessInstance( processDefinition1 );
       processInstance.getContextInstance( ).setVariable( "a", "2" );
       processInstance.signal( );
       assertEquals( processDefinition1.getNode( "b" ),
       processInstance.getRootToken( ).getNode( ) );
      
       //test def 2 - doesn't work on JBPM 3.2 ? (but used to work on 3.1.4 ?)
       ProcessInstance processInstance2 = new ProcessInstance( processDefinition2 );
       processInstance2.getContextInstance( ).setVariable( "a", "2" );
       processInstance2.signal( );
       assertEquals( processDefinition2.getNode( "b" ),
       processInstance2.getRootToken( ).getNode( ) );
       }
      }
      


        • 1. Re: conditional trans in 3.2 - deprecated syntax doesn't wor
          dario.oliveros

          Hi,

          I am having the same problem. My process definition would work in previous release, but not in 3.2 GA.
          Here's an excerpt of my processdefinition.xml:

           <transition name="t1" to="end">
           <condition expression="#{contextInstance.variables['x'] == 'xxx'"/>
           </transition>
          


          I also tried the following, but it did not work:
           <condition>#{contextInstance.variables['x'] eq 'xxx'}</condition>
          


          Any thoughts ?

          Dário


          • 2. Re: conditional trans in 3.2 - deprecated syntax doesn't wor
            cristim1979


            from what i've seen, you can use simpler condition / access context variables in a simpler way in conditions.

            you should try like this (hope it works for you):

            x =='xxx'

            , where x is a variable on the process context.

            did it work ? :)

            • 3. Re: conditional trans in 3.2 - deprecated syntax doesn't wor
              cristim1979

              correction (condition tags missing):

              <condition> x == 'xxx' </condition>
              


              • 5. Re: conditional trans in 3.2 - deprecated syntax doesn't wor
                cristim1979

                JBPM-854 is not related, i've checked it already.
                But http://jira.jboss.com/jira/browse/JBPM-853 is exactly this issue (haven't found it before), and explains the cause and a fix.
                thanks, topic can be closed.

                • 6. Re: conditional trans in 3.2 - deprecated syntax doesn't wor
                  dario.oliveros

                  I could not get 'condition' working when deploying my process definition to JBoss AS. It used to work in 3.1.3, but not 3.2. Here's my PD:

                  <?xml version="1.0" encoding="UTF-8"?>
                  
                  <process-definition
                   xmlns="" name="sample">
                   <swimlane name="swimlane1">
                   <assignment expression="user(ernie)"></assignment>
                   </swimlane>
                   <start-state name="start1">
                   <transition name="" to="task1"></transition>
                   </start-state>
                   <task-node name="task1">
                   <task name="task1" swimlane="swimlane1">
                   <controller>
                   <variable name="var1" access="read,write,required"></variable>
                   </controller>
                   </task>
                   <transition name="t1" to="decision1"></transition>
                   </task-node>
                   <decision name="decision1">
                   <transition name="1" to="end1">
                   <condition>#{contextInstance.variables.var1 == '1'}</condition>
                   </transition>
                   <transition name="2" to="task2">
                   <condition>#{contextInstance.variables.var1 == '2'}</condition>
                   </transition>
                   </decision>
                   <end-state name="end1"></end-state>
                   <task-node name="task2">
                   <task name="task2" swimlane="swimlane1">
                   <controller>
                   <variable name="var1" access="read"></variable>
                   <variable name="var2" access="read,write,required"></variable>
                   </controller>
                   </task>
                   <transition name="" to="end1"></transition>
                   </task-node>
                  </process-definition>



                  "cristim1979" wrote:
                  correction (condition tags missing):

                  <condition> x == 'xxx' </condition>
                  


                  • 7. Re: conditional trans in 3.2 - deprecated syntax doesn't wor
                    cristim1979

                    simply try to write your conditions in decision node simpler, like this:

                    <decision name="decision1">
                     <transition name="1" to="end1">
                     <condition>var1 == '1'</condition>
                     </transition>
                     <transition name="2" to="task2">
                     <condition>var1 == '2'</condition>
                     </transition>
                     </decision>
                    


                    i think it should work (from my experience). if you still want to use #{...} expresions, i think there the "==" doesn't work (so you should try .equals, or eq form, or something - sorry, haven't played more with EL)

                    • 8. Re: conditional trans in 3.2 - deprecated syntax doesn't wor
                      dario.oliveros

                      I'd already tried the simpler condition like you suggested, but it did not work either. It does work in jBPM starters kit 3.1.3 though, but not in 3.2GA.
                      It seems a bug with the new jBPM console, but I am not sure.


                      • 9. Re: conditional trans in 3.2 - deprecated syntax doesn't wor
                        cristim1979

                        Take a look at this issue then, might be related to your problem:
                        http://jira.jboss.com/jira/browse/JBPM-854

                        Looks like conditions on transitions are not correctly retrieved from db, for 3.2. If your process def works ok in a JUnit test without persistence in db (but parsing directly the def from a xml and using it), but fails when process is stored in db, that JIRA issues probably applies. (you can test this by running the method testDecision() mentioned there, but commenting out the line: processDefinition = saveAndReload(processDefinition); )

                        I should have mentioned that I first applied the fix there (changing a line in jbpm sources in Decision.java, and then recompile that class, and use the modified jpbm library from then on). and had no trouble with deployed definitions.

                        • 10. Re: conditional trans in 3.2 - deprecated syntax doesn't wor
                          dario.oliveros

                          Finally I got my process definition working.
                          Basically I had to apply that fix to Decision.java (thanks for your suggestion) and also change the expression to start with '#{' and end with '}' as shown below.

                          <decision name="decision1">
                           <transition name="1" to="end1">
                           <condition>#{var1 == '1'}</condition>
                           </transition>
                           <transition name="2" to="task2">
                           <condition>#{var1 == '2'}</condition>
                           </transition>
                           </decision>


                          When debugging the code, I noticed that there was a method to translate expression to dollar (in JbpmExpressionEvaluator.java) which in turn would expect an expression starting with '#{'. So I decided to change my process definition in order to see if that would make a difference at all. Hopefully it did.

                          Thanks for your help,
                          Dário