Search in sources :

Example 21 with Definitions

use of org.kie.dmn.model.api.Definitions in project drools by kiegroup.

the class DefinitionsConverter method writeAttributes.

@Override
protected void writeAttributes(HierarchicalStreamWriter writer, Object parent) {
    super.writeAttributes(writer, parent);
    Definitions def = (Definitions) parent;
    if (def.getExpressionLanguage() != null)
        writer.addAttribute(EXPRESSION_LANGUAGE, def.getExpressionLanguage());
    if (def.getTypeLanguage() != null)
        writer.addAttribute(TYPE_LANGUAGE, def.getTypeLanguage());
    if (def.getNamespace() != null)
        writer.addAttribute(NAMESPACE, def.getNamespace());
    if (def.getExporter() != null)
        writer.addAttribute(EXPORTER, def.getExporter());
    if (def.getExporterVersion() != null)
        writer.addAttribute(EXPORTER_VERSION, def.getExporterVersion());
}
Also used : TDefinitions(org.kie.dmn.model.v1_4.TDefinitions) Definitions(org.kie.dmn.model.api.Definitions)

Example 22 with Definitions

use of org.kie.dmn.model.api.Definitions in project drools by kiegroup.

the class DefinitionsConverter method assignChildElement.

@Override
protected void assignChildElement(Object parent, String nodeName, Object child) {
    Definitions def = (Definitions) parent;
    if (IMPORT.equals(nodeName)) {
        def.getImport().add((Import) child);
    } else if (ITEM_DEFINITION.equals(nodeName)) {
        def.getItemDefinition().add((ItemDefinition) child);
    } else if (child instanceof DRGElement) {
        def.getDrgElement().add((DRGElement) child);
    } else if (child instanceof Artifact) {
        def.getArtifact().add((Artifact) child);
    } else if (ELEMENT_COLLECTION.equals(nodeName)) {
        def.getElementCollection().add((ElementCollection) child);
    } else if (child instanceof BusinessContextElement) {
        def.getBusinessContextElement().add((BusinessContextElement) child);
    } else if (child instanceof DMNDI) {
        DMNDI dmndi = (DMNDI) child;
        dmndi.normalize();
        def.setDMNDI(dmndi);
    } else {
        super.assignChildElement(def, nodeName, child);
    }
}
Also used : TDefinitions(org.kie.dmn.model.v1_4.TDefinitions) Definitions(org.kie.dmn.model.api.Definitions) ItemDefinition(org.kie.dmn.model.api.ItemDefinition) DMNDI(org.kie.dmn.model.api.dmndi.DMNDI) BusinessContextElement(org.kie.dmn.model.api.BusinessContextElement) Artifact(org.kie.dmn.model.api.Artifact) DRGElement(org.kie.dmn.model.api.DRGElement)

Example 23 with Definitions

use of org.kie.dmn.model.api.Definitions in project drools by kiegroup.

the class DMNModelImpl method readExternal.

@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    this.serializedAs = (SerializationFormat) in.readObject();
    this.resource = (Resource) in.readObject();
    this.messages = new DefaultDMNMessagesManager(this.resource);
    String xml = (String) in.readObject();
    if (!(in instanceof DroolsObjectInputStream)) {
        throw new UnsupportedOperationException();
    // TODO assume some defaults
    }
    DroolsObjectInputStream is = (DroolsObjectInputStream) in;
    DMNCompilerImpl compiler = (DMNCompilerImpl) is.getCustomExtensions().get(DMNAssemblerService.DMN_COMPILER_CACHE_KEY);
    List<DMNExtensionRegister> dmnRegisteredExtensions = compiler.getRegisteredExtensions();
    Definitions definitions = DMNMarshallerFactory.newMarshallerWithExtensions(dmnRegisteredExtensions).unmarshal(xml);
    this.definitions = definitions;
    this.wireTypeRegistry(definitions);
    DMNModelImpl compiledModel = (DMNModelImpl) compiler.compile(definitions);
    this.inputs = compiledModel.inputs;
    this.decisions = compiledModel.decisions;
    this.bkms = compiledModel.bkms;
    this.itemDefs = compiledModel.itemDefs;
    this.messages = compiledModel.messages;
    this.types = compiledModel.types;
    this.runtimeTypeCheck = compiledModel.runtimeTypeCheck;
    this.importAliases = compiledModel.importAliases;
}
Also used : DroolsObjectInputStream(org.drools.core.common.DroolsObjectInputStream) DMNCompilerImpl(org.kie.dmn.core.compiler.DMNCompilerImpl) Definitions(org.kie.dmn.model.api.Definitions) DefaultDMNMessagesManager(org.kie.dmn.core.util.DefaultDMNMessagesManager) DMNExtensionRegister(org.kie.dmn.api.marshalling.DMNExtensionRegister)

