1

Based on distance and night surcharge, I have rules to get taxi fare.
Decision table excel sheet : rule_fare in com.rules package

Facts :

class TaxiRide {private Boolean isNightSurcharge;private Integer distanceInMile;}
class Fare {private Integer nightSurcharge;private Integer rideFare;}

Now, if one rule is execute from above then only second rule from below decision table should fire.

Based on condition we will give discount to customer.

Decision table excel sheet : rule_discount in com.rules package

Fact :

class TaxiRide {private Boolean isNightSurcharge;private Integer distanceInMile;}
class Discount {private Boolean isDiscount;Integer discount;}

kmodule.xml

<?xml version="1.0" encoding="UTF-8"?>
<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <kbase name="rules_xls" packages="com.rules">
        <ksession name="rulesSession" />
    </kbase>
</kmodule>

Code snippet :

KieSession kieSession = KieServices.Factory.get().getKieClasspathContainer().newKieSession("rulesSession");
FactHandle rideFactHandle = kieSession.insert(taxiRide);
FactHandle discountFactHandle = kieSession.insert(discount);

Integer count = kieSession.fireAllRules();

getting error :

o.d.c.kie.builder.impl.KieProject        : Unable to build KieBaseModel:rules_xls
[10,16]: [ERR 102] Line 10:16 mismatched input '>=' in rule "Discount 1"
[21,16]: [ERR 102] Line 21:16 mismatched input '>=' in rule "Discount 2"
[32,16]: [ERR 102] Line 32:16 mismatched input '>' in rule "Discount 3"
[0,0]: Parser returned a null Package

rule_fare sheet rule_discount sheet

G10
  • 118
  • 1
  • 8
  • The obvious answer would be to fire the rules from decision table 1, collect the results, and then fire the rules from decision table 2 (passing in the results of table 1). Does that not work for you for some reason? – Roddy of the Frozen Peas Nov 13 '20 at 15:20
  • @Roddy of the Frozen Peas Thanks for you comment. I am trying to execute rules from both decision table with one ksession only. If I will do as you suggest, I have to use two different session, right? I am new to drool so do not have much idea about internal mechanism. Can we do that with one session ? – G10 Nov 14 '20 at 07:51
  • Why does it matter how many sessions you use? – Roddy of the Frozen Peas Nov 14 '20 at 13:50
  • do you have any idea about above error? – G10 Nov 14 '20 at 16:55
  • Your question is now instead about this syntax error, not about firing multiple decision tables?? – Roddy of the Frozen Peas Nov 16 '20 at 03:11
  • earlier it was only one excel sheet with both fare and discount rule. I am doing POC and want to make two excel for two different purpose fare and discount. with one sheet it was working fine and got the proper result every time. but now getting this error. and I don't get it. can you please let me what is my mistake here with discount sheet – G10 Nov 17 '20 at 02:18
  • Thank you :) It is worked for me with one session only, with two excel sheet rule table and same fact for both table – G10 Nov 17 '20 at 12:34
  • @G10, I did that but the updated fact from the first table didn't impact the second table conditions?? – Walid Ahmed Feb 21 '21 at 11:06
  • @walid Ahmed. Can you share your code..for me it is working with both tables. – G10 Feb 23 '21 at 04:29

0 Answers0