For the sake of clarification: Are you saying that there is, or should be, some magic which would make a constraint like Map ( this["departureDate"] == "07-Jan-2009" ) 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?
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... -W 2009/11/8 Edson Tirelli <[email protected]> > > 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. > > 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. > > 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). > > Same explanation for the NPE. > > Edson > > 2009/11/8 Leonardo Gomes <[email protected]> > > 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 <[email protected]> >> wrote: >> > On Sat, Nov 7, 2009 at 6:00 PM, Leonardo Gomes < >> [email protected]> >> > 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 >> >> [email protected] >> >> https://lists.jboss.org/mailman/listinfo/rules-users >> > >> > >> >> _______________________________________________ >> rules-users mailing list >> [email protected] >> https://lists.jboss.org/mailman/listinfo/rules-users >> > > > > -- > Edson Tirelli > JBoss Drools Core Development > JBoss by Red Hat @ www.jboss.com > > _______________________________________________ > rules-users mailing list > [email protected] > https://lists.jboss.org/mailman/listinfo/rules-users > >
_______________________________________________ rules-users mailing list [email protected] https://lists.jboss.org/mailman/listinfo/rules-users
