How to get a Fact creating BRL in Guvnor and querying Drools Server -


i'm stuck brl rules in guvnor.. i'm trying execute rules application using drools server (this solution because in production can use more server , maybe improve performance.. not sure it's first time in company using drools)..

so rule .. given object route setting property "selectedoutboundjourney" uploaded in guvnor in jar, i'd object property "selectedreturnjourney" set.. (but possible same object??) route object selectedreturnjourney null.

i'm not sure if using brl solution given troubles i'm having.. seems easy use non technical people may want change rules or creating new ones.

anyway..

this brl created in guvnor:

rule "selected return dover - calais"    dialect "mvel"     when         route( selectedoutboundjourney == "doca" )             route fact0 = new route();         fact0.setselectedreturnjourney( "cado" );         insertlogical( fact0 );         end 

this code i'm using:

final list<command> commands = new arraylist<command>(); final command insertobjectcommand = commandfactory.newinsert(input, result, true, "default"); final command getobjectcommand = commandfactory.newgetobjects(); final command fireallrulescommand = commandfactory.newfireallrules(); commands.add(insertobjectcommand); commands.add(getobjectcommand); commands.add(fireallrulescommand);  final executionresults executionresults = droolshttpclient.calldroolsserver(commands); return executionresults.getvalue(result); 

the class droolshttpclient is:

public executionresults calldroolsserver(final list<command> commands) throws  droolsexception {     postmethod postmethod = null;     try     {         final httpclient httpclient = new httpclient();         final string droolsserverhost = config.getstring(poferriesrulesengineconstants.drools_server_host, "");         final int droolsserverport = config.getint(poferriesrulesengineconstants.drools_server_port, 0);         httpclient.gethostconfiguration().sethost(droolsserverhost, droolsserverport);          final string droolsserverurl = config.getstring(poferriesrulesengineconstants.drools_server_url, "");         postmethod = new postmethod(droolsserverurl);          final batchexecutioncommand command = commandfactory.newbatchexecution(commands, poferriesrulesengineconstants.drools_session);         final xstream xstreammarshaller = batchexecutionhelper.newxstreammarshaller();         final string xmlcommand = xstreammarshaller.toxml(command);          final stringrequestentity request = new stringrequestentity(xmlcommand, mediatype.text_plain_value, charencoding.utf_8);         postmethod.setrequestentity(request);          httpclient.executemethod(postmethod);         if (postmethod.getstatuscode() != 200)         {             throw new runtimeexception("drools communication error, code: " + postmethod.getstatuscode());         }         final string response = postmethod.getresponsebodyasstring();          final executionresults executionresults = (executionresults) xstreammarshaller.fromxml(response);         return executionresults;     }     catch (final exception e)     {         throw new droolsexception(e.getmessage());     }         {         postmethod.releaseconnection();     } } 

if use drl below words without using getobjectcommand:

rule "selected return routes dover calais"      when     r : route(selectedoutboundjourney == "doca")     r.setselectedreturnjourney("cado")  end 

can me out, please?

assuming have 1 fact in knowledge session @ start, after execution of following rule

rule "selected return dover - calais" dialect "mvel" when     route( selectedoutboundjourney == "doca" )     route fact0 = new route()     fact0.setselectedreturnjourney( "cado" )     insert( fact0 ) end 

you have 2 route facts in session, since have inserted second one.

route: selectedoutboundjourney = "doca", selectedreturnjourney=null route: selectedoutboundjourney = null, selectedreturnjourney="daco" 

if want modify original fact use following rule:

rule "selected return routes dover calais" when    $r : route(selectedoutboundjourney == "doca")    modify ($r) {      selectedreturnjourney = "cado"    } end 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

IIS->Tomcat Redirect: multiple worker with default -