[rules-users] Accessing properties of an object within a Nested Collection of a Nested Collection

James K james_kosa at verizon.net
Fri May 4 10:16:01 EDT 2012


Thank you laune and manstis for the excellent / relevant information!  I have
a follow on question based on my findings the last couple of days using the
information you have provided.  I am using Drools Flow, firing the following
rule in a *Rules Task* in my flow.  Initially, I am only inserting a
populated *AutoManufacturer* into the flow as my transport object. In the
flow, I am able to access the sub-objects / collections on the parent to
control flow.  I prefer to keep it this way.  

However, it does not appear the sub-objects on the parent object are
available for LHS evaluation in the rule. So, I am creating a memory entry
for the automanufacturer objects and then iterating collections on the
object  / sub-objects to insert them as facts.  This is working, however, is
there not a way to do some sort of introspect on collections on the parent
object instead of inserting all of the additional facts and joining them
back together? Is there a better way to be doing this?  Another perspective
to approach this?


Rule Code
--------------------------------------------------------------
package com.nabble.demo
 
import com.nabble.demo.model.Part;
import com.nabble.demo.model.Brand;
import com.nabble.demo.model.Model;
import com.nabble.demo.model.AutoManufacturer;
 
rule "Insert additional facts from AutoManufacturer Base Class"
ruleflow-group "determineVendors"
 when
  $autoMfg : AutoManufacturer() 
 then
 
    for(Brand brand : $autoMfg.getBrandsCollection()){                          
        System.out.println ("Adding Brand Fact: " + brand.getBrandName());
        insert(brand); 
        for (Model model : brand.getBrandModels())
          {
            System.out.println ("Adding Model as Fact: " +
model.getModelName());
            insert(model);
            for (Part part : model.getPartsList())
               {
                  System.out.println ("Adding Part as Fact: " +
part.getPartsName());
                  insert(part);
               }
          }       
      } 
 end
 
rule "Part Vendor = PV999999"
ruleflow-group "determineVendors"
    when
  $p: Part( partVendor == "PV999999" )
  $m: Model( partsList contains $p )
  $b: Brand( brandModels contains $m)
  $a : AutoManufacturer( brandsCollection contains $b )
      
    then
        System.out.println( "Manf: " +$a.getManufacturerName() + " , Brand
Name: " + $b.getBrandName() + " , Brand ID: " + $b.getBrandId() + " , Model
Name: " + $m.getModelName() + " ,  Part ID: " +  $p.getPartsId()+ " , Part
Name: " +  $p.getPartsName());
end

--
View this message in context: http://drools.46999.n3.nabble.com/Accessing-properties-of-an-object-within-a-Nested-Collection-of-a-Nested-Collection-tp3955591p3962475.html
Sent from the Drools: User forum mailing list archive at Nabble.com.


More information about the rules-users mailing list