[rules-users] Value is not reflected in Fact Object at Drool Client Side

Hushen Savani hushen.savani at elitecore.com
Tue Dec 4 09:07:27 EST 2012


Hi,

 

                I m a newbie. Again, stuck with a problem. 

 

                I have created a package in Drools Guvnor as:

 

                

 

                Created two POJO. Driver and Car as following:

 

                Driver.java:

                package kijanowski.eu;

 

public class Driver {

 

        private String name;

        private int age;

        private Car car;

        

        public Driver(String name, int age, Car car) {

                this.name = name;

                this.age = age;

                this.car = car;

        }

      

         .

 

         //Setter and Getters 

 

         .         

}

 

                Car.java:

                package kijanowski.eu;

 

public class Car {

 

        private String color;

        private double value;

 

        public Car() {}

 

        public Car(String color, double value) {

                this.color = color;

                this.value = value;

        }

 

        .

 

        //Setter and Getters

 

        . 

        

}

 

      Prepared its jar and uploaded to Guvnor as following:

 

      

 

      Both POJO are loaded successfully:

 

      

 

 

      Then I created a new rule as following:

 

      

 

      

      Then I verified, build and created Snapshot.

 

                Now, I prepared a client program to consume rules deployed
in guvnor as following:

 

      package kijanowski.eu;

 

import java.util.Collection;

import java.util.Iterator;

 

import org.drools.KnowledgeBase;

import org.drools.agent.KnowledgeAgent;

import org.drools.agent.KnowledgeAgentFactory;

import org.drools.runtime.StatefulKnowledgeSession;

 

public class GuvnorTest {

 

        public static final void main(String[] args) {

 

                  KnowledgeAgent kagent =
KnowledgeAgentFactory.newKnowledgeAgent("/Guvnor.properties"); 

                  KnowledgeBase kbase = kagent.getKnowledgeBase();

 

                  StatefulKnowledgeSession workingMemory =
kbase.newStatefulKnowledgeSession();

 

                Driver d = new Driver("Jarek", 20, null);

                workingMemory.insert(d);

 

                workingMemory.fireAllRules();

                

                Collection c = workingMemory.getObjects();

                

                for (Iterator i = c.iterator(); i.hasNext();) {

                  d = (Driver)i.next();

                  System.out.println(" Age: " + d.getAge() + " Name: " +
d.getName() + " Car: " + d.getCar() + " Object: " + d);

                }

        }

 

}

 

      And Guvnor.properties is as following:

      

url=http://localhost:10080/guvnor-5.5.0.Final-tomcat-6.0/org.drools.guvnor.G
uvnor/package/myNewPackage/car_example_snapshot

enableBasicAuthentication=true

username=admin

password=admin

name=drooltest

      

      But when I run the client, I get following o/p:

 

            Age: 20 Name: Jarek Car: null Object:
kijanowski.eu.Driver at 15b9e68

      

      I cannot see name changed to "Applicable" and cannot even see the o/p
of sysout on server side:

 



 

 

                Can anyone please help me with this. Thanks.    

 

Best Regards

Hushen Savani 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20121204/22a26249/attachment-0001.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 859 bytes
Desc: not available
Url : http://lists.jboss.org/pipermail/rules-users/attachments/20121204/22a26249/attachment-0005.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 13458 bytes
Desc: not available
Url : http://lists.jboss.org/pipermail/rules-users/attachments/20121204/22a26249/attachment-0006.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 16022 bytes
Desc: not available
Url : http://lists.jboss.org/pipermail/rules-users/attachments/20121204/22a26249/attachment-0007.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 6928 bytes
Desc: not available
Url : http://lists.jboss.org/pipermail/rules-users/attachments/20121204/22a26249/attachment-0008.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 22372 bytes
Desc: not available
Url : http://lists.jboss.org/pipermail/rules-users/attachments/20121204/22a26249/attachment-0009.png 


More information about the rules-users mailing list