[rules-users] null POJO attribute causing template issues -- is there a better way?

dunnlow dunnlow at yahoo.com
Mon Jan 30 16:47:10 EST 2012


Hi,
I'm using a template to validate information in my POJO.  I've got a row for
the different valid possibilities.  

My template rule (in guvnor) looks like:

WHEN
There is a MyBean[$mb] with:
    itemname matches templateItemName
    cost greater than templateCost
    caveat matches templateCaveat
THEN
. 8<

(I have columns in my template for templateItemName, templateCost and
templateCaveat).

Almost always, I don't care about the value in $mb.caveat, so I have a ".*"
in the entry for that row.  This works fine as long as $mb bean has a caveat
(ie, $mb.caveat !=null).  But when caveat is null the check for caveat
matches templateCaveat (where templateCaveat = ".*") fails.  I tried the
regex ".*|null" but that doesn't work either, which I suppose isn't so
surprising (although I never see a NPE error msg).

Modifying the template like this doesn't work:

    itemname matches templateItemName
    cost greater than templateCost
    any of the following:
          caveat==null
          caveat matches templateCaveat

because when a null valued caveat comes in, this then matches both the rule
I want to fire and the lone one or two with a constraint on that field
(something other than ".*").  I know I can set the salience so that the rows
with ".*" fire first, but that seems REALLY ugly.

I also considered putting in a rule with a high salience that adds a dummy
caveat if one doesn't exist, but this still seems somewhat ugly.

What I'd like to do is have a constraint such as: if caveat matches
templateCaveat or (if caveat is null and templateCaveat does not match ".*")

Does anyone have any insight about the best way to implement this?

Thank you,
-J





--
View this message in context: http://drools.46999.n3.nabble.com/null-POJO-attribute-causing-template-issues-is-there-a-better-way-tp3701360p3701360.html
Sent from the Drools: User forum mailing list archive at Nabble.com.



More information about the rules-users mailing list