[TODO - DEVELOPMENT] - Recursion in rules execution
by tarandeep.singh
Hi,
I've below rules in my rule file, when i execute this drl, it leads to recursion when rules are fired. It'll be really great if somebody can suggest what can be done to avoid recursion during execution of dynamic rules given below.
| package com.globallogic.rules
| import com.thirdpillar.QuoteUpdater
| import java.lang.String
| import java.math.BigDecimal
|
| global BigDecimal TEMP
| global BigDecimal GL_SD_Amt
|
| rule "gst_rate_ol"
| no-loop true
| salience 50
| when
| QuoteUpdater:QuoteUpdater()
| eval(QuoteUpdater.getCustomerTypeCountry().equals("New Zealand") &&
| QuoteUpdater.isFinanceLease() == true ||
| QuoteUpdater.isRental() == true ||
| QuoteUpdater.isOperatingLease() == true ||
| QuoteUpdater.isHirePurchase() == true)
| then
| System.out.println("1");
| TEMP = BigDecimal . valueOf ( 0.125 ) ;
| QuoteUpdater . setQuoteLevelGSTRate ( BigDecimal . valueOf ( TEMP . doubleValue ( ) ) ) ;
| modify(QuoteUpdater);
| end
| rule "NZ_SD"
| no-loop true
| salience 45
| when
| QuoteUpdater:QuoteUpdater()
| eval(QuoteUpdater . getCustomerTypeCountry ( ).equals("New Zealand"))
| then
| System.out.println("2");
| QuoteUpdater . setQuoteLevelGSTStreamRate ( BigDecimal . valueOf ( 0 ) ) ;
| QuoteUpdater . setQuoteLevelStampDutyRate ( BigDecimal . valueOf ( 0 ) ) ;
| GL_SD_Amt = BigDecimal . valueOf ( 0 ) ;
| QuoteUpdater . setQuoteLevelStampDutyAmount ( BigDecimal . valueOf ( 0 ) ) ;
| modify(QuoteUpdater);
| end
| rule "gst_stream_rate_ol"
| salience 40
| no-loop true
| when
| QuoteUpdater:QuoteUpdater()
| eval(QuoteUpdater.getCustomerTypeCountry().equals("New Zealand") &&
| QuoteUpdater.isRental() == true ||
| QuoteUpdater.isOperatingLease() == true)
| then
| System.out.println("3");
| TEMP = BigDecimal . valueOf ( 0.125 ) ;
| QuoteUpdater . setQuoteLevelGSTStreamRate ( BigDecimal . valueOf ( TEMP . doubleValue ( ) ) ) ;
| modify(QuoteUpdater);
| end
|
code in my test class is given below.
| /**
| *
| */
| package com.thirdpillar;
|
| import java.io.InputStreamReader;
| import java.io.Reader;
|
| import org.drools.RuleBase;
| import org.drools.RuleBaseFactory;
| import org.drools.WorkingMemory;
| import org.drools.compiler.PackageBuilder;
| import org.drools.rule.Package;
|
| /**
| * @author tarun.singh
| *
| */
| public class BasedOnDynamic {
|
| /**
| * @param args
| */
| public static void main(String[] args) {
| try {
| QuoteUpdater quoteUpdater = new QuoteUpdater();
| quoteUpdater.setCustomerTypeCountry("New Zealand");
| quoteUpdater.setFinanceLease(true);
| quoteUpdater.setRental(true);
| quoteUpdater.setOperatingLease(true);
| quoteUpdater.setHirePurchase(true);
|
| final Reader source = new InputStreamReader( QuoteUpdater.class.getResourceAsStream( "BasedOnDynamic.drl" ) );
| final PackageBuilder builder = new PackageBuilder();
| builder.addPackageFromDrl( source );
| final Package pkg = builder.getPackage();
| final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
| ruleBase.addPackage( pkg );
|
| final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
| workingMemory.assertObject( quoteUpdater );
| workingMemory.fireAllRules();
|
| } catch (Exception e) {
| e.printStackTrace();
| }
| }
|
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4009214#4009214
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4009214
17 years, 3 months