I am using drools 6.5.0.Final to create my drools project. I am trying to use the guided decision tables (.gdst) in the workbench. I want to use some java code in the WHEN and THEN part of the rules, like I am allowed to in the .drl files, like below:
rule "filter rule"
when
//conditions
$Cp : CpClass( name == "Tom",
Math.abs(score) > 10
&&
// How do I use functions like below?
($Cp.parseTime(CurrTime).getTime() -
$Cp.parseTime(PrevTime).getTime())/1000 > 120
)
then
//actions
System.out.println("Rule passed for : "+ $Cp.toString());
$Cp.isGoodCp = true;
end
The object used in the above example:
public class CpClass {
public String name;
public String currTime;
public String prevTime;
public boolean isGoodCp = false;
// Function to parse string to date
public Date parseTime(String time) {
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
Date parsedDate = null;
try {
if(time != null)
parsedDate = sdf.parse(time.substring(11));
else
parsedDate = sdf.parse("00:00:00");
} catch (Exception e) {
System.out.println("Error parsing:"+e);
}
return parsedDate;
}
}
Is there a way to use the user-defined/built-in java functions like I have here in a guided decision table?
$tickCp
,CurrTime
andPrevTime
? Which of the values do you want to vary in the rows of your decision table? Have you thought about hiding the "Java functions" as methods of classCpClass
? – launeCurrTime
andPrevTime
are members of the user defined classCpClass
, andCp
is an object of the same. If I make the functions a method of the Class, likeparseTime()
will I be able to use it in a guided table? – ar7