Thanks for your helping me out. In my real application, there is a 1 to *
relationship between orders and items.
My App looks like :
Item truckShippedItem = new Item();
Order order = new Order();
order.getItems().add(truckShippedItem);
truckShippedItem.setParentOrder(order);
Rate bc = new Rate("additive_charge",10);
truckShippedItem.getRates().put("additive_charge", bc);
try {
workingMemory.assertObject( truckShippedItem );
workingMemory.assertObject( order );
workingMemory.fireAllRules( );
} catch (FactException fe)
{
System.out.println("FactErrorOccured" +
fe.getMessage());
} catch (Exception e)
{
System.out.println(e.getMessage());
}
My 2 rules looks like:
<rule name="Order Level" salience="1" >
<parameter identifier="order">
<class>com.amazon.shipping.ruleengine.Order</class>
</parameter>
<java:condition>
((Rate)order.getOrderLevelRates().get("additive_charge")).getRateCost() <
order.getMaxAdditiveCharge().getRateCost() </java:condition>
<java:consequence>
System.out.println("Modifying additive Charge for order");
order.getOrderLevelRates().put("additive_charge",order.getMaxadditiveCharge());
drools.modifyObject(order);
</java:consequence>
</rule>
<rule name="additive Charge Allocation" >
<parameter identifier="order">
<class>com.amazon.shipping.ruleengine.Order</class>
</parameter>
<parameter identifier="item">
<class>com.amazon.shipping.ruleengine.Item</class>
</parameter>
<java:condition>item.parentOrder == order</java:condition>
<java:condition>item.containsCharge("additive_charge")</java:condition>
<java:condition>order.containsCharge("additive_charge")</java:condition>
<java:condition>((Rate)order.getOrderLevelRates().get("additive_charge")).getRateCost()
!= 0 </java:condition>
<java:consequence>
System.out.println("Calculating additive Charge Allocation");
</java:consequence>
</rule>
public class Order {
List<Item> items = new LinkedList();
Map<String,Shipment> shipments = new HashMap();
Map<String,Rate> orderLevelRates = new HashMap(); }
public class Item {
Map<String,Rate> itemLevelRates = new HashMap<String,Rate>();
Map<String,CatalogProperty> catalogProperties = new
HashMap<String,CatalogProperty>();
Order parentOrder;
String name;
}
The second rule is my biggest problem. It fires whenever any Object or and item
is modified
Thanks,
Alan Ho
-----Original Message-----
From: Michael Neale [mailto:[EMAIL PROTECTED]
Sent: Wednesday, February 08, 2006 4:20 PM
To: [email protected]
Subject: Re: [drools-user] How do I control firing of rules ?
how are you calling the rule engine - can you show a snippet of code?
On 2/9/06, Ho, Alan <[EMAIL PROTECTED]> wrote:
>
> I don't quite get your drift.
>
> If I modify N orders, each order with 1 item, I have to activate my
> rule N*N times. That's really costly.
>
> Regards,
> Alan
>
>
> -----Original Message-----
> From: Michael Neale [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, February 08, 2006 3:39 PM
> To: [email protected]
> Subject: Re: [drools-user] How do I control firing of rules ?
>
> so you are asserting into working memories orders, and items as "exploded"
> apart from each other? (if you get my drift).
>
>
> Michael.
>
> On 2/9/06, Ho, Alan <[EMAIL PROTECTED]> wrote:
> >
> > Hi,
> >
> > I'm fairly new to drools, and was curious if there is a way to
> > reduce the firing of rules.
> >
> > Whenever a fact is modified, drools fires all rules who's parameter
> > ( is the same class type of the fact.
> >
> > e. g.
> >
> > <rule name="Order Level" salience="1" >
> > <parameter identifier="order">
> > <class>com.blah.shipping.ruleengine.Order</class>
> > </parameter >
> > <parameter identifier="item">
> > <class>com.blah.shipping.ruleengine.Item</class>
> > </parameter >
> > :
> > :
> > :
> > </rule>
> >
> > Whenever we modify any fact of type object Item or type Order, this
> > above rule will fire.
> >
> >
> > Can we somehow specify a parameter based a sub-field of an object.
> > Something like
> >
> > <rule name="Order Level" salience="1" >
> > <parameter identifier="order">
> > <class>com.blah.shipping.ruleengine.Order</class>
> > </parameter >
> > <parameter identifier="Item">
> > <instance>order.orderItem</instance>
> > </parameter >
> > :
> > :
> > :
> > </rule>
> >
> > Where order.orderItem is of type Item. In this scenario, the rule
> > will only fire when an order fact or order.orderItem is modifed.
> >
> > Right now, to emulate the behaviour I am looking for, I am doing a
> > check in a rule condition:
> >
> >
> > <rule name="Order Level" salience="1" >
> > <parameter identifier="order">
> > <class>com.blah.shipping.ruleengine.Order</class>
> > </parameter >
> > <parameter identifier="item">
> > <class>com.blah.shipping.ruleengine.Item</class>
> > </parameter >
> >
> > <java:condition>order.orderItem == item</java:condition>
> >
> > :
> > :
> > :
> > </rule>
> >
> > Thanks,
> > Alan Ho
> >
> >
>