4 Replies Latest reply on Mar 12, 2009 10:51 AM by turpin vincent

    Using Drools for jBPM decision

    turpin vincent Newbie


      I'm starting to use Seam and i've got some problems using Drools in order to manage decisions in my process and nobody is able to help me on Seam forum.

      Configuration Jboss 5.0.0 GA Seam 2.1.1 GA Ant 1.7 Jboss Tool Eclipse 3.4

      When i use Drools to manage assignment, it works fine, but now i would like to use it for decison managment and i got this error:

      Exception during request processing:

      Caused by javax.el.ELException with message: "org.jbpm.JbpmException: decision 'decision69' selected non existing transition 'null'"

      I give you a part of my code but if something else is needed tell me.

       <task-node name="PlaceOrder">
       <task name="placeOrderTask">
       <assignment class="org.jboss.seam.drools.DroolsAssignmentHandler">
       <transition name="cancel" to="error" />
       <transition to="decision69" name="todecision"></transition>
       <decision name="decision69">
       <handler class="org.jboss.seam.drools.DroolsDecisionHandler">
       <transition to="Deliver" name="toDeliver">
       <action class="org.jboss.seam.drools.DroolsActionHandler">
       </action >
       <transition to="end" name="toend"></transition>
       <task-node name="Deliver">
       <task name="getFromStock">
       <assignment actor-id="#{actor.id}" />
       <transition name="next" to="end" />
       <transition name="cancel" to="error" />


      <persistence:managed-persistence-context name="entityManager"
       <persistence:entity-manager-factory name="testEntityManagerFactory"
       <drools:rule-base name="securityRules">
       <drools:managed-working-memory name="securityRulesWorkingMemory" auto-create="true" rule-base="#{securityRules}"/>
       <security:rule-based-permission-resolver security-rules="#{securityRules}"/>
       <drools:rule-base name="accountApprovalRules">
       <drools:managed-working-memory name="accountApprovalWorkingMemory" auto-create="true" rule-base="#{accountApprovalRules}"/>

      package AccountApproval;
      import org.jboss.seam.bpm.Actor;
      import org.domain.test.session.OrderStock;
      import org.jboss.seam.drools.Decision;
      global Decision decision
      rule "Approve Order For Loyal Customer"
       OrderStock ( processQuantity >= 0 )

      So i would like to know if someone can tell me why it happends.

      thank's in advance

      And i'm sorry for my english witch isn't as fine sa i would like (I'm a french student)

        • 1. Re: Using Drools for jBPM decision
          Ronald van Kuijk Master

          looks like your handler on the decision does not return a valid transition. (null is not the name of one of the transitions) it should return 'toDeliver' or 'toend'

          btw, why do you execute the same rules again on the transition 'toDeliver'?

          • 2. Re: Using Drools for jBPM decision
            turpin vincent Newbie


            First thanks for answering me so fast. Actually i understood that the problem comes from the data handler witch return "null" in spite of "toDeliver" or "toEnd". But i can't find why, the file AccountAproval.drl is correctly parsed and even if when the rule doesn't evaluate to setOutcome("toDeliver"), it return null, i think that the condition in the rule is evaluated (if the syntaxe condition isn't correct i get an error about that).

            For the moment i just can add that i'm working from this example: http://docs.jboss.com/seam/latest/reference/en-US/html/drools.html (chapter 14.3) btw that's why i execute the same rules again on the transition 'toDeliver' (to be closest from the example) and there is no difference if i delete this part:

            <action class="org.jboss.seam.drools.DroolsActionHandler">
            </action >

            I'm going to try an other way with less code in the process and more in the java class like in this example: http://www.jboss.org/community/docs/DOC-11096.

            I give my java class too (mabe it will help) i think that the problem can come from the fact that i dont know if i have to declare again the data handler in this class or if the code in the process is enough.
            package org.domain.test.session;
             import org.jboss.seam.annotations.bpm.CreateProcess;
             import org.jboss.seam.annotations.bpm.EndTask;
             import org.jboss.seam.annotations.Name;
             import org.jboss.seam.annotations.bpm.StartTask;
             import org.jboss.seam.annotations.*;
             import org.jboss.seam.ScopeType;
             public class OrderStock
             @Out(scope=ScopeType.BUSINESS_PROCESS, required=false)
             Long processQuantity;
             public Long getProcessQuantity() {
             return processQuantity;
             public void setProcessQuantity(Long processQuantity) {
             this.processQuantity = processQuantity;
             private int quantity ;
             public int getQuantity()
             return quantity;
             public void setQuantity(int quantity) {
             this.quantity = quantity;
             public void startProcess()
             processQuantity = new Long(getQuantity());
             System.out.println("Order: "+getQuantity());
             public void done()
             public void cancel()

            • 3. Re: Using Drools for jBPM decision
              Ronald van Kuijk Master


              even if when the rule doesn't evaluate to setOutcome("toDeliver"), it return null,

              This IS the problem.

              And yes it does not make a difference if you remove the second call to the rule, I was just wondering *why* you did that

              Oh, and the documentation you refer to is not a full example. It just demonstrates that a descsionrule and an assignment rule should call different methods for the result. Look in the seam source for the full examples

              • 4. Re: Using Drools for jBPM decision
                turpin vincent Newbie

                For testing, i have recreate a Decision handler based on the code below:

                16: public class DroolsDecisionHandler extends DroolsHandler implements
                17: DecisionHandler {
                18: private static final long serialVersionUID = -8900810376838166513L;
                20: public List<String> assertObjects;
                21: public String workingMemoryName;
                23: public String decide(ExecutionContext executionContext)
                24: throws Exception {
                25: WorkingMemory workingMemory = getWorkingMemory(
                26: workingMemoryName, assertObjects, executionContext);
                27: workingMemory.setGlobal("decision", new Decision());
                28: workingMemory.fireAllRules();
                29: return ((Decision) workingMemory.getGlobal("decision"))
                30: .getOutcome();
                31: }
                33: }

                And I have found that the executionContext was unable to solve my objects.
                For example,
                (Iteration on assertObjects)
                 ContextInstance ci = executionContext.getContextInstance();
                while (iter.hasNext()) {
                 objectName = (String) iter.next();
                 object = ci.getVariable(objectName);
                 System.out.println("object name is: " + objectName);

                object are always null!
                That shows me that object are never mapped!