Java Code Examples for org.kie.api.builder.KieBuilder#getKieModule()
The following examples show how to use
org.kie.api.builder.KieBuilder#getKieModule() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimulateTestBase.java From kogito-runtimes with Apache License 2.0 | 5 votes |
protected ReleaseId createKJar(String... pairs) throws IOException { KieServices ks = KieServices.Factory.get(); KieModuleModel kproj = ks.newKieModuleModel(); KieFileSystem kfs = ks.newKieFileSystem(); for ( int i = 0; i < pairs.length; i += 2 ) { String id = pairs[i]; String rule = pairs[i + 1]; kfs.write( "src/main/resources/" + id.replaceAll( "\\.", "/" ) + "/rule" + i + ".drl", rule ); KieBaseModel kBase1 = kproj.newKieBaseModel( id ) .setEqualsBehavior( EqualityBehaviorOption.EQUALITY ) .setEventProcessingMode( EventProcessingOption.STREAM ) .addPackage( id ); KieSessionModel ksession1 = kBase1.newKieSessionModel(id + ".KSession1") .setType(KieSessionModel.KieSessionType.STATEFUL) .setClockType(ClockTypeOption.get("pseudo")); } kfs.writeKModuleXML(kproj.toXML()); // buildAll() automatically adds the module to the kieRepository KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll(); assertTrue(kieBuilder.getResults().getMessages().isEmpty()); KieModule kieModule = kieBuilder.getKieModule(); return kieModule.getReleaseId(); }
Example 2
Source File: SimulateTestBase.java From kogito-runtimes with Apache License 2.0 | 5 votes |
public static ReleaseId createKJarWithMultipleResources(String id, String[] resources, ResourceType[] types) { KieServices ks = KieServices.Factory.get(); KieModuleModel kproj = ks.newKieModuleModel(); KieFileSystem kfs = ks.newKieFileSystem(); for ( int i = 0; i < resources.length; i++ ) { String res = resources[i]; String type = types[i].getDefaultExtension(); kfs.write( "src/main/resources/" + id.replaceAll( "\\.", "/" ) + "/org/test/res" + i + "." + type, res ); } KieBaseModel kBase1 = kproj.newKieBaseModel( id ) .setEqualsBehavior( EqualityBehaviorOption.EQUALITY ) .setEventProcessingMode( EventProcessingOption.STREAM ); KieSessionModel ksession1 = kBase1.newKieSessionModel( id + ".KSession1" ) .setDefault(true) .setType(KieSessionModel.KieSessionType.STATEFUL) .setClockType( ClockTypeOption.get( "pseudo" ) ); kfs.writeKModuleXML(kproj.toXML()); KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll(); assertTrue(kieBuilder.getResults().getMessages().isEmpty()); KieModule kieModule = kieBuilder.getKieModule(); return kieModule.getReleaseId(); }
Example 3
Source File: KieHelloWorldTest.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Test public void testHelloWorldWithSpace() throws Exception { // DROOLS-2338 final KieServices kieServices = KieServices.get(); final Path dir = Paths.get("/tmp/t tt"); Files.createDirectories(dir); final String text = "rule \"Hello world rule\"\n" + "when\n" + "then\n" + " System.out.println(\"Hello world\");" + "end\n"; final Path filePath = dir.resolve("one.drl"); Files.write(filePath, text.getBytes()); final KieFileSystem fs = kieServices.newKieFileSystem(); fs.write( ResourceFactory.newUrlResource("file:/tmp/t%20tt/one.drl")); KieBuilder kieBuilder = kieServices.newKieBuilder(fs); kieBuilder.buildAll(); KieModule kieModule = kieBuilder.getKieModule(); KieSession ksession = kieServices.newKieContainer(kieModule.getReleaseId()).newKieSession(); ksession.insert(new Object()); int count = ksession.fireAllRules(); assertEquals( 1, count ); }
Example 4
Source File: KieFileSystemScannerTest.java From kogito-runtimes with Apache License 2.0 | 5 votes |
private InternalKieModule createKieJar( KieServices ks, ReleaseId releaseId, String... rules) throws IOException { KieModuleModel kproj = ks.newKieModuleModel(); KieFileSystem kfs = ks.newKieFileSystem(); kfs.writeKModuleXML(kproj.toXML()); kfs.writePomXML(getPom(releaseId)); for (String rule : rules) { String file = "org/test/" + rule + ".drl"; kfs.write("src/main/resources/KBase1/" + file, createDRL(rule)); } KieBuilder kieBuilder = ks.newKieBuilder(kfs); assertTrue(kieBuilder.buildAll().getResults().getMessages().isEmpty()); return (InternalKieModule) kieBuilder.getKieModule(); }
Example 5
Source File: TaxiFareConfiguration.java From tutorials with MIT License | 5 votes |
@Bean public KieContainer kieContainer() { KieServices kieServices = KieServices.Factory.get(); KieFileSystem kieFileSystem = kieServices.newKieFileSystem(); kieFileSystem.write(ResourceFactory.newClassPathResource(drlFile)); KieBuilder kieBuilder = kieServices.newKieBuilder(kieFileSystem); kieBuilder.buildAll(); KieModule kieModule = kieBuilder.getKieModule(); return kieServices.newKieContainer(kieModule.getReleaseId()); }