Value is not reflected in Fact Object at Drool Client Side
by Hushen Savani
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@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
13 years, 3 months
Rules Unit Testing
by John Poole
How is unit testing handled for rules? I'm playing with the nurse
rostering app and the only test I see is a performance test.
-John
13 years, 3 months
Using outcome of previous planning as input of new planning
by Michiel Vermandel
Hi,
We need to plan tasks over a period of 6 months.
But when the next planning is done (months after the first planning) we need to know some details about the previous planning.
For example, a person should not execute the same task twice in a row.
So I need to know who did a specific task in the previous planning in order to verify that it is not the same in this planning.
Do I need to persist the solution of the first planning?
Is there any example amongst the list of available examples which can give me a head-start on this?
Any help is greatly appreciated.
Regards,
Michiel
-----------------
http://www.codessentials.com - Your essential software, for free!
Follow us at http://twitter.com/#!/Codessentials
13 years, 3 months
how to get first and last element of list of facts?
by Michiel Vermandel
Hi,
I need to plan some tasks within a nr of timeslots.
Until now a task was always done within the period of one timeslot and I could validate my rules since a task has a planning variablegetTimeSlot/ setTimeSlot.
Now requirements have changed and a task can take more than one timeslot to complete.
What is the best way to validate that the task is not started in a timeslot that would end the task after the last timeslot?
- Timeslots are always equally long (for example a week).
- All timeslots in the list of timeslots are sequential (no gaps).
So if I have a list of timeslots W18, W19, W20, W21 and I have a task taking 3 TimeSlots to complete, it should start in W18 or W19.
Should I create a single planningRange fact, holding the first and last slot?
Any directions would be appreciated.
Regards,
Michiel Vermandel
-----------------
http://www.codessentials.com - Your essential software, for free!
Follow us at http://twitter.com/#!/Codessentials
13 years, 3 months
To access at the fact object
by Mister Nono
Hi,
I have the drools rule (made in guvnor server) :
1. | rule "driverRule"
2. | salience 10
3. | dialect "mvel"
4. | when
5. | Driver( driverAge : age > 18 && < 65 )
6. | then
7. | Driver fact0 = new Driver();
8. | fact0.setName( "TOTO" );
9. | insert( fact0 );
10. | end
... and the java code source :
KnowledgeAgent agent =
KnowledgeAgentFactory.newKnowledgeAgent("/Guvnor.properties");
KnowledgeBase ruleBase = agent.getKnowledgeBase();
StatefulKnowledgeSession workingMemory =
ruleBase.newStatefulKnowledgeSession();
Driver d = new Driver("Jack", 28, null);
workingMemory.insert(d);
workingMemory.fireAllRules();
for(Iterator i = workingMemory.getObjects().iterator(); i.hasNext();)
{
Object obj = i.next();
System.out.println(obj.getClass().getCanonicalName());
if (obj instanceof Driver)
{
System.out.println("Driver name => " + ((Driver)obj).getName());
System.out.println("Driver age => " + ((Driver)obj).getAge());
}
}
But the drools rule changes the driver name "Jack" by "TOTO", but in the
console the initial name "Jack" is always displayed.
How to access at the objet who is in knowledge base (the modified objet) ?
Thank. ;)
--
View this message in context: http://drools.46999.n3.nabble.com/To-access-at-the-fact-object-tp4021064....
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 3 months
Different results with same fact base
by raffi
Hi,
I have a strange behavior with the Drools Expert 5.5.0. After running the
main class few times in a row, the results suddenly differ from the ones
before it. That means there are somtimes 3, 4 or 5 results shown in console.
I am using a statefulknowledgesession. Inserting of all facts is done with
normal java lists. For my last type of facts I insert one, call
fireAllRules(), and retract it again. Showing in console is solved with
queries. At the end I'm calling the dispose()-method. I added it to see if
there is a change in behavior. But with or without it there is the same
problem with different results after few directly runnings.
Rules and queries are defined in a drl-file and loaded via
knowledgebuilder's add()-method. I am working with eclipse and of course the
plugin for it.
Could it be a problem with something memory like (in a way like a cache or
similar to the garbage collection)?
I hope with this short explanation you can give me a feedback. If not its
not problem to describe in a more detailed way.
Thank you.
--
View this message in context: http://drools.46999.n3.nabble.com/Different-results-with-same-fact-base-t...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 3 months
Drools Courses
by Matteo Cusmai
Hi all,
i and my company are interested on some Drools+JBPM courses?
Are there any courses from Red Hat or other companies?
Best Regards,
Mattteo.
13 years, 3 months