use of org.kie.api.builder.model.KieBaseModel in project drools by kiegroup.
the class QueryInRHSCepTest method withInsertBeforeQueryCloudTest.
@Test
public void withInsertBeforeQueryCloudTest() {
String drl = "package org.drools.compiler.integrationtests\n" + "import " + SolicitFirePojo.class.getCanonicalName() + "\n" + "import " + QueryItemPojo.class.getCanonicalName() + "\n" + "global java.util.List myGlobal \n" + "query \"myQuery\"\n" + " $r : QueryItemPojo()\n" + "end\n" + "rule \"drools-usage/WLHxG8S\"\n" + " no-loop\n" + " when\n" + " SolicitFirePojo()\n" + " then\n" + " insert(new QueryItemPojo());\n" + " myGlobal.add(drools.getKieRuntime().getQueryResults(\"myQuery\"));\n" + " end\n";
System.out.println(drl);
final KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
KieModuleModel kmodule = ks.newKieModuleModel();
KieBaseModel baseModel = kmodule.newKieBaseModel("defaultKBase").setDefault(true).setEventProcessingMode(EventProcessingOption.CLOUD);
baseModel.newKieSessionModel("defaultKSession").setDefault(true);
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();
myGlobal = new ArrayList<>();
ksession.setGlobal("myGlobal", myGlobal);
ksession.insert(new QueryItemPojo());
ksession.insert(new SolicitFirePojo());
int fired = ksession.fireAllRules();
assertEquals(1, fired);
assertEquals(1, myGlobal.size());
// notice 1 is manually inserted, 1 get inserted from rule's RHS, for a total of 2.
assertEquals(2, ((QueryResults) myGlobal.get(0)).size());
}
use of org.kie.api.builder.model.KieBaseModel in project drools by kiegroup.
the class RuleUnit method createKieProjectWithPackages.
private KieModuleModel createKieProjectWithPackages(KieServices ks) {
KieModuleModel kproj = ks.newKieModuleModel();
KieBaseModel kieBaseModel1 = kproj.newKieBaseModel("KBase1").setEventProcessingMode(EventProcessingOption.STREAM).addPackage("*").setDefault(true);
kieBaseModel1.newKieSessionModel("KSession1").setType(KieSessionModel.KieSessionType.STATEFUL).setClockType(ClockTypeOption.get("pseudo")).setDefault(true);
return kproj;
}
use of org.kie.api.builder.model.KieBaseModel in project drools by kiegroup.
the class KieModuleDeploymentConfig method getKieProject.
KieModuleModel getKieProject() {
if (kproj != null) {
return kproj;
}
kproj = getKieServicesInstance().newKieModuleModel();
KieBaseModel kieBaseModel = kproj.newKieBaseModel(getKbaseName()).setDefault(true);
kieBaseModel.newKieSessionModel(getKsessionName()).setDefault(true);
return kproj;
}
use of org.kie.api.builder.model.KieBaseModel in project drools by kiegroup.
the class AbstractKieProject method indexKieModule.
private void indexKieModule(Map<String, InternalKieModule> kJarFromKBaseName, InternalKieModule kJar, boolean isMainModule) {
boolean defaultKieBaseFromMain = false;
boolean defaultKieSessionFromMain = false;
boolean defaultStatelessKieSessionFromMain = false;
KieModuleModel kieProject = kJar.getKieModuleModel();
for (KieBaseModel kieBaseModel : kieProject.getKieBaseModels().values()) {
if (kieBaseModel.isDefault()) {
if (defaultKieBase == null || (isMainModule && !defaultKieBaseFromMain)) {
defaultKieBase = kieBaseModel;
defaultKieBaseFromMain = isMainModule;
} else {
defaultKieBase = null;
log.warn("Found more than one default KieBase: disabling all. KieBases will be accessible only by name");
}
}
kBaseModels.put(kieBaseModel.getName(), kieBaseModel);
// should already be set, but just in case
((KieBaseModelImpl) kieBaseModel).setKModule(kieProject);
kJarFromKBaseName.put(kieBaseModel.getName(), kJar);
for (KieSessionModel kieSessionModel : kieBaseModel.getKieSessionModels().values()) {
if (kieSessionModel.isDefault()) {
if (kieSessionModel.getType() == KieSessionModel.KieSessionType.STATEFUL) {
if (defaultKieSession == null || (isMainModule && !defaultKieSessionFromMain)) {
defaultKieSession = kieSessionModel;
defaultKieSessionFromMain = isMainModule;
} else {
defaultKieSession = null;
log.warn("Found more than one default KieSession: disabling all. KieSessions will be accessible only by name");
}
} else {
if (defaultStatelessKieSession == null || (isMainModule && !defaultStatelessKieSessionFromMain)) {
defaultStatelessKieSession = kieSessionModel;
defaultStatelessKieSessionFromMain = isMainModule;
} else {
defaultStatelessKieSession = null;
log.warn("Found more than one default StatelessKieSession: disabling all. StatelessKieSessions will be accessible only by name");
}
}
}
// should already be set, but just in case
((KieSessionModelImpl) kieSessionModel).setKBase(kieBaseModel);
kSessionModels.put(kieSessionModel.getName(), kieSessionModel);
}
}
}
use of org.kie.api.builder.model.KieBaseModel in project drools by kiegroup.
the class KieBuilderImpl method setDefaultsforEmptyKieModule.
public static boolean setDefaultsforEmptyKieModule(KieModuleModel kModuleModel) {
if (kModuleModel != null && kModuleModel.getKieBaseModels().isEmpty()) {
// would be null if they pass a corrupted kModuleModel
KieBaseModel kieBaseModel = kModuleModel.newKieBaseModel("defaultKieBase").addPackage("*").setDefault(true);
kieBaseModel.newKieSessionModel("defaultKieSession").setDefault(true);
kieBaseModel.newKieSessionModel("defaultStatelessKieSession").setType(KieSessionModel.KieSessionType.STATELESS).setDefault(true);
return true;
}
return false;
}
Aggregations