Search in sources :

Example 11 with Decision

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

the class DMNCompilerImpl method resolveTypeRef.

/**
 * Resolve the QName typeRef accordingly to definition of builtin (FEEL) types, local model ItemDef or imported definitions.
 * If the typeRef cannot be resolved, (FEEL) UNKNOWN is returned and an error logged using standard DMN message logging.
 */
public DMNType resolveTypeRef(DMNModelImpl dmnModel, NamedElement model, DMNModelInstrumentedBase localElement, QName typeRef) {
    if (typeRef != null) {
        QName nsAndName = getNamespaceAndName(localElement, dmnModel.getImportAliasesForNS(), typeRef, dmnModel.getNamespace());
        DMNType type = dmnModel.getTypeRegistry().resolveType(nsAndName.getNamespaceURI(), nsAndName.getLocalPart());
        if (type == null && localElement.getURIFEEL().equals(nsAndName.getNamespaceURI())) {
            if (model instanceof Decision && ((Decision) model).getExpression() instanceof DecisionTable) {
                DecisionTable dt = (DecisionTable) ((Decision) model).getExpression();
                if (dt.getOutput().size() > 1) {
                    // implicitly define a type for the decision table result
                    CompositeTypeImpl compType = new CompositeTypeImpl(dmnModel.getNamespace(), model.getName() + "_Type", model.getId(), dt.getHitPolicy().isMultiHit());
                    for (OutputClause oc : dt.getOutput()) {
                        DMNType fieldType = resolveTypeRef(dmnModel, model, oc, oc.getTypeRef());
                        compType.addField(oc.getName(), fieldType);
                    }
                    dmnModel.getTypeRegistry().registerType(compType);
                    return compType;
                } else if (dt.getOutput().size() == 1) {
                    return resolveTypeRef(dmnModel, model, dt.getOutput().get(0), dt.getOutput().get(0).getTypeRef());
                }
            }
        } else if (type == null) {
            MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, localElement, dmnModel, null, null, Msg.UNKNOWN_TYPE_REF_ON_NODE, typeRef.toString(), localElement.getParentDRDElement().getIdentifierString());
            type = dmnModel.getTypeRegistry().unknown();
        }
        return type;
    }
    return dmnModel.getTypeRegistry().unknown();
}
Also used : OutputClause(org.kie.dmn.model.api.OutputClause) DecisionTable(org.kie.dmn.model.api.DecisionTable) QName(javax.xml.namespace.QName) Decision(org.kie.dmn.model.api.Decision) CompositeTypeImpl(org.kie.dmn.core.impl.CompositeTypeImpl) DMNType(org.kie.dmn.api.core.DMNType)

Example 12 with Decision

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

the class MessageReporterTest method aDecision.

private DMNModelInstrumentedBase aDecision() {
    Decision d = new TDecision();
    d.setId(UUID.randomUUID().toString());
    return d;
}
Also used : TDecision(org.kie.dmn.model.v1_3.TDecision) TDecision(org.kie.dmn.model.v1_3.TDecision) Decision(org.kie.dmn.model.api.Decision)

Example 13 with Decision

use of org.kie.dmn.model.api.Decision 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 14 with Decision

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

the class DecisionConverter method writeChildren.

@Override
protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext context, Object parent) {
    super.writeChildren(writer, context, parent);
    Decision dec = (Decision) parent;
    if (dec.getQuestion() != null)
        writeChildrenNodeAsValue(writer, context, dec.getQuestion(), QUESTION);
    if (dec.getAllowedAnswers() != null)
        writeChildrenNodeAsValue(writer, context, dec.getAllowedAnswers(), ALLOWED_ANSWERS);
    if (dec.getVariable() != null)
        writeChildrenNode(writer, context, dec.getVariable(), VARIABLE);
    for (InformationRequirement ir : dec.getInformationRequirement()) {
        writeChildrenNode(writer, context, ir, INFORMATION_REQUIREMENT);
    }
    for (KnowledgeRequirement kr : dec.getKnowledgeRequirement()) {
        writeChildrenNode(writer, context, kr, KNOWLEDGE_REQUIREMENT);
    }
    for (AuthorityRequirement ar : dec.getAuthorityRequirement()) {
        writeChildrenNode(writer, context, ar, AUTHORITY_REQUIREMENT);
    }
    for (DMNElementReference so : dec.getSupportedObjective()) {
        writeChildrenNode(writer, context, so, SUPPORTED_OBJECTIVE);
    }
    for (DMNElementReference ipi : dec.getImpactedPerformanceIndicator()) {
        writeChildrenNode(writer, context, ipi, IMPACTED_PERFORMANCE_INDICATOR);
    }
    for (DMNElementReference dm : dec.getDecisionMaker()) {
        writeChildrenNode(writer, context, dm, DECISION_MAKER);
    }
    for (DMNElementReference downer : dec.getDecisionOwner()) {
        writeChildrenNode(writer, context, downer, DECISION_OWNER);
    }
    for (DMNElementReference up : dec.getUsingProcess()) {
        writeChildrenNode(writer, context, up, USING_PROCESS);
    }
    for (DMNElementReference ut : dec.getUsingTask()) {
        writeChildrenNode(writer, context, ut, USING_TASK);
    }
    if (dec.getExpression() != null) {
        Expression e = dec.getExpression();
        String nodeName = MarshallingUtils.defineExpressionNodeName(xstream, e);
        writeChildrenNode(writer, context, e, nodeName);
    }
}
Also used : KnowledgeRequirement(org.kie.dmn.model.api.KnowledgeRequirement) DMNElementReference(org.kie.dmn.model.api.DMNElementReference) InformationRequirement(org.kie.dmn.model.api.InformationRequirement) Expression(org.kie.dmn.model.api.Expression) AuthorityRequirement(org.kie.dmn.model.api.AuthorityRequirement) Decision(org.kie.dmn.model.api.Decision) TDecision(org.kie.dmn.model.v1_4.TDecision)

Example 15 with Decision

use of org.kie.dmn.model.api.Decision 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)

Aggregations

Decision (org.kie.dmn.model.api.Decision)19 Definitions (org.kie.dmn.model.api.Definitions)8 InputData (org.kie.dmn.model.api.InputData)6 BusinessKnowledgeModel (org.kie.dmn.model.api.BusinessKnowledgeModel)5 DMNElementReference (org.kie.dmn.model.api.DMNElementReference)5 DRGElement (org.kie.dmn.model.api.DRGElement)5 InformationRequirement (org.kie.dmn.model.api.InformationRequirement)5 Artifact (org.kie.dmn.model.api.Artifact)4 Association (org.kie.dmn.model.api.Association)4 AuthorityRequirement (org.kie.dmn.model.api.AuthorityRequirement)4 BusinessContextElement (org.kie.dmn.model.api.BusinessContextElement)4 ElementCollection (org.kie.dmn.model.api.ElementCollection)4 Expression (org.kie.dmn.model.api.Expression)4 Import (org.kie.dmn.model.api.Import)4 ItemDefinition (org.kie.dmn.model.api.ItemDefinition)4 KnowledgeRequirement (org.kie.dmn.model.api.KnowledgeRequirement)4 KnowledgeSource (org.kie.dmn.model.api.KnowledgeSource)4 OrganizationUnit (org.kie.dmn.model.api.OrganizationUnit)4 PerformanceIndicator (org.kie.dmn.model.api.PerformanceIndicator)4 TextAnnotation (org.kie.dmn.model.api.TextAnnotation)4