Let's suppose we have these classes, which are also Hibernate entities, in a Java EE application:
public class A {
private String code;
private List<B> tests;
}
public class B {
private String code;
private List<C> steps;
}
public class C {
private String code;
private List<D> subSteps;
}
In last years, some Swing windows were created to let configurators users create ad deploy DRools packages rules in order to customize the workflow required by our customers. These windows, in some way, convert Swing components into Drool Mvel text to avoid configurators users writing raw code. These rules are then saved and deployed into their DB tables in BLOB fields and executed when required. The problem is that now we are required to implement a new hierarchy of facts on which to perform assertions to trigger rules. Using a fact of class A from my example code, this code is generated from our DRools windows:
rule "RULE_TRY"
dialect "mvel"
salience 10
enabled true
no-loop false
when
$a : A( )
$b : B( code == "testCode" ) from $a.tests
$c : C( code== "stepCode" ) from $a.tests.steps
then
end
It is clear that this rule and facts mirror our DB structure, where "code" is the PK or a FK in corresponding relative tables.
But this code causes a DRools error to be raised when package is compiled and deployed:
Unable to build expression for 'from' : Failed to compile: 1 compilation error(s): - (1,26) unqualified type in strict mode for: steps'$a.tests.steps' : [Rule name='RULE_TRY']
Maybe, is this the right syntax:
when
$a : A( )
$b : B( code == "testCode" ) from $a
$c : C( code== "stepCode" ) from $b
?
Because, considering Mvel code as a sort of getter/setter, I would expect that a syntax like from $a.tests
returns a List<B>
and only on a single B-ith element I could eval .steps
.
I don't know why rules are converted with that syntax, as there are too many EJBs without comment doing this in our core application, written by people who do not work with us anymore. But before correct them or write new ones for these requirements, I need to know if DRools can support an arbitrary nesting level with java List in facts and how to correctly access them, as it the first time our product has had to support these kinds of facts with many lists in rules.
Our version of DRools is 5.0.1
For the moment, I see that final String in DRL language is created by calling method dump()
on class DrlDumper
.
I think the syntax you are looking for is:
rule "RULE_TRY"
dialect "mvel"
salience 10
enabled true
no-loop false
when
$a : A( )
$b : B( code == "testCode" ) from $a.tests
$c : C( code== "stepCode" ) from $b.steps
then
//...
end
Hope it helps,