Search in sources :

Example 41 with Resource

use of org.kie.api.io.Resource in project drools by kiegroup.

the class UnicodeTest method testCzechDomainSpecificLanguage.

@Test
public void testCzechDomainSpecificLanguage() {
    final KieServices kieServices = KieServices.Factory.get();
    final Resource dsl = kieServices.getResources().newClassPathResource("unicode.dsl", getClass());
    final Resource dslr = kieServices.getResources().newClassPathResource("unicode.dslr", getClass());
    final KieBase kbase = KieBaseUtil.getKieBaseFromResources(kieBaseTestConfiguration, dsl, dslr);
    final KieSession ksession = kbase.newKieSession();
    final List<Command<?>> commands = new ArrayList<Command<?>>();
    final List<Člověk> dospělí = new ArrayList<Člověk>();
    commands.add(kieServices.getCommands().newSetGlobal("dospělí", dospělí));
    final Člověk Řehoř = new Člověk();
    Řehoř.setVěk(30);
    Řehoř.setJméno("Řehoř");
    commands.add(kieServices.getCommands().newInsert(Řehoř));
    commands.add(kieServices.getCommands().newFireAllRules());
    ksession.execute(kieServices.getCommands().newBatchExecution(commands, null));
    Assertions.assertThat(kbase.getRule(TestConstants.PACKAGE_FUNCTIONAL, "pokusné doménově specifické pravidlo")).isNotNull();
    Assertions.assertThat(dospělí.size()).isEqualTo(1);
    Assertions.assertThat(dospělí.iterator().next().getJméno()).isEqualTo("Řehoř");
}
Also used : Command(org.kie.api.command.Command) KieBase(org.kie.api.KieBase) Resource(org.kie.api.io.Resource) ArrayList(java.util.ArrayList) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Example 42 with Resource

use of org.kie.api.io.Resource in project drools by kiegroup.

the class UnicodeTest method testCzechXLSDecisionTable.

@Test
public void testCzechXLSDecisionTable() throws FileNotFoundException {
    final KieServices kieServices = KieServices.Factory.get();
    final Resource resource = kieServices.getResources().newClassPathResource("unicode.xls", getClass());
    final KieBase kbase = KieBaseUtil.getKieBaseFromResources(kieBaseTestConfiguration, resource);
    final KieSession ksession = kbase.newKieSession();
    final List<Command<?>> commands = new ArrayList<Command<?>>();
    final List<Člověk> dospělí = new ArrayList<Člověk>();
    commands.add(kieServices.getCommands().newSetGlobal("dospělí", dospělí));
    final Člověk Řehoř = new Člověk();
    Řehoř.setVěk(30);
    Řehoř.setJméno("Řehoř");
    commands.add(kieServices.getCommands().newInsert(Řehoř));
    commands.add(kieServices.getCommands().newFireAllRules());
    ksession.execute(kieServices.getCommands().newBatchExecution(commands, null));
    Assertions.assertThat(kbase.getRule(TestConstants.PACKAGE_FUNCTIONAL, "přidej k dospělým")).isNotNull();
    Assertions.assertThat(dospělí.size()).isEqualTo(1);
    Assertions.assertThat(dospělí.iterator().next().getJméno()).isEqualTo("Řehoř");
}
Also used : Command(org.kie.api.command.Command) KieBase(org.kie.api.KieBase) Resource(org.kie.api.io.Resource) ArrayList(java.util.ArrayList) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Example 43 with Resource

use of org.kie.api.io.Resource in project drools by kiegroup.

the class BuildtimeUtil method createKieBaseFromResources.

public static KieBase createKieBaseFromResources(final KieBaseConfiguration kieBaseConfiguration, final Resource... resources) {
    final KieHelper kieHelper = new KieHelper();
    for (final Resource resource : resources) {
        kieHelper.addResource(resource);
    }
    final KieBase kieBase = kieHelper.build(kieBaseConfiguration);
    return kieBase;
}
Also used : KieBase(org.kie.api.KieBase) Resource(org.kie.api.io.Resource) KieHelper(org.kie.internal.utils.KieHelper)

Example 44 with Resource

use of org.kie.api.io.Resource in project drools by kiegroup.

the class DslParserTest method testParserDsl.

@Test
public void testParserDsl() {
    final Resource dslResource = KieServices.Factory.get().getResources().newFileSystemResource(dsl);
    final Resource dslrResource = KieServices.Factory.get().getResources().newFileSystemResource(file);
    KieUtil.getKieBuilderFromResources(kieBaseTestConfiguration, true, dslResource, dslrResource);
}
Also used : Resource(org.kie.api.io.Resource) Test(org.junit.Test)

Example 45 with Resource

use of org.kie.api.io.Resource 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

Resource (org.kie.api.io.Resource)162 Test (org.junit.Test)100 KieSession (org.kie.api.runtime.KieSession)50 KieServices (org.kie.api.KieServices)43 KieBase (org.kie.api.KieBase)42 ArrayList (java.util.ArrayList)30 KieContainer (org.kie.api.runtime.KieContainer)27 StringReader (java.io.StringReader)23 ReleaseId (org.kie.api.builder.ReleaseId)23 KieBuilder (org.kie.api.builder.KieBuilder)20 KieModule (org.kie.api.builder.KieModule)20 KieFileSystem (org.kie.api.builder.KieFileSystem)19 ClassPathResource (org.drools.core.io.impl.ClassPathResource)18 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)17 FactType (org.kie.api.definition.type.FactType)17 KnowledgeBuilder (org.kie.internal.builder.KnowledgeBuilder)16 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)14 ByteArrayResource (org.drools.core.io.impl.ByteArrayResource)14 IOException (java.io.IOException)13 PMMLResource (org.drools.compiler.compiler.PMMLResource)11