tags:

views:

454

answers:

2

I have a rule LHS like that

when 
    $location : Location() 
    $cabinets : ArrayList() from collect ( Cabinet() from $location.elements() )
then

an when I print the content of @cabinets in RHS I see that it contains all elements (also those that are not of class Cabinet ).

I want to collect ontly cabinets from $location>elements().

What did I do wrong ?

A: 

I think you would say something along the lines of

Cabinet(class == Cabinet.class)

I dont think that Drools is doing an explicit type check on the Cabinet classes as you have them afaik.

LenW
after doing that I getUnable to create a Field value of type 'ValueType = 'Object'' and value 'Cabinet.class' : [Rule name=Urządzenia bez szafy, agendaGroup=MAIN, salience=0, no-loop=false]java.lang.NoSuchFieldException: classUnable to create restriction '[QualifiedIndentifierRestr: == Cabinet.class ]' for field 'class' in the rule 'Urządzenia bez szafy' : [Rule name=Urządzenia bez szafy, agendaGroup=MAIN, salience=0, no-loop=false]so it is propably wrong
lbownik
A: 

Hello,

Your question is about the 'from' pattern, not the 'collect' one.

Following rule should help to test:

when 
  $location : Location() 
  $cabinet : Cabinet() from $location.elements()
then

This rule should fire for each Cabinet in location.

You can try to post your question on the rule-users user list

pgras
Yse but what if i need to ount the amount of collected cabinets ?
lbownik
like this$cabinets : ArrayList( size == 3) from collect ( Cabinet() from $location.elements() )
lbownik
Sure then you'll need to use collect, but the problem you have is that 'from' returns elements from other type than Cabinet. So if you can have 'from' to return only cabinets, you can use collect to build an ArrayList containing only cabinets...
pgras