Search in sources :

Example 6 with KieRepository

use of org.kie.api.builder.KieRepository in project drools by kiegroup.

the class DroolsAbstractPMMLTest method getModelSession.

protected KieSession getModelSession(String[] pmmlSources, boolean verbose) {
    KieServices ks = KieServices.Factory.get();
    KieRepository kr = ks.getRepository();
    KieFileSystem kfs = ks.newKieFileSystem();
    for (int j = 0; j < pmmlSources.length; j++) {
        Resource res = ResourceFactory.newClassPathResource(pmmlSources[j]).setResourceType(ResourceType.PMML);
        kfs.write(res);
    }
    KieModuleModel model = ks.newKieModuleModel();
    model.setConfigurationProperty("drools.propertySpecific", "ALLOWED");
    KieBaseModel kbModel = model.newKieBaseModel(DEFAULT_KIEBASE).setDefault(true).addPackage(BASE_PACK).setEventProcessingMode(EventProcessingOption.STREAM);
    kfs.writeKModuleXML(model.toXML());
    KieBuilder kb = ks.newKieBuilder(kfs);
    kb.buildAll();
    if (kb.getResults().hasMessages(Message.Level.ERROR)) {
        throw new RuntimeException("Build Errors:\n" + kb.getResults().toString());
    }
    KieContainer kContainer = ks.newKieContainer(kr.getDefaultReleaseId());
    KieBase kieBase = kContainer.getKieBase();
    setKbase(kieBase);
    return kieBase.newKieSession();
}
Also used : KieBaseModel(org.kie.api.builder.model.KieBaseModel) KieRepository(org.kie.api.builder.KieRepository) KieFileSystem(org.kie.api.builder.KieFileSystem) KieModuleModel(org.kie.api.builder.model.KieModuleModel) KieBase(org.kie.api.KieBase) Resource(org.kie.api.io.Resource) KieServices(org.kie.api.KieServices) KieBuilder(org.kie.api.builder.KieBuilder) KieContainer(org.kie.api.runtime.KieContainer)

Example 7 with KieRepository

use of org.kie.api.builder.KieRepository in project drools by kiegroup.

the class KieRepositoryTest method testKieModuleRemoval.

private void testKieModuleRemoval(final ReleaseId releaseId) {
    final KieRepository kieRepository = kieServices.getRepository();
    this.createKieModule(releaseId);
    Assertions.assertThat(kieRepository.getKieModule(releaseId)).as("KieModule should be in KieRepository").isNotNull();
    kieRepository.removeKieModule(releaseId);
    Assertions.assertThat(kieRepository.getKieModule(releaseId)).as("KieModule should NOT be in KieRepository").isNull();
}
Also used : KieRepository(org.kie.api.builder.KieRepository)

Example 8 with KieRepository

use of org.kie.api.builder.KieRepository in project drools by kiegroup.

the class DefaultKieSessionFromByteArrayExampleTest method go.

public void go(PrintStream out) {
    KieServices ks = KieServices.Factory.get();
    KieRepository kr = ks.getRepository();
    KieModule kModule = kr.addKieModule(ks.getResources().newByteArrayResource(getKjarAsByteArray(getFile("default-kiesession"))));
    KieContainer kContainer = ks.newKieContainer(kModule.getReleaseId());
    KieSession kSession = kContainer.newKieSession();
    kSession.setGlobal("out", out);
    Object msg1 = createMessage(kContainer, "Dave", "Hello, HAL. Do you read me, HAL?");
    kSession.insert(msg1);
    kSession.fireAllRules();
}
Also used : KieRepository(org.kie.api.builder.KieRepository) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) KieModule(org.kie.api.builder.KieModule) KieContainer(org.kie.api.runtime.KieContainer)

Example 9 with KieRepository

use of org.kie.api.builder.KieRepository in project drools by kiegroup.

the class NamedKieSessionFromFileExample method go.

public void go(PrintStream out) {
    KieServices ks = KieServices.Factory.get();
    KieRepository kr = ks.getRepository();
    KieModule kModule = kr.addKieModule(ks.getResources().newFileSystemResource(getFile("named-kiesession")));
    KieContainer kContainer = ks.newKieContainer(kModule.getReleaseId());
    KieSession kSession = kContainer.newKieSession("ksession1");
    kSession.setGlobal("out", out);
    Object msg1 = createMessage(kContainer, "Dave", "Hello, HAL. Do you read me, HAL?");
    kSession.insert(msg1);
    kSession.fireAllRules();
}
Also used : KieRepository(org.kie.api.builder.KieRepository) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) KieModule(org.kie.api.builder.KieModule) KieContainer(org.kie.api.runtime.KieContainer)

Example 10 with KieRepository

use of org.kie.api.builder.KieRepository in project drools by kiegroup.

the class DroolsAbstractPMMLTest method getModelSession.

protected KieSession getModelSession(String[] pmmlSources, boolean verbose) {
    KieServices ks = KieServices.Factory.get();
    KieRepository kr = ks.getRepository();
    KieFileSystem kfs = ks.newKieFileSystem();
    for (int j = 0; j < pmmlSources.length; j++) {
        Resource res = ResourceFactory.newClassPathResource(pmmlSources[j]).setResourceType(ResourceType.PMML);
        kfs.write(res);
    }
    KieModuleModel model = ks.newKieModuleModel();
    model.setConfigurationProperty("drools.propertySpecific", "ALLOWED");
    KieBaseModel kbModel = model.newKieBaseModel(DEFAULT_KIEBASE).addPackage(BASE_PACK).setEventProcessingMode(EventProcessingOption.CLOUD);
    kfs.writeKModuleXML(model.toXML());
    KieBuilder kb = ks.newKieBuilder(kfs);
    kb.buildAll();
    if (kb.getResults().hasMessages(Message.Level.ERROR)) {
        throw new RuntimeException("Build Errors:\n" + kb.getResults().toString());
    }
    KieContainer kContainer = ks.newKieContainer(kr.getDefaultReleaseId());
    // KieBase kieBase = kContainer.getKieBase("SampleMine_SampleMineSegmentation_SEGMENT_1");
    KieBase kieBase = kContainer.getKieBase();
    setKbase(kieBase);
    return kieBase.newKieSession();
}
Also used : KieBaseModel(org.kie.api.builder.model.KieBaseModel) KieRepository(org.kie.api.builder.KieRepository) KieFileSystem(org.kie.api.builder.KieFileSystem) KieModuleModel(org.kie.api.builder.model.KieModuleModel) KieBase(org.kie.api.KieBase) Resource(org.kie.api.io.Resource) KieServices(org.kie.api.KieServices) KieBuilder(org.kie.api.builder.KieBuilder) KieContainer(org.kie.api.runtime.KieContainer)

Aggregations

KieRepository (org.kie.api.builder.KieRepository)28 KieServices (org.kie.api.KieServices)23 KieContainer (org.kie.api.runtime.KieContainer)18 KieBuilder (org.kie.api.builder.KieBuilder)11 KieFileSystem (org.kie.api.builder.KieFileSystem)10 KieModule (org.kie.api.builder.KieModule)10 Resource (org.kie.api.io.Resource)8 Test (org.junit.Test)7 KieBase (org.kie.api.KieBase)7 ReleaseId (org.kie.api.builder.ReleaseId)7 KieSession (org.kie.api.runtime.KieSession)7 KieBaseModel (org.kie.api.builder.model.KieBaseModel)6 KieModuleModel (org.kie.api.builder.model.KieModuleModel)6 URLClassLoader (java.net.URLClassLoader)4 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)4 ArrayList (java.util.ArrayList)3 FileOutputStream (java.io.FileOutputStream)2 List (java.util.List)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1