Search in sources :

Example 26 with ItemDefinition

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

the class TDefinitions method processQNameURIs.

private static void processQNameURIs(ItemDefinition iDef) {
    final QName typeRef = iDef.getTypeRef();
    if (typeRef != null && XMLConstants.NULL_NS_URI.equals(typeRef.getNamespaceURI())) {
        final String namespace = iDef.getNamespaceURI(typeRef.getPrefix());
        iDef.setTypeRef(new QName(namespace, typeRef.getLocalPart(), typeRef.getPrefix()));
    }
    for (ItemDefinition comp : iDef.getItemComponent()) {
        processQNameURIs(comp);
    }
}
Also used : QName(javax.xml.namespace.QName) ItemDefinition(org.kie.dmn.model.api.ItemDefinition)

Example 27 with ItemDefinition

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

the class TDefinitions method processQNameURIs.

private static void processQNameURIs(ItemDefinition iDef) {
    final QName typeRef = iDef.getTypeRef();
    if (typeRef != null && XMLConstants.NULL_NS_URI.equals(typeRef.getNamespaceURI())) {
        final String namespace = iDef.getNamespaceURI(typeRef.getPrefix());
        iDef.setTypeRef(new QName(namespace, typeRef.getLocalPart(), typeRef.getPrefix()));
    }
    for (ItemDefinition comp : iDef.getItemComponent()) {
        processQNameURIs(comp);
    }
}
Also used : QName(javax.xml.namespace.QName) ItemDefinition(org.kie.dmn.model.api.ItemDefinition)

Example 28 with ItemDefinition

use of org.kie.dmn.model.api.ItemDefinition in project kie-wb-common by kiegroup.

the class DMNMarshallerImportsHelperStandaloneImplTest method testGetItemDefinitionsWithNamespace.

@Test
public void testGetItemDefinitionsWithNamespace() {
    final Definitions definitions = mock(Definitions.class);
    final Import anImport = mock(Import.class);
    final ItemDefinition itemDefinition1 = new TItemDefinition();
    final ItemDefinition itemDefinition2 = new TItemDefinition();
    final ItemDefinition itemDefinition3 = new TItemDefinition();
    final ItemDefinition itemDefinition4 = new TItemDefinition();
    final ItemDefinition itemDefinition5 = new TItemDefinition();
    final List<ItemDefinition> itemDefinitions = asList(itemDefinition1, itemDefinition2, itemDefinition3, itemDefinition4, itemDefinition5);
    itemDefinition1.setName("tUUID");
    itemDefinition2.setName("tPerson");
    itemDefinition3.setName("id");
    itemDefinition4.setName("name");
    itemDefinition5.setName("age");
    itemDefinition1.setTypeRef(new QName("string"));
    itemDefinition2.setTypeRef(null);
    itemDefinition3.setTypeRef(new QName("tUUID"));
    itemDefinition4.setTypeRef(new QName("string"));
    itemDefinition5.setTypeRef(new QName("number"));
    when(anImport.getName()).thenReturn("model");
    when(definitions.getItemDefinition()).thenReturn(itemDefinitions);
    final List<ItemDefinition> actualItemDefinitions = helper.getItemDefinitionsWithNamespace(definitions, anImport);
    assertEquals(5, actualItemDefinitions.size());
    final ItemDefinition actualItemDefinition1 = actualItemDefinitions.get(0);
    assertEquals("model.tUUID", actualItemDefinition1.getName());
    assertEquals("string", actualItemDefinition1.getTypeRef().getLocalPart());
    final ItemDefinition actualItemDefinition2 = actualItemDefinitions.get(1);
    assertEquals("model.tPerson", actualItemDefinition2.getName());
    assertNull(actualItemDefinition2.getTypeRef());
    final ItemDefinition actualItemDefinition3 = actualItemDefinitions.get(2);
    assertEquals("model.id", actualItemDefinition3.getName());
    assertEquals("model.tUUID", actualItemDefinition3.getTypeRef().getLocalPart());
    final ItemDefinition actualItemDefinition4 = actualItemDefinitions.get(3);
    assertEquals("model.name", actualItemDefinition4.getName());
    assertEquals("string", actualItemDefinition4.getTypeRef().getLocalPart());
    final ItemDefinition actualItemDefinition5 = actualItemDefinitions.get(4);
    assertEquals("model.age", actualItemDefinition5.getName());
    assertEquals("number", actualItemDefinition5.getTypeRef().getLocalPart());
}
Also used : Import(org.kie.dmn.model.api.Import) QName(javax.xml.namespace.QName) Definitions(org.kie.dmn.model.api.Definitions) TItemDefinition(org.kie.dmn.model.v1_2.TItemDefinition) TItemDefinition(org.kie.dmn.model.v1_2.TItemDefinition) ItemDefinition(org.kie.dmn.model.api.ItemDefinition) Test(org.junit.Test)

Example 29 with ItemDefinition

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

the class DMNRuntimeTest method testAssignNullToAllowedValues.

@Test
public void testAssignNullToAllowedValues() {
    // DROOLS-3132 DMN assign null to ItemDefinition with allowedValues
    final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("assignNullToAllowedValues.dmn", this.getClass());
    final DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/dmn/definitions/_700a46e0-01ed-4361-9034-4afdb2537ea4", "Drawing 1");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    final DMNContext context = DMNFactory.newContext();
    context.set("an input letter", null);
    final DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    LOG.debug("{}", dmnResult);
    DMNRuntimeUtil.formatMessages(dmnResult.getMessages());
    assertThat(dmnResult.hasErrors(), is(true));
    assertThat(dmnResult.getMessages().stream().anyMatch(m -> m.getSourceId().equals("_24e8b31b-9505-4f52-93af-6dd9ef39c72a")), is(true));
    assertThat(dmnResult.getMessages().stream().anyMatch(m -> m.getSourceId().equals("_09945fda-2b89-4148-8758-0bcb91a66e4a")), 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) 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.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) 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) BeforeEvaluateContextEntryEvent(org.kie.dmn.api.core.event.BeforeEvaluateContextEntryEvent) Mockito.verify(org.mockito.Mockito.verify) DynamicTypeUtils.mapOf(org.kie.dmn.core.util.DynamicTypeUtils.mapOf) 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) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) Test(org.junit.Test)

Example 30 with ItemDefinition

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

the class TDefinitions method processQNameURIs.

private static void processQNameURIs(ItemDefinition iDef) {
    final QName typeRef = iDef.getTypeRef();
    if (typeRef != null && XMLConstants.NULL_NS_URI.equals(typeRef.getNamespaceURI())) {
        final String namespace = iDef.getNamespaceURI(typeRef.getPrefix());
        iDef.setTypeRef(new QName(namespace, typeRef.getLocalPart(), typeRef.getPrefix()));
    }
    for (ItemDefinition comp : iDef.getItemComponent()) {
        processQNameURIs(comp);
    }
}
Also used : QName(javax.xml.namespace.QName) ItemDefinition(org.kie.dmn.model.api.ItemDefinition)

Aggregations

ItemDefinition (org.kie.dmn.model.api.ItemDefinition)50 TItemDefinition (org.kie.dmn.model.v1_1.TItemDefinition)19 Test (org.junit.Test)15 QName (javax.xml.namespace.QName)13 Definitions (org.kie.dmn.model.api.Definitions)13 ArrayList (java.util.ArrayList)10 DRGElement (org.kie.dmn.model.api.DRGElement)9 List (java.util.List)7 Collectors (java.util.stream.Collectors)7 Artifact (org.kie.dmn.model.api.Artifact)7 BusinessContextElement (org.kie.dmn.model.api.BusinessContextElement)7 Decision (org.kie.dmn.model.api.Decision)7 Import (org.kie.dmn.model.api.Import)7 Collection (java.util.Collection)6 TItemDefinition (org.kie.dmn.model.v1_2.TItemDefinition)6 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 DecisionService (org.kie.dmn.model.api.DecisionService)5 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4