[rules-users] Rules Firing / Java Objects Not Manipulated

dfsmith dfsmith at llbean.com
Tue Apr 9 13:39:41 EDT 2013


Hi,

I am new to Drools and Guvnor, so I am likely overlooking something simple.
I am prototyping a proof of concept for integrating Drools into SOLR and
using Guvnor for business rule management. 

I have a Guvnor generated rule that looks like this:

rule "t1"
    dialect "mvel"
    when
        SearchState( searchTerms == "monitor" )
    then
        SearchActions fact0 = new SearchActions();
        fact0.setUrlRedirect( "junk" );
        insert( fact0 );
        System.out.println("Created junk!!!");
end

In a custom SOLR search component, the Drools POC integration code is as
follows:

try {

	if (rb.stage == ResponseBuilder.STAGE_START) {

		// load package
		kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

		kbuilder.add( ResourceFactory.newFileResource(new
File("c:\\data\\guvnor\\searchLatest.pkg")), ResourceType.PKG);

		// create the knowledge base
		kbase = KnowledgeBaseFactory.newKnowledgeBase();

		// add the package to the kbase
		kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );

		System.out.println("In QueryInterceptorComponent.handleRequestBody(). q =
" + rb.req.getParams().get("q"));

		StatelessKnowledgeSession ksession = kbase.newStatelessKnowledgeSession();

		SearchState searchState = new SearchState();
		searchState.setSearchTerms(rb.req.getParams().get("q"));

		//More search state attribute setting here ...

		Collection list = new ArrayList();
		list.add(searchState);

		ksession.execute(list);

		System.out.println("EXECUTED RULES");

	} 

} catch(Exception e) {
	System.out.println("Caught exception " + e);
}

Running in Debug mode on Tomcat and searching on "monitor", I can see that I
step through all of the code above without any exceptions. The console
output shows me that the rule successfully fired and that the When condition
was satisfied as it performed the When side of the rule; it wrote the sysout
message I expected.

In QueryInterceptorComponent.handleRequestBody(). q = monitor
/*Created junk!!!*/
EXECUTED RULES

But when I then access the list collection again in the debugger, there is
no SearchActions object added to the list. I've also tried modifying the
rule to just change a value on the SearchState object that is driving the
When condition. That doesn't result in any object changes either.

Can someone point me in the right direction? Again, I'm new at this.

Any assistance most greatly appreciated.

Thanks,

David





--
View this message in context: http://drools.46999.n3.nabble.com/Rules-Firing-Java-Objects-Not-Manipulated-tp4023270.html
Sent from the Drools: User forum mailing list archive at Nabble.com.


More information about the rules-users mailing list