Search in sources :

Example 81 with KieModule

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);
}
Also used : CanonicalKieModule(org.drools.modelcompiler.CanonicalKieModule) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) File(java.io.File) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieModule(org.kie.api.builder.KieModule) CanonicalKieModule(org.drools.modelcompiler.CanonicalKieModule) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule)

Example 82 with KieModule

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;
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) CanonicalKieModule(org.drools.modelcompiler.CanonicalKieModule) KieServices(org.kie.api.KieServices) KieBuilder(org.kie.api.builder.KieBuilder) File(java.io.File) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) CanonicalKieModule(org.drools.modelcompiler.CanonicalKieModule) KieModule(org.kie.api.builder.KieModule)

Example 83 with 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);
}
Also used : KieBaseModel(org.kie.api.builder.model.KieBaseModel) KieModuleModel(org.kie.api.builder.model.KieModuleModel) KieModule(org.kie.api.builder.KieModule)

Example 84 with KieModule

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);
}
Also used : KieBaseConfiguration(org.kie.api.KieBaseConfiguration) Resource(org.kie.api.io.Resource) KieServices(org.kie.api.KieServices) KieModule(org.kie.api.builder.KieModule)

Example 85 with KieModule

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());
}
Also used : ArrayList(java.util.ArrayList) KieServices(org.kie.api.KieServices) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieModule(org.kie.api.builder.KieModule) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Aggregations

KieModule (org.kie.api.builder.KieModule)124 KieServices (org.kie.api.KieServices)104 Test (org.junit.Test)94 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)84 ReleaseId (org.kie.api.builder.ReleaseId)84 KieContainer (org.kie.api.runtime.KieContainer)75 KieSession (org.kie.api.runtime.KieSession)64 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)53 Message (org.drools.compiler.Message)25 KieFileSystem (org.kie.api.builder.KieFileSystem)23 Resource (org.kie.api.io.Resource)20 ArrayList (java.util.ArrayList)15 KieModuleModel (org.kie.api.builder.model.KieModuleModel)15 KieBuilder (org.kie.api.builder.KieBuilder)13 KieRepository (org.kie.api.builder.KieRepository)10 MemoryFileSystem (org.drools.compiler.compiler.io.memory.MemoryFileSystem)7 KieBaseModel (org.kie.api.builder.model.KieBaseModel)7 KieBase (org.kie.api.KieBase)6 List (java.util.List)5 Results (org.kie.api.builder.Results)5