Search in sources :

Example 1 with DDTAOutputClause

use of org.kie.dmn.validation.dtanalysis.model.DDTAOutputClause 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)

Aggregations

ArrayList (java.util.ArrayList)1 QName (javax.xml.namespace.QName)1 ProcessedUnaryTest (org.kie.dmn.feel.codegen.feel11.ProcessedUnaryTest)1 UnaryTestListNode (org.kie.dmn.feel.lang.ast.UnaryTestListNode)1 UnaryTestNode (org.kie.dmn.feel.lang.ast.UnaryTestNode)1 UnaryTestInterpretedExecutableExpression (org.kie.dmn.feel.lang.impl.UnaryTestInterpretedExecutableExpression)1 OutputClause (org.kie.dmn.model.api.OutputClause)1 DDTAOutputClause (org.kie.dmn.validation.dtanalysis.model.DDTAOutputClause)1 Interval (org.kie.dmn.validation.dtanalysis.model.Interval)1