Search in sources :

Example 16 with LiteralExpression

use of org.kie.dmn.model.api.LiteralExpression in project kie-wb-common by kiegroup.

the class BaseLiteralExpressionPropertyConverterTest method testDMNFromWB.

@Test
public void testDMNFromWB() {
    final org.kie.workbench.common.dmn.api.definition.model.ImportedValues importedValues = new org.kie.workbench.common.dmn.api.definition.model.ImportedValues();
    importedValues.setImportedElement(IMPORTED_ELEMENT);
    final org.kie.workbench.common.dmn.api.definition.model.LiteralExpression wb = new org.kie.workbench.common.dmn.api.definition.model.LiteralExpression(new Id(UUID), new Description(DESCRIPTION), BuiltInType.BOOLEAN.asQName(), new Text(TEXT), importedValues, new ExpressionLanguage(EXPRESSION_LANGUAGE));
    final LiteralExpression dmn = LiteralExpressionPropertyConverter.dmnFromWB(wb);
    assertThat(dmn.getId()).isEqualTo(UUID);
    assertThat(dmn.getDescription()).isEqualTo(DESCRIPTION);
    assertThat(dmn.getTypeRef().getNamespaceURI()).isEmpty();
    assertThat(dmn.getTypeRef().getLocalPart()).isEqualTo(BuiltInType.BOOLEAN.getName());
    assertThat(dmn.getText()).isEqualTo(TEXT);
    assertThat(dmn.getImportedValues()).isNotNull();
    assertThat(dmn.getImportedValues().getImportedElement()).isEqualTo(IMPORTED_ELEMENT);
    assertThat(dmn.getExpressionLanguage()).isEqualTo(EXPRESSION_LANGUAGE);
}
Also used : Description(org.kie.workbench.common.dmn.api.property.dmn.Description) TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) IsLiteralExpression(org.kie.workbench.common.dmn.api.definition.model.IsLiteralExpression) LiteralExpression(org.kie.dmn.model.api.LiteralExpression) Text(org.kie.workbench.common.dmn.api.property.dmn.Text) ExpressionLanguage(org.kie.workbench.common.dmn.api.property.dmn.ExpressionLanguage) ImportedValues(org.kie.dmn.model.api.ImportedValues) TImportedValues(org.kie.dmn.model.v1_2.TImportedValues) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) Test(org.junit.Test)

Example 17 with LiteralExpression

use of org.kie.dmn.model.api.LiteralExpression in project kie-wb-common by kiegroup.

the class BaseLiteralExpressionPropertyConverterTest method testWBFromDMN.

@Test
public void testWBFromDMN() {
    final LiteralExpression dmn = new TLiteralExpression();
    final QName typeRef = new QName(KIE.getUri(), LOCAL, KIE.getPrefix());
    final ImportedValues importedValues = new TImportedValues();
    importedValues.setImportedElement(IMPORTED_ELEMENT);
    dmn.setId(UUID);
    dmn.setDescription(DESCRIPTION);
    dmn.setTypeRef(typeRef);
    dmn.setText(TEXT);
    dmn.setImportedValues(importedValues);
    final T wb = convertWBFromDMN(dmn);
    assertThat(wb.getId().getValue()).isEqualTo(UUID);
    assertThat(wb.getDescription().getValue()).isEqualTo(DESCRIPTION);
    assertThat(wb.getTypeRef().getNamespaceURI()).isEqualTo(KIE.getUri());
    assertThat(wb.getTypeRef().getLocalPart()).isEqualTo(LOCAL);
    assertThat(wb.getTypeRef().getPrefix()).isEqualTo(KIE.getPrefix());
    assertThat(wb.getText().getValue()).isEqualTo(TEXT);
    assertThat(wb.getImportedValues().getImportedElement()).isEqualTo(IMPORTED_ELEMENT);
    assertThat(wb.getImportedValues().getParent()).isEqualTo(wb);
}
Also used : QName(javax.xml.namespace.QName) TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) IsLiteralExpression(org.kie.workbench.common.dmn.api.definition.model.IsLiteralExpression) LiteralExpression(org.kie.dmn.model.api.LiteralExpression) ImportedValues(org.kie.dmn.model.api.ImportedValues) TImportedValues(org.kie.dmn.model.v1_2.TImportedValues) TImportedValues(org.kie.dmn.model.v1_2.TImportedValues) TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) Test(org.junit.Test)

Example 18 with LiteralExpression

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

the class LiteralExpressionConverter method writeChildren.

@Override
protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext context, Object parent) {
    super.writeChildren(writer, context, parent);
    LiteralExpression le = (LiteralExpression) parent;
    if (le.getText() != null)
        writeChildrenNodeAsValue(writer, context, le.getText(), TEXT);
    if (le.getImportedValues() != null)
        writeChildrenNode(writer, context, le.getImportedValues(), IMPORTED_VALUES);
}
Also used : TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) LiteralExpression(org.kie.dmn.model.api.LiteralExpression)

Example 19 with LiteralExpression

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

the class LiteralExpressionConverter method assignAttributes.

@Override
protected void assignAttributes(HierarchicalStreamReader reader, Object parent) {
    super.assignAttributes(reader, parent);
    LiteralExpression le = (LiteralExpression) parent;
    String exprLanguage = reader.getAttribute(EXPR_LANGUAGE);
    le.setExpressionLanguage(exprLanguage);
}
Also used : TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) LiteralExpression(org.kie.dmn.model.api.LiteralExpression)

Example 20 with LiteralExpression

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

LiteralExpression (org.kie.dmn.model.api.LiteralExpression)31 UnaryTests (org.kie.dmn.model.api.UnaryTests)11 DecisionRule (org.kie.dmn.model.api.DecisionRule)9 TLiteralExpression (org.kie.dmn.model.v1_2.TLiteralExpression)8 InputClause (org.kie.dmn.model.api.InputClause)6 ArrayList (java.util.ArrayList)5 QName (javax.xml.namespace.QName)5 InformationItem (org.kie.dmn.model.api.InformationItem)5 Collections (java.util.Collections)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 Test (org.junit.Test)4 DMNMessage (org.kie.dmn.api.core.DMNMessage)4 DMNType (org.kie.dmn.api.core.DMNType)4 DMNNode (org.kie.dmn.api.core.ast.DMNNode)4 DMNExpressionEvaluator (org.kie.dmn.core.api.DMNExpressionEvaluator)4 Decision (org.kie.dmn.model.api.Decision)4 DecisionTable (org.kie.dmn.model.api.DecisionTable)4 Entry (java.util.Map.Entry)3 Objects (java.util.Objects)3