It appears that you want to reason about travel bookings or some such thing.<br><br>You are thinking of the various attributes as individual (abstract) things that<br>have a designation (such as "Adult Fare") and a value, with the intent to<br>
handle this with a set of facts, each of which has these two fields. While<br>this "property list" view of data may have its merits, it complicates the writing<br>of rules in system like Drools.<br><br>Moreover, keeping this data in a map is fine from the Java point of view, but it<br>
leads to complications while processing it in DRL rules. (To say nothing<br>about the poor performance due to eval all over the place.) I'm not sure<br>about the relation between your Java class RuleAttributes and the<br>
HashMap instance hmAttriList, but even if the latter were an instance<br>of the former (so it is a subclass of HashMap), it is questionable what<br>the $a.Values["..."] returns - most likely not an Integer, and this is<br>
confirmed by the compiler's error message.<br><br>Try to view a Booking as a Java Bean with attributes<br>int numberOfAdults<br>int numberOfChildren<br>int childFare<br>int adultFare<br>boolean rejected<br>and any other attribute of a booking you might want to put there.<br>
<br>Create an instance of this bean and add it to Working Memory.<br><br>A rule could now be written as<br><br>rule "adt_chld_fare"<br>no-loop true<br>when<br> $b: Booking( $af : adultFare, childFare > ($af - 1500) )<br>
then<br> modify( $b ){ setRejected( true ); }<br>end<br><br>There are many possible variations on this. Here is just one idea:<br><br>You might not want to have the rejection being stored in the Booking bean,<br>so you could, perhaps assert an instance of another suitably composed Bean<br>
class Rejection<br> Booking booking<br> String reason<br><br>Much of the design depends on what and how you need to get the results<br>of rule firing back to the application, so I won't continue.<br><br>-W<br>
<div class="gmail_quote">On Thu, Mar 19, 2009 at 7:52 AM, Nikhil_dev <span dir="ltr"><<a href="mailto:k.nikhil@verchaska.com" target="_blank">k.nikhil@verchaska.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;"><br>
i have combined all the rules into a single RuleBase,<br>
below is the content of drl file,<br>
<br>
package com.vtech.ruleengine.module.rulemanagermodule<br>
import com.vtech.ruleengine.module.rulemanagermodule.RuleAttributes;<br>
import java.util.Map;<br>
<br>
rule "adt_chld_fare"<br>
dialect "mvel"<br>
when<br>
$a : RuleAttributes()<br>
eval ($a.Values["Adult Fare"]> ($a.Values["Child Fare"]+ 1500 ) )<br>
then<br>
($a.Values["AcceptRejectFilter"]='Reject')<br>
end<br>
<br>
<br>
rule "DEMO_RULE"<br>
dialect "mvel"<br>
when<br>
$a : RuleAttributes()<br>
eval ($a.Values["Adult Fare"]> 8000 )<br>
then<br>
($a.Values["Nett Payable"]= ($a.Values["Adult Fare"]* 0.80 ) )<br>
end<br>
<br>
<br>
rule "Compare_date_1"<br>
dialect "mvel"<br>
when<br>
$a : RuleAttributes()<br>
eval ('12-Jan-2009'>='15-Jan-2008')<br>
then<br>
($a.Values["Adult Fare"]= 5000 )<br>
end<br>
<br>
<br>
rule "Rule_20090106_1"<br>
dialect "mvel"<br>
when<br>
$a : RuleAttributes()<br>
eval ( ($a.Values["No Of Adults"]< 10 ) && ($a.Values["No Of<br>
Adults"]> 5 ) )<br>
then<br>
($a.Values["Adult Fare"]= ($a.Values["Adult Fare"]+ -50 ) )<br>
end<br>
<br>
<br>
rule "Rule_20090107_Markup"<br>
dialect "mvel"<br>
when<br>
$a : RuleAttributes()<br>
eval ($a.Values["markupPerc"]>= 0 )<br>
then<br>
($a.Values["markupAmount"]=<br>
($a.Values["buyingAmount"]*$a.Values["markupPerc"]) )<br>
end<br>
<br>
<br>
rule "Sample_Rule"<br>
dialect "mvel"<br>
when<br>
$a : RuleAttributes()<br>
eval ($a.Values["Sector"]< 0 )<br>
then<br>
($a.Values["Via"]= ($a.Values["Via1"]+ 1250 ) )<br>
end<br>
<br>
i am passing following hashmap containing,<br>
hmAttriList.put("Adult Fare", 8000);<br>
hmAttriList.put("Child Fare", 80);<br>
hmAttriList.put("Gross Fare", 0);<br>
hmAttriList.put("Published Fare", 0);<br>
<br>
while executing it i am getting following error message<br>
SEVERE [global]<br>
org.mvel.CompileException: could not perform numeric operation on<br>
non-numeric types: left-type=null; right-type=java.lang.Integer<br>
at<br>
org.mvel.math.IEEEFloatingPointMath.doOperationNonNumeric(IEEEFloatingPointMath.java:149)<br>
at<br>
org.mvel.math.IEEEFloatingPointMath._doOperations(IEEEFloatingPointMath.java:102)<br>
at<br>
org.mvel.math.IEEEFloatingPointMath.doOperation(IEEEFloatingPointMath.java:43)<br>
at org.mvel.util.ParseTools.doOperations(ParseTools.java:810)<br>
at<br>
org.mvel.ast.BinaryOperation.getReducedValueAccelerated(BinaryOperation.java:21)<br>
at org.mvel.ExecutableAccessor.getValue(ExecutableAccessor.java:45)<br>
at<br>
org.mvel.ast.Substatement.getReducedValueAccelerated(Substatement.java:24)<br>
.............<br>
..............<br>
==>[ActivationCreated(0): rule=adt_chld_fare;<br>
tuple=[fid:1:1:com.vtech.ruleengine.module.rulemanagermodule.RuleAttributes@14a0fe1]<br>
]<br>
Error Message : org.mvel.CompileException: could not perform numeric<br>
operation on non-numeric types: left-type=null; right-type=java.lang.Integer<br>
<br>
<br></blockquote></div><br>