Dirk,

    JBRules is working correctly in this case.
    The syntax for any operator is always:

[bindingVar :] <fieldName> <operator> <value>

   So, if you write:

Record( $things contains number )

JBRules will try to find field "$things" in class Record, that obviously does not exists, returning the error saying it can't create the field extractor (on a side note, maybe we can improve the error message... suggestions welcome).

Unfortunatelly, I can't think of another way (based only on the information you provided) to do it, except this:

 collect( Record( num : number -> ( $rlis.contains(num) ) ) )

Please note that if the container is the one changing it's contents, you should need to only modify the container, not each record object. []s
   Edson



Dirk Bergstrom wrote:

I have a container class that has a field that exposes a collection of record
numbers.  In the working memory, I have a bunch of record objects, and one
container object.  I want to write a rule that fires when it encounters a
container that has records matching some criteria.  Here's what I thought
would work:

1 when
2  Container( $things : things -> ( $things.size() > 0 ) )
3  $count : ArrayList( size > 0 ) from
4   collect( Record( $things contains number, otherfield == "somevalue" ) )
5 then
6  ...

Unfortunately, that gets me an error:

 InvalidRulePackage: Unable to create Field Extractor for '$things'

(I determined that the problem is in line 4)

Seems to me that what I'm doing is reasonable, and ought to work.  Is this a
bug, an oversight in drools, or is it in fact unreasonable?

The following "works":

 collect( Record( num : number -> ( $rlis.contains(num) ) ) )

But since the predicate is not time-constant (the list of things in the
Container will change), I'd have to modify() every Record every time I wanted
to re-run the rules.  That would not be very performant...

Note that this is actually unrelated to "collect" -- this doesn't work either:

1 when
2  Container( $things : things )
3  Record( $things contains number )
4 then

(I'm using trunk, revision 8056, updated this morning)



--
Edson Tirelli
Software Engineer - JBoss Rules Core Developer
Office: +55 11 3124-6000
Mobile: +55 11 9218-4151
JBoss, a division of Red Hat @ www.jboss.com



---------------------------------------------------------------------
To unsubscribe from this list please visit:

   http://xircles.codehaus.org/manage_email

Reply via email to