Example 24 with Definitions

use of org.kie.dmn.model.api.Definitions in project drools by kiegroup.

the class DMNRuntimeTest method testSharedDependency.

@Test
public void testSharedDependency() {
    final Definitions defs = buildSimplifiedDefinitions("ns", "a", "b", "c");
    final DecisionNodeImpl a = buildSimplifiedDecisionNode(defs, "a");
    final DecisionNodeImpl b = buildSimplifiedDecisionNode(defs, "b");
    final DecisionNodeImpl c = buildSimplifiedDecisionNode(defs, "c");
    a.addDependency("c", c);
    b.addDependency("c", c);
    final DMNModelImpl model = new DMNModelImpl(defs);
    model.setDefinitions(defs);
    model.addDecision(a);
    model.addDecision(b);
    model.addDecision(c);
    final DMNRuntime runtime = DMNRuntimeUtil.createRuntime(this.getClass());
    final DMNResult result = runtime.evaluateAll(model, DMNFactory.newContext());
    assertFalse(result.hasErrors());
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) TDefinitions(org.kie.dmn.model.v1_1.TDefinitions) Definitions(org.kie.dmn.model.api.Definitions) DMNModelImpl(org.kie.dmn.core.impl.DMNModelImpl) DecisionNodeImpl(org.kie.dmn.core.ast.DecisionNodeImpl) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) Test(org.junit.Test)

Example 25 with Definitions

use of org.kie.dmn.model.api.Definitions in project drools by kiegroup.

the class DMNRuntimeTest method test_countCSATradeRatings.

