[rules-users] check whether a key is present in global Map, i.e. mimicking containsKey() behavior

Wolfgang Laun wolfgang.laun at gmail.com
Mon Jul 4 10:05:31 EDT 2011


On 4 July 2011 15:53, esstrata <esstrata at yahoo.es> wrote:

> Hello,
>
>  I'm using Drools 5.1.1 in a JavaSE 6 project.
>
> I can't get running a rule where a value obtained from WM is check for
> existence as a key of a global Map.
>
> I have a map of the type ProductTextCode -> Product, where keys are String
> and values Product
> /global Map productMap/
>
> Then in a rule a I want a condition where each String in WM is tested
> against map keyset.
> /
> rule "Product ID not in products map"
>    dialect "mvel"
>    when
>        $pid : String()
>        => Here goes the condition <=
>    then
>        System.out.println("Invalid product id: " + $pid)
>        retract ($pid)
>    end
> /
>
> So far I've tried with productMap.containsKey($pid)


Did you enclose this in eval(...) ?
-W


> but a get a MVEL error
> as it takes 'containsKey' as a property.
>
> Please help. Thank you.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20110704/98f1d770/attachment.html 


More information about the rules-users mailing list