[rules-users] looping over list
Bruno Freudensprung
bruno.freudensprung at temis.com
Wed Jan 26 04:33:56 EST 2011
Hi,
Maybe can you try the "collect" keyword? According to what I see in the
documentation (4.8.3.9. Conditional Element collect) it seems to fit
your needs.
I'll probably give this a try:
rule "Select Officer"
ruleflow-group "select_officer"
no-loop true
salience 20
when
$processInstance: WorkflowProcessInstance()
$requestData: RequestData($genre : genre, $cost : cost)
$sublist : ArrayList()
from collect( Officer( minimumCost <= $cost, $cost <=
maximumCost ) from $genre)
then
System.out.println("Hey!");
List shrunkOfficersWithGenre = $sublist;
end
Best regards,
Bruno (newbie).
odelyaholiday a écrit :
> I have a list of officers:
> public static final Map<String, List<Officer>> officersPerGenre = new
> HashMap<String, List<Officer>>();
>
> Where the Officer with:
>
> String name;
> Integer mininumCost;
> Integer maximumCost;
>
> in officersPerGenre I fill for each genre list of officers.
>
> In my drools:
>
> rule "Select Officer"
> ruleflow-group "select_officer"
> no-loop true
> salience 20
> when
> $processInstance: WorkflowProcessInstance()
> $requestData: RequestData();
> then
> System.out.println("Hey!");
> List officersWithGenre = (List)officers.get($requestData.getGenre());
> end
>
> Now I need to shrink the officersWithGenre only to officers that
> $requestData.cost is between their mininumCost and maximum cost.
>
> How do I write it in drools? In java i will simply iterate over the
> collection.
>
>
>
More information about the rules-users
mailing list