[
http://jira.jboss.com/jira/browse/JBRULES-1220?page=all ]
Mark Proctor closed JBRULES-1220.
---------------------------------
Fix Version/s: 4.0.2
Resolution: Cannot Reproduce Bug
I have just added an integration test for a custom global resolver, for the type of
problem you just showed me, it works ok for me. Here is the code snippet.
public void testCustomGlobalResolver() throws Exception {
final PackageBuilder builder = new PackageBuilder();
builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream(
"test_globalCustomResolver.drl" ) ) );
final Package pkg = builder.getPackage();
final RuleBase ruleBase = getRuleBase();
ruleBase.addPackage( pkg );
final WorkingMemory workingMemory = ruleBase.newStatefulSession();
final Map map = new HashMap();
List list = new ArrayList();
String string = "stilton";
map.put("list", list);
map.put("string", string);
workingMemory.setGlobalResolver( new GlobalResolver() {
public Object resolveGlobal(String identifier) {
return map.get( identifier );
}
public void setGlobal(String identifier,
Object value) {
map.put( identifier, value );
}
} );
workingMemory.fireAllRules();
assertEquals( new Integer( 5 ),
list.get( 0 ) );
}
-------------------------------------------------------------
package org.drools.test;
import org.drools.Cheese;
global java.util.List list
global java.lang.String string
rule "global rule test"
when
eval( "stilton".equals( string ) )
then
list.add( new Integer(5) );
end
Integration with jBPM does not work
-----------------------------------
Key: JBRULES-1220
URL:
http://jira.jboss.com/jira/browse/JBRULES-1220
Project: JBoss Rules
Issue Type: Bug
Security Level: Public(Everyone can see)
Affects Versions: 4.0.1
Reporter: Jiri Pechanec
Assigned To: Mark Proctor
Priority: Minor
Fix For: 4.0.2
We had a code that intgrates JBoss Rules Global Resolver with jBPM variable pool
workingMemory.setGlobalResolver(new GlobalResolver() {
private static final long serialVersionUID = 1L;
public Object resolveGlobal(String identifier) {
System.out.println("!!!!!!!!!! resolve " + identifier);
return ci.getVariable(identifier);
}
public void setGlobal(String identifier, Object value) {
System.out.println("!!!!!!!!!! set " + identifier);
ci.setVariable(identifier, value);
}
});
And a rule file that serves as test
package org.jbpm.action
import org.jbpm.resolveraction.Customer;
import org.jbpm.resolveraction.Order;
import org.jbpm.context.exe.ContextInstance;
global java.lang.String shipper
rule "Determine Shipper"
when
Customer( region >= 1 )
Order( totalAmount >= 0 )
then
System.out.println(shipper);
drools.getWorkingMemory().setGlobal( "shipper", "FEDX" );
System.out.println("ship via FEDX " );
end
The output of the test is as expected
11:50:51,226 INFO [STDOUT] !!!!!!!!!! resolve shipper
11:50:51,227 INFO [STDOUT] None
11:50:51,227 INFO [STDOUT] !!!!!!!!!! set shipper
11:50:51,227 INFO [STDOUT] ship via FEDX
But if we modify the rule file to
package org.jbpm.action
import org.jbpm.resolveraction.Customer;
import org.jbpm.resolveraction.Order;
import org.jbpm.context.exe.ContextInstance;
global java.lang.String shipper
rule "Determine Shipper"
when
eval ("None".equals(shipper))
Customer( region >= 1 )
Order( totalAmount >= 0 )
then
System.out.println(shipper);
drools.getWorkingMemory().setGlobal( "shipper", "FEDX" );
System.out.println("ship via FEDX " );
end
then nothing is printed - no attempt to resolve shipper global variable
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira