I am new to drools and even more new to Guvnor.
I have a below code with simple rules (just 2) which doesn't work as
expected, any help would be greatly appreciated.
I attempted to copy the contents of guvnor generated drl file to a local drl
file and tested with drools expert, it works well.
For the below program,
Drools expert (minor changes to java program -
ResourceFactory.newClassPathResource("test.drl")) show the s.o.p (after
firing 1st rule) and prints 90000 (after firing 2nd rule) as expected.
Drools guvnor prints salary as 0.0.
Not sure what is going wrong while integrating with Guvnor, doesn't work as
expected. need help!
[code]
/* Java main method. */
public static void main(String as[]){
KnowledgeBase kbase = readKnowledgeBase1();
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
Employee employee = new Employee();
employee.setName("David");
employee.setExperience(1);
ksession.insert(employee);
ksession.fireAllRules();
System.out.println(employee.getSalary());
}
private static KnowledgeBase readKnowledgeBase() throws Exception {
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
KnowledgeAgentConfiguration kaconf = KnowledgeAgentFactory
.newKnowledgeAgentConfiguration();
kaconf.setProperty("drools.agent.scanDirectories", "false");
KnowledgeAgent kagent = KnowledgeAgentFactory.newKnowledgeAgent("test
agent", kaconf);
kagent.applyChangeSet(ResourceFactory.newClassPathResource("change-set.xml"));
return kbase;
}
/* Change set xml contents: */
<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-set
http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-api/src/...
<add
<resource
source='http://localhost:8080/guvnor-5.5.0.Final-tomcat-6.0/org.drools.guvnor.Guvnor/package/EmployeeDetails/LATEST.drl'
type='DRL'
basicAuthentication="enabled" username="admin"
password="admin"/
</add
</change-set
/* Rule file as downloaded from the below link
*
http://localhost:8080/guvnor-5.5.0.Final-tomcat-6.0/rest/packages/Employe...
*/
package EmployeeDetails
import com.sample.Employee
rule "Rule 1"
no-loop true
dialect "mvel"
when
Employee( experience < 3 )
then
System.out.println("User does not have enough experience");
end
rule "Rule 2"
no-loop true
dialect "mvel"
when
emp : Employee( name == "David" )
then
emp.setSalary( 90000 );
update( emp );
end
[/code]
--
View this message in context:
http://drools.46999.n3.nabble.com/Guvnor-Unable-to-fire-rules-from-standa...
Sent from the Drools: User forum mailing list archive at
Nabble.com.