0
votes

Is there any easier way to handle Null checks for parameters when using decision tables in drools? What i am trying to do is to migrate certain business rules in java to drools and so happens that the data is abstracted into multiple layers of objects. So unless i do a null check on them i am not able to proceed. Any suggestions are welcome. The business rule that i want to move to a decision table is of the form:

> When   new A().getB().getC().getData() > 0  then 
> System.out.println("Result found");

Its just too much of a pain to write a condition corresponding to null check of every field

Thanks in Advance.

1

1 Answers

0
votes

The existence of an object is a fundamental prerequisite for accessing its attributes. Thus, Drools isn't any worse than your run-of-the-mill Java code. Any technique that works in Java code is also applicable in Drools.

One simple way around this problem in Java is to introduce a method in class A: boolean isBCDataPositive().

Using Drools you can also write rules that will not proceed to evaluate when an object isn't present, e.g.

rule "is b.c.data positive"
when
    A( $b: B )
    B( this == $b, $c: c )
    C( this == $c, data > 0 )
then ... end

This requires the insertion of the contained objects A.b, A.b.c, provided they exist, but the rule will obviously be simple, also when using the spreadsheet notation.