I am using Drools 6.1.0 in my application.
We are planning to write a single huge .drl file which will contain all the rules.
There will be mainly 2 categories of the rules 1. Null checks 2. Business validation
Using ruleflow-group, activation-group and salience I am planning to manage which rules to execute / fire when a fact is added to the session.
Even if with this approach the solution is not working for me because.
Lets say I have below .drl file
rule "rule1"
ruleflow-group "primary"
activation-group "NullCheck"
salience 5
when
$m : Message(innerMsg.something == null)
then
// do something
rule "rule2"
ruleflow-group "primary"
activation-group "NullCheck"
salience 4
when
$m : Message(innerMsg.something.something == null)
then
// do something
rule "rule3"
ruleflow-group "primary"
activation-group "NullCheck"
salience 3
when
$m : Message(innerMsg.something.something.something == null)
then
// do something
Drools documentation says this "All constraints are evaluated when a fact is inserted. From the Drools manual: The condition evaluation is not tied to a specific evaluation sequence or point in time, but that it happens continually, at any time during the life time of the engine."
So what is happening is that the code which is executing this file is throwing Nullpointer Exception on rule2 because innerMsg.something.something
is NULL
Note: I do not want to club all the null checks using || in a single when statement because I want to capture specific null condition and based on that create the error message.
My questions are as below.
- Is it a good idea to use drools rules to do a Nullchecks for chaining objects.
- Should I use something else like sequential rule execution (Not sure if that is available in Drools) which will allow me to execute the rules in specific order.
- Is there another way to achieve this