Search in sources :

Example 66 with KieBuilder

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

the class QueryBadResultTest method testQueriesWithSameNameInTwoFiles.

@Test
public void testQueriesWithSameNameInTwoFiles() {
    final KieBuilder kieBuilder = KieUtil.getKieBuilderFromClasspathResources(kieBaseTestConfiguration, getClass(), false, "query-same-name-1.drl", "query-same-name-2.drl");
    Assertions.assertThat(kieBuilder.getResults().getMessages(Level.ERROR).isEmpty()).isFalse();
}
Also used : KieBuilder(org.kie.api.builder.KieBuilder) Test(org.junit.Test)

Example 67 with KieBuilder

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

the class QueryBadResultTest method testBadAccessToParameterWithoutType.

@Test
public void testBadAccessToParameterWithoutType() {
    final KieBuilder kieBuilder = KieUtil.getKieBuilderFromClasspathResources(kieBaseTestConfiguration, getClass(), false, "query-bad-parametr-access.drl");
    Assertions.assertThat(kieBuilder.getResults().getMessages(Level.ERROR).isEmpty()).isFalse();
}
Also used : KieBuilder(org.kie.api.builder.KieBuilder) Test(org.junit.Test)

Example 68 with KieBuilder

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

the class BuildtimeUtil method createKJarFromResources.

public static ReleaseId createKJarFromResources(final boolean useCanonicalModel, final Resource... resources) throws IOException {
    final KieServices kieServices = KieServices.get();
    final KieBuilder kieBuilder = getKieBuilderFromResources(kieServices.newKieFileSystem(), useCanonicalModel, resources);
    generateKJarFromKieBuilder(kieBuilder, useCanonicalModel);
    return kieBuilder.getKieModule().getReleaseId();
}
Also used : KieServices(org.kie.api.KieServices) KieBuilder(org.kie.api.builder.KieBuilder)

Example 69 with KieBuilder

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

the class DefaultKieSessionFromFSExampleTest method go.

public void go(PrintStream out) {
    String currentFolder = null;
    try {
        currentFolder = new File(".").getCanonicalPath();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    File rootFolder = null;
    if (currentFolder.endsWith("drools")) {
        rootFolder = new File("drools-examples-api/default-kiesession");
    } else if (currentFolder.endsWith("drools-examples-api")) {
        rootFolder = new File("default-kiesession");
    } else {
        rootFolder = new File(".");
    }
    KieServices ks = KieServices.Factory.get();
    KieBuilder kieBuilder = ks.newKieBuilder(rootFolder).buildAll();
    KieSession kSession = ks.newKieContainer(kieBuilder.getKieModule().getReleaseId()).newKieSession();
    kSession.setGlobal("out", out);
    kSession.insert(new Message("Dave", "Hello, HAL. Do you read me, HAL?"));
    kSession.fireAllRules();
}
Also used : KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) IOException(java.io.IOException) KieBuilder(org.kie.api.builder.KieBuilder) File(java.io.File)

Example 70 with KieBuilder

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

the class KieModuleModelExample method go.

public void go(PrintStream out) {
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem();
    Resource ex1Res = ks.getResources().newFileSystemResource(getFile("named-kiesession"));
    Resource ex2Res = ks.getResources().newFileSystemResource(getFile("kiebase-inclusion"));
    ReleaseId rid = ks.newReleaseId("org.drools", "kiemodulemodel-example", Drools.getFullVersion());
    kfs.generateAndWritePomXML(rid);
    KieModuleModel kModuleModel = ks.newKieModuleModel();
    kModuleModel.newKieBaseModel("kiemodulemodel").addInclude("kbase1").addInclude("kbase2").newKieSessionModel("ksession6");
    kfs.writeKModuleXML(kModuleModel.toXML());
    kfs.write("src/main/resources/kiemodulemodel/HAL6.drl", getRule());
    KieBuilder kb = ks.newKieBuilder(kfs);
    kb.setDependencies(ex1Res, ex2Res);
    // kieModule is automatically deployed to KieRepository if successfully built.
    kb.buildAll();
    if (kb.getResults().hasMessages(Level.ERROR)) {
        throw new RuntimeException("Build Errors:\n" + kb.getResults().toString());
    }
    KieContainer kContainer = ks.newKieContainer(rid);
    KieSession kSession = kContainer.newKieSession("ksession6");
    kSession.setGlobal("out", out);
    Object msg1 = createMessage(kContainer, "Dave", "Hello, HAL. Do you read me, HAL?");
    kSession.insert(msg1);
    kSession.fireAllRules();
    Object msg2 = createMessage(kContainer, "Dave", "Open the pod bay doors, HAL.");
    kSession.insert(msg2);
    kSession.fireAllRules();
    Object msg3 = createMessage(kContainer, "Dave", "What's the problem?");
    kSession.insert(msg3);
    kSession.fireAllRules();
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) KieModuleModel(org.kie.api.builder.model.KieModuleModel) Resource(org.kie.api.io.Resource) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) KieBuilder(org.kie.api.builder.KieBuilder) KieContainer(org.kie.api.runtime.KieContainer)

Aggregations

KieBuilder (org.kie.api.builder.KieBuilder)211 KieFileSystem (org.kie.api.builder.KieFileSystem)179 KieServices (org.kie.api.KieServices)145 Test (org.junit.Test)134 KieSession (org.kie.api.runtime.KieSession)59 KieModuleModel (org.kie.api.builder.model.KieModuleModel)57 InternalKieBuilder (org.kie.internal.builder.InternalKieBuilder)54 KieContainer (org.kie.api.runtime.KieContainer)48 IncrementalResults (org.kie.internal.builder.IncrementalResults)35 ReleaseId (org.kie.api.builder.ReleaseId)34 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)33 Results (org.kie.api.builder.Results)32 Message (org.kie.api.builder.Message)30 KieBase (org.kie.api.KieBase)29 ArrayList (java.util.ArrayList)22 KieBaseModel (org.kie.api.builder.model.KieBaseModel)22 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)21 Resource (org.kie.api.io.Resource)19 FactType (org.kie.api.definition.type.FactType)16 KieModule (org.kie.api.builder.KieModule)12