I would like to create a new Date object representing the current date and use
that as a global. I have tried the following:
(in Java code)
setGlobal("todaysDate", new Date());
(in rules file)
global java.utils.Date todaysDate;
rule "LevelTwo: Associate birth date must be before today"
when
Associate(birthDt <= todaysDate)
then
System.out.println("Birth Date must be before today");
end
with this code I get the following error:
Error creating bean with name 'ruleBase' defined in class path resource
[spring-beans.xml]: Invocation of init method failed; nested exception is
org.drools.rule.InvalidRulePackage: org.drools.compiler.GlobalError@b51c29
Caused by: org.drools.rule.InvalidRulePackage:
org.drools.compiler.GlobalError@b51c29
at org.drools.rule.Package.checkValidity(Package.java:408)
at org.drools.common.AbstractRuleBase.addPackage
(AbstractRuleBase.java:288)
at com.sample.RuleBaseBeanFactory.afterPropertiesSet
(RuleBaseBeanFactory.java:63)
etc...
I have also tried to set a constant date with the date format that I found in
the Drools docs (dd-MMM-yyyy) like such:
statefulSession.setGlobal("todaysDate", "10-Jul-1974");
and I get the same error message.
The rule does work correctly when I hard code a value in place of todaysDate
within the rule so I know the rule works (but obviously that is not an option).
What is the proper way to set a Date global? Is it possible this is a bug?
Thanks in advance,
Brian Enderle