Error Executing Rule with Domain Model Classes
reynoldsm88 Dec 29, 2015 2:14 PMHello,
I am testing some updates in upstream Drools to see if it fixes one of the issues I am having, however I do not believe the rules are executing as I expect. The changes in question are detailed here: https://github.com/droolsjbpm/drools/pull/589
I am trying to execute my Drools code by handing off a "request" object with Domain Model facts into a BRMS service. However, any rules that use the domain model objects do not seem to be able to match and create an activation with the rule. Also, as demonstrated in the rule included, it seems that this only applies to the Domain model classes from my project, regular java.lang classes seem to work fine. Here is the code that actually executes the rules:
public RulesResponse execute( RulesRequest request ) {
List<Command> commands = new ArrayList<Command>();
KieSession kSession = kieSessionService.getNamedKieSession( request.getKieSession() );
commands.add( CommandFactory.newEnableAuditLog( "/home/developer", "audit" ) );
if ( request.getProcessName() != null && !"".equals( request.getProcessName() ) ) {
commands.add( CommandFactory.newStartProcess( request.getProcessName() ) );
}
commands.add( CommandFactory.newInsertElements( request.getFacts() ) );
commands.add( CommandFactory.newFireAllRules() );
kSession.execute( CommandFactory.newBatchExecution( commands ) );
RulesResponse response = request.getResponse();
response.processResults( kSession );
kSession.dispose();
return response;
}
Here are my rules, I have another jar which exports MyModelObj and MyOtherModelObj. The curious thing is that the first rule does not fire, despite the fact that the output of the second rule (which does fire) confirms that the classes line up. Nevertheless, no activations are created for the first rule ever.
//created on: Dec 3, 2015
package com.redhat.rules
//list any import classes here.
import com.redhat.drools.camel.model.MyModelObj;
import com.redhat.drools.camel.model.MyOtherModelObj;
//declare any global variables here
rule "Your First Rule"
when
MyModelObj()
then
System.err.println( "here" );
end
rule "Test"
when
$o : Object()
then
System.err.println( $o.getClass() );
end
The output of executing this produces the output in the console "class com.redhat.drools.camel.model.
MyModelObj", meaning that the first rule fired and printed out the class of the inserted fact. Also for reference, here is the Audit log detailing what happened during the engine execution:
Enter code here...<object-stream>
<org.drools.core.audit.WorkingMemoryLog>
<version>6.1</version>
<events>
<org.drools.core.audit.event.ObjectLogEvent>
<type>1</type>
<factId>1</factId>
<objectToString>MyModelObj [value=0987654]</objectToString>
</org.drools.core.audit.event.ObjectLogEvent>
<org.drools.core.audit.event.ActivationLogEvent>
<type>4</type>
<activationId>Test [1]</activationId>
<rule>Test</rule>
<declarations>$o=MyModelObj [value=0987654]</declarations>
<factHandleIds>1</factHandleIds>
</org.drools.core.audit.event.ActivationLogEvent>
<org.drools.core.audit.event.ActivationLogEvent>
<type>6</type>
<activationId>Test [1]</activationId>
<rule>Test</rule>
<declarations>$o=MyModelObj [value=0987654]</declarations>
<factHandleIds>1</factHandleIds>
</org.drools.core.audit.event.ActivationLogEvent>
<org.drools.core.audit.event.ActivationLogEvent>
<type>7</type>
<activationId>Test [1]</activationId>
<rule>Test</rule>
<declarations>$o=MyModelObj [value=0987654]</declarations>
<factHandleIds>1</factHandleIds>
</org.drools.core.audit.event.ActivationLogEvent>
</events>
<engine>PHREAK</engine>
</org.drools.core.audit.WorkingMemoryLog>
</object-stream>
Can anyone lend some insight into why I do not see the first rule fire, despite the fact that everything I've done seems to indicate that it should fire? For those interested the full source code of this use case is provided here: https://github.com/reynoldsm88/brms-fuse-integration
Thanks,
Michael