[
https://issues.jboss.org/browse/JBRULES-3506?page=com.atlassian.jira.plug...
]
Mario Fusco commented on JBRULES-3506:
--------------------------------------
I am pasting below the test I developed to (unsuccessfully) reproduce this issue.
Please provide a failing test case if you think the bug is still present.
@Test
public void testModifyFunctionInPackage() throws Exception {
// JBRULES-3506
String func1 =
"package org.drools.test.func\n" +
"function String getValue() {\n" +
" return \"1\";\n" +
"}\n";
String func2 =
"package org.drools.test.func\n" +
"function String getValue() {\n" +
" return \"2\";\n" +
"}\n";
String rule =
"package org.drools.test.rule\n" +
"global java.util.List list\n" +
"rule R1 when\n" +
"then\n" +
" list.add( org.drools.test.func.GetValue.getValue() );\n" +
"end\n";
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( ResourceFactory.newByteArrayResource( func1.getBytes() ),
ResourceType.DRL );
kbuilder.add( ResourceFactory.newByteArrayResource( rule.getBytes() ),
ResourceType.DRL );
if ( kbuilder.hasErrors() ) {
fail( kbuilder.getErrors().toString() );
}
for (KnowledgePackage pkg : kbuilder.getKnowledgePackages()) {
writePackage( pkg, fileManager.newFile(
pkg.getName().endsWith("rule") ? "rule.pkg" : "func.pkg" )
);
}
fileManager.write( "function.drl", func1 );
fileManager.write( "rule.drl", rule );
String xml = "";
xml += "<change-set
xmlns='http://drools.org/drools-5.0/change-set'";
xml += "
xmlns:xs='http://www.w3.org/2001/XMLSchema-instance'";
xml += "
xs:schemaLocation='http://drools.org/drools-5.0/change-set
http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-api/src/...
>";
xml += " <add> ";
xml += " <resource source='http://localhost:" +
this.getPort() + "/func.pkg' type='PKG' />";
xml += " <resource source='http://localhost:" +
this.getPort() + "/rule.pkg' type='PKG' />";
xml += " </add> ";
xml += "</change-set>";
File fxml = fileManager.write( "changeset.xml", xml );
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
KnowledgeAgent kagent = createKAgent( kbase );
applyChangeSet( kagent, ResourceFactory.newUrlResource( fxml.toURI().toURL() ) );
StatefulKnowledgeSession ksession = createKnowledgeSession(
kagent.getKnowledgeBase() );
List<String> list = new ArrayList<String>();
ksession.setGlobal( "list", list );
ksession.fireAllRules();
ksession.dispose();
assertEquals( 1, list.size() );
assertEquals( "1", list.get(0) );
list.clear();
kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( ResourceFactory.newByteArrayResource( func2.getBytes() ),
ResourceType.DRL );
KnowledgePackage pkg = kbuilder.getKnowledgePackages().iterator().next();
writePackage( pkg, fileManager.newFile( "func.pkg" ) );
scan( kagent );
ksession = createKnowledgeSession( kagent.getKnowledgeBase() );
list = new ArrayList<String>();
ksession.setGlobal( "list", list );
ksession.fireAllRules();
ksession.dispose();
assertEquals( 1, list.size() );
assertEquals( "2", list.get(0) );
kagent.dispose();
}
KnowledgeAgent is not detecting changes of a function defined in a
package
--------------------------------------------------------------------------
Key: JBRULES-3506
URL:
https://issues.jboss.org/browse/JBRULES-3506
Project: Drools
Issue Type: Bug
Security Level: Public(Everyone can see)
Components: drools-core
Affects Versions: 5.4.0.Final
Reporter: Elisabeth Wirth
Assignee: Mario Fusco
I have a pkg containing a function and I am checking, if there are any changes in my pkg
by using the KnowledgeAgent.
Now I have the problem, that changes of the function are not recognized.
In the log I see the following entry:
KnowledgeAgent: impossible to add a map for a null resource! skiping.
I have analyzed the code of KnowledgeAgentImpl and found the reason for the problem:
in the method createPackageFromResource(Resource resource, KnowledgeBuilder kbuilder) in
KnowledgeAgentImpl
the mapping for functions is missing.
I have added the following code and everything works as expected:
for( KnowledgePackage kpkg : kpkgs ) {
for ( Rule rule : ((KnowledgePackageImp)kpkg).pkg.getRules() ) {
rule.setResource( resource );
} ....
// added
for ( Function function :
((KnowledgePackageImp)kpkg).pkg.getFunctions().values() ) {
function.setResource( resource );
}
}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see:
http://www.atlassian.com/software/jira