Search in sources :

Example 31 with DMNModel

use of org.kie.dmn.api.core.DMNModel in project drools by kiegroup.

the class DMNWeaverService method merge.

@Override
public void merge(KieBase kieBase, KiePackage kiePkg, DMNPackage dmnpkg) {
    Map<ResourceType, ResourceTypePackage> map = ((InternalKnowledgePackage) kiePkg).getResourceTypePackages();
    DMNPackageImpl existing = (DMNPackageImpl) map.get(ResourceType.DMN);
    if (existing == null) {
        existing = new DMNPackageImpl(dmnpkg.getNamespace());
        map.put(ResourceType.DMN, existing);
    }
    for (Map.Entry<String, DMNModel> entry : dmnpkg.getAllModels().entrySet()) {
        existing.addModel(entry.getKey(), entry.getValue());
    }
    existing.addProfiles(((DMNPackageImpl) dmnpkg).getProfiles());
}
Also used : DMNPackageImpl(org.kie.dmn.core.impl.DMNPackageImpl) ResourceType(org.kie.api.io.ResourceType) ResourceTypePackage(org.kie.api.internal.io.ResourceTypePackage) Map(java.util.Map) DMNModel(org.kie.dmn.api.core.DMNModel) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage)

Example 32 with DMNModel

use of org.kie.dmn.api.core.DMNModel in project drools by kiegroup.

the class DMNAssemblerTest method testStrictMode.

@Test
public void testStrictMode() {
    System.setProperty("org.kie.dmn.strictConformance", "true");
    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);
    assertNull(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 33 with DMNModel

use of org.kie.dmn.api.core.DMNModel 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());
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) KieFileSystem(org.kie.api.builder.KieFileSystem) KieModuleModel(org.kie.api.builder.model.KieModuleModel) DMNContext(org.kie.dmn.api.core.DMNContext) KieServices(org.kie.api.KieServices) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 34 with DMNModel

use of org.kie.dmn.api.core.DMNModel in project drools by kiegroup.

the class DMNCompilerTest method testImport.

@Test
public void testImport() {
    System.out.println(null instanceof Definitions);
    DMNRuntime runtime = DMNRuntimeUtil.createRuntimeWithAdditionalResources("Importing_Model.dmn", this.getClass(), "Imported_Model.dmn");
    DMNModel importedModel = runtime.getModel("http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df36", "Imported Model");
    assertThat(importedModel, notNullValue());
    for (DMNMessage message : importedModel.getMessages()) {
        LOG.debug("{}", message);
    }
    DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edab52", "Importing Model");
    assertThat(dmnModel, notNullValue());
    for (DMNMessage message : dmnModel.getMessages()) {
        LOG.debug("{}", message);
    }
    DMNContext context = runtime.newContext();
    context.set("A Person", mapOf(entry("name", "John"), entry("age", 47)));
    DMNResult evaluateAll = runtime.evaluateAll(dmnModel, context);
    for (DMNMessage message : evaluateAll.getMessages()) {
        LOG.debug("{}", message);
    }
    LOG.debug("{}", evaluateAll);
    assertThat(evaluateAll.getDecisionResultByName("Greeting").getResult(), is("Hello John!"));
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) DMNMessage(org.kie.dmn.api.core.DMNMessage) Definitions(org.kie.dmn.model.v1_1.Definitions) 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 35 with DMNModel

use of org.kie.dmn.api.core.DMNModel in project drools by kiegroup.

the class DMNDecisionTableHitPolicyTest method testSimpleDecisionTableHitPolicyPriority.

@Test
public void testSimpleDecisionTableHitPolicyPriority() {
    final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("0004-simpletable-P.dmn", this.getClass());
    final DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", "0004-simpletable-P");
    assertThat(dmnModel, notNullValue());
    final DMNContext context = getSimpleTableContext(BigDecimal.valueOf(70), "Medium", true);
    final DMNContext result = evaluateSimpleTableWithContext(dmnModel, runtime, context);
    assertThat(result.get("Approval Status"), is("Declined"));
}
Also used : 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)

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