use of org.kie.dmn.api.core.DMNModel in project drools by kiegroup.
the class DMNCompilerImpl method compile.
@Override
public DMNModel compile(Definitions dmndefs, Collection<DMNModel> dmnModels) {
if (dmndefs == null) {
return null;
}
DMNModelImpl model = new DMNModelImpl(dmndefs);
model.setRuntimeTypeCheck(((DMNCompilerConfigurationImpl) dmnCompilerConfig).getOption(RuntimeTypeCheckOption.class).isRuntimeTypeCheck());
DMNCompilerContext ctx = new DMNCompilerContext();
if (!dmndefs.getImport().isEmpty()) {
for (Import i : dmndefs.getImport()) {
if (ImportDMNResolverUtil.whichImportType(i) == ImportType.DMN) {
Either<String, DMNModel> resolvedResult = ImportDMNResolverUtil.resolveImportDMN(i, dmnModels, (DMNModel m) -> new QName(m.getNamespace(), m.getName()));
DMNModel located = resolvedResult.cata(msg -> {
MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, i, model, null, null, Msg.IMPORT_NOT_FOUND_FOR_NODE, msg, i);
return null;
}, Function.identity());
if (located != null) {
String iAlias = Optional.ofNullable(i.getAdditionalAttributes().get(Import.NAME_QNAME)).orElse(located.getName());
model.setImportAliasForNS(iAlias, located.getNamespace(), located.getName());
importFromModel(model, located);
}
}
}
}
processItemDefinitions(ctx, feel, model, dmndefs);
processDrgElements(ctx, feel, model, dmndefs);
return model;
}
use of org.kie.dmn.api.core.DMNModel in project drools by kiegroup.
the class ValidatorTest method testMACDInputDefinitions.
@Test
public void testMACDInputDefinitions() {
DMNRuntime runtime = DMNRuntimeUtil.createRuntime("MACD-enhanced_iteration.dmn", DMNInputRuntimeTest.class);
DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_6cfe7d88-6741-45d1-968c-b61a597d0964", "MACD-enhanced iteration");
assertThat(dmnModel, notNullValue());
Definitions definitions = dmnModel.getDefinitions();
assertThat(definitions, notNullValue());
List<DMNMessage> messages = DMNValidatorFactory.newValidator().validate(definitions, VALIDATE_MODEL, VALIDATE_COMPILATION);
assertThat(messages.toString(), messages.size(), is(0));
}
use of org.kie.dmn.api.core.DMNModel in project drools by kiegroup.
the class DMNRuntimeImpl method getModels.
@Override
public List<DMNModel> getModels() {
List<DMNModel> models = new ArrayList<>();
runtime.getKieBase().getKiePackages().forEach(kpkg -> {
DMNPackage dmnPkg = (DMNPackage) ((InternalKnowledgePackage) kpkg).getResourceTypePackages().get(ResourceType.DMN);
if (dmnPkg != null) {
dmnPkg.getAllModels().values().forEach(model -> models.add(model));
}
});
return models;
}
use of org.kie.dmn.api.core.DMNModel in project drools by kiegroup.
the class DMNAssemblerTest method testExtendedMode.
@Test
public void testExtendedMode() {
DMNRuntime runtime = DMNRuntimeUtil.createRuntime("strictMode.dmn", this.getClass());
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);
assertEquals(DateTimeFormatter.ISO_TIME.parse("14:30:22z", OffsetTime::from), result.getDecisionResultByName("time").getResult());
}
use of org.kie.dmn.api.core.DMNModel in project drools by kiegroup.
the class DMNCompilerTest method testRecursiveFunctions.
@Test
public void testRecursiveFunctions() {
DMNRuntime runtime = DMNRuntimeUtil.createRuntime("Recursive.dmn", this.getClass());
DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", "Recursive");
assertThat(dmnModel, notNullValue());
assertFalse(runtime.evaluateAll(dmnModel, DMNFactory.newContext()).hasErrors());
}
Aggregations