3 Replies Latest reply on Nov 30, 2007 12:11 PM by jeffdelong

    Custom Object data fetching .drl/.dsl integration

    vsahni

      Hi all,
      I have added a custom object ErrorList in JBOSS esb message using the .drl/.dsl syntax below. The adding errorcode data works fine but I want to conditionally fire a rule "Send to MissingData" after that. I would like to to check the sze property of the ErrorList object as shown in the .dsl file below.

      PS: I have verified that errorlist object gets populated with error codes added in the the .drl file.

      In my program the addition of error codes (AddError) works fine but while doing a conditional check on errorlist size (GetErrors) always returns 0.

      Can someone help on this? Thanks.


      .drl code

      rule "Missing Settlement Date "
      salience 94
       when
       xpathEmpty "/olcmf/olcmfMessage/messageData/dataRecord/tradeRecord/tradeDates/settlementDate"
       Errors
       then
       AddToError : "Settlement Date";
       Log : "5.~~~~ Missing Settlement Date";
      end
      
      rule "Send to MissingData"
      salience 93
       when
       GetErrors
       then
       Log : "6.~~~~ Send to MissingData Action";
       Destination : "MissingData";
      end
      
      
      
      .dsl definitions:
      [when]Errors= errors : ErrorList();
      [when]GetErrors= errors : ErrorList(sze > 0);
      [when]xpathValidateAllotment "{xpath}"=msg : Message( type == MessageType.JBOSS_XML ) and eval( com.oldlane.esb.util.OLDSLHelper.validateAllotment(msg, "{xpath}") )
      [then]Log : "{message}"=System.out.println("{message}");
      [then]Destination : "{message}"=destinations.add("{message}");
      [then]AddToError : "{message}"=errors.setError("{message}");
      


        • 1. Re: Custom Object data fetching .drl/.dsl integration
          jeffdelong

          When your ErrorList is inserted into working memory is when the rules are evaluated. At that time, the list is empty, so the second rule is not fired. In order to make it fire, you would need to update the ErrorList object in the RHS of the first rule.

          However, this will cause your first rule to be re-executed in an infinite loop, unless you add the no-loop attribute to the first rule. See the drools documentation for modify and no-loop.

          However in the rules you have described, it is not clear why you don't do this with a single rule whose RHS both adds to the ErrorList and sets the Destination.

          • 2. Re: Custom Object data fetching .drl/.dsl integration
            vsahni

            Hi Jeff,
            I believe I did not clearly state the problem in the previous email which led to a bit of unclarity in the response.

            Here is an attempt to decsribe the objective and the Rule Engine when statement order evaluation problem.

            Rule Step 1: Use a combination of [when]Errors and [then]AddToError to add a number of error codes in a an arraylist.

            Rule Step 2: Use GetErrorsSize to check if there was any error populated in the earlier rules and then fire an action to a destination.

            Problem: Although I am using higher salience for Errors and lower salience number for GetErrorSize, it appears that GetErrorSize's when statement gets evaluated before Errors rules. Which means it returns a 0 value of the size.

            I want to be able to force the when statement evaluation order to force 1. Errors and 2.GetErrors order.

            How this can be done? Thanks you very much.

            [when]Errors= errors : ErrorList();
            [when]GetErrorsSize= errors : ErrorList(sze > 0);
            [then]AddToError : "{message}"=errors.setError("{message}");

            • 3. Re: Custom Object data fetching .drl/.dsl integration
              jeffdelong

              You need to read the Drools documentation and learn a bit about how rule engines work. When facts are inserted into working memory, the LHS of the rules are evaluated. As facts are modified, and the engine explicitly notified of the modifications, then the LHS constraints are re-evaluated. Salience only applies when multiple rules have all satisfied their respective constraints.

              So when your ErrorList is inserted into working memory is when the rules are evaluated. At that time, the list is empty, so the second rule is not fired. In order to make it fire, you would need to update the ErrorList object in the RHS of the first rule.

              no-loop true
              when
               xpathEmpty "/olcmf/olcmfMessage/messageData/dataRecord/tradeRecord/tradeDates/settlementDate"
               Errors
              then
               AddToError : "Settlement Date";
               Log : "5.~~~~ Missing Settlement Date";
               update Errors;
              
              


              Where update Errors has been added to your DSL to map to update(errors).

              However, this will cause your first rule to be re-executed in an infinite loop, unless you add the no-loop attribute to the first rule. See the drools documentation for more information on modify and no-loop.

              You don't need salience in this case. The second rule will execute after the first because the constraints of the second rule will not be met until after the first rule has executed and tupdated the errorList.