4 Replies Latest reply on Nov 11, 2009 4:38 PM by Mas Mohktar

    Couple of new features in seam-drools integration

    Tihomir Surdilovic Master

      We added a couple of new features to the seam-drools integration:


      1. Support for Decision Tables (JBSEAM-4188):




      <drools:rule-base name="ruleBase" rule-files="myDecisionTable.xls"/>



      You can now compile rules from your Decision Table (xls) when using the drools:rule-base component in components.xml


      2. Support for Drools Custom Consequence Exception Handlers (JBSEAM-4049):




      <drools:rule-base name="ruleBase" rule-files="myDecisionTable.xls" consequence-exception-handler="#{myConsequenceExceptionHandler}"/>




      You can use the new consequence-exception-handler attribute to add a new exception handler. This exception handler can be a Seam component and can look like:




      Scope(ScopeType.APPLICATION)
      @Startup
      @Name("myConsequenceExceptionHandler")
      public class MyConsequenceExceptionHandler implements ConsequenceExceptionHandler, Externalizable {
      
         public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
         }
      
         public void writeExternal(ObjectOutput out) throws IOException {
         }
      
         public void handleException(Activation activation,
                                     WorkingMemory workingMemory,
                                     Exception exception) {
             throw new ConsequenceException( exception,
                                             activation.getRule() );
         }
      
      }
      




      3. Support for Drools Event Listeners (JBSEAM-4225):




      <drools:managed-working-memory name="workingMemory" rule-base="#{ruleBase}">
               <drools:event-listeners>
                 <value>org.drools.event.DebugWorkingMemoryEventListener</value>
                 <value>org.drools.event.DebugAgendaEventListener</value>
              </drools:event-listeners>
      </drools:managed-working-memory>



      This allows you to be notified of rule engine events, including rules firing, objects being asserted, etc by simply adding the drools:event-listeners element to your managed-working-memory component in components.xml as shown in the example


      These updates will be available in 2.2.0.CR1. We are also working on adding RuleFlow support in the near future.

        • 1. Re: Couple of new features in seam-drools integration
          Gilson Tavares Newbie

          I believe this link to thread in the rule-dev mail list gives further information about Seam / Drools integration and offers a way to send comments and suggestions on this subject (JBSEAM-4260):


          http://lists.jboss.org/pipermail/rules-dev/2009-August/001414.html
          • 2. Re: Couple of new features in seam-drools integration
            Mas Mohktar Newbie

            Hi, could you please help me,


            i try to inject the working memory in the Seam component


            @In


            WorkingMemory decisionWM


            but when i run the server, i got error.


            Please help me. thank you

            • 3. Re: Couple of new features in seam-drools integration
              Tihomir Surdilovic Master

              Hello Mas,


              What is the Seam version used? Post your entire error and your components.xml so we can try to help.


              Thanks.

              • 4. Re: Couple of new features in seam-drools integration
                Mas Mohktar Newbie
                Hi Tihomir,

                Sorry for my late reply. Ok, this is my scenario. I am using seam 2.1.2. I create a process in my project, in the first node, the process will call some data from the dB, pass the data to the second node. In the second node, i want to evaluate the data using Drools. This is a part of my processDefinition.xml;

                ....

                        <node name="Collect Data">
                                <event type="node-enter">
                                        <action expression="#{notifyPatient.notification}"/>
                                </event>
                                <transition to="Evaluate Data"></transition>
                        </node>

                        <node name="Evaluate Data">
                                <event type="node-enter">
                                        <action expression="#{evaluateData.evaluatStatus}"/>
                                </event>
                                <transition to="Send Email"></transition>
                        </node>
                .....

                I'm having trouble in the EvaluateData, in this seam component, i want to inject the workingMemory like the code below;

                @Name("evaluateData")
                public class EvaluateData {

                @In WorkingMemory evaluationRulesWorkingMemory;
                @In Status status;
                @In Result result;

                public void evaluateStatus() throws FactException
                {

                    policyPricingWorkingMemory.insert(status);
                    policyPricingWorkingMemory.fireAllRules();
                }
                ....


                The error is at the @In WorkingMemory..where it will create a null value, and will create error in the JBPM context. The error will also occur if i define the workingmemory directly in processDefinition. I do not have problem injecting the data that i pass from the previous node. And the output from the .drl file is a just strings.

                This is my Drools part in the component.xml;

                ...

                     <component name="evaluationRule"
                        class="org.jboss.seam.drools.RuleBase">
                        <property name="ruleFiles">evaluation.drl</property>
                     </component>
                    
                     <component name="evaluationRulesWorkingMemory"
                        class="org.jboss.seam.drools.ManagedWorkingMemory" auto-create="true">
                        <property name="ruleBase">"#{evaluationRules}"</property>
                      </component>

                .........

                Another question is, where should i put my .drl file? Currently, i put it in the EAR folder.

                Thank you for your time.