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

Wolfgang Laun wolfgang.laun at gmail.com
Tue Apr 9 13:48:53 EDT 2013


By "list collection" you mean the argument you pass to ksession.execute()?
This collection ist a one way ticket, not meant to be changed by the
execute method.

I'm not sure about what you did when you tried to "change a value on the
SearchState object". Only code will tell ;-)

-W


On 9 April 2013 19:39, dfsmith <dfsmith at llbean.com> wrote:

> 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.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20130409/d734fb19/attachment.html 


More information about the rules-users mailing list