I need to be able to display all of the rules I have defined in a drl, what
the target value is, actual value and whether the rule fired or not. Below
is sample code and rule file to illustrate what I'm trying to do. The way I
attempted to do this was to read in the rule file using the DRL parser and
created a Rule object for each I found and set the name from the
RuleDescr.getName(). The name of the rule is the key in the Map of Rules in
TestClass. Then, I pass in my TestClass to the rule engine to evaluate the
rules. Everything works fine for the evaluation of the rule. But, I was
hoping to be able to keep all the logic of "greater than 5" or "less than
10" in the drl file itself, not having to duplicate in my client java code.
So, if the values needed to change or I added rules to the drl file I would
not have to change the client java code.
But, I do not see a way to set the target value on a rule unless it fires
(RHS). If it does not fire, then target value will not be set. If I want
to show a list of all the rules and target values, I cannot see a way to do
this in the drl alone. Any ideas?
Desired Output:
RuleName Target Actual Value In Compliance
______________________________________________________________________
Test Rule 1 > 5 5 6 True
Test Rule 2 < 10 10 12 False
________________________________________________________________________
package test
#list any import classes here.
import TestClass;
import Rule;
#declare any global variables here
rule "Test Rule 1"
when
testClass : TestClass(actualValue1 > 5)
then
Rule aRule = testClass.get(drools.getRule().getName());
aRule.setInCompliance(true);
aRule.setTargetValue(5);
end
rule "Test Rule 2"
when
testClass : TestClass(actualValue2 < 10)
then
Rule aRule = testClass.get(drools.getRule().getName());
aRule.setInCompliance(false);
aRule.setTargetValue(10);
end
________________________________________________________________________
public class TestClass
{
private double actualValue1 = 6;
private double actualValue2 = 12;
// Map of Rule objects keyed by rule name
private Map rules;
public Map getRules()
{
// rules initialized by using DrlParser and creating a Rule object for
each in the file
return rules;
}
public double getActualValue1()
{
return actualValue1;
}
public double getActualValue2()
{
return actualValue2;
}
}
public class Rule
{
private String ruleName;
private double targetValue;
private boolean inCompliance;
public boolean isInCompliance()
{
return inCompliance;
}
public void setInCompliance(boolean inCompliance)
{
this.inCompliance = inCompliance;
}
public String getRuleName()
{
return ruleName;
}
public void setTargetValue(double targetValue)
{
this.targetValue = targetValue;
}
}
--
View this message in context:
http://www.nabble.com/Display-rules-and-criteria-defined-in-DRL-tf2504324.html#a6982122
Sent from the drools - user mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email