I need to implement a simple rules engine with hierarchical fallback support. I have already looked into the DROOLS library but I am not sure if it supports my use case.
The use case is rather simple which makes me thinking whether I need a rules engine at all? Nevertheless, here is the use case -
I have a modal with bunch of fields
Public Class Entity {
public int val0;
public int val1;
public int val2;
public int val3;
.....
}
Now, I want to create rules against these fields as follow
RULE1 --- IF val0 == 1 && val1 == 1 && val2 == 1 && val3 == 1 --- (1,1,1,1) THEN DO this
RULE2 --- IF val0 == 1 && val1 == 1 && val2 == 1 && val3 == 2, --- (1,1,1,2) THEN DO this
RULE3 --- IF val0 == 1 && val1 == 1 && val2 == 1 && val3 == *, --- (1,1,1,*) THEN DO this
RULE4 --- IF val0 == 1 && val1 == 1 && val2 == * && val3 == *, --- (1,1,*,*) THEN DO this
The problem is with RULE3 and RULE4 where val2 and val3 can match any value.
e.g.
val0=1, val1=1, val2=1, val3=1 -- should execute RULE1 - specific match
val0=1, val1=1, val2=1, val3=3 -- should execute RULE3 - generic match as there's no specific match for val3
val0=1, val1=1, val2=10, val3=5 -- should execute RULE4 - generic match as there's no specific match for val2 and val3
So depending on the query, either I will find the matching rule or I will have to fallback to the more generic rules. Is there any existing rules engine library that provides this functionality or rather do I even need a rules engine library to implement this functionality?