[rules-users] one rule not fired properly.

Greg Barton greg_barton at yahoo.com
Thu Nov 27 13:13:40 EST 2008


Is this supposed to react to the total price value being set in the other rules?  If so you need to notify the engine that the object has been updated.   Pass the object to update() in the right hand side of the rules where it's modified.

--- On Thu, 11/27/08, manyasri.m <manyasri.m at gmail.com> wrote:

> From: manyasri.m <manyasri.m at gmail.com>
> Subject: Re: [rules-users] one rule not fired properly.
> To: rules-users at lists.jboss.org
> Date: Thursday, November 27, 2008, 3:52 AM
> Hi,
> 
> > eval($p.getTotalprice() > 1000)
> 
> In This case i am getting  getTotalprice() value 0.i am
> getting default
> value.But, in this case i want totalprice value.Can
> somebody plz take a look
> at what is going wrong.
> 
> thanks,
> --manya
> 
> 
> manyasri.m wrote:
> > 
> > Hi,
> >   
> > The business requirements are as follows.
> > 
> > We have 3 rules which need to be fired depending upon
> the criteria which
> > will be met.  We have an order object which has
> various orderline items
> > and the following business rules need to be executed
> depending upon the
> > inserted facts.
> > •	If a particular item is on discount, the discount
> % is applied to the
> > line item.
> > •	If the quantity for a particular item is greater
> than 10, an added 10%
> > discount is given for the order.
> > •	If the total order amount is greater than 1000,
> then an additional 5%
> > discount is given on the order.
> > 
> > The above rules need to be executed at the same time.
> > 
> > In This case i tryed all the conditions it's
> working fine.But,
> > rule "Apply 5% discount if Total Price greater
> than 1000"  is not fired.
> > 
> > package com.sample.orderItem
> > 
> > import com.sample.orderItem.DiscountDetails
> > import com.sample.orderItem.ItemQuantity
> > import com.sample.orderItem.PriceCal
> > import com.sample.orderItem.PriceDetails
> > 
> > expander Sample.dsl
> > 
> > 
> > 
> > rule "Purchase Item"
> >     salience 10
> >  when
> >    > $p:PriceCal(itemName:itemName,
> quantity:quantity,
> > discountPer:discountPer, itemprice:itemprice,
> totalprice:totalprice,
> > totalPriceAfterDiscount:totalPriceAfterDiscount)
> >   
> >  then
> >    >  System.out.println("Purchased Item     :
> " +itemName ); 
> >    >  System.out.println("Itemprice Prise    :
> " +itemprice);
> >    >  System.out.println("Itemprice quantity :
> " +quantity); 
> >    >  System.out.println("discountPer        :
> " +discountPer);
> > end 
> > 
> > rule "Item Discountper equal to null"
> >     salience 10
> >  when
> >    > $p:PriceCal(itemName:itemName,
> quantity:quantity,
> > discountPer:discountPer, itemprice:itemprice,
> totalprice:totalprice,
> > totalPriceAfterDiscount:totalPriceAfterDiscount)
> >    > eval($p.getDiscountPer() == null)
> >  then
> >  
> >    > 
> $p.setTotalprice(totalprice+itemprice*quantity);
> >    >  System.out.println("totalprice non Disc 
>        : "
> > +$p.getTotalprice() );
> > end 
> > 
> > rule "Item Discountper not equal to null"
> >     salience 10
> >  when
> > 				
> >    > $p:PriceCal(itemName:itemName,
> quantity:quantity,
> > discountPer:discountPer, itemprice:itemprice,
> totalprice:totalprice,
> > totalPriceAfterDiscount:totalPriceAfterDiscount)
> >    > eval($p.getDiscountPer() != null)
> >  then
> >    
> >    > 
> $p.setItemprice(itemprice*(100-Integer.parseInt(discountPer))/100);
> >    >  System.out.println("default discountl:
> "+$p.getItemprice());
> >    > 
> $p.setTotalprice(totalprice+$p.getItemprice()*quantity);
> >    >  System.out.println("Totalprice         :
> " +$p.getTotalprice() );
> > end 
> > 
> > rule "Apply 10% discount if quantity greater than
> 10"
> > 				
> >  when
> >    > $p:PriceCal(itemName:itemName,
> quantity:quantity,
> > discountPer:discountPer, itemprice:itemprice,
> totalprice:totalprice,
> > totalPriceAfterDiscount:totalPriceAfterDiscount)
> >    > eval($p.getQuantity() > 10)
> >    
> >  then
> >    >  $p.setTotalprice($p.getTotalprice()*0.90);
> >    >  System.out.println("Apply 10% discount
> if quantity greater than 10        
> > : " +$p.getTotalprice() ); 
> >    
> > end 
> > 
> > rule "Apply 5% discount if Total Price greater
> than 1000"
> > 
> >  when
> >    > $p:PriceCal(itemName:itemName,
> quantity:quantity,
> > discountPer:discountPer, itemprice:itemprice,
> totalprice:totalprice,
> > totalPriceAfterDiscount:totalPriceAfterDiscount)
> >    > eval($p.getTotalprice() > 1000)
> >   
> >  then
> >     
> >    >  $p.setTotalprice($p.getTotalprice()*0.95);
> >    >  System.out.println("Apply 5% discount if
> Total Price greater than
> > 1000        : " +$p.getTotalprice() ); 
> >   
> > end 
> > 
> > Result:
> > -------
> > Purchased Item     : abc
> > Itemprice Prise    : 100.0
> > Itemprice quantity : 13
> > discountPer          : 5
> > default discount   l: 95.0
> > Totalprice         : 1235.0
> > Apply 10% discount if quantity greater than 10        
> : 1111.5
> > 
> > 
> > please give me proper suggestion of this.
> > 
> > 
> > thanks,
> > manyasri.
> >  
> > 
> 
> -- 
> View this message in context:
> http://www.nabble.com/one-rule-not-fired-properly.-tp20706884p20715596.html
> 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