Search in sources :

Example 1 with DMNRelationEvaluator

use of org.kie.dmn.core.ast.DMNRelationEvaluator in project drools by kiegroup.

the class DMNEvaluatorCompiler method compileRelation.

private DMNExpressionEvaluator compileRelation(DMNCompilerContext ctx, DMNModelImpl model, DMNBaseNode node, String relationName, Relation expression) {
    Relation relationDef = expression;
    DMNRelationEvaluator relationEval = new DMNRelationEvaluator(node.getName(), node.getSource(), relationDef);
    for (InformationItem col : relationDef.getColumn()) {
        DMNCompilerHelper.checkVariableName(model, col, col.getName());
        relationEval.addColumn(col.getName());
    }
    for (org.kie.dmn.model.api.List row : relationDef.getRow()) {
        java.util.List<DMNExpressionEvaluator> values = new ArrayList<>();
        for (Expression expr : row.getExpression()) {
            if (expr instanceof LiteralExpression) {
                // DROOLS-2439
                LiteralExpression literalExpression = (LiteralExpression) expr;
                if (literalExpression.getText() == null || literalExpression.getText().isEmpty()) {
                    LiteralExpression nullProxy = (literalExpression instanceof org.kie.dmn.model.v1_1.TLiteralExpression) ? new org.kie.dmn.model.v1_1.TLiteralExpression() : new org.kie.dmn.model.v1_2.TLiteralExpression();
                    nullProxy.setText("null");
                    nullProxy.setImportedValues(literalExpression.getImportedValues());
                    nullProxy.setExpressionLanguage(literalExpression.getExpressionLanguage());
                    nullProxy.setTypeRef(literalExpression.getTypeRef());
                    nullProxy.setId(literalExpression.getId());
                    nullProxy.setLabel(literalExpression.getLabel());
                    nullProxy.setDescription(literalExpression.getDescription());
                    nullProxy.setExtensionElements(literalExpression.getExtensionElements());
                    nullProxy.setParent(literalExpression.getParent());
                    nullProxy.getNsContext().putAll(literalExpression.getNsContext());
                    nullProxy.setAdditionalAttributes(literalExpression.getAdditionalAttributes());
                    nullProxy.setLocation(literalExpression.getLocation());
                    // do not add `temp` as child of parent.
                    expr = nullProxy;
                }
            }
            values.add(compileExpression(ctx, model, node, relationName, expr));
        }
        relationEval.addRow(values);
    }
    return relationEval;
}
Also used : DMNExpressionEvaluator(org.kie.dmn.core.api.DMNExpressionEvaluator) LiteralExpression(org.kie.dmn.model.api.LiteralExpression) ArrayList(java.util.ArrayList) InformationItem(org.kie.dmn.model.api.InformationItem) Relation(org.kie.dmn.model.api.Relation) LiteralExpression(org.kie.dmn.model.api.LiteralExpression) CompiledExpression(org.kie.dmn.feel.lang.CompiledExpression) Expression(org.kie.dmn.model.api.Expression) DMNRelationEvaluator(org.kie.dmn.core.ast.DMNRelationEvaluator)

Aggregations

ArrayList (java.util.ArrayList)1 DMNExpressionEvaluator (org.kie.dmn.core.api.DMNExpressionEvaluator)1 DMNRelationEvaluator (org.kie.dmn.core.ast.DMNRelationEvaluator)1 CompiledExpression (org.kie.dmn.feel.lang.CompiledExpression)1 Expression (org.kie.dmn.model.api.Expression)1 InformationItem (org.kie.dmn.model.api.InformationItem)1 LiteralExpression (org.kie.dmn.model.api.LiteralExpression)1 Relation (org.kie.dmn.model.api.Relation)1