Search in sources :

Example 41 with ItemDefinition

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

the class DMNCompilerImpl method processItemDefinitions.

private void processItemDefinitions(DMNCompilerContext ctx, DMNModelImpl model, Definitions dmndefs) {
    dmndefs.normalize();
    List<ItemDefinition> ordered = new ItemDefinitionDependenciesSorter(model.getNamespace()).sort(dmndefs.getItemDefinition());
    Set<String> names = new HashSet<>();
    for (ItemDefinition id : ordered) {
        boolean added = names.add(id.getName());
        if (!added) {
            MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, id, model, null, null, Msg.DUPLICATED_ITEM_DEFINITION, id.getName());
        }
        if (id.getItemComponent() != null && id.getItemComponent().size() > 0) {
            DMNCompilerHelper.checkVariableName(model, id, id.getName());
            CompositeTypeImpl compType = new CompositeTypeImpl(model.getNamespace(), id.getName(), id.getId(), id.isIsCollection());
            DMNType preregistered = model.getTypeRegistry().registerType(compType);
        }
    }
    for (ItemDefinition id : ordered) {
        ItemDefNodeImpl idn = new ItemDefNodeImpl(id);
        DMNType type = buildTypeDef(ctx, model, idn, id, null);
        idn.setType(type);
        model.addItemDefinition(idn);
    }
}
Also used : ItemDefinition(org.kie.dmn.model.api.ItemDefinition) ItemDefNodeImpl(org.kie.dmn.core.ast.ItemDefNodeImpl) CompositeTypeImpl(org.kie.dmn.core.impl.CompositeTypeImpl) HashSet(java.util.HashSet) DMNType(org.kie.dmn.api.core.DMNType)

Example 42 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";
        }
        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";
        }
        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);
    }
}
Also used : Import(org.kie.dmn.model.api.Import) PerformanceIndicator(org.kie.dmn.model.api.PerformanceIndicator) TDefinitions(org.kie.dmn.model.v1_1.TDefinitions) Definitions(org.kie.dmn.model.api.Definitions) 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) 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 43 with ItemDefinition

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

the class ItemDefinitionConverter method writeAttributes.

@Override
protected void writeAttributes(HierarchicalStreamWriter writer, Object parent) {
    super.writeAttributes(writer, parent);
    ItemDefinition id = (ItemDefinition) parent;
    if (id.getTypeLanguage() != null)
        writer.addAttribute(TYPE_LANGUAGE, id.getTypeLanguage());
    writer.addAttribute(IS_COLLECTION, Boolean.valueOf(id.isIsCollection()).toString());
}
Also used : ItemDefinition(org.kie.dmn.model.api.ItemDefinition) TItemDefinition(org.kie.dmn.model.v1_1.TItemDefinition)

Example 44 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) TDefinitions(org.kie.dmn.model.v1_4.TDefinitions) Definitions(org.kie.dmn.model.api.Definitions) 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 45 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 : ItemDefinition(org.kie.dmn.model.api.ItemDefinition) TItemDefinition(org.kie.dmn.model.v1_4.TItemDefinition)

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