Search in sources :

Example 1 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(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) TDecision(org.kie.dmn.model.v1_1.TDecision) Decision(org.kie.dmn.model.api.Decision)

Example 2 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(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) TDecision(org.kie.dmn.model.v1_2.TDecision) Decision(org.kie.dmn.model.api.Decision)

Example 3 with Decision

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

the class DMNXMLLoaderTest method testLoadingDefinitions.

@Test
public void testLoadingDefinitions() {
    final DMNMarshaller DMNMarshaller = DMNMarshallerFactory.newDefaultMarshaller();
    final InputStream is = this.getClass().getResourceAsStream("0001-input-data-string.dmn");
    final InputStreamReader isr = new InputStreamReader(is);
    final Definitions def = DMNMarshaller.unmarshal(isr);
    assertThat(def, not(nullValue()));
    assertThat(def.getName(), is("0001-input-data-string"));
    assertThat(def.getId(), is("_0001-input-data-string"));
    assertThat(def.getNamespace(), is("https://github.com/agilepro/dmn-tck"));
    assertThat(def.getDrgElement().size(), is(2));
    assertThat(def.getDrgElement().get(0), is(instanceOf(Decision.class)));
    Decision dec = (Decision) def.getDrgElement().get(0);
    assertThat(dec.getName(), is("Greeting Message"));
    assertThat(dec.getId(), is("d_GreetingMessage"));
    assertThat(dec.getVariable().getName(), is("Greeting Message"));
    assertThat(dec.getVariable().getTypeRef().getPrefix(), is("feel"));
    assertThat(dec.getVariable().getTypeRef().getLocalPart(), is("string"));
    assertThat(dec.getVariable().getTypeRef().getNamespaceURI(), is(XMLConstants.NULL_NS_URI));
    assertThat(dec.getInformationRequirement().size(), is(1));
    assertThat(dec.getInformationRequirement().get(0).getRequiredInput().getHref(), is("#i_FullName"));
    assertThat(dec.getExpression(), is(instanceOf(LiteralExpression.class)));
    LiteralExpression le = (LiteralExpression) dec.getExpression();
    assertThat(le.getText(), is("\"Hello \" + Full Name"));
    InputData idata = (InputData) def.getDrgElement().get(1);
    assertThat(idata.getId(), is("i_FullName"));
    assertThat(idata.getName(), is("Full Name"));
    assertThat(idata.getVariable().getName(), is("Full Name"));
    assertThat(idata.getVariable().getTypeRef().getPrefix(), is("feel"));
    assertThat(idata.getVariable().getTypeRef().getLocalPart(), is("string"));
    assertThat(idata.getVariable().getTypeRef().getNamespaceURI(), is(XMLConstants.NULL_NS_URI));
}
Also used : DMNMarshaller(org.kie.dmn.api.marshalling.DMNMarshaller) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Definitions(org.kie.dmn.model.api.Definitions) LiteralExpression(org.kie.dmn.model.api.LiteralExpression) InputData(org.kie.dmn.model.api.InputData) Decision(org.kie.dmn.model.api.Decision) Test(org.junit.Test)

Example 4 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) 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 5 with Decision

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

the class DMNEvaluatorCompiler method inferTypeRef.

public static BaseDMNTypeImpl inferTypeRef(DMNModelImpl model, DecisionTable dt, OutputClause oc) {
    BaseDMNTypeImpl typeRef = (BaseDMNTypeImpl) model.getTypeRegistry().unknown();
    if (oc.getTypeRef() != null) {
        QName outputExpressionTypeRef = oc.getTypeRef();
        QName resolvedOutputExpressionTypeRef = DMNCompilerImpl.getNamespaceAndName(oc, model.getImportAliasesForNS(), outputExpressionTypeRef, model.getNamespace());
        typeRef = (BaseDMNTypeImpl) model.getTypeRegistry().resolveType(resolvedOutputExpressionTypeRef.getNamespaceURI(), resolvedOutputExpressionTypeRef.getLocalPart());
        if (typeRef == null) {
            typeRef = (BaseDMNTypeImpl) model.getTypeRegistry().unknown();
        }
    } else if (dt.getOutput().size() == 1 && (dt.getParent() instanceof Decision || dt.getParent() instanceof BusinessKnowledgeModel || dt.getParent() instanceof ContextEntry)) {
        QName inferredTypeRef = recurseUpToInferTypeRef(model, oc, dt);
        // if inferredTypeRef is null, a std err will have been reported
        if (inferredTypeRef != null) {
            QName resolvedInferredTypeRef = DMNCompilerImpl.getNamespaceAndName(oc, model.getImportAliasesForNS(), inferredTypeRef, model.getNamespace());
            typeRef = (BaseDMNTypeImpl) model.getTypeRegistry().resolveType(resolvedInferredTypeRef.getNamespaceURI(), resolvedInferredTypeRef.getLocalPart());
        }
    }
    return typeRef;
}
Also used : QName(javax.xml.namespace.QName) BusinessKnowledgeModel(org.kie.dmn.model.api.BusinessKnowledgeModel) BaseDMNTypeImpl(org.kie.dmn.core.impl.BaseDMNTypeImpl) Decision(org.kie.dmn.model.api.Decision) ContextEntry(org.kie.dmn.model.api.ContextEntry)

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