Search in sources :

Example 91 with DMNModel

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;
}
Also used : Import(org.kie.dmn.model.v1_1.Import) QName(javax.xml.namespace.QName) DMNModelImpl(org.kie.dmn.core.impl.DMNModelImpl) DMNModel(org.kie.dmn.api.core.DMNModel)

Example 92 with DMNModel

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));
}
Also used : DMNMessage(org.kie.dmn.api.core.DMNMessage) Definitions(org.kie.dmn.model.v1_1.Definitions) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) Test(org.junit.Test) DMNInputRuntimeTest(org.kie.dmn.core.DMNInputRuntimeTest)

Example 93 with DMNModel

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;
}
Also used : DMNPackage(org.kie.dmn.api.core.DMNPackage) ArrayList(java.util.ArrayList) DMNModel(org.kie.dmn.api.core.DMNModel) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage)

Example 94 with DMNModel

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());
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) DMNContext(org.kie.dmn.api.core.DMNContext) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) Test(org.junit.Test)

Example 95 with DMNModel

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());
}
Also used : DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) Test(org.junit.Test)

Aggregations

DMNModel (org.kie.dmn.api.core.DMNModel)163 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)152 Test (org.junit.Test)143 DMNContext (org.kie.dmn.api.core.DMNContext)131 DMNResult (org.kie.dmn.api.core.DMNResult)123 BigDecimal (java.math.BigDecimal)26 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)26 HashMap (java.util.HashMap)25 ArrayList (java.util.ArrayList)22 List (java.util.List)22 Map (java.util.Map)22 KieServices (org.kie.api.KieServices)21 KieContainer (org.kie.api.runtime.KieContainer)21 DMNMessage (org.kie.dmn.api.core.DMNMessage)16 CoreMatchers.is (org.hamcrest.CoreMatchers.is)13 CoreMatchers.notNullValue (org.hamcrest.CoreMatchers.notNullValue)13 AfterEvaluateDecisionTableEvent (org.kie.dmn.api.core.event.AfterEvaluateDecisionTableEvent)13 DMNRuntimeEventListener (org.kie.dmn.api.core.event.DMNRuntimeEventListener)13 UUID (java.util.UUID)11 CoreMatchers.nullValue (org.hamcrest.CoreMatchers.nullValue)11