Hi all,
I’ve been working with Drools DRL 8.44 and recently started experimenting with Rule Units. In my current implementation, the facts are dynamic — their classes are only known at runtime. To handle this, I’ve created a RuleFact class that wraps the actual fact as an Object.
In the traditional KieSession approach, I insert these wrapped facts using a BatchCommand before executing the session. Now, I’m trying to replicate a similar approach using Rule Units.
But I am unable to parse dataSources value in DRL. I am not able to find any example for such implementation, I took some inspiration from
https://github.com/kiegroup/drools/blob/main/drools-ruleunits/drools-ruleunits-dsl/src/main/java/org/drools/ruleunits/dsl/SyntheticRuleUnit.javaAny help on how I can do this.
Note:
I have many DRL that I load from DB. each DRL has its own facts. And use same RuleUnitData class for all using NamedRuleUnitData
##################
public class VirtualRuleUnit implements NamedRuleUnitData {
private final String unitName;
private final Map<String, DataSourceDefinition> dataSources;
VirtualRuleUnit(String unitName, Map<String, DataSourceDefinition> dataSources) {
this.unitName = unitName;
this.dataSources = dataSources;
}
@Override
public String getUnitName() {
return unitName;
}
public Map<String, DataSourceDefinition> getDataSources() {
return dataSources;
}
rule "Print SimpleFact per fact"
salience 0
when
$d : /dataSources
$sf : SimpleFact() from $d.get("SimpleFact")
then
System.out.println("Print SimpleFact per fact triggered." + $sf);
end