Problems with rules accessing nested properties

280 views
Skip to first unread message

Alena Bayanova

unread,
Aug 3, 2015, 11:45:04 AM8/3/15
to Drools Usage
Hi,

i have troubles with rules accessing nested properties of my objects. Here simple use case showing the problem:

Data-Structure:
package test;

public class A {
    public B b = new B();
}

public class B {
    public int b1=1;
    public int b2=2;
    public int b3=3;
}


Rules:
package rules

rule "One"
when test.A(b.b1==1)
then
    System.out.println("One");
end

rule "Two"
when  test.A(b.b2==2)
then
    System.out.println("Two");
end

rule "Three"
when  test.A(b.b3==3)
then
    System.out.println("Three");
end

Program launching the test:
package com.sample;

import org.kie.api.KieServices;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;

import test.A;

/**
 * This is a sample class to launch a rule.
 */
public class DroolsTest {

    public static final void main(String[] args) {
        KieServices ks = KieServices.Factory.get();
        KieContainer kContainer = ks.getKieClasspathContainer();
        KieSession kSession = kContainer.newKieSession("ksession-rules");

        kSession.insert(new A());

        int fireAllRules = kSession.fireAllRules();
        System.out.println("Fired:" + fireAllRules);

    }

}

After running the program i see that only the rule "One" has fired. I would expect, that all the rules fire. Do i anything wrong?

Thanks!

Mario Fusco

unread,
Aug 3, 2015, 1:33:46 PM8/3/15
to drools...@googlegroups.com
Hi Alena,

this was indeed a bug. I reported it here https://issues.jboss.org/browse/DROOLS-870 and fixed it with this commit https://github.com/droolsjbpm/drools/commit/cda8e1d22

Thanks for having reported this,
Mario

--
You received this message because you are subscribed to the Google Groups "Drools Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage...@googlegroups.com.
To post to this group, send email to drools...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-usage/cbca2e67-6f98-4eee-bf7d-497089b8ff8a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alena Bayanova

unread,
Aug 4, 2015, 3:00:01 AM8/4/15
to Drools Usage
Cool, thank you!
Reply all
Reply to author
Forward
0 new messages