use of org.kie.api.builder.model.KieModuleModel 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.model.KieModuleModel 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();
}
use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.
the class DMNAssemblerTest method testStrictModeProp.
@Test
public void testStrictModeProp() {
final KieServices services = KieServices.Factory.get();
final KieFileSystem fileSystem = services.newKieFileSystem();
KieModuleModel moduleModel = services.newKieModuleModel();
moduleModel.setConfigurationProperty("org.kie.dmn.strictConformance", "true");
fileSystem.writeKModuleXML(moduleModel.toXML());
fileSystem.write(services.getResources().newClassPathResource("strictMode.dmn", this.getClass()));
services.newKieBuilder(fileSystem).buildAll();
final KieContainer container = services.newKieContainer(services.getRepository().getDefaultReleaseId());
DMNRuntime runtime = container.newKieSession().getKieRuntime(DMNRuntime.class);
DMNModel model = runtime.getModel("http://www.trisotech.com/dmn/definitions/_ecf4ea54-2abc-4e2f-a101-4fe14e356a46", "strictMode");
DMNContext ctx = runtime.newContext();
ctx.set("timestring", "2016-12-20T14:30:22z");
DMNResult result = runtime.evaluateAll(model, ctx);
assertNull(result.getDecisionResultByName("time").getResult());
}
use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.
the class KieModuleBuilderTest method testKieModuleUsingPOMMissingKBaseDefinition.
@Test
public void testKieModuleUsingPOMMissingKBaseDefinition() throws Exception {
KieServices ks = KieServices.Factory.get();
// Build a KieModule jar, deploy it into local Maven repository
ReleaseId releaseId = ks.newReleaseId("org.kie", "metadata-test2", "1.0-SNAPSHOT");
String pomText = getPom(releaseId);
File pomFile = new File(System.getProperty("java.io.tmpdir"), MavenRepository.toFileName(releaseId, null) + ".pom");
try {
FileOutputStream fos = new FileOutputStream(pomFile);
fos.write(pomText.getBytes());
fos.flush();
fos.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
KieFileSystem kfs = ks.newKieFileSystem();
kfs.writePomXML(getPom(releaseId));
kfs.write("src/main/java/org/kie/test/Bean.java", createJavaSourceInPackage());
KieBuilder kieBuilder1 = ks.newKieBuilder(kfs);
Assert.assertTrue(kieBuilder1.buildAll().getResults().getMessages().isEmpty());
InternalKieModule kieModule = (InternalKieModule) kieBuilder1.getKieModule();
KieMavenRepository.getKieMavenRepository().installArtifact(releaseId, kieModule, pomFile);
// Build a second KieModule, depends on the first KieModule jar which we have deployed into Maven
ReleaseId releaseId2 = ks.newReleaseId("org.kie", "metadata-test-using-pom", "1.0-SNAPSHOT");
String pomText2 = getPom(releaseId2, releaseId);
File pomFile2 = new File(System.getProperty("java.io.tmpdir"), MavenRepository.toFileName(releaseId2, null) + ".pom");
try {
FileOutputStream fos = new FileOutputStream(pomFile2);
fos.write(pomText2.getBytes());
fos.flush();
fos.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
// Try building the second KieModule
KieServices kieServices = KieServices.Factory.get();
KieFileSystem kieFileSystem = kieServices.newKieFileSystem();
InputStream is = new FileInputStream(pomFile2);
KieModuleModel kproj2 = ks.newKieModuleModel();
kieFileSystem.write("pom.xml", KieServices.Factory.get().getResources().newInputStreamResource(is));
kieFileSystem.writeKModuleXML(kproj2.toXML());
kieFileSystem.write("src/main/resources/rule.drl", createDRLWithImport("rule1"));
KieBuilder kieBuilder = kieServices.newKieBuilder(kieFileSystem);
kieBuilder.buildAll();
assertTrue(kieBuilder.getResults().getMessages().isEmpty());
}
use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.
the class KieModuleDeploymentHelperImpl method createKieFileSystemWithKProject.
/**
* Create the {@link KieFileSystem} instance to store the content going into the KJar.
*
* @param kbaseName
* @param ksessionName
* @return
*/
private KieFileSystem createKieFileSystemWithKProject(String kbaseName, String ksessionName) {
KieModuleModel kproj = config.getKieProject();
KieFileSystem kfs = config.getKieServicesInstance().newKieFileSystem();
kfs.writeKModuleXML(kproj.toXML());
return kfs;
}
Aggregations