use of org.kie.api.builder.KieModule in project drools by kiegroup.
the class KieBaseUtil method generateKieModuleForCanonicalModel.
private static void generateKieModuleForCanonicalModel(KieBuilder kieBuilder) {
KieServices ks = KieServices.get();
ReleaseId releaseId = kieBuilder.getKieModule().getReleaseId();
InternalKieModule kieModule = (InternalKieModule) kieBuilder.getKieModule();
File kjarFile = FileUtil.bytesToTempKJARFile(releaseId, kieModule.getBytes(), ".jar");
KieModule zipKieModule = new CanonicalKieModule(releaseId, KieUtil.getDefaultKieModuleModel(ks), kjarFile);
ks.getRepository().addKieModule(zipKieModule);
}
use of org.kie.api.builder.KieModule in project drools by kiegroup.
the class KieUtil method buildAndInstallKieModuleIntoRepo.
public static KieModule buildAndInstallKieModuleIntoRepo(final KieBaseTestConfiguration kieBaseTestConfiguration, final ReleaseId releaseId, final KieModuleModel kieModuleModel, final Resource... resources) {
final KieServices kieServices = KieServices.Factory.get();
final KieFileSystem fileSystem = getKieFileSystemWithKieModule(kieModuleModel, releaseId, resources);
final KieBuilder builder = getKieBuilderFromKieFileSystem(kieBaseTestConfiguration, fileSystem, true);
KieModule kieModule = builder.getKieModule();
if (kieBaseTestConfiguration.useCanonicalModel()) {
final File kjarFile = FileUtil.bytesToTempKJARFile(releaseId, ((InternalKieModule) kieModule).getBytes(), ".jar");
kieModule = new CanonicalKieModule(releaseId, kieModuleModel, kjarFile);
}
kieServices.getRepository().addKieModule(kieModule);
return kieModule;
}
use of org.kie.api.builder.KieModule in project drools by kiegroup.
the class KieSessionUtil method getKieSessionFromKieBaseModel.
public static Session getKieSessionFromKieBaseModel(final String moduleGroupId, final KieBaseTestConfiguration kieBaseTestConfiguration, final KieSessionTestConfiguration kieSessionTestConfiguration, final Resource... resources) {
final KieModuleModel module = KieUtil.createKieModuleModel();
final KieBaseModel kieBaseModel = kieBaseTestConfiguration.getKieBaseModel(module);
kieSessionTestConfiguration.getKieSessionModel(kieBaseModel);
final KieModule kieModule = KieUtil.buildAndInstallKieModuleIntoRepo(kieBaseTestConfiguration, moduleGroupId, module, resources);
return getDefaultKieSessionFromReleaseId(kieModule.getReleaseId(), kieSessionTestConfiguration.isStateful(), false);
}
use of org.kie.api.builder.KieModule in project drools by kiegroup.
the class DeclarativeAgendaTest method buildKieBase.
private KieBase buildKieBase(final String drlFile) {
final KieServices kieServices = KieServices.Factory.get();
final Resource resource = kieServices.getResources().newClassPathResource(drlFile, getClass());
final KieModule kieModule = KieBaseUtil.getKieModuleAndBuildInstallModule(TestConstants.PACKAGE_FUNCTIONAL, KieBaseTestConfiguration.CLOUD_IDENTITY, resource);
final KieBaseConfiguration kbconf = kieServices.newKieBaseConfiguration();
kbconf.setOption(DeclarativeAgendaOption.ENABLED);
return kieServices.newKieContainer(kieModule.getReleaseId()).newKieBase(kbconf);
}
use of org.kie.api.builder.KieModule in project drools by kiegroup.
the class IncrementalCompilationTest method testChangeParentRule.
@Test
public void testChangeParentRule() {
String drl1 = "global java.util.List list;" + "rule B extends A when\n" + " $s : String()\n" + "then\n" + " list.add( $s );\n" + "end\n" + "\n" + "rule A when\n" + " $i : Integer( this > 3 )\n" + "then\n" + "end";
String drl2 = "global java.util.List list;" + "rule B extends A when\n" + " $s : String()\n" + "then\n" + " list.add( $s );\n" + "end\n" + "\n" + "rule A when\n" + " $i : Integer( this > 2 )\n" + "then\n" + "end";
String drl3 = "global java.util.List list;" + "rule B extends A when\n" + " $s : String()\n" + "then\n" + " list.add( $s );\n" + "end\n" + "\n" + "rule A when\n" + " $i : Integer( this > 5 )\n" + "then\n" + "end";
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade", "1.0.0");
KieModule km = createAndDeployJar(ks, releaseId1, drl1);
KieContainer kc = ks.newKieContainer(km.getReleaseId());
KieSession ksession = kc.newKieSession();
List<String> list = new ArrayList<String>();
ksession.setGlobal("list", list);
ksession.insert(4);
ksession.insert("test");
ksession.fireAllRules();
assertEquals(1, list.size());
list.clear();
ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.0");
createAndDeployJar(ks, releaseId2, drl2);
kc.updateToVersion(releaseId2);
ksession.fireAllRules();
assertEquals(1, list.size());
list.clear();
ReleaseId releaseId3 = ks.newReleaseId("org.kie", "test-upgrade", "1.2.0");
createAndDeployJar(ks, releaseId3, drl3);
kc.updateToVersion(releaseId3);
ksession.fireAllRules();
assertEquals(0, list.size());
}
Aggregations