[rules-users] forall with nested collections

Jan Šťastný newohybat at gmail.com
Wed May 14 09:49:03 EDT 2014


Hi,

I am not sure, what you try to achieve.
You have a person and you want find out, whether all of his vehicles are 
of only one make?

rule "Do Stuff If Person Has Vehicles Of Only One Make"
     when
         PersonData( $id:identifierCode)
         accumulate(
             VehicleData(
                 ownerIdentifierCode == $id
                 ,$y:VehicleYearData()
             )
             and $v: VehicleEntity() from $y
             ,$vehicles:collectSet($v.make)
             ,$vehicles.size==1
         )
     then
         // has of the same make, do action
end

Didn't test it, but it should work. I used similar solution once. If 
make field is String it is fine, if anything else, you have to overload 
the equals and hashCode methods.
Hope that helps

Jan


Dne 14.5.2014 15:28, braveheart85 napsal(a):
> Hello,
>
> I'm pretty new to Drools hence i apologize if my question is newbie but i'm
> getting crazy.
> I'm trying to write a functioning query since yesterday without fortune.
> I have data about vehicles owned by person organized for year. My structure
> is:
>
>       VechicleData
>       |___VehicleYearData
>             |____Vehicle
>
> I have inserted in Drools only the root of the hierarchy (VehicleData)
> because insert all objects has been problematic for me. Now i need to check
> if a person has all vehicle of the same make.
> I have tried this:
>
> $result: PersonData( $id: identifierCode )
> 	forall
> 		(
> 			($o: VehicleData( ownerIdentifierCode == $result.identifierCode )) &&
> 			($y: VehicleYearData( ) from $o.data) &&
> 			($v: VehicleEntity( ) from $y.vehicleEntity)
> 		)
> 		VehicleEntity( this == $v, make == "BMW" )
> 	)
>
> and this:
>
> 	PersonData( $id: identifierCode )
> 	$list: List( ) from accumulate (
> 		(and
> 			$o: VehicleData( ownerIdentifierCode == $id )
> 			$y: VehicleYearData( ) from $o.data
> 			$e: VehicleEntity( ) from $y.vehicleEntity
> 		),
> 		collectList( $e )
> 	)
> 	forall (
> 		$v: VehicleEntity( ) from $list
> 		VehicleEntity( this == $v, make == "BMW" )
> 	)
>
> and many other...
> Someone can help me??
>
> Thank you.
> Andrea
>
>
>
> --
> View this message in context: http://drools.46999.n3.nabble.com/forall-with-nested-collections-tp4029572.html
> Sent from the Drools: User forum 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