[rules-users] Lists and enums in Drools

David Sinclair dsinclair at chariotsolutions.com
Thu May 14 08:52:53 EDT 2009


Just to add to what Wolfgang said, the left hand side of a constraint is
always the field name on the fact you are matching. In your care the 1st
constraint "type == Class.ALPHA", type is the field, the 2nd constraint
again would be type, but written using memberOf instead of contains

AlphaWrapperClass(type == Class.ALPHA && type memberOf alphaList)

dave

2009/5/14 Wolfgang Laun <wolfgang.laun at gmail.com>

> The list that might contain the value of type is alphaList, not $test,
> which is the reference to the object containing the list as a field.
> -W
>
> 2009/5/14 Armaghan Mahmud <mahmud.armaghan at gmail.com>
>
>> Hi,
>>
>> I need help with constructing rules for my scenario.
>>
>> I started off by creating enum values in the main java file and comparing
>> them with the rules to get different responses for different enum values.
>> That was easy.
>>
>> This time, I'm constructing a list of enum values and passing them into
>> the rules engine as well. I would like to configure my rules in such a way
>> that when they look for the different enum values, they should also look in
>> the list to test if the enum value passed into the rules engine is a member
>> of the list or not.  My old rules looked like this:
>>
>> rule "Testing for Alpha"
>> salience 100
>> when
>>     alpha : AlphaWrapperClass(type == Class.ALPHA)
>> then
>>     System.out.println("Found Alpha");
>>     alpha.isFound(true);
>> end
>>
>> I tweaked the above rule to :
>>
>> rule "Testing for Alpha"
>> salience 100
>> when
>>     $test: AlphaEnumCollectionsWrapperClass(alphaList : alphaList)
>>     alpha : AlphaWrapperClass(type == Class.ALPHA && $test contains type )
>> then
>>     System.out.println("Found Loudspeaker Equipment. Who wants to jam
>> that? Must resist... Jamming sequence in progress... ");
>>     materiel.setJam(true);
>> end
>>
>> But I'm seeing the following error:
>>
>> org.drools.rule.InvalidRulePackage: Unable to create Field Extractor for
>> '$test' of '[ClassObjectType classAlphaEnumCollectionsWrapperClass]' in rule
>> "Testing for Alpha": [Rule name=Testing for Alpha, agendaGroup=MAIN,
>> salience=100, no-loop=false]
>>
>> I'd greatly appreciate your help.
>>
>> Thanks,
>> Armaghan
>>
>>
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20090514/d69fca53/attachment.html 


More information about the rules-users mailing list