Here is the console output..

......CategoryOfService---------15

......ProviderclaimNumber--130430007701

........Executing......message rule

Hello World

Goodbye cruel world

........Executing......message rule

 

 

From: rules-users-bounces@lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Gopu Shrestha
Sent: Wednesday, March 26, 2014 1:38 PM
To: Rules Users List
Subject: [rules-users] inserted object now working

 

I am struggling to identify why my another object (Claim) inserted into ksession is not working..

However, I tried the object Message() is working but not Claim(). I printed values of Claim Object its working but not in rule.

 

Where I missed??? Please help…

 

Here is the code.

 

     KnowledgeBase kbase = readKnowledgeBase();

            StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();

 

            // go !

            Message message = new Message();

            message.setMessage("Hello World");

            message.setStatus(Message.HELLO);

           

            TClaim claim = loadFile();

           

              System.out.println("......CategoryOfService---------"+claim.getClaimIdentificationInfo().getCategoryOfService().getValue());//working

              System.out.println("......ProviderclaimNumber--"+claim.getClaimIdentificationInfo().getProviderClaimNumber().getValue()); //working

 

            ksession.insert(message);

            ksession.insert(claim);

            ksession.fireAllRules();

 

private static TClaim loadFile() throws JAXBException, FileNotFoundException {

       JAXBContext jaxbContext = JAXBContext.newInstance("com.sample");

              Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();

              JAXBElement<?> unmarshalledObject = (JAXBElement<?>) unmarshaller.unmarshal(new FileInputStream("Encounter.xml"));

              TClaim claim = (TClaim) unmarshalledObject.getValue();

             

              return claim;

       }

 

private static KnowledgeBase readKnowledgeBase() throws Exception {

        KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

        kbuilder.add(ResourceFactory.newClassPathResource("Sample.drl"), ResourceType.DRL);

        kbuilder.add(ResourceFactory.newClassPathResource("setBaseECN.drl"), ResourceType.DRL);

       

        KnowledgeBuilderErrors errors = kbuilder.getErrors();

        if (errors.size() > 0) {

            for (KnowledgeBuilderError error: errors) {

                System.err.println(error);

            }

            throw new IllegalArgumentException("Could not parse knowledge.");

        }

        KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();

        kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());

        return kbase;

    }

 

----Rule file setBaseECN.drl----

 

rule "testing claim rule"

 

when

Claim();

then

       System.out.println("..........Executing.......claim...rule.");//not working

end

 

rule "testing message rule"

when

       Message()

then

       System.out.println("........Executing......message rule");//working

end