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ř");
}
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ř");
}
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;
}
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);
}
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();
}
Aggregations