With drools, is there a way to tell which part of a rule's "when" clause has failed that prevented the rule from firing? Or, barring that, to tell whether a rule did not fire because its conditions were not satisfied, or if it simply had a lower salience than a rule that halted the context?
Related
I have written a Drool rule as shown below:
rule "first and second"
activation-group "first"
activation-group "second"
when
// conditions
then
// actions
end
However, when compiling, I get this error:
Duplicate attribute definition: activation-group in rule first and second
I want to know if it is possible to include multiple activation-groups in a rule. If this is possible, how can you do it?
Thanks in advance.
It's not possible to use multiple activation groups in a single rule. If you feel the need to do this then you should restructure your rules to be a little smarter with your conditions so you can get it to a state that would work with single activation groups (per rule).
We have a scenario to be implemented in Decision Table to exit from executing the remaining rules if certain rule successfully executes the action part of the rule. Suppose I have 50 rules and 5th rule is something which says insurance claim is invalid then we set claim as invalid to the object, then there is no need to execute remaining rules. How could this can be achieved. Please suggest
You can
retract the fact under evaluation, after setting invalid to true, on that rule's RHS,
throw an exception (ugly, ugly),
run the session using fireUntilHalt and call method halt on the session on that rule's RHS - here you'll need a very low salience rule (added in a .drl file) to call halt in case the fact passes all decision table rules.
For reusable perspective, I have one Rule with Rule Flow group. I have use same rule flow group multiple times in flow. Now the situation is its should be fire same rule more then one time,but its only fire that rule single time.
I don't understand why its happens.
Can you give me an idea why its happening and whats the solution for same?
A Rule Task in a flow does not "execute" the rules in a rule-flow-group, it merely activates that group in the agenda so IF there are active rules, they will fire.
If between 2 executions of your Rule Task you modify the session in a way that new activations are created, consecutive executions of your task should fire new activations of those rules.
Hope it helps,
I need to execute some rule as the last rule. Any one knows how to do this ?
Also can a rule change behavior of other rules ? For example can a rule be used to execute certain rule package ?
Thanks in Advance.
yes you can use the rule attribute salience to give your rules priority.
You can insert a fact in the Right Hand Side of the rule to make another rules match.
You can also read the documentation for Agenda Groups to select different groups of rules that will be executed at different times.
Hope it helps!
I defined multiples rules in one DRL file, how to set order, want to execute one after another (top to bottom).
Rules are fired automatically when the conditions are met when the inserted facts(objects) are updated. But if in case you want to run it from top to bottom, you can set a property called salience in the rule. The value it takes is an integer. The rule with the highest salience is executed first.
rule "First name mandatory"
salience 10
when
(Person(firstName=="" || firstName==null))
then
...
end
If you use salience you will be killing the rule engine, because you will be forcing the rule execution order instead of letting the engine decide.
Cheers
Setting priority to rules is the best form.
Use Salience to determine the priority of each rule, where a higher number denotes a higher priority.
The default Salience for rules is 0, and you can give negative Salience, for example,if you want a rule to be fired last.