Hi,
I was trying out the following simple program to do some tests with drools 6.3.0.Final:
// the rule
def drl = '''
dialect "mvel"
rule "Person is over 18"
when
$person : Person(age > 18)
then
System.out.println("Person is "+$person.name);
end
'''
// setup for rule
KieServices kieServices = KieServices.Factory.get()
KieFileSystem kfs = kieServices.newKieFileSystem()
kfs.write( "src/main/resources/simple.drl",
kieServices.getResources().newReaderResource( new StringReader(drl) ) )
KieBuilder kieBuilder = kieServices.newKieBuilder( kfs ).buildAll()
// check there have been no errors for rule setup
Results results = kieBuilder.getResults();
if( results.hasMessages( Message.Level.ERROR ) ){
println( results.getMessages() )
throw new IllegalStateException( "### errors ###" )
}
KieContainer kieContainer =
kieServices.newKieContainer( kieBuilder.getKieModule().getReleaseId() )
KieSession kieSession = kieContainer.newKieSession()
// insert facts and fire rules
kieSession.insert(new Person("Jon Doe", 21))
kieSession.insert(new Person("Jon Darcy", 1))
kieSession.fireAllRules()
kieSession.dispose()
@Immutable
class Person {
String name
int age
}
I managed to get a rule like this firing:
rule hello
when then
System.out.println( "Hello!" );
end
But the rule "Person is over 18" above never fires. I can see by using eventlistener and logger, that adding the Person objects asserts them. I can ensure the rule is actually seen, by changing it to something invalid.But I cannot get the rule to fire. I also found out, that if I use "normal" java classes, that this works. My testing also shows that the Person class is found by Drools and the properties are seen. Still it does not work. Can it be, that there is something in the layout of the Person class that gives drools a problem? For example the metaClass property Groovy adds to every class? Or any of the synthethic methods Groovy adds? Is anybody aware of such problems? Or is this a bug in Drools 6.3.0.FINAL and a different version would work? If yes which?
Thanks for helping,
Jochen