@Test
public void test_countCSATradeRatings() {
    // DROOLS-1563
    final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("countCSATradeRatings.dmn", this.getClass());
    final DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_1a7d184c-2e38-4462-ae28-15591ef6d534", "countCSATradeRatings");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    final DMNContext ctx = runtime.newContext();
    final List<Map<?, ?>> ratings = new ArrayList<>();
    ratings.add(prototype(entry("Agency", "FITCH"), entry("Value", "val1")));
    ratings.add(prototype(entry("Agency", "MOODY"), entry("Value", "val2")));
    ctx.set("CSA Trade Ratings", ratings);
    final DMNResult dmnResult = runtime.evaluateAll(dmnModel, ctx);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
    final DMNContext result = dmnResult.getContext();
    assertThat(result.get("Trade Ratings"), is(new BigDecimal(2)));
    final DMNContext ctx2 = runtime.newContext();
    ctx2.set("CSA Trade Ratings", null);
    final DMNResult dmnResult2 = runtime.evaluateAll(dmnModel, ctx2);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult2.getMessages()), dmnResult2.hasErrors(), is(true));
    assertThat(dmnResult2.getMessages().stream().anyMatch(m -> m.getMessageType().equals(DMNMessageType.FEEL_EVALUATION_ERROR)), is(true));
    assertThat(dmnResult2.getDecisionResultByName("Trade Ratings").getEvaluationStatus(), is(DecisionEvaluationStatus.FAILED));
    final DMNResult dmnResult3 = runtime.evaluateAll(dmnModel, runtime.newContext());
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult3.getMessages()), dmnResult3.hasErrors(), is(true));
    assertThat(dmnResult3.getMessages().stream().anyMatch(m -> m.getMessageType().equals(DMNMessageType.REQ_NOT_FOUND)), is(true));
}
Also used : BeforeEvaluateDecisionTableEvent(org.kie.dmn.api.core.event.BeforeEvaluateDecisionTableEvent) CoreMatchers.is(org.hamcrest.CoreMatchers.is) Arrays(java.util.Arrays) DMNMessage(org.kie.dmn.api.core.DMNMessage) DMNResult(org.kie.dmn.api.core.DMNResult) ZonedDateTime(java.time.ZonedDateTime) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) FEELProperty(org.kie.dmn.feel.lang.FEELProperty) TDefinitions(org.kie.dmn.model.v1_1.TDefinitions) LoggerFactory(org.slf4j.LoggerFactory) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) BigDecimal(java.math.BigDecimal) DMNModel(org.kie.dmn.api.core.DMNModel) AfterEvaluateContextEntryEvent(org.kie.dmn.api.core.event.AfterEvaluateContextEntryEvent) Person(org.kie.dmn.core.model.Person) Duration(java.time.Duration) Map(java.util.Map) DecisionEvaluationStatus(org.kie.dmn.api.core.DMNDecisionResult.DecisionEvaluationStatus) LocalTime(java.time.LocalTime) ZoneOffset(java.time.ZoneOffset) OffsetTime(java.time.OffsetTime) BeforeEvaluateDecisionEvent(org.kie.dmn.api.core.event.BeforeEvaluateDecisionEvent) DMNRuntimeEventListener(org.kie.dmn.api.core.event.DMNRuntimeEventListener) DMNFactory(org.kie.dmn.core.api.DMNFactory) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Collection(java.util.Collection) BuiltInType(org.kie.dmn.feel.lang.types.BuiltInType) DMNModelImpl(org.kie.dmn.core.impl.DMNModelImpl) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) DMNRuntimeUtil(org.kie.dmn.core.util.DMNRuntimeUtil) List(java.util.List) Matchers.anything(org.hamcrest.Matchers.anything) Matchers.contains(org.hamcrest.Matchers.contains) VerificationModeFactory.times(org.mockito.internal.verification.VerificationModeFactory.times) ComparablePeriod(org.kie.dmn.feel.lang.types.impl.ComparablePeriod) Assert.assertFalse(org.junit.Assert.assertFalse) LocalDate(java.time.LocalDate) DMNContext(org.kie.dmn.api.core.DMNContext) FEELStringMarshaller(org.kie.dmn.feel.marshaller.FEELStringMarshaller) ItemDefinition(org.kie.dmn.model.api.ItemDefinition) KieHelper(org.kie.dmn.core.util.KieHelper) ChronoPeriod(java.time.chrono.ChronoPeriod) DMNDecisionResult(org.kie.dmn.api.core.DMNDecisionResult) AfterEvaluateDecisionEvent(org.kie.dmn.api.core.event.AfterEvaluateDecisionEvent) EvalHelper(org.kie.dmn.feel.util.EvalHelper) Mockito.mock(org.mockito.Mockito.mock) AfterEvaluateDecisionTableEvent(org.kie.dmn.api.core.event.AfterEvaluateDecisionTableEvent) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) DMNContextEvaluator(org.kie.dmn.core.ast.DMNContextEvaluator) DynamicTypeUtils.prototype(org.kie.dmn.core.util.DynamicTypeUtils.prototype) DMNMessageType(org.kie.dmn.api.core.DMNMessageType) LocalDateTime(java.time.LocalDateTime) CoreMatchers.not(org.hamcrest.CoreMatchers.not) DynamicTypeUtils.entry(org.kie.dmn.core.util.DynamicTypeUtils.entry) HashMap(java.util.HashMap) Definitions(org.kie.dmn.model.api.Definitions) ArrayList(java.util.ArrayList) ArgumentCaptor(org.mockito.ArgumentCaptor) TDecision(org.kie.dmn.model.v1_1.TDecision) KieServices(org.kie.api.KieServices) Decision(org.kie.dmn.model.api.Decision) Matchers.hasSize(org.hamcrest.Matchers.hasSize) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) Period(java.time.Period) Matchers.hasEntry(org.hamcrest.Matchers.hasEntry) Logger(org.slf4j.Logger) DMNTestUtil.getAndAssertModelNoErrors(org.kie.dmn.core.util.DMNTestUtil.getAndAssertModelNoErrors) KieContainer(org.kie.api.runtime.KieContainer) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Severity(org.kie.dmn.api.core.DMNMessage.Severity) BeforeEvaluateContextEntryEvent(org.kie.dmn.api.core.event.BeforeEvaluateContextEntryEvent) Mockito.verify(org.mockito.Mockito.verify) DynamicTypeUtils.mapOf(org.kie.dmn.core.util.DynamicTypeUtils.mapOf) ChronoUnit(java.time.temporal.ChronoUnit) Ignore(org.junit.Ignore) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) DecisionNodeImpl(org.kie.dmn.core.ast.DecisionNodeImpl) DMNResult(org.kie.dmn.api.core.DMNResult) DMNContext(org.kie.dmn.api.core.DMNContext) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Aggregations

Definitions (org.kie.dmn.model.api.Definitions)114 Test (org.junit.Test)71 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)39 DMNMessage (org.kie.dmn.api.core.DMNMessage)37 DMNModel (org.kie.dmn.api.core.DMNModel)34 DMNResult (org.kie.dmn.api.core.DMNResult)32 TDefinitions (org.kie.dmn.model.v1_1.TDefinitions)31 Arrays (java.util.Arrays)28 Assert.assertTrue (org.junit.Assert.assertTrue)28 List (java.util.List)26 ItemDefinition (org.kie.dmn.model.api.ItemDefinition)26 Logger (org.slf4j.Logger)26 LoggerFactory (org.slf4j.LoggerFactory)26 HashMap (java.util.HashMap)25 Decision (org.kie.dmn.model.api.Decision)25 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)24 Assert.assertFalse (org.junit.Assert.assertFalse)24 DecisionNodeImpl (org.kie.dmn.core.ast.DecisionNodeImpl)24 DMNModelImpl (org.kie.dmn.core.impl.DMNModelImpl)24 ArrayList (java.util.ArrayList)23