Please use the new "knowledge" API for compiling and building a knowledge (not: rule) base.<br><br>This bug has been fixed for 5.3.0. It is one of several that may occur when you use 5.2.0 and deviate from the constraint syntax as defined with 5.1.1.<br>
<br>-W<br><br><br><div class="gmail_quote">On 26 September 2011 22:51, matvey1414 <span dir="ltr"><<a href="mailto:matvey1414@gmail.com">matvey1414@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi,<br>
<br>
I am working with Drools to implement a high-profile rules-engine. I have<br>
two rules defined. Clearly, only the first should fire, but both do. Here is<br>
my DRL:<br>
<br>
<br>
package com.sample<br>
<br>
import com.sample.DroolsTest.Request;<br>
<br>
rule "ExpensiveCanonShopper0"<br>
when<br>
Request( attributeMap["camera0"] == "canon" &&<br>
attributeMap["price0"] >= 500 )<br>
then<br>
System.out.println("ExpensiveCanonShopper0");<br>
end<br>
<br>
rule "ExpensiveCanonShopper1"<br>
when<br>
Request( attributeMap["camera1"] == "canon" &&<br>
attributeMap["price1"] >= 500 )<br>
then<br>
System.out.println("ExpensiveCanonShopper1");<br>
end<br>
<br>
And the Java class to execute it:<br>
<br>
public class DroolsTest {<br>
<br>
@SuppressWarnings({ "rawtypes", "unchecked" })<br>
public static final void main(String[] args) {<br>
try {<br>
//Loading the Rules<br>
System.out.println("Loading rules");<br>
RuleBase ruleBase = readRule();<br>
StatelessSession workingMemory =<br>
ruleBase.newStatelessSession();<br>
<br>
System.out.println("Firing rules");<br>
<br>
Map map = new HashMap();<br>
map.put("camera0", "canon");<br>
map.put("price0", 600);<br>
<br>
Request request = new Request();<br>
request.setAttributeMap(map);<br>
workingMemory.execute(request);<br>
<br>
} catch (Throwable t) {<br>
t.printStackTrace();<br>
}<br>
}<br>
<br>
/**<br>
* Please note that this is the “low level” rule assembly API.<br>
*/<br>
private static RuleBase readRule() throws Exception {<br>
//read in the source<br>
Reader source = new FileReader(new File("drl",<br>
"Generated.drl"));<br>
<br>
//optionally read in the DSL (if you are using it).<br>
//Reader dsl = new InputStreamReader(<br>
DroolsTest.class.getResourceAsStream( “/mylang.dsl” ) );<br>
<br>
//Use package builder to build up a rule package.<br>
//An alternative lower level class called “DrlParser” can<br>
also be used…<br>
<br>
PackageBuilder builder = new PackageBuilder();<br>
<br>
//this wil parse and compile in one step<br>
//NOTE: There are 2 methods here, the one argument one is<br>
for normal DRL.<br>
builder.addPackageFromDrl( source );<br>
if (builder.hasErrors()) {<br>
PackageBuilderErrors errors = builder.getErrors();<br>
throw new RuntimeException("Error adding package to<br>
builder: " + errors.toString());<br>
}<br>
<br>
//Use the following instead of above if you are using a DSL:<br>
//builder.addPackageFromDrl( source, dsl );<br>
<br>
//get the compiled package (which is serializable)<br>
Package pkg = builder.getPackage();<br>
<br>
//add the package to a rulebase (deploy the rule package).<br>
RuleBase ruleBase = RuleBaseFactory.newRuleBase();<br>
ruleBase.addPackage( pkg );<br>
return ruleBase;<br>
}<br>
<br>
public static class Request {<br>
private Map attributeMap;<br>
<br>
public Map getAttributeMap() {<br>
return attributeMap;<br>
}<br>
<br>
public void setAttributeMap(Map attributeMap) {<br>
this.attributeMap = attributeMap;<br>
}<br>
}<br>
}<br>
<br>
The output is this, meaning both rules fired:<br>
Loading rules<br>
Firing rules<br>
ExpensiveCanonShopper1<br>
ExpensiveCanonShopper0<br>
<br>
I have two questions:<br>
<br>
1. Is this a bug, or am I doing something wrong? Only<br>
"ExpensiveCanonShopper0" should fire.<br>
<br>
2. I am pretty sure this is somehow related to the fact that I'm using Map<br>
attributes, and not POJO to get "price0" and "camera0". My issue is that I<br>
won't know the parameters in advance (they are coming in a URL), so I can't<br>
pre-declare them, and thus need something dynamic like a Map. Is this how<br>
Drools is intended to be used? The documentation appears very POJO-centric.<br>
<br>
I am using Drools 5.2<br>
<br>
Thank you!<br>
-Matt<br>
<font color="#888888"><br>
--<br>
View this message in context: <a href="http://drools.46999.n3.nabble.com/Unsatisfied-rule-fires-Drools-bug-tp3370653p3370653.html" target="_blank">http://drools.46999.n3.nabble.com/Unsatisfied-rule-fires-Drools-bug-tp3370653p3370653.html</a><br>
Sent from the Drools: User forum mailing list archive at Nabble.com.<br>
<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</font></blockquote></div><br>