Hello, I'm attempting to use the Drools 5.1.1 Guvnor with the
"mortgage-example" available in the drools downloads. It looks like I get
some, but not all of the rules, to run. I suspect it has something to do
with how I insert the rules, as I can debug and poke around and see the
rules present in the KnowledgeBase object when I debug.
The examples distro on the drools homepage is labeled 5.1.1, however if you
go to the directory
"drools-examples-brms\mortgage-example\mortgage-client\lib" you'll see the
5.0.1 Drools JARs . Therefore using the examples in a pristine fashion,
without modification, was not an option.
I've instead written the class below, and used the XML configuration file
below. In guvnor I've turned the authentication off (not that it makes a
difference when you are requesting a PKG file), imported
"mortgage-sample-repository.xml", and rebuilt the packages.
However, when I run the source code below, it looks as if only one rule
runs, and the state of any of the objects below (i.e. approved or unapproved
mortgage app) fails to change.
Any ideas what I'm doing wrong?
*MyMortgageApplication.java:*
public class MyMortgageApplication {
public static void main(String[] args) throws Throwable {
KnowledgeBase knowledgeBase = createKnowledgeBase();
StatefulKnowledgeSession session =
knowledgeBase.newStatefulKnowledgeSession();
FactType appType =
knowledgeBase.getFactType("mortgages","LoanApplication");
FactType incomeType =
knowledgeBase.getFactType("mortgages","IncomeSource");
session.addEventListener(new DebugAgendaEventListener());
session.addEventListener(new DebugWorkingMemoryEventListener());
Object application = appType.newInstance();
Object income = incomeType.newInstance();
appType.set(application, "amount", 25000);
appType.set(application, "deposit", 1500);
appType.set(application, "lengthYears", 20);
incomeType.set(income, "type", "Job");
incomeType.set(income, "amount", 65000);
appType.set(application, "amount", 25000);
appType.set(application, "deposit", 1);
appType.set(application, "lengthYears", 1);
incomeType.set(income, "type", "Job");
incomeType.set(income, "amount", 6);
System.out.println("FactCount: " + session.getFactCount());
session.insert(appType);
session.insert(incomeType);
System.out.println("FireAllRules: " + session.fireAllRules());
System.out.println("FactCount: " + session.getFactCount());
session.dispose();
System.exit(0);
}
private static KnowledgeBase createKnowledgeBase() {
KnowledgeAgentConfiguration kaconf =
KnowledgeAgentFactory.newKnowledgeAgentConfiguration();
kaconf.setProperty("drools.agent.scanDirectories", "false");
kaconf.setProperty("drools.agent.newInstance", "true");
KnowledgeAgent kagent =
KnowledgeAgentFactory.newKnowledgeAgent("MortgageAgent", kaconf);
kagent.applyChangeSet(ResourceFactory.newClassPathResource("my-guvnor.xml"));
return kagent.getKnowledgeBase();
}
}
*my-guvnor.xml:*
<change-set
xmlns="http://drools.org/drools-5.0/change-set"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="http://drools.org/drools-5.0/change-setdrools-cha...
<add>
<resource
source="
http://localhost/drools-guvnor/org.drools.guvnor.Guvnor/package/mortgages...
"
basicAuthentication="enabled" username="admin"
password="admin" type="PKG"
/>
</add>
</change-set>