use of org.kie.api.builder.model.KieBaseModel in project drools by kiegroup.
the class QueryCepFireUntilHaltTest method prepare.
@Before
public void prepare() {
String drl = "package org.drools.compiler.integrationtests\n" + "import " + TestEvent.class.getCanonicalName() + "\n" + "declare TestEvent\n" + " @role( event )\n" + "end\n" + "query EventsFromStream\n" + " $event : TestEvent() from entry-point FirstStream\n" + "end\n" + "query ZeroToNineteenSeconds\n" + " $event : TestEvent() from entry-point FirstStream\n" + " $result : TestEvent ( this after [0s, 19s] $event) from entry-point SecondStream\n" + "end\n";
final KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
KieModuleModel kmodule = ks.newKieModuleModel();
KieBaseModel baseModel = kmodule.newKieBaseModel("defaultKBase").setDefault(true).setEventProcessingMode(EventProcessingOption.STREAM);
baseModel.newKieSessionModel("defaultKSession").setDefault(true).setClockType(ClockTypeOption.get("pseudo"));
kfs.writeKModuleXML(kmodule.toXML());
kfs.write(ResourceFactory.newByteArrayResource(drl.getBytes()).setTargetPath("org/drools/compiler/integrationtests/queries.drl"));
assertTrue(ks.newKieBuilder(kfs).buildAll().getResults().getMessages().isEmpty());
ksession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();
firstEntryPoint = ksession.getEntryPoint("FirstStream");
secondEntryPoint = ksession.getEntryPoint("SecondStream");
clock = ksession.getSessionClock();
this.startEngine();
}
use of org.kie.api.builder.model.KieBaseModel in project drools by kiegroup.
the class QueryInRHSCepTest method prepare1.
private void prepare1() {
String drl = "package org.drools.compiler.integrationtests\n" + "import " + SolicitFirePojo.class.getCanonicalName() + "\n" + "import " + QueryItemPojo.class.getCanonicalName() + "\n" + "global java.util.List myGlobal \n" + "declare SolicitFirePojo\n" + " @role( event )\n" + "end\n" + "query \"myQuery\"\n" + " $r : QueryItemPojo()\n" + "end\n" + "rule \"drools-usage/WLHxG8S\"\n" + " no-loop\n" + " when\n" + " SolicitFirePojo()\n" + " then\n" + " myGlobal.add(drools.getKieRuntime().getQueryResults(\"myQuery\"));\n" + " end\n";
final KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
KieModuleModel kmodule = ks.newKieModuleModel();
KieBaseModel baseModel = kmodule.newKieBaseModel("defaultKBase").setDefault(true).setEventProcessingMode(EventProcessingOption.STREAM);
baseModel.newKieSessionModel("defaultKSession").setDefault(true).setClockType(ClockTypeOption.get("pseudo"));
kfs.writeKModuleXML(kmodule.toXML());
kfs.write(ResourceFactory.newByteArrayResource(drl.getBytes()).setTargetPath("org/drools/compiler/integrationtests/" + this.getClass().getName() + ".drl"));
assertTrue(ks.newKieBuilder(kfs).buildAll().getResults().getMessages().isEmpty());
ksession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();
clock = ksession.getSessionClock();
myGlobal = new ArrayList<>();
ksession.setGlobal("myGlobal", myGlobal);
}
use of org.kie.api.builder.model.KieBaseModel in project drools by kiegroup.
the class QueryCepTest method prepare.
@Before
public void prepare() {
String drl = "package org.drools.compiler.integrationtests\n" + "import " + TestEvent.class.getCanonicalName() + "\n" + "declare TestEvent\n" + " @role( event )\n" + "end\n" + "query EventsFromStream\n" + " $event : TestEvent() from entry-point FirstStream\n" + "end\n" + "query ZeroToNineteenSeconds\n" + " $event : TestEvent() from entry-point FirstStream\n" + " $result : TestEvent ( this after [0s, 19s] $event) from entry-point SecondStream\n" + "end\n";
final KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
KieModuleModel kmodule = ks.newKieModuleModel();
KieBaseModel baseModel = kmodule.newKieBaseModel("defaultKBase").setDefault(true).setEventProcessingMode(EventProcessingOption.STREAM);
baseModel.newKieSessionModel("defaultKSession").setDefault(true).setClockType(ClockTypeOption.get("pseudo"));
kfs.writeKModuleXML(kmodule.toXML());
kfs.write(ResourceFactory.newByteArrayResource(drl.getBytes()).setTargetPath("org/drools/compiler/integrationtests/queries.drl"));
assertTrue(ks.newKieBuilder(kfs).buildAll().getResults().getMessages().isEmpty());
ksession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();
firstEntryPoint = ksession.getEntryPoint("FirstStream");
secondEntryPoint = ksession.getEntryPoint("SecondStream");
clock = ksession.getSessionClock();
}
use of org.kie.api.builder.model.KieBaseModel in project drools by kiegroup.
the class KieHelloWorldTest method createKieProjectWithPackages.
private KieModuleModel createKieProjectWithPackages(KieServices ks, String pkg) {
KieModuleModel kproj = ks.newKieModuleModel();
KieBaseModel kieBaseModel1 = kproj.newKieBaseModel().setEqualsBehavior(EqualityBehaviorOption.EQUALITY).setEventProcessingMode(EventProcessingOption.STREAM).addPackage(pkg);
KieSessionModel ksession1 = kieBaseModel1.newKieSessionModel("KSession1").setType(KieSessionType.STATEFUL).setClockType(ClockTypeOption.get("realtime")).setDefault(true);
return kproj;
}
use of org.kie.api.builder.model.KieBaseModel in project drools by kiegroup.
the class KnowledgeBuilderTest method testResourceMapping.
@Ignore
@Test
public void testResourceMapping() throws Exception {
ServiceRegistryImpl serviceRegistry = (ServiceRegistryImpl) ServiceRegistry.getInstance();
serviceRegistry.reset();
ServiceDiscoveryImpl.getInstance().addService(PMMLCompiler.class.getCanonicalName(), new PMMLCompiler() {
public String compile(InputStream stream, ClassLoader cl) {
return "rule R2 when then end";
}
@Override
public List<KnowledgeBuilderResult> getResults() {
return Collections.emptyList();
}
@Override
public void clearResults() {
// To change body of implemented methods use File | Settings | File Templates.
}
public Resource[] transform(Resource input, ClassLoader classLoader) {
return new Resource[0];
}
public String getCompilerVersion() {
return "KnowledgeBuilderTest";
}
@Override
public List<PMMLResource> precompile(InputStream stream, ClassLoader classLoader, KieBaseModel rootModel) {
return Collections.emptyList();
}
@Override
public List<PMMLResource> precompile(String fileName, ClassLoader classLoader, KieBaseModel rootModel) {
return Collections.emptyList();
}
@Override
public Map<String, String> getJavaClasses(InputStream stream) {
return Collections.emptyMap();
}
@Override
public Map<String, String> getJavaClasses(String fileName) {
return Collections.emptyMap();
}
});
serviceRegistry.reload();
String rule = "package org.drools.compiler.test\n" + "rule R1 when\n" + " \n" + "then\n" + "end\n";
Resource res1 = ResourceFactory.newByteArrayResource(rule.getBytes());
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(res1, ResourceType.DRL);
assertFalse(kbuilder.getErrors().toString(), kbuilder.hasErrors());
KiePackage kp1 = kbuilder.getKnowledgePackages().iterator().next();
assertEquals(1, kp1.getRules().size());
Rule r = kp1.getRules().iterator().next();
assertEquals(res1, ((RuleImpl) r).getResource());
String pmml = "<PMML version=\"4.0\"><Header/></PMML>";
Resource res2 = ResourceFactory.newByteArrayResource(pmml.getBytes());
KnowledgeBuilder kbuilder2 = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder2.add(res2, ResourceType.PMML);
assertFalse(kbuilder2.getErrors().toString(), kbuilder2.hasErrors());
KiePackage kp2 = kbuilder2.getKnowledgePackages().iterator().next();
assertEquals(1, kp2.getRules().size());
Rule r2 = kp2.getRules().iterator().next();
assertEquals(res2, ((RuleImpl) r2).getResource());
}
Aggregations