[rules-users] Issues with groovy fact objects not matching

Ilya Sterin sterini at gmail.com
Mon Oct 26 12:04:49 EDT 2009


I have a bit more info now, as I tested various scenarios.  Inferring
groovy based facts work fine when the class is present in the
classpath (statically), not when the class is dynamically compiled.  I
know for a fact that compilation works fine and that the classloader
makes that class available to drools, as without these custom steps
drools fails with issues loading the class of course.  With the
GroovyClassLoader present, classloading all works fine, except that
when the class is compiled at runtime, somehow predicate inferences do
not work.

Any ideas?

Ilya


On Sun, Oct 25, 2009 at 4:06 PM, Ilya Sterin <sterini at gmail.com> wrote:
> I have an application that dynamically compiles a groovy object with
> properties and uses it as a bean class.  The object is a statically
> defined object, though...
>
> package com.buycentives.types
> import com.buycentives.incengine.*
> class TestIncentive extends IncentiveData<MonetaryIncentive> {
>    String name
>    Integer age
> }
>
> The rules compile just fine, as I load the groovy class using a
> GroovyClassLoader and inject the groovy class loader like this...
>
> PackageBuilderConfiguration config = new PackageBuilderConfiguration();
> config.setClassLoader(loader);
> JavaDialectConfiguration dialectConf = (JavaDialectConfiguration)
> config.getDialectConfiguration("java");
> dialectConf.setCompiler(JavaDialectConfiguration.JANINO);
> KnowledgeBuilder kBldr = KnowledgeBuilderFactory.newKnowledgeBuilder(config);
> /// Here I add some rules to the builder...
> KnowledgeBase kb = KnowledgeBaseFactory.newKnowledgeBase(new
> RuleBaseConfiguration(loader));
> kb.addKnowledgePackages(kBldr.getKnowledgePackages());
>
>
> So the rule actually resolves the TestIncentive type just fine, but it
> never fires the side effect, as the pattern never seems to match.
>
> TestIncentive incentive = new TestIncentive();
> incentive.setAge(25);
>
> // Below never matches...
> $input: TestIncentive( age >= 20, age < 30 )
>
> I verify that the injected object actually has an age of 25...
>
> The crazy thing is, that this rule...
>
> $input: Object()
>
> matches the TestIncentive fact in the knowledge base and when I print
> out the object in the side effect, it's the same as the one injected,
> so it should match the pattern above just fine.
>
> The same rules work just fine when I use a plain Java object or if I
> declare a fact type in the drl file.
>
> Any ideas?
>
> Ilya Sterin
>




More information about the rules-users mailing list