}
@Override
protected StatefulKnowledgeSession registerKnowledgeRuntime(String identifier,
String rule) {
KnowledgeBuilder kbuilder = node.get( KnowledgeBuilderFactoryService.class ).newKnowledgeBuilder();
Options xjcOpts = new Options();
xjcOpts.setSchemaLanguage( Language.XMLSCHEMA );
JaxbConfiguration jaxbConfiguration = KnowledgeBuilderFactory.newJaxbConfiguration( xjcOpts,
"xsd" );
kbuilder.add( ResourceFactory.newClassPathResource( "person.xsd",
getClass() ),
ResourceType.XSD,
jaxbConfiguration );
if ( rule != null && rule.length() > 0 ) {
kbuilder.add( ResourceFactory.newByteArrayResource( rule.getBytes() ),
ResourceType.DRL );
if ( kbuilder.hasErrors() ) {
LOG.info( "Errors while adding rule. ",
kbuilder.getErrors() );
}
}
String process1 = "";
process1 += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
process1 += "<process xmlns=\"http://drools.org/drools-5.0/process\"\n";
process1 += " xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
process1 += " xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\"\n";
process1 += " type=\"RuleFlow\" name=\"flow\" id=\"org.drools.actions\" package-name=\"org.drools\" version=\"1\" >\n";
process1 += "\n";
process1 += " <header>\n";
process1 += " <imports>\n";
process1 += " <import name=\"org.drools.camel.testdomain.Person\" />\n";
process1 += " </imports>\n";
process1 += " <globals>\n";
process1 += " <global identifier=\"list\" type=\"java.util.List\" />\n";
process1 += " </globals>\n";
process1 += " <variables>\n";
process1 += " <variable name=\"person\" >\n";
process1 += " <type name=\"org.drools.process.core.datatype.impl.type.ObjectDataType\" className=\"Person\" />\n";
process1 += " </variable>\n";
process1 += " </variables>\n";
process1 += " </header>\n";
process1 += "\n";
process1 += " <nodes>\n";
process1 += " <start id=\"1\" name=\"Start\" />\n";
process1 += " <actionNode id=\"2\" name=\"MyActionNode\" >\n";
process1 += " <action type=\"expression\" dialect=\"mvel\" >System.out.println(\"Triggered\");\n";
// process1 += "list.add(person.name);\n";
process1 += "</action>\n";
process1 += " </actionNode>\n";
process1 += " <end id=\"3\" name=\"End\" />\n";
process1 += " </nodes>\n";
process1 += "\n";
process1 += " <connections>\n";
process1 += " <connection from=\"1\" to=\"2\" />\n";
process1 += " <connection from=\"2\" to=\"3\" />\n";
process1 += " </connections>\n" + "\n";
process1 += "</process>";
kbuilder.add( ResourceFactory.newByteArrayResource( process1.getBytes() ),
ResourceType.DRF );
if ( kbuilder.hasErrors() ) {
System.out.println( "Errors while adding process rule 1. " + kbuilder.getErrors() );
}
assertFalse( kbuilder.hasErrors() );
String process2 = "";
process2 += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
process2 += "<process xmlns=\"http://drools.org/drools-5.0/process\"\n";
process2 += " xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
process2 += " xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\"\n";
process2 += " type=\"RuleFlow\" name=\"flow\" id=\"org.drools.event\" package-name=\"org.drools\" version=\"1\" >\n";
process2 += "\n";
process2 += " <header>\n";
process2 += " <variables>\n";
process2 += " <variable name=\"MyVar\" >\n";
process2 += " <type name=\"org.drools.process.core.datatype.impl.type.StringDataType\" />\n";
process2 += " <value>SomeText</value>\n";
process2 += " </variable>\n";
process2 += " </variables>\n";
process2 += " </header>\n";
process2 += "\n";
process2 += " <nodes>\n";
process2 += " <start id=\"1\" name=\"Start\" />\n";
process2 += " <eventNode id=\"2\" name=\"Event\" variableName=\"MyVar\" >\n";
process2 += " <eventFilters>\n";
process2 += " <eventFilter type=\"eventType\" eventType=\"MyEvent\" />\n";
process2 += " </eventFilters>\n";
process2 += " </eventNode>\n";
process2 += " <join id=\"3\" name=\"Join\" type=\"1\" />\n";
process2 += " <end id=\"4\" name=\"End\" />\n";
process2 += " </nodes>\n";
process2 += "\n";
process2 += " <connections>\n";
process2 += " <connection from=\"1\" to=\"3\" />\n";
process2 += " <connection from=\"2\" to=\"3\" />\n";
process2 += " <connection from=\"3\" to=\"4\" />\n";
process2 += " </connections>\n";
process2 += "\n";
process2 += "</process>";
kbuilder.add( ResourceFactory.newByteArrayResource( process2.getBytes() ),
ResourceType.DRF );
if ( kbuilder.hasErrors() ) {
LOG.info( "Errors while adding process rule 2. ",
kbuilder.getErrors() );
}
assertFalse( kbuilder.hasErrors() );
KnowledgeBase kbase = node.get( KnowledgeBaseFactoryService.class ).newKnowledgeBase();
kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
StatefulKnowledgeSession session = kbase.newStatefulKnowledgeSession();
node.set( identifier,
session );
return session;