<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:arial,helvetica,sans-serif;font-size:10pt"><div style="font-family: arial,helvetica,sans-serif; font-size: 10pt;">Hi,<br><br>I'll try to explain my case...<br>I have an Object which has around 90 fields. For each of these fields, there can be unlimited validations that needs to be made. By unlimited, I mean that the user can create rules for each specific field. So not all rules are applicable to all fields. The objects I'm placing on the Map are the field structure of the 90 fields. These are things like the maxlength, mandatory/optional, alphanumeric/numeric of each field.<br>Here is a sample code wherein I just used the Map in the <span style="font-style: italic;">then clause...</span><br><br>==================<br><br><span style="font-family: courier,monaco,monospace,sans-serif;">global java.util.HashMap recordTypeMap;</span><br
style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;">global java.util.TreeMap structMap;</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;">global java.util.ArrayList structList;</span><br><br><font size="1"><span style="font-family: courier,monaco,monospace,sans-serif;">function CDRError setCDRError(RaCdrMoc cdr, CDRError cdrError, TreeMap structMap, </span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;"> String fieldName, String errorType, String editedValue, boolean autoCorrected) {</span><br style="font-family: courier,monaco,monospace,sans-serif;"><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;"> cdrError = new
CDRError();</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;"> </span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;"> cdrError.setCdrUploadId(cdr.getId().getCdruploadId());</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;"> cdrError.setCdrNo(cdr.getId().getCdrNo());</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;"> cdrError.setCdrType(0); </span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;"> </span><br style="font-family:
courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;"> RaCdrStructure cdrStructure = new RaCdrStructure();</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;"> cdrStructure = (RaCdrStructure) structMap.get(fieldName); </span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;"> cdrError.setFieldNo(cdrStructure.getId().getFieldNo()); </span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;"> cdrError.setErrorType(errorType); </span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family:
courier,monaco,monospace,sans-serif;"> cdrError.setEditedFieldValue(editedValue);</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;"> cdrError.setAutoCorrected(autoCorrected); </span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;"> </span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;"> return cdrError;</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;">}</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;"> </span><br style="font-family:
courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;">rule "MOC Check Missing Filename"</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;"> when</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;"> cdr : RaCdrMoc(mocflnm == ""); //this is the Object with 90 fields</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;"> cdrError : CDRError(); //the resulting object that will be added to the list</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;"> errorList :
LinkedList(); //all errors will be placed here</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;"> cdrStructure : RaCdrStructure();</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;"> then</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;"> System.out.println("========No filename================"); </span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;"> cdr.setMocflnm("Testfile.csv"); </span><br style="font-family:
courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;"> cdrError = setCDRError(cdr, cdrError, structMap, "MOCFLNM", "01", "Testfile.csv", true);</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;"> errorList.addLast(cdrError);</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;">end</span></font><br>=========================<br><br>My other rules would require the accessing of Hashmaps from the <span style="font-style: italic;">when </span>clause. IWould there be a need to change my data model <br><br>Thanks a lot,<br><br>shaz<br><br><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;">----- Original Message ----<br>From: "Anstis, Michael (M.)"
<manstis1@ford.com><br>To: Rules Users List <rules-users@lists.jboss.org><br>Sent: Friday, November 2, 2007 5:20:38 PM<br>Subject: RE: [rules-users] Accessing maps (hashmaps) keys and values in rules<br><br>
<style type="text/css">DIV {
MARGIN:0px;}
</style>
<div dir="ltr" align="left"><span class="448075808-02112007"><font color="#0000ff" face="Arial" size="2">IMHO you should still think about putting the Map values
into working memory.</font></span></div>
<div dir="ltr" align="left"><span class="448075808-02112007"><font color="#0000ff" face="Arial" size="2"></font></span> </div>
<div dir="ltr" align="left"><span class="448075808-02112007"><font color="#0000ff" face="Arial" size="2">This would both simplify your rules and make their
execution faster (eval cannot be indexed, if I remember
correctly).</font></span></div>
<div dir="ltr" align="left"><span class="448075808-02112007"><font color="#0000ff" face="Arial" size="2"></font></span> </div>
<div dir="ltr" align="left"><span class="448075808-02112007"><font color="#0000ff" face="Arial" size="2">You might need to adapt your data model representation into
one that is more efficient for use in a RETE network.</font></span></div>
<div dir="ltr" align="left"><span class="448075808-02112007"><font color="#0000ff" face="Arial" size="2"></font></span> </div>
<div dir="ltr" align="left"><span class="448075808-02112007"><font color="#0000ff" face="Arial" size="2">Can you explain your use case to help understand? Unless
you have very good reason to keep the facts in the Map your life will be more
difficult than it need be.</font></span></div>
<div dir="ltr" align="left"><span class="448075808-02112007"><font color="#0000ff" face="Arial" size="2"></font></span> </div>
<div dir="ltr" align="left"><span class="448075808-02112007"><font color="#0000ff" face="Arial" size="2">An "eval" returns a boolean indiciating whether the
"pattern" matched and therefore, whilst you can reference other bound LHS facts,
you cannot bind other objects to variables.</font></span></div>
<div dir="ltr" align="left"><span class="448075808-02112007"><font color="#0000ff" face="Arial" size="2"></font></span> </div>
<div dir="ltr" align="left"><span class="448075808-02112007"><font color="#0000ff" face="Arial" size="2">Thanks,</font></span></div>
<div dir="ltr" align="left"><span class="448075808-02112007"><font color="#0000ff" face="Arial" size="2"></font></span> </div>
<div dir="ltr" align="left"><span class="448075808-02112007"><font color="#0000ff" face="Arial" size="2">Mike</font></span></div><br>
<blockquote style="margin-right: 0px;">
<div class="OutlookMessageHeader" dir="ltr" align="left" lang="en-us">
<hr tabindex="-1">
<font face="Tahoma" size="2"><b>From:</b> rules-users-bounces@lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] <b>On Behalf Of
</b>shaz<br><b>Sent:</b> 02 November 2007 02:32<br><b>To:</b> Rules Users
List<br><b>Subject:</b> Re: [rules-users] Accessing maps (hashmaps) keys and
values in rules<br></font><br></div>
<div></div>
<div style="font-size: 10pt; font-family: arial,helvetica,sans-serif;">
<div style="font-size: 10pt; font-family: arial,helvetica,sans-serif;">Hi,
<br><br>I am placing objects in the Hashmap that were retrieved from the
database. There are currently a hundred objects that I'm storing in the
HashMap. I just made a simple example earlier :) . What works for me now is
putting the getting of the values in the eval(). However, I don't know how to
assign the values that I've taken from the Map.<br><br>eval( (
(MyClass)mapOfObj.get("keyOfObj")).getId() > 30);<br><br>How do I assign
(MyClass)mapOfObj.get("keyOfObj") to a
variable?<br><br><br>tnx,<br><br>shaz<br><br><br>
<div style="font-size: 12pt; font-family: times new roman,new york,times,serif;">-----
Original Message ----<br>From: "Anstis, Michael (M.)"
<manstis1@ford.com><br>To: Rules Users List
<rules-users@lists.jboss.org><br>Sent: Friday, November 2, 2007 12:17:51
AM<br>Subject: RE: [rules-users] Accessing maps (hashmaps) keys and values in
rules<br><br>
<div dir="ltr" align="left"><span class="886131616-01112007"><font color="#0000ff" face="Arial" size="2">By way of example (if you misunderstand how the rule
engine should be used):-</font></span></div>
<div dir="ltr" align="left"><span class="886131616-01112007"><font color="#0000ff" face="Arial" size="2"></font></span> </div>
<div><font color="#0000ff"><font size="2"><font face="Courier New">rule
chkobj<br>when<br><span class="886131616-01112007"> $o :
</span>MyClass(<span class="886131616-01112007"> </span>id == "1"<span class="886131616-01112007">, </span><span class="886131616-01112007">n</span>ame == "name"<span class="886131616-01112007">
)</span></font></font></font></div>
<div><span class="886131616-01112007"></span><span class="886131616-01112007"></span><font color="#0000ff" size="2"><font face="Courier New">t<span class="886131616-01112007">hen</span></font></font></div>
<div><font size="-0"><span class="886131616-01112007"></span><font color="#0000ff"><font face="Courier New" size="2"><span class="886131616-01112007"> //Do something
else</span></font></font></font></div>
<div><font size="-0"><font size="-0"><span class="886131616-01112007"></span><font color="#0000ff"><font face="Courier New" size="2"><span class="886131616-01112007">
$o.doSomething();</span></font></font></font></font></div>
<div><font size="-0"><font size="-0"><font size="-0"><font size="-0"><font size="-0"><font size="-0"><span class="886131616-01112007"></span><span class="886131616-01112007"></span><font color="#0000ff" face="Courier New" size="2">e<span class="886131616-01112007">nd</span></font></font></font></font></font></font></font></div><br>
<blockquote style="margin-right: 0px;">
<div class="OutlookMessageHeader" dir="ltr" align="left" lang="en-us">
<hr tabindex="-1">
<font face="Tahoma" size="2"><b>From:</b> rules-users-bounces@lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] <b>On Behalf Of </b>Edson
Tirelli<br><b>Sent:</b> 01 November 2007 15:48<br><b>To:</b> Rules Users
List<br><b>Subject:</b> Re: [rules-users] Accessing maps (hashmaps) keys and
values in rules<br></font><br></div>
<div></div><br> Shaz,<br><br> We strongly advise you
to move to 4.0.3, but this is not related to your problem. <br>
I think you are misunderstanding something. Why are you using the global map
to store your fact? Simply insert it into the working memory and it will
work fine. <br><br> []s<br> Edson<br><br><br>
<div><span class="gmail_quote">2007/11/1, Shaz Tumulak <<a rel="nofollow" ymailto="mailto:shauii@yahoo.com" target="_blank" href="mailto:shauii@yahoo.com">shauii@yahoo.com</a>>:</span>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>Hi,<br><br>I
can't seem to make this syntax work in Drools 4.0.2. Pls. see my
sample<br>code below.<br>________________________________________<br>class
MyClass {<br> String
id;<br> String
name;<br><br> MyClass(String
id, String
name){<br> <a rel="nofollow" target="_blank" href="http://this.id">this.id</a> =
id;<br> <a rel="nofollow" target="_blank" href="http://this.name">this.name</a> =
name;<br> }<br> :<br> getter,
setter methods
<br> :<br>}<br><br>MyClass
obj = new MyClass("1"", "name");<br><br>TreeMap<String, MyClass>
mapOfObj = new TreeMap<String,
MyClass>();<br>mapOfObj.put("keyOfObj", obj);
<br>________________________________________<br><br>DRL
file<br>-------<br><br>global java.util.TreeMap mapOfObj;<br><br>rule
chkobj<br>when<br> obj :
MyClass(mapOfObj["keyOfObj"].id ==
"1");<br> eval(obj.getName()
== "name");<br>________________________________________<br><br>I'm getting
this error:
org.drools.RuntimeDroolsException:<br>java.lang.NullPointerException<br> at
<br>org.drools.rule.EvalCondition.isAllowed(EvalCondition.java:76)<br><br>Is
my syntax correct and has someone used this in 4.0.2 or should I move
on<br>to Drools 4.0.3? Thanks in
advance.<br><br>Regards,<br><br>shaz<br><br><br>Edson Tirelli-3
wrote:<br>><br>> Denis,<br>><br>> If
you are using latest build from trunk (I'm not sure it already
works<br>> in MR3), you can use a simplified MVEL
syntax:<br>><br>> when <br>> Person(
address["business"].phone == "99999999" )<br>>
then<br>> ...<br>>
end<br>><br>> Although, the above will be
converted into an inline-eval. Not as bad<br>> as <br>> a top level
eval, but still more costly then using regular
fields.<br>><br>> []s<br>> Edson<br>><br>>
2007/7/19, Ryan, Dennis (Dennis) <<a rel="nofollow" ymailto="mailto:dennisryan@avaya.com" target="_blank" href="mailto:dennisryan@avaya.com">dennisryan@avaya.com
</a>>:<br>>><br>>> We are using Maps (HashMaps)
in our rules and the only way we have found<br>>> to access keys and
values in the Map in the "when" clauses is thru use on<br>>> eval()
which I know is a big no-no by rules purists. Is there a better
<br>>> way,<br>>> maybe some shorthand I'm not familiar with
to deal with Maps in the when<br>>>
clause?<br>>><br>>><br>>><br>>>
Thanks,<br>>><br>>> Dennis<br>>> <br>>>
_______________________________________________<br>>> rules-users
mailing list<br>>> <a rel="nofollow" ymailto="mailto:rules-users@lists.jboss.org" target="_blank" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>>>
<a rel="nofollow" target="_blank" href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>>><br>>><br>><br>><br>>
--<br>> Edson Tirelli<br>> Software Engineer
- JBoss Rules Core Developer<br>> Office: +55 11 3529-6000
<br>> Mobile: +55 11 9287-5646<br>> JBoss, a
division of Red Hat @ <a rel="nofollow" target="_blank" href="http://www.jboss.com">www.jboss.com</a><br>><br>>
_______________________________________________<br>> rules-users
mailing list <br>> <a rel="nofollow" ymailto="mailto:rules-users@lists.jboss.org" target="_blank" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>>
<a rel="nofollow" target="_blank" href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>>
<br>><br><a rel="nofollow" ymailto="mailto:shauii@yahoo.com" target="_blank" href="mailto:shauii@yahoo.com">shauii@yahoo.com</a><br>--<br>View this
message in context: <a rel="nofollow" target="_blank" href="http://www.nabble.com/Accessing-maps-%28hashmaps%29-keys-and-values-in-rules-tf4112197.html#a13524477">http://www.nabble.com/Accessing-maps-%28hashmaps%29-keys-and-values-in-rules-tf4112197.html#a13524477
</a><br>Sent from the drools - user mailing list archive at <a rel="nofollow" target="_blank" href="http://Nabble.com">Nabble.com</a>.<br><br>_______________________________________________<br>rules-users
mailing list<br><a rel="nofollow" ymailto="mailto:rules-users@lists.jboss.org" target="_blank" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br><a rel="nofollow" target="_blank" href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a><br></blockquote></div><br><br clear="all"><br>-- <br> Edson Tirelli <br> Software
Engineer - JBoss Rules Core Developer<br> Office: +55 11
3529-6000<br> Mobile: +55 11 9287-5646<br> JBoss, a
division of Red Hat @ <a rel="nofollow" target="_blank" href="http://www.jboss.com">www.jboss.com</a> </blockquote></div><br></div></div><br>
<hr size="1">
<font face="Arial" size="-1">Platonic friends of the opposite sex - the real
deal?<br>Be a better buddy<br><a rel="nofollow" target="_blank" href="http://ph.answers.yahoo.com/dir/index;_ylt=AsCq4OcgSoQ9qZZdke2cnGhL5Qt.;_ylv=3?link=over&sid=396545433">Find
out at Yahoo! Answers</a></font> </blockquote></div><br></div></div><br>
<hr size="1"><FONT face=Arial size=-1>
Tired of spam? Yahoo! Mail has the best spam protection around<BR>
<a href="http://sg.rd.yahoo.com/mail/ph/footer/def/*http://ph.mail.yahoo.com ">http://ph.mail.yahoo.com</a></FONT></body></html>