Search in sources :

Example 11 with LiteralExpression

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

the class ListUIModelMapperTest method testFromDMNModelCellTypes.

@Test
public void testFromDMNModelCellTypes() {
    setup(new LiteralExpression(), false);
    IntStream.range(0, 1).forEach(rowIndex -> {
        mapper.fromDMNModel(rowIndex, ROW_COLUMN_INDEX);
        mapper.fromDMNModel(rowIndex, EXPRESSION_COLUMN_INDEX);
    });
    assertThat(uiModel.getCell(0, ROW_COLUMN_INDEX)).isInstanceOf(ContextGridCell.class);
    assertThat(uiModel.getCell(0, EXPRESSION_COLUMN_INDEX)).isInstanceOf(ContextGridCell.class);
}
Also used : LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) Test(org.junit.Test)

Example 12 with LiteralExpression

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

the class RelationUIModelMapperTest method setup.

@Before
public void setup() {
    this.uiModel = new BaseGridData();
    this.uiModel.appendRow(new BaseGridRow());
    this.uiModel.appendRow(new BaseGridRow());
    this.uiModel.appendColumn(uiRowNumberColumn);
    this.uiModel.appendColumn(uiRelationColumn1);
    this.uiModel.appendColumn(uiRelationColumn2);
    when(uiRowNumberColumn.getIndex()).thenReturn(0);
    when(uiRelationColumn1.getIndex()).thenReturn(1);
    when(uiRelationColumn2.getIndex()).thenReturn(2);
    this.relation = new Relation();
    this.relation.getColumn().add(new InformationItem());
    this.relation.getColumn().add(new InformationItem());
    final List rowList1 = new List();
    rowList1.getExpression().add(HasExpression.wrap(rowList1, new LiteralExpression() {

        {
            getText().setValue("le(1,0)");
        }
    }));
    rowList1.getExpression().add(HasExpression.wrap(rowList1, new LiteralExpression() {

        {
            getText().setValue("le(2,0)");
        }
    }));
    final List rowList2 = new List();
    rowList2.getExpression().add(HasExpression.wrap(rowList2, new LiteralExpression() {

        {
            getText().setValue("le(1,1)");
        }
    }));
    rowList2.getExpression().add(HasExpression.wrap(rowList2, new LiteralExpression() {

        {
            getText().setValue("le(2,1)");
        }
    }));
    this.relation.getRow().add(rowList1);
    this.relation.getRow().add(rowList2);
    this.mapper = new RelationUIModelMapper(() -> uiModel, () -> Optional.of(relation), listSelector, DEFAULT_HEIGHT);
    this.cellValueSupplier = Optional::empty;
}
Also used : Relation(org.kie.workbench.common.dmn.api.definition.model.Relation) BaseGridRow(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow) Optional(java.util.Optional) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) List(org.kie.workbench.common.dmn.api.definition.model.List) BaseGridData(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData) Before(org.junit.Before)

Example 13 with LiteralExpression

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

the class RelationUIModelMapperTest method testToDMNModelLiteralExpressionsNullValue.

@Test
public void testToDMNModelLiteralExpressionsNullValue() {
    cellValueSupplier = () -> Optional.of(new BaseGridCellValue<>(null));
    for (int uiRowIndex = 0; uiRowIndex < uiModel.getRowCount(); uiRowIndex++) {
        for (int uiColumnIndex = 1; uiColumnIndex < uiModel.getColumnCount(); uiColumnIndex++) {
            mapper.toDMNModel(uiRowIndex, uiColumnIndex, cellValueSupplier);
            final LiteralExpression le = (LiteralExpression) relation.getRow().get(uiRowIndex).getExpression().get(uiColumnIndex - RelationUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT).getExpression();
            assertNull(le.getText().getValue());
        }
    }
}
Also used : LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) BaseGridCellValue(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue) Test(org.junit.Test)

Example 14 with LiteralExpression

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

the class RelationUIModelMapperTest method testToDMNModelLiteralExpressionsNonEmptyValue.

@Test
public void testToDMNModelLiteralExpressionsNonEmptyValue() {
    for (int uiRowIndex = 0; uiRowIndex < uiModel.getRowCount(); uiRowIndex++) {
        for (int uiColumnIndex = 1; uiColumnIndex < uiModel.getColumnCount(); uiColumnIndex++) {
            final String value = "(" + uiColumnIndex + "," + uiRowIndex + ")";
            cellValueSupplier = () -> Optional.of(new BaseGridCellValue<>(value));
            mapper.toDMNModel(uiRowIndex, uiColumnIndex, cellValueSupplier);
            final LiteralExpression le = (LiteralExpression) relation.getRow().get(uiRowIndex).getExpression().get(uiColumnIndex - RelationUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT).getExpression();
            assertEquals(value, le.getText().getValue());
        }
    }
}
Also used : LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) BaseGridCellValue(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue) Test(org.junit.Test)

Example 15 with LiteralExpression

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

the class FunctionDefinitionPropertyConverter method convertContextEntryExpression.

private static void convertContextEntryExpression(final ContextEntry contextEntry, final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer) {
    final Expression expression = contextEntry.getExpression();
    if (expression instanceof LiteralExpression) {
        final LiteralExpression le = (LiteralExpression) expression;
        final String variableName = contextEntry.getVariable().getName().getValue();
        if (Objects.equals(LiteralExpressionPMMLDocument.VARIABLE_DOCUMENT, variableName)) {
            final LiteralExpressionPMMLDocument e = convertLiteralExpressionToPMMLDocument(le);
            // Ensure ComponentWidths are updated for the converted LiteralExpression
            hasComponentWidthsConsumer.accept(e.getId().getValue(), e);
            contextEntry.setExpression(e);
        } else if (Objects.equals(LiteralExpressionPMMLDocumentModel.VARIABLE_MODEL, variableName)) {
            final LiteralExpressionPMMLDocumentModel e = convertLiteralExpressionToPMMLDocumentModel(le);
            // Ensure ComponentWidths are updated for the converted LiteralExpression
            hasComponentWidthsConsumer.accept(e.getId().getValue(), e);
            contextEntry.setExpression(e);
        }
    }
}
Also used : LiteralExpressionPMMLDocumentModel(org.kie.workbench.common.dmn.api.definition.model.LiteralExpressionPMMLDocumentModel) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) JSITExpression(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITExpression) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) LiteralExpressionPMMLDocument(org.kie.workbench.common.dmn.api.definition.model.LiteralExpressionPMMLDocument)

Aggregations

LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)113 Test (org.junit.Test)64 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)25 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)25 InformationItem (org.kie.workbench.common.dmn.api.definition.model.InformationItem)23 HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)21 List (org.kie.workbench.common.dmn.api.definition.model.List)20 UnaryTests (org.kie.workbench.common.dmn.api.definition.model.UnaryTests)16 DecisionRule (org.kie.workbench.common.dmn.api.definition.model.DecisionRule)15 BaseGridRow (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow)14 Before (org.junit.Before)13 RuleAnnotationClauseText (org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText)12 Optional (java.util.Optional)11 TLiteralExpression (org.kie.dmn.model.v1_2.TLiteralExpression)11 HasComponentWidths (org.kie.workbench.common.dmn.api.definition.HasComponentWidths)11 FunctionDefinition (org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition)11 Context (org.kie.workbench.common.dmn.api.definition.model.Context)10 BaseGridData (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData)10 ContextEntry (org.kie.workbench.common.dmn.api.definition.model.ContextEntry)9 Expression (org.kie.workbench.common.dmn.api.definition.model.Expression)9