For the sake of clarification: Are you saying that there is, or should be, some magic which would make a constraint like<br> Map ( this["departureDate"] == "07-Jan-2009" )<br>behave as a comparison between two java.util.Date values if the LHS Object is of this type? And also if it is a GregorianCalendar object?<br>
<br>Since even you are "not sure" regarding MVEL: What is the definite reference for MVEL in Drools? I have a vague recollection of reading somewhere that not all of MVEL is available...<br><br>-W<br><br><br><div class="gmail_quote">
2009/11/8 Edson Tirelli <span dir="ltr"><<a href="mailto:ed.tirelli@gmail.com">ed.tirelli@gmail.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br> Ok, without discussing the merits of using (or not) maps, the reason you are having problems with dates is that the "string-based" date is syntax sugar in Drools parser/compiler. Although, when you create expressions using nested accessors or [] for collection/map element access, drools wraps the whole thing into an "eval" and delegates to MVEL. We do some transformations to bridge the gap between drools operators and mvel operators, but I don't think drools has anything to "transform" the string-based date into something mvel understands.<br>
<br> Having said that, we should probably add this functionality to the "MVELDumper" class for better integration. Would you please open a jira for that? Also, patches are welcome in case someone would like to help. This is an isolated part of the code and easy to understand.<br>
<br> Meanwhile, best you can do is avoid the use of this Map syntax + string-based dates, or write your expressions directly in a way the mvel understands (not sure mvel has a special syntax for dates).<br> <br> Same explanation for the NPE.<br>
<br> Edson<br><br><div class="gmail_quote">2009/11/8 Leonardo Gomes <span dir="ltr"><<a href="mailto:leonardo.f.gomes@gmail.com" target="_blank">leonardo.f.gomes@gmail.com</a>></span><div><div></div><div class="h5">
<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi Wolfgang,<br>
<br>
Here's the context:<br>
<br>
We're replacing a very basic home-made rule engine with drools. Today,<br>
fact data can be added dynamically b/c for all rules our fact is<br>
nothing more than a Map and we can register new fact data through an<br>
UI where you say what's the key and what's the type of the value.<br>
Rules can also be created dynamically and operate against those newly<br>
created attributes of my fact.<br>
<br>
Incoming requests are key / value structures and we have a service<br>
that will look at the list of registered fact data and try to find<br>
that information in the incoming request by looking for the keys and<br>
getting the corresponding values, then populating the Map I just<br>
talked about which will be injected in the working memory for<br>
evaluation against our rules.<br>
<br>
That's why, in Drools, I need to have my rules accessing data from a<br>
Map. By using MVEL, as I said, it works fine with strings, integers<br>
and list of strings, but I'm having problems with dates and would like<br>
some advice on that case.<br>
<br>
Here's another example of things that work:<br>
<br>
rule "test rule"<br>
when<br>
<div> Map ( this["airportCode"] == "GIG"<br>
, this["numberOfPassengers"] > 1<br>
</div> , this["class"] in ("BUSINESS", "FIRST CLASS") )<br>
then<br>
m.addMessage("rule matched");<br>
end<br>
<br>
And here's where I have problems,<br>
<br>
Map ( this["departureDate"] ) == "07-Jan-2009" )<br>
<br>
<br>
Thanks a lot,<br>
Leo.<br>
<div><div></div><div><br>
<br>
<br>
On Sun, Nov 8, 2009 at 10:56 AM, Wolfgang Laun <<a href="mailto:wolfgang.laun@gmail.com" target="_blank">wolfgang.laun@gmail.com</a>> wrote:<br>
> On Sat, Nov 7, 2009 at 6:00 PM, Leonardo Gomes <<a href="mailto:leonardo.f.gomes@gmail.com" target="_blank">leonardo.f.gomes@gmail.com</a>><br>
> wrote:<br>
>><br>
>> Hello,<br>
>><br>
>> I'm feeding my working memory with Maps (unfortunately, this is a<br>
>> requirement and I can't use beans).<br>
>><br>
><br>
> Before people start racking their brains to overcome all the resulting<br>
> difficulties: Could you please explain what this requirement is meant to<br>
> achieve?<br>
> -W<br>
><br>
><br>
>><br>
>> To access the values in this maps I use the following MVEL expression :<br>
>><br>
>> Map ( this["airportCode"] == "GIG"<br>
>> , this["numberOfPassengers"] > "1"<br>
>> , this["class"] memberOf ("BUSINESS", "FIRST") )<br>
>><br>
>> And it works fine, except for dates where I get a ClassCastException,<br>
>> even tough I'm using the right pattern:<br>
>><br>
>> Map ( this["departureDate"] > "07-Nov-2009" ) --- fails<br>
>><br>
>> Is there anything I need to do to make the dynamic cast of dates work,<br>
>> in this particular case?<br>
>><br>
>> --<br>
>><br>
>> Morever, I get NPEs if there's no value for a given key. For example,<br>
>> the expression Map ( this ["name"] == 'Leonardo' ) would fail if<br>
>> there's no entry with "name" as the key.<br>
>><br>
>> Any help is welcome!<br>
>><br>
>> Thanks in advance,<br>
>> Leo.<br>
>> _______________________________________________<br>
>> rules-users mailing list<br>
>> <a href="mailto:rules-users@lists.jboss.org" target="_blank">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>
><br>
><br>
<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">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>
</div></div></blockquote></div></div></div><font color="#888888"><br><br clear="all"><br>-- <br> Edson Tirelli<br> JBoss Drools Core Development<br> JBoss by Red Hat @ <a href="http://www.jboss.com" target="_blank">www.jboss.com</a><br>
</font><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>
<br></blockquote></div><br>