0

I am a bit new to drools. I have 2 rules namely DateYYYYMMDD and TotalChargesAndTax in my drl file. I am using the following syntax to execute the 2 rules from my main method.

 Command<?> syntacticValidation = new FireAllRulesCommand(
 new RuleNameEqualsAgendaFilter("DateYYYYMMDD")); 
 Command<?> semanticValidation = new FireAllRulesCommand(
 new RuleNameEqualsAgendaFilter("TotalChargesAndTax"));
 List<Command> commands = new ArrayList<Command>();
 commands.add(semanticValidation);
 commands.add(syntacticValidation);
 session.execute(CommandFactory
 .newBatchExecution(commands));

But when I run my application, only the TotalChargesAndTax rule is executed and the DateYYYYMMDD rule is skipped. If I interchange the position of the command objects in the ArayList as shown below,

 commands.add(syntacticValidation);
 commands.add(semanticValidation);

then the DateYYYYMMDD rule is executed and the TotalChargesAndTax rule is skipped. Is there a way to execute both the rules and execute the consequence of both the rules? As of now, only one consequence is executed depending on which command is first in the array list.

asked Sep 21, 2011 at 6:26

1 Answer 1

1

When you write rules you cannot say which rule must fire. Rules will be picked by the rule engine based on the facts/pojos that you insert in your knowledge session. I recommend you to not use Agenda filters to try to force rules execution. Multiple rules will be executed automatically if the objects that you insert match with your rules conditional side (WHEN). If you want to share how your rules looks like we can help you. Cheers

answered Sep 22, 2011 at 11:12
Sign up to request clarification or add additional context in comments.

1 Comment

I just happened to see your reply today. It was my first day with Drools when I posted the above question. What you are saying is exactly what I realized a few days later. I have gone a long way in efficiently defining my fact model so that it is easy for me to write rules. Although I have a new question about compiling a .drl file from the windows shell. Can you help me with this? :).. Here is the link to the question :-stackoverflow.com/questions/7992569/…

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.