Search in sources :

Example 1 with OutputClause

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

the class DMNDTAnalyser method compileTableOutputClauses.

private void compileTableOutputClauses(DMNModel model, DecisionTable dt, DDTATable ddtaTable) {
    for (int jColIdx = 0; jColIdx < dt.getOutput().size(); jColIdx++) {
        OutputClause oe = dt.getOutput().get(jColIdx);
        Interval infDomain = new Interval(RangeBoundary.CLOSED, Interval.NEG_INF, Interval.POS_INF, RangeBoundary.CLOSED, 0, jColIdx + 1);
        String allowedValues = null;
        if (oe.getOutputValues() != null) {
            allowedValues = oe.getOutputValues().getText();
        } else {
            QName outputTypeRef = (oe.getTypeRef() == null && dt.getOutput().size() == 1) ? dt.getTypeRef() : oe.getTypeRef();
            if (outputTypeRef != null) {
                QName typeRef = DMNCompilerImpl.getNamespaceAndName(dt, ((DMNModelImpl) model).getImportAliasesForNS(), outputTypeRef, model.getNamespace());
                allowedValues = findAllowedValues(model, typeRef);
            }
        }
        if (allowedValues != null) {
            ProcessedUnaryTest compileUnaryTests = (ProcessedUnaryTest) FEEL.compileUnaryTests(allowedValues, FEEL.newCompilerContext());
            UnaryTestInterpretedExecutableExpression interpreted = compileUnaryTests.getInterpreted();
            UnaryTestListNode utln = (UnaryTestListNode) interpreted.getASTNode();
            if (utln.getElements().size() != 1) {
                verifyUnaryTestsAllEQ(utln, dt);
                List<Comparable<?>> discreteValues = getDiscreteValues(utln);
                List<Comparable<?>> outputOrder = new ArrayList<>(discreteValues);
                Collections.sort((List) discreteValues);
                Interval discreteDomainMinMax = new Interval(RangeBoundary.CLOSED, discreteValues.get(0), discreteValues.get(discreteValues.size() - 1), RangeBoundary.CLOSED, 0, jColIdx + 1);
                DDTAOutputClause ic = new DDTAOutputClause(discreteDomainMinMax, discreteValues, outputOrder);
                ddtaTable.getOutputs().add(ic);
            } else if (utln.getElements().size() == 1) {
                UnaryTestNode utn0 = (UnaryTestNode) utln.getElements().get(0);
                Interval interval = utnToInterval(utn0, infDomain, null, 0, jColIdx + 1);
                DDTAOutputClause ic = new DDTAOutputClause(interval);
                ddtaTable.getOutputs().add(ic);
            } else {
                throw new IllegalStateException("inputValues not null but utln: " + utln);
            }
        } else {
            DDTAOutputClause ic = new DDTAOutputClause(infDomain);
            ddtaTable.getOutputs().add(ic);
        }
    }
}
Also used : UnaryTestNode(org.kie.dmn.feel.lang.ast.UnaryTestNode) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) ProcessedUnaryTest(org.kie.dmn.feel.codegen.feel11.ProcessedUnaryTest) DDTAOutputClause(org.kie.dmn.validation.dtanalysis.model.DDTAOutputClause) OutputClause(org.kie.dmn.model.api.OutputClause) DDTAOutputClause(org.kie.dmn.validation.dtanalysis.model.DDTAOutputClause) UnaryTestInterpretedExecutableExpression(org.kie.dmn.feel.lang.impl.UnaryTestInterpretedExecutableExpression) UnaryTestListNode(org.kie.dmn.feel.lang.ast.UnaryTestListNode) Interval(org.kie.dmn.validation.dtanalysis.model.Interval)

Example 2 with OutputClause

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

the class XLS2DMNParser method appendDecisionDT.

private void appendDecisionDT(Definitions definitions, Map<String, DTHeaderInfo> headerInfos) {
    for (DTHeaderInfo hi : headerInfos.values()) {
        Decision decision = new TDecision();
        decision.setName(hi.getSheetName());
        decision.setId("d_" + CodegenStringUtil.escapeIdentifier(hi.getSheetName()));
        InformationItem variable = new TInformationItem();
        variable.setName(hi.getSheetName());
        variable.setId("dvar_" + CodegenStringUtil.escapeIdentifier(hi.getSheetName()));
        variable.setTypeRef(new QName("Any"));
        decision.setVariable(variable);
        for (String ri : hi.getRequiredInput()) {
            InformationRequirement ir = new TInformationRequirement();
            DMNElementReference er = new TDMNElementReference();
            er.setHref("#id_" + CodegenStringUtil.escapeIdentifier(ri));
            ir.setRequiredInput(er);
            decision.getInformationRequirement().add(ir);
        }
        for (String ri : hi.getRequiredDecision()) {
            InformationRequirement ir = new TInformationRequirement();
            DMNElementReference er = new TDMNElementReference();
            er.setHref("#d_" + CodegenStringUtil.escapeIdentifier(ri));
            ir.setRequiredDecision(er);
            decision.getInformationRequirement().add(ir);
        }
        DecisionTable dt = new TDecisionTable();
        dt.setOutputLabel(hi.getSheetName());
        dt.setId("ddt_" + CodegenStringUtil.escapeIdentifier(hi.getSheetName()));
        dt.setHitPolicy(HitPolicy.ANY);
        for (String ri : hi.getRequiredInput()) {
            InputClause ic = new TInputClause();
            ic.setLabel(ri);
            LiteralExpression le = new TLiteralExpression();
            le.setText(ri);
            ic.setInputExpression(le);
            dt.getInput().add(ic);
        }
        for (String rd : hi.getRequiredDecision()) {
            InputClause ic = new TInputClause();
            ic.setLabel(rd);
            LiteralExpression le = new TLiteralExpression();
            le.setText(rd);
            ic.setInputExpression(le);
            dt.getInput().add(ic);
        }
        OutputClause oc = new TOutputClause();
        dt.getOutput().add(oc);
        decision.setExpression(dt);
        definitions.getDrgElement().add(decision);
    }
}
Also used : TInformationRequirement(org.kie.dmn.model.v1_2.TInformationRequirement) QName(javax.xml.namespace.QName) TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) LiteralExpression(org.kie.dmn.model.api.LiteralExpression) TInformationItem(org.kie.dmn.model.v1_2.TInformationItem) InformationItem(org.kie.dmn.model.api.InformationItem) TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) Decision(org.kie.dmn.model.api.Decision) TDecision(org.kie.dmn.model.v1_2.TDecision) OutputClause(org.kie.dmn.model.api.OutputClause) TOutputClause(org.kie.dmn.model.v1_2.TOutputClause) DecisionTable(org.kie.dmn.model.api.DecisionTable) TDecisionTable(org.kie.dmn.model.v1_2.TDecisionTable) DMNElementReference(org.kie.dmn.model.api.DMNElementReference) TDMNElementReference(org.kie.dmn.model.v1_2.TDMNElementReference) TInputClause(org.kie.dmn.model.v1_2.TInputClause) TInformationRequirement(org.kie.dmn.model.v1_2.TInformationRequirement) InformationRequirement(org.kie.dmn.model.api.InformationRequirement) TDecision(org.kie.dmn.model.v1_2.TDecision) TDecisionTable(org.kie.dmn.model.v1_2.TDecisionTable) TInformationItem(org.kie.dmn.model.v1_2.TInformationItem) TDMNElementReference(org.kie.dmn.model.v1_2.TDMNElementReference) TOutputClause(org.kie.dmn.model.v1_2.TOutputClause) TInputClause(org.kie.dmn.model.v1_2.TInputClause) InputClause(org.kie.dmn.model.api.InputClause)

Example 3 with OutputClause

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

the class OutputClauseConverter method writeAttributes.

@Override
protected void writeAttributes(HierarchicalStreamWriter writer, Object parent) {
    super.writeAttributes(writer, parent);
    OutputClause oc = (OutputClause) parent;
    if (oc.getName() != null)
        writer.addAttribute(NAME, oc.getName());
    if (oc.getTypeRef() != null)
        writer.addAttribute(TYPE_REF, MarshallingUtils.formatQName(oc.getTypeRef()));
}
Also used : TOutputClause(org.kie.dmn.model.v1_1.TOutputClause) OutputClause(org.kie.dmn.model.api.OutputClause)

Example 4 with OutputClause

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

the class OutputClauseConverter method writeChildren.

@Override
protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext context, Object parent) {
    super.writeChildren(writer, context, parent);
    OutputClause oc = (OutputClause) parent;
    if (oc.getOutputValues() != null)
        writeChildrenNode(writer, context, oc.getOutputValues(), OUTPUT_VALUES);
    if (oc.getDefaultOutputEntry() != null)
        writeChildrenNode(writer, context, oc.getDefaultOutputEntry(), DEFAULT_OUTPUT_ENTRY);
}
Also used : TOutputClause(org.kie.dmn.model.v1_1.TOutputClause) OutputClause(org.kie.dmn.model.api.OutputClause)

Example 5 with OutputClause

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

the class OutputClauseConverter method assignAttributes.

@Override
protected void assignAttributes(HierarchicalStreamReader reader, Object parent) {
    super.assignAttributes(reader, parent);
    OutputClause oc = (OutputClause) parent;
    String name = reader.getAttribute(NAME);
    String typeRefValue = reader.getAttribute(TYPE_REF);
    oc.setName(name);
    if (typeRefValue != null)
        oc.setTypeRef(MarshallingUtils.parseQNameString(typeRefValue));
}
Also used : TOutputClause(org.kie.dmn.model.v1_1.TOutputClause) OutputClause(org.kie.dmn.model.api.OutputClause)

Aggregations

OutputClause (org.kie.dmn.model.api.OutputClause)22 DecisionTable (org.kie.dmn.model.api.DecisionTable)7 InputClause (org.kie.dmn.model.api.InputClause)7 DecisionRule (org.kie.dmn.model.api.DecisionRule)5 QName (javax.xml.namespace.QName)4 TOutputClause (org.kie.dmn.model.v1_2.TOutputClause)4 ArrayList (java.util.ArrayList)3 Decision (org.kie.dmn.model.api.Decision)3 TOutputClause (org.kie.dmn.model.v1_1.TOutputClause)3 TOutputClause (org.kie.dmn.model.v1_3.TOutputClause)3 DMNType (org.kie.dmn.api.core.DMNType)2 BaseDMNTypeImpl (org.kie.dmn.core.impl.BaseDMNTypeImpl)2 InformationItem (org.kie.dmn.model.api.InformationItem)2 LiteralExpression (org.kie.dmn.model.api.LiteralExpression)2 RuleAnnotationClause (org.kie.dmn.model.api.RuleAnnotationClause)2 TDecisionTable (org.kie.dmn.model.v1_2.TDecisionTable)2 TOutputClause (org.kie.dmn.model.v1_4.TOutputClause)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1