[rules-users] MVEL and Maps

Leonardo Gomes leonardo.f.gomes at gmail.com
Sun Nov 8 09:16:26 EST 2009


Hi Wolfgang,

Here's the context:

We're replacing a very basic home-made rule engine with drools. Today,
fact data can be added dynamically b/c for all rules our fact is
nothing more than a Map and we can register new fact data through an
UI where you say what's the key and what's the type of the value.
Rules can also be created dynamically and operate against those newly
created attributes of my fact.

Incoming requests are key / value structures and we have a service
that will look at the list of registered fact data and try to find
that information in the incoming request by looking for the keys and
getting the corresponding values, then populating the Map I just
talked about which will be injected in the working memory for
evaluation against our rules.

That's why, in Drools, I need to have my rules accessing data from a
Map. By using MVEL, as I said, it works fine with strings, integers
and list of strings, but I'm having problems with dates and would like
some advice on that case.

Here's another example of things that work:

rule "test rule"
	when
		Map ( this["airportCode"] == "GIG"
			, this["numberOfPassengers"] > 1
			, this["class"] in ("BUSINESS", "FIRST CLASS") )
	then
		m.addMessage("rule matched");
end

And here's where I have problems,

Map ( this["departureDate"] ) == "07-Jan-2009" )


Thanks a lot,
Leo.



On Sun, Nov 8, 2009 at 10:56 AM, Wolfgang Laun <wolfgang.laun at gmail.com> wrote:
> On Sat, Nov 7, 2009 at 6:00 PM, Leonardo Gomes <leonardo.f.gomes at gmail.com>
> wrote:
>>
>> Hello,
>>
>> I'm feeding my working memory with Maps (unfortunately, this is a
>> requirement and I can't use beans).
>>
>
> Before people start racking their brains to overcome all the resulting
> difficulties: Could you please explain what this requirement is meant to
> achieve?
> -W
>
>
>>
>> To access the values in this maps I use the following MVEL expression :
>>
>>                Map ( this["airportCode"] == "GIG"
>>                        , this["numberOfPassengers"] > "1"
>>                        , this["class"] memberOf ("BUSINESS", "FIRST") )
>>
>> And it works fine, except for dates where I get a ClassCastException,
>> even tough I'm using the right pattern:
>>
>> Map ( this["departureDate"] > "07-Nov-2009" )   --- fails
>>
>> Is there anything I need to do to make the dynamic cast of dates work,
>> in this particular case?
>>
>> --
>>
>> Morever, I get NPEs if there's no value for a given key. For example,
>> the expression Map ( this ["name"] == 'Leonardo' ) would fail if
>> there's no entry with "name" as the key.
>>
>> Any help is welcome!
>>
>> Thanks in advance,
>> Leo.
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>
>




More information about the rules-users mailing list