Search in sources :

Example 16 with ItemDefinition

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

the class ItemDefinitionDependenciesTest method testOrdering4.

@Test
public void testOrdering4() {
    final ItemDefinition _TypeDecisionA1 = build("TypeDecisionA1");
    final ItemDefinition _TypeDecisionA2_x = build("TypeDecisionA2.x", _TypeDecisionA1);
    final ItemDefinition _TypeDecisionA3 = build("TypeDecisionA3", _TypeDecisionA2_x);
    final ItemDefinition _TypeDecisionB1 = build("TypeDecisionB1");
    final ItemDefinition _TypeDecisionB2_x = build("TypeDecisionB2.x", _TypeDecisionB1);
    final ItemDefinition _TypeDecisionB3 = build("TypeDecisionB3", _TypeDecisionB2_x, _TypeDecisionA3);
    final ItemDefinition _TypeDecisionC1 = build("TypeDecisionC1", _TypeDecisionA3, _TypeDecisionB3);
    final ItemDefinition _TypeDecisionC4 = build("TypeDecisionC4");
    final List<ItemDefinition> originalList = Arrays.asList(_TypeDecisionA1, _TypeDecisionA2_x, _TypeDecisionA3, _TypeDecisionB1, _TypeDecisionB2_x, _TypeDecisionB3, _TypeDecisionC1, _TypeDecisionC4);
    final List<ItemDefinition> orderedList = orderingStrategy(originalList);
    assertTrue("Index of _TypeDecisionA1 < _TypeDecisionA2_x", orderedList.indexOf(_TypeDecisionA1) < orderedList.indexOf(_TypeDecisionA2_x));
    assertTrue("Index of _TypeDecisionA2_x < _TypeDecisionA3", orderedList.indexOf(_TypeDecisionA2_x) < orderedList.indexOf(_TypeDecisionA3));
    assertTrue("Index of _TypeDecisionA3 < _TypeDecisionB3", orderedList.indexOf(_TypeDecisionA3) < orderedList.indexOf(_TypeDecisionB3));
    assertTrue("Index of _TypeDecisionA3 < _TypeDecisionC1", orderedList.indexOf(_TypeDecisionA3) < orderedList.indexOf(_TypeDecisionC1));
    assertTrue("Index of _TypeDecisionB1 < _TypeDecisionB2_x", orderedList.indexOf(_TypeDecisionB1) < orderedList.indexOf(_TypeDecisionB2_x));
    assertTrue("Index of _TypeDecisionB2_x < _TypeDecisionB3", orderedList.indexOf(_TypeDecisionB2_x) < orderedList.indexOf(_TypeDecisionB3));
    assertTrue("Index of _TypeDecisionB3 < _TypeDecisionC1", orderedList.indexOf(_TypeDecisionB3) < orderedList.indexOf(_TypeDecisionC1));
}
Also used : ItemDefinition(org.kie.dmn.model.api.ItemDefinition) TItemDefinition(org.kie.dmn.model.v1_1.TItemDefinition) Test(org.junit.Test)

Example 17 with ItemDefinition

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

the class ItemDefinitionDependenciesTest method addComponent.

private void addComponent(ItemDefinition i, String componentName) {
    final ItemDefinition c = new TItemDefinition();
    c.setName("_" + i.getName() + "-" + componentName);
    c.setTypeRef(new QName(TEST_NS, componentName));
    i.getItemComponent().add(c);
}
Also used : QName(javax.xml.namespace.QName) TItemDefinition(org.kie.dmn.model.v1_1.TItemDefinition) ItemDefinition(org.kie.dmn.model.api.ItemDefinition) TItemDefinition(org.kie.dmn.model.v1_1.TItemDefinition)

Example 18 with ItemDefinition

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

the class ItemDefinitionDependenciesTest method testGeneric.

@Test
public void testGeneric() {
    final ItemDefinition a = build("a");
    final ItemDefinition b = build("b");
    final ItemDefinition c = build("c", a, b);
    final ItemDefinition d = build("d", c);
    final List<ItemDefinition> originalList = Arrays.asList(d, c, b, a);
    final List<ItemDefinition> orderedList = orderingStrategy(originalList);
    assertThat(orderedList.subList(0, 2), containsInAnyOrder(a, b));
    assertThat(orderedList.subList(2, 4), contains(c, d));
}
Also used : ItemDefinition(org.kie.dmn.model.api.ItemDefinition) TItemDefinition(org.kie.dmn.model.v1_1.TItemDefinition) Test(org.junit.Test)

Example 19 with ItemDefinition

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

the class DefinitionsConverter method writeChildren.

@Override
protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext context, Object parent) {
    super.writeChildren(writer, context, parent);
    Definitions def = (Definitions) parent;
    for (Import i : def.getImport()) {
        writeChildrenNode(writer, context, i, IMPORT);
    }
    for (ItemDefinition id : def.getItemDefinition()) {
        writeChildrenNode(writer, context, id, ITEM_DEFINITION);
    }
    for (DRGElement e : def.getDrgElement()) {
        String nodeName = DRG_ELEMENT;
        if (e instanceof BusinessKnowledgeModel) {
            nodeName = "businessKnowledgeModel";
        } else if (e instanceof Decision) {
            nodeName = "decision";
        } else if (e instanceof InputData) {
            nodeName = "inputData";
        } else if (e instanceof KnowledgeSource) {
            nodeName = "knowledgeSource";
        } else if (e instanceof DecisionService) {
            nodeName = "decisionService";
        }
        writeChildrenNode(writer, context, e, nodeName);
    }
    for (Artifact a : def.getArtifact()) {
        String nodeName = ARTIFACT;
        if (a instanceof Association) {
            nodeName = "association";
        } else if (a instanceof TextAnnotation) {
            nodeName = "textAnnotation";
        } else if (a instanceof Group) {
            nodeName = "group";
        }
        writeChildrenNode(writer, context, a, nodeName);
    }
    for (ElementCollection ec : def.getElementCollection()) {
        writeChildrenNode(writer, context, ec, ELEMENT_COLLECTION);
    }
    for (BusinessContextElement bce : def.getBusinessContextElement()) {
        String nodeName = BUSINESS_CONTEXT_ELEMENT;
        if (bce instanceof OrganizationUnit) {
            nodeName = "organizationUnit";
        } else if (bce instanceof PerformanceIndicator) {
            nodeName = "performanceIndicator";
        }
        writeChildrenNode(writer, context, bce, nodeName);
    }
    if (def.getDMNDI() != null) {
        writeChildrenNode(writer, context, def.getDMNDI(), "DMNDI");
    }
}
Also used : Group(org.kie.dmn.model.api.Group) Import(org.kie.dmn.model.api.Import) PerformanceIndicator(org.kie.dmn.model.api.PerformanceIndicator) Definitions(org.kie.dmn.model.api.Definitions) TDefinitions(org.kie.dmn.model.v1_3.TDefinitions) ItemDefinition(org.kie.dmn.model.api.ItemDefinition) BusinessContextElement(org.kie.dmn.model.api.BusinessContextElement) Decision(org.kie.dmn.model.api.Decision) Artifact(org.kie.dmn.model.api.Artifact) DecisionService(org.kie.dmn.model.api.DecisionService) Association(org.kie.dmn.model.api.Association) KnowledgeSource(org.kie.dmn.model.api.KnowledgeSource) OrganizationUnit(org.kie.dmn.model.api.OrganizationUnit) BusinessKnowledgeModel(org.kie.dmn.model.api.BusinessKnowledgeModel) ElementCollection(org.kie.dmn.model.api.ElementCollection) InputData(org.kie.dmn.model.api.InputData) TextAnnotation(org.kie.dmn.model.api.TextAnnotation) DRGElement(org.kie.dmn.model.api.DRGElement)

Example 20 with ItemDefinition

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

the class ItemDefinitionConverter method assignAttributes.

@Override
protected void assignAttributes(HierarchicalStreamReader reader, Object parent) {
    super.assignAttributes(reader, parent);
    ItemDefinition id = (ItemDefinition) parent;
    String typeLanguage = reader.getAttribute(TYPE_LANGUAGE);
    String isCollectionValue = reader.getAttribute(IS_COLLECTION);
    id.setTypeLanguage(typeLanguage);
    id.setIsCollection(Boolean.valueOf(isCollectionValue));
}
Also used : TItemDefinition(org.kie.dmn.model.v1_3.TItemDefinition) 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