[rules-users] RE: Struggling with Rule syntax - please help...

Anstis, Michael (M.) manstis1 at ford.com
Fri Mar 23 05:31:37 EDT 2007


I don't think your project is dead at all; you just need to re-consider
how you might achieve your objective.

Edson's example you refer to used a List.contains() within a "return
value operator" (example 3.13 in the 3.0.5 docs):-

[Edson's example]

rule "retrieving the list"
when  
    Customer( $custCode : customer_code )
then
    List codes = lookupDAO.getLookup( $custCode );
    assert( codes );
end

rule "doing something"
when
    Customer( $custCode : customer_code )
<-- Bound column
    $list : List()
<-- Bound column (to a List() fact which must implement List)
    SHIPMENT_MOVE(
	customer_code == $custCode,
<-- Field constraint
	$sc : ship_code,
<-- Bound column
      $dc : deliver_code,
<-- Bound column 
	$pc : port_code,
<-- Bound column
      ( $list.containts($sc) || $list.containts($dc) ||
$list.containts($pc) )	<-- Return value operator
    ) 
then
    // do something
End

His other option was to use 3.1's "from" statement. This requires a
"LookupTableResult()" object that exposes a "List getElements()" method
and a "lookupDAO" object (possibly in global scope, but I'm unsure) that
has a "LookupTableResult getLookup(...)" method which returns a
LookupTableResult object containing an elements List containing the
codes you need to validate against. 

when
    SHIPMENT_MOVE(
	customer_code == "abc",

	$sc : ship_code,
	$dc : deliver_code, 
	$pc : port_code )
    LookupTableResult( elements contains $sc | contains $dc | contains
$pc ) from lookupDAO.getLookup(...) 
    )
then
   // consequence
end

I think both would serve your purpose.

With kind regards,

Mike

-----Original Message-----
From: rules-users-bounces at lists.jboss.org
[mailto:rules-users-bounces at lists.jboss.org] On Behalf Of jdepaul
Sent: 22 March 2007 17:04
To: rules-users at lists.jboss.org
Subject: [rules-users] RE: Struggling with Rule syntax - please help...



Anstis, Michael (M.) wrote:
> 
> You can't use a bound object as the list against which "contains"
> operates.
> 

Guys - think this is bad news for me...  I need to use 'contains'
keyword as
List comparison against several variables from the primary Fact and
possibly
against several Lists.   Without the ability to bind variable names to
specific ArrayList objects I don't know how I can do this type of
comparison
in my rules - I hope there is a work-around to my problem, otherwise
this
may be a deal killer for my project...

What I dont understand is that Edson's example seemed to get me so close
-
he gave this example some time in the past, which seems to illustrate
that
variable binding to List object is possible.   How is his example
different
from what I'm trying to do in my code?

Again, this is what I need:

Several Lookup list objects each with many String elements asserted into
memory.  One main Fact (GATEIN) asserted into memory as well, the GATEIN
fact has CustNumber, shipper_code, forwarder_code, cosignee_code, etc).


Rule needs to check for existence of one of these codes in ONE or MORE
lookup lists.  Something like this:

if (CustomerNumber = "293" and (ShippersList contains shipper_code or
ShipperList contains forwarder_code, or ShipperList contains
cosignee_code)
).

Is this possible given the syntax constraints?  BTW, I'm using 3.1.0M1

James

Edson's prvious example:
------------------------------------------------
> rule "retrieving the list"
> when  
>     Customer( $custCode : customer_code )
> then
>     List codes = lookupDAO.getLookup( $custCode );
>     assert( codes );
> end
>
> rule "doing something"
> when
>     Customer( $custCode : customer_code )
>     $list : List()
>     SHIPMENT_MOVE(customer_code == $custCode, $sc : ship_code,
>                                       $dc : deliver_code, $pc :
port_code,
>                                       ( $list.containts($sc) ||
> $list.containts($dc) || $list.containts($pc) ) )
> then
>     // do something
> end 
------------------------------------------------



-- 
View this message in context:
http://www.nabble.com/Struggling-with-Rule-syntax---please-help...-tf340
8727.html#a9619455
Sent from the drools - user mailing list archive at Nabble.com.

_______________________________________________
rules-users mailing list
rules-users at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users




More information about the rules-users mailing list