[
https://jira.jboss.org/jira/browse/JBRULES-2274?page=com.atlassian.jira.p...
]
Brian DeCamp updated JBRULES-2274:
----------------------------------
Description:
When combining deep facts and nested 'or' statements, rules do not fire. I've
reduced the problem as much as possible with the following example:
Note: I've used 'eval(true)' in this example, but it also happens with any
expression that evaluates to true in the or clause.
------- begin test.drl --------
rule "find one and two with 'or' clause - WORKS"
when
com.xyz.SimpleFact(name == "one");
(eval(true) or eval(true));
com.xyz.SimpleFact(name == "two");
then
System.out.println("found one and two with 'or' clause");
end
rule "Deep one and two without 'or' - WORKS"
when
d1: com.xyz.DeepFact();
com.xyz.SimpleFact(name=="one") from d1.simple;
d2: com.xyz.DeepFact();
com.xyz.SimpleFact(name=="two") from d2.simple;
then
System.out.println("Found deep facts with simple facts one and two without
'or' clause");
end
rule "Deep one and two with nested 'or' - FAILURE!!!"
when
d1: com.xyz.DeepFact();
com.xyz.SimpleFact(name=="one") from d1.simple;
(eval(true) or eval(true));
d2: com.xyz.DeepFact();
com.xyz.SimpleFact(name=="two") from d2.simple;
then
System.out.println("THIS DOES NOT FIRE");
end
-------end test.drl --------
------- begin DeepFact.java --------
package com.xyz;
public class DeepFact {
private SimpleFact simple;
public SimpleFact getSimple() {
return simple;
}
public void setSimple(SimpleFact simple) {
this.simple = simple;
}
}
------- end DeepFact.java --------
------- begin SimpleFact.java --------
package com.xyz;
public class SimpleFact {
private String name;
public SimpleFact() {}
public SimpleFact(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
------- end SimpleFact.java --------
------- begin test code-------
public void testRules() {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
org.drools.io.Resource ruleResource;
try {
ruleResource = ResourceFactory.newInputStreamResource(new
FileInputStream("test.drl"));
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
kbuilder.add(ruleResource, ResourceType.DRL);
if ( kbuilder.hasErrors() ) {
System.err.println( kbuilder.getErrors().toString() );
}
Collection<KnowledgePackage> compiledPackages =
kbuilder.getKnowledgePackages();
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(compiledPackages);
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
// Insert facts
ksession.insert(new SimpleFact("one"));
ksession.insert(new SimpleFact("two"));
DeepFact d1 = new DeepFact();
d1.setSimple(new SimpleFact("one"));
ksession.insert(d1);
DeepFact d2 = new DeepFact();
d2.setSimple(new SimpleFact("two"));
ksession.insert(d2);
ksession.fireAllRules();
ksession.dispose();
}
------- end test code --------
was:
When combining deep facts and nested 'or' statements, rules do not fire. I've
reduced the problem as much as possible with the following example:
------- begin test.drl --------
rule "find one and two with 'or' clause - WORKS"
when
com.xyz.SimpleFact(name == "one");
(eval(true) or eval(true));
com.xyz.SimpleFact(name == "two");
then
System.out.println("found one and two with 'or' clause");
end
rule "Deep one and two without 'or' - WORKS"
when
d1: com.xyz.DeepFact();
com.xyz.SimpleFact(name=="one") from d1.simple;
d2: com.xyz.DeepFact();
com.xyz.SimpleFact(name=="two") from d2.simple;
then
System.out.println("Found deep facts with simple facts one and two without
'or' clause");
end
rule "Deep one and two with nested 'or' - FAILURE!!!"
when
d1: com.xyz.DeepFact();
com.xyz.SimpleFact(name=="one") from d1.simple;
(eval(true) or eval(true));
d2: com.xyz.DeepFact();
com.xyz.SimpleFact(name=="two") from d2.simple;
then
System.out.println("THIS DOES NOT FIRE");
end
-------end test.drl --------
------- begin DeepFact.java --------
package com.xyz;
public class DeepFact {
private SimpleFact simple;
public SimpleFact getSimple() {
return simple;
}
public void setSimple(SimpleFact simple) {
this.simple = simple;
}
}
------- end DeepFact.java --------
------- begin SimpleFact.java --------
package com.xyz;
public class SimpleFact {
private String name;
public SimpleFact() {}
public SimpleFact(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
------- end SimpleFact.java --------
------- begin test code-------
public void testRules() {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
org.drools.io.Resource ruleResource;
try {
ruleResource = ResourceFactory.newInputStreamResource(new
FileInputStream("test.drl"));
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
kbuilder.add(ruleResource, ResourceType.DRL);
if ( kbuilder.hasErrors() ) {
System.err.println( kbuilder.getErrors().toString() );
}
Collection<KnowledgePackage> compiledPackages =
kbuilder.getKnowledgePackages();
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(compiledPackages);
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
// Insert facts
ksession.insert(new SimpleFact("one"));
ksession.insert(new SimpleFact("two"));
DeepFact d1 = new DeepFact();
d1.setSimple(new SimpleFact("one"));
ksession.insert(d1);
DeepFact d2 = new DeepFact();
d2.setSimple(new SimpleFact("two"));
ksession.insert(d2);
ksession.fireAllRules();
ksession.dispose();
}
------- end test code --------
Rule does not fire as expected using deep object model and nested
'or' clause
-----------------------------------------------------------------------------
Key: JBRULES-2274
URL:
https://jira.jboss.org/jira/browse/JBRULES-2274
Project: Drools
Issue Type: Bug
Security Level: Public(Everyone can see)
Components: drools-core (expert)
Affects Versions: 5.0.1.FINAL
Environment: Windows XP with JBoss 4.2.2GA using the 5.0.1 jars for core,
compiler and api.
Reporter: Brian DeCamp
Assignee: Mark Proctor
When combining deep facts and nested 'or' statements, rules do not fire. I've
reduced the problem as much as possible with the following example:
Note: I've used 'eval(true)' in this example, but it also happens with any
expression that evaluates to true in the or clause.
------- begin test.drl --------
rule "find one and two with 'or' clause - WORKS"
when
com.xyz.SimpleFact(name == "one");
(eval(true) or eval(true));
com.xyz.SimpleFact(name == "two");
then
System.out.println("found one and two with 'or' clause");
end
rule "Deep one and two without 'or' - WORKS"
when
d1: com.xyz.DeepFact();
com.xyz.SimpleFact(name=="one") from d1.simple;
d2: com.xyz.DeepFact();
com.xyz.SimpleFact(name=="two") from d2.simple;
then
System.out.println("Found deep facts with simple facts one and two without
'or' clause");
end
rule "Deep one and two with nested 'or' - FAILURE!!!"
when
d1: com.xyz.DeepFact();
com.xyz.SimpleFact(name=="one") from d1.simple;
(eval(true) or eval(true));
d2: com.xyz.DeepFact();
com.xyz.SimpleFact(name=="two") from d2.simple;
then
System.out.println("THIS DOES NOT FIRE");
end
-------end test.drl --------
------- begin DeepFact.java --------
package com.xyz;
public class DeepFact {
private SimpleFact simple;
public SimpleFact getSimple() {
return simple;
}
public void setSimple(SimpleFact simple) {
this.simple = simple;
}
}
------- end DeepFact.java --------
------- begin SimpleFact.java --------
package com.xyz;
public class SimpleFact {
private String name;
public SimpleFact() {}
public SimpleFact(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
------- end SimpleFact.java --------
------- begin test code-------
public void testRules() {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
org.drools.io.Resource ruleResource;
try {
ruleResource = ResourceFactory.newInputStreamResource(new
FileInputStream("test.drl"));
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
kbuilder.add(ruleResource, ResourceType.DRL);
if ( kbuilder.hasErrors() ) {
System.err.println( kbuilder.getErrors().toString() );
}
Collection<KnowledgePackage> compiledPackages =
kbuilder.getKnowledgePackages();
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(compiledPackages);
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
// Insert facts
ksession.insert(new SimpleFact("one"));
ksession.insert(new SimpleFact("two"));
DeepFact d1 = new DeepFact();
d1.setSimple(new SimpleFact("one"));
ksession.insert(d1);
DeepFact d2 = new DeepFact();
d2.setSimple(new SimpleFact("two"));
ksession.insert(d2);
ksession.fireAllRules();
ksession.dispose();
}
------- end test code --------
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira