use of org.kie.api.builder.KieBuilder in project drools by kiegroup.
the class GenericsWithModifyTest method initialize.
@Before
public void initialize() throws IOException {
final Resource resource = KieServices.Factory.get().getResources().newByteArrayResource(DRL.getBytes(Charset.forName("UTF-8")));
resource.setTargetPath(TestConstants.DRL_TEST_TARGET_PATH);
final KieBuilder kbuilder = KieUtil.getKieBuilderFromResources(kieBaseTestConfiguration, true, resource);
final KieContainer kieContainer = KieServices.Factory.get().newKieContainer(kbuilder.getKieModule().getReleaseId());
this.kieSession = kieContainer.newKieSession();
}
use of org.kie.api.builder.KieBuilder in project drools by kiegroup.
the class BenchmarkUtil method createJarFile.
public static KJarWithKnowledgeFiles createJarFile(KieServices kieServices, ReleaseId releaseId, int numberOfRules, int numberOfRulesPerFile, BenchmarkType type) {
final KieFileSystem kieFileSystem = kieServices.newKieFileSystem();
kieFileSystem.writeKModuleXML(getDefaultKieModuleModel(kieServices).toXML());
kieFileSystem.writePomXML(getPom(releaseId));
writeDomainModelToKJar(kieServices, kieFileSystem);
Collection<String> generatedKnowledge = type.useRuleModel ? generateRuleModelSourcesToKJar(kieFileSystem, numberOfRules, numberOfRulesPerFile, type.generateExprId) : generateDRLsToKJar(kieFileSystem, numberOfRules, numberOfRulesPerFile);
final KieBuilder kieBuilder = kieServices.newKieBuilder(kieFileSystem);
testGeneratedKnowledge(kieBuilder);
final File jarFile = writeKJarToFile(kieBuilder, releaseId);
return new KJarWithKnowledgeFiles(jarFile, generatedKnowledge);
}
use of org.kie.api.builder.KieBuilder in project drools by kiegroup.
the class DMNExtensionRegisterTest method testUsingKModuleProperty_WrongClasses.
@Test
public void testUsingKModuleProperty_WrongClasses() {
final KieServices ks = KieServices.Factory.get();
final KieFileSystem kfs = ks.newKieFileSystem();
KieModuleModel kmm = ks.newKieModuleModel();
kmm.setConfigurationProperty("org.kie.dmn.profiles.FirstNameLastNameProfile", "foo");
kfs.writeKModuleXML(kmm.toXML());
kfs.write(ks.getResources().newClassPathResource("0001-input-data-string-with-extensions.dmn", this.getClass()));
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
Results results = kieBuilder.getResults();
LOG.info("buildAll() completed.");
results.getMessages(Level.WARNING).forEach(e -> LOG.warn("{}", e));
assertTrue(results.getMessages(Level.WARNING).size() > 0);
final KieContainer kieContainer = ks.newKieContainer(ks.getRepository().getDefaultReleaseId());
DMNRuntime runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class);
DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", "0001-input-data-string");
assertThat(dmnModel, notNullValue());
assertThat(formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
assertEquals(3, dmnModel.getDefinitions().getDrgElement().size());
InputData inputData1 = (InputData) dmnModel.getDefinitions().getDrgElement().get(1);
assertEquals("First Name", inputData1.getName());
DMNElement.ExtensionElements id1elements = inputData1.getExtensionElements();
assertTrue(id1elements != null);
assertEquals(0, id1elements.getAny().size());
InputData inputData2 = (InputData) dmnModel.getDefinitions().getDrgElement().get(2);
assertEquals("Last Name", inputData2.getName());
DMNElement.ExtensionElements id2elements = inputData2.getExtensionElements();
assertTrue(id2elements != null);
assertEquals(0, id2elements.getAny().size());
}
use of org.kie.api.builder.KieBuilder in project drools by kiegroup.
the class DMNExtensionRegisterTest method testUsingKModuleProperty.
@Test
public void testUsingKModuleProperty() {
final KieServices ks = KieServices.Factory.get();
final KieFileSystem kfs = ks.newKieFileSystem();
KieModuleModel kmm = ks.newKieModuleModel();
kmm.setConfigurationProperty("org.kie.dmn.profiles.FirstNameLastNameProfile", FirstNameLastNameProfile.class.getCanonicalName());
kfs.writeKModuleXML(kmm.toXML());
kfs.write(ks.getResources().newClassPathResource("0001-input-data-string-with-extensions.dmn", this.getClass()));
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
Results results = kieBuilder.getResults();
LOG.info("buildAll() completed.");
results.getMessages(Level.WARNING).forEach(e -> LOG.warn("{}", e));
assertTrue(results.getMessages(Level.WARNING).size() == 0);
final KieContainer kieContainer = ks.newKieContainer(ks.getRepository().getDefaultReleaseId());
DMNRuntime runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class);
DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", "0001-input-data-string");
assertThat(dmnModel, notNullValue());
assertThat(formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
assertEquals(3, dmnModel.getDefinitions().getDrgElement().size());
InputData inputData1 = (InputData) dmnModel.getDefinitions().getDrgElement().get(1);
assertEquals("First Name", inputData1.getName());
DMNElement.ExtensionElements id1elements = inputData1.getExtensionElements();
assertTrue(id1elements != null);
assertEquals(1, id1elements.getAny().size());
FirstNameDescription firstNameDescription = (FirstNameDescription) id1elements.getAny().get(0);
assertTrue(firstNameDescription.getContent().equals("First name in latin characters"));
InputData inputData2 = (InputData) dmnModel.getDefinitions().getDrgElement().get(2);
assertEquals("Last Name", inputData2.getName());
DMNElement.ExtensionElements id2elements = inputData2.getExtensionElements();
assertTrue(id2elements != null);
assertEquals(1, id2elements.getAny().size());
LastNameDescription lastNameDescription = (LastNameDescription) id2elements.getAny().get(0);
assertTrue(lastNameDescription.getContent().equals("Last name in latin characters"));
}
use of org.kie.api.builder.KieBuilder 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();
}
Aggregations