Drools ksession firing rules. Looks like its not reading the rules file

218 Views Asked by At

I'm trying to build the sample example as shown here in this tutorial LINK. The rule files are same as shown. The execution file is as below:

public class TaxCalculationApp {

    public static void main(String[] args) {

        System.out.println( "Bootstrapping the Rule Engine ..." );      

        KieServices ks = KieServices.Factory.get();
        KieContainer kContainer = ks.getKieClasspathContainer();
        KieSession kSession =  kContainer.newKieSession("ksession-rules");
        KieRuntimeLogger kieLogger = ks.getLoggers().newFileLogger(kSession, "log");


        ItemCity item1 = new ItemCity();
        item1.setPurchaseCity(City.PUNE);
        item1.setTypeofItem(Type.MEDICINES);
        item1.setSellPrice(new BigDecimal(10));
        kSession.insert(item1);

        ItemCity item2 = new ItemCity();
        item2.setPurchaseCity(City.PUNE);
        item2.setTypeofItem(Type.GROCERIES);
        item2.setSellPrice(new BigDecimal(10));
        kSession.insert(item2);

        ItemCity item3 = new ItemCity();
        item3.setPurchaseCity(City.NAGPUR);
        item3.setTypeofItem(Type.MEDICINES);
        item3.setSellPrice(new BigDecimal(10));
        kSession.insert(item3);

        ItemCity item4 = new ItemCity();
        item4.setPurchaseCity(City.NAGPUR);
        item4.setTypeofItem(Type.GROCERIES);
        item4.setSellPrice(new BigDecimal(10));
        kSession.insert(item4);     

        int fired = kSession.fireAllRules();        
        System.out.println( "Number of Rules executed = " + fired );
        System.out.println(item1.getPurchaseCity().toString() + " " + item1.getLocalTax().intValue());
        System.out.println(item2.getPurchaseCity().toString() + " " + item2.getLocalTax().intValue());             
        System.out.println(item3.getPurchaseCity().toString() + " " + item3.getLocalTax().intValue());             
        System.out.println(item4.getPurchaseCity().toString() + " " + item4.getLocalTax().intValue());

        kieLogger.close();

    }   
}

my kmodule file is

<?xml version="1.0" encoding="UTF-8"?>
<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule">
    <kbase name="rules" packages="com.sample.rules">
        <ksession name="ksession-rules"/>
    </kbase>
    <kbase name="dtables" packages="dtables">
        <ksession name="ksession-dtables"/>
    </kbase>
    <kbase name="process" packages="process">
        <ksession name="ksession-process"/>
    </kbase>
</kmodule>

When I try to run, I get the following error

Bootstrapping the Rule Engine ...
Exception in thread "main" Number of Rules executed = 0
java.lang.NullPointerException
    at com.sample.TaxCalculationApp.main(TaxCalculationApp.java:55)

Looks like its not reading any rules from the rule file. Am I missing something ?

0

There are 0 best solutions below