-
1. Re: Custom Object data fetching .drl/.dsl integration
jeffdelong Nov 29, 2007 6:17 PM (in response to vsahni)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 Nov 30, 2007 11:33 AM (in response to 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 Nov 30, 2007 12:11 PM (in response to vsahni)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.