Search in sources :

Example 51 with LiteralExpression

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

the class LiteralExpressionPropertyConverterTest method testWBFromDMN.

@Test
public void testWBFromDMN() {
    when(literalExpression.getId()).thenReturn(UUID);
    when(literalExpression.getDescription()).thenReturn(DESCRIPTION);
    when(literalExpression.getTypeRef()).thenReturn(TYPE_REF);
    when(literalExpression.getText()).thenReturn(TEXT);
    when(literalExpression.getExpressionLanguage()).thenReturn(EXPRESSION_LANGUAGE);
    when(literalExpression.getImportedValues()).thenReturn(jsitImportedValues);
    when(jsitImportedValues.getImportedElement()).thenReturn(IMPORTED_ELEMENT);
    final LiteralExpression result = LiteralExpressionPropertyConverter.wbFromDMN(literalExpression);
    assertThat(result.getId().getValue()).isEqualTo(UUID);
    assertThat(result.getDescription().getValue()).isEqualTo(DESCRIPTION);
    assertThat(result.getTypeRef().getNamespaceURI()).isEmpty();
    assertThat(result.getTypeRef().getLocalPart()).isEqualTo(TYPE_REF);
    assertThat(result.getText().getValue()).isEqualTo(TEXT);
    assertThat(result.getExpressionLanguage().getValue()).isEqualTo(EXPRESSION_LANGUAGE);
    assertThat(result.getImportedValues().getImportedElement()).isEqualTo(IMPORTED_ELEMENT);
    assertThat(result.getImportedValues().getParent()).isEqualTo(result);
}
Also used : LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) JSITLiteralExpression(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITLiteralExpression) Test(org.junit.Test)

Example 52 with LiteralExpression

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

the class AddOutputClauseCommand method newGraphCommand.

@Override
protected Command<GraphCommandExecutionContext, RuleViolation> newGraphCommand(final AbstractCanvasHandler context) {
    return new AbstractGraphCommand() {

        @Override
        protected CommandResult<RuleViolation> check(final GraphCommandExecutionContext context) {
            return GraphCommandResultBuilder.SUCCESS;
        }

        @Override
        public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) {
            dtable.getComponentWidths().add(uiColumnIndex, null);
            final int clauseIndex = uiColumnIndex - DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT - dtable.getInput().size();
            dtable.getOutput().add(clauseIndex, outputClause);
            outputClause.setName(name);
            dtable.getRule().forEach(rule -> {
                final LiteralExpression le = new LiteralExpression();
                le.getText().setValue(DecisionTableDefaultValueUtilities.OUTPUT_CLAUSE_EXPRESSION_TEXT);
                rule.getOutputEntry().add(clauseIndex, le);
                le.setParent(rule);
            });
            outputClause.setParent(dtable);
            return GraphCommandResultBuilder.SUCCESS;
        }

        @Override
        public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context) {
            dtable.getComponentWidths().remove(uiColumnIndex);
            final int clauseIndex = dtable.getOutput().indexOf(outputClause);
            dtable.getRule().forEach(rule -> rule.getOutputEntry().remove(clauseIndex));
            dtable.getOutput().remove(outputClause);
            return GraphCommandResultBuilder.SUCCESS;
        }
    };
}
Also used : LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) AbstractGraphCommand(org.kie.workbench.common.stunner.core.graph.command.impl.AbstractGraphCommand) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation)

Example 53 with LiteralExpression

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

the class DeleteOutputClauseCommand method newGraphCommand.

@Override
protected Command<GraphCommandExecutionContext, RuleViolation> newGraphCommand(final AbstractCanvasHandler handler) {
    return new AbstractGraphCommand() {

        @Override
        protected CommandResult<RuleViolation> check(final GraphCommandExecutionContext gce) {
            return GraphCommandResultBuilder.SUCCESS;
        }

        @Override
        public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext gce) {
            dtable.getComponentWidths().remove(uiColumnIndex);
            final int clauseIndex = getOutputClauseIndex();
            dtable.getRule().forEach(row -> row.getOutputEntry().remove(clauseIndex));
            dtable.getOutput().remove(clauseIndex);
            return GraphCommandResultBuilder.SUCCESS;
        }

        @Override
        public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext gce) {
            dtable.getComponentWidths().add(uiColumnIndex, oldUiModelColumn.getWidth());
            final int clauseIndex = getOutputClauseIndex();
            dtable.getOutput().add(clauseIndex, oldOutputClause);
            IntStream.range(0, dtable.getRule().size()).forEach(rowIndex -> {
                final LiteralExpression value = oldColumnData.get(rowIndex);
                dtable.getRule().get(rowIndex).getOutputEntry().add(clauseIndex, value);
            });
            return GraphCommandResultBuilder.SUCCESS;
        }
    };
}
Also used : LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) AbstractGraphCommand(org.kie.workbench.common.stunner.core.graph.command.impl.AbstractGraphCommand) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation)

Example 54 with LiteralExpression

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

the class MoveColumnsCommand method newGraphCommand.

@Override
protected Command<GraphCommandExecutionContext, RuleViolation> newGraphCommand(final AbstractCanvasHandler context) {
    return new AbstractGraphCommand() {

        @Override
        protected CommandResult<RuleViolation> check(final GraphCommandExecutionContext context) {
            return isColumnInValidSection() ? GraphCommandResultBuilder.SUCCESS : GraphCommandResultBuilder.failed();
        }

        private boolean isColumnInValidSection() {
            final DecisionTableSection section = DecisionTableUIModelMapperHelper.getSection(dtable, index);
            return section == DecisionTableSection.INPUT_CLAUSES || section == DecisionTableSection.OUTPUT_CLAUSES || section == DecisionTableSection.ANNOTATION_CLAUSES;
        }

        @Override
        public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context) {
            return moveClauses(index);
        }

        @Override
        public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context) {
            return moveClauses(oldIndex);
        }

        private CommandResult<RuleViolation> moveClauses(final int index) {
            final DecisionTableSection section = DecisionTableUIModelMapperHelper.getSection(dtable, index);
            if (section == DecisionTableSection.INPUT_CLAUSES) {
                final int oldIndex = uiModel.getColumns().indexOf(columns.get(0));
                final int relativeIndex = DecisionTableUIModelMapperHelper.getInputEntryIndex(dtable, index);
                final int relativeOldIndex = DecisionTableUIModelMapperHelper.getInputEntryIndex(dtable, oldIndex);
                final List<Integer> uiColumnIndexesToMove = columns.stream().map(c -> uiModel.getColumns().indexOf(c)).collect(Collectors.toList());
                final List<Integer> inputClauseIndexesToMove = uiColumnIndexesToMove.stream().map(i -> DecisionTableUIModelMapperHelper.getInputEntryIndex(dtable, i)).collect(Collectors.toList());
                moveClauses(relativeIndex, relativeOldIndex, dtable.getInput(), inputClauseIndexesToMove);
                CommandUtils.moveComponentWidths(index, oldIndex, dtable.getComponentWidths(), uiColumnIndexesToMove);
                final List<List<UnaryTests>> decisionRulesInputEntries = dtable.getRule().stream().map(DecisionRule::getInputEntry).collect(Collectors.toList());
                updateDecisionRules(relativeIndex, relativeOldIndex, decisionRulesInputEntries, inputClauseIndexesToMove);
                return GraphCommandResultBuilder.SUCCESS;
            } else if (section == DecisionTableSection.OUTPUT_CLAUSES) {
                final int oldIndex = uiModel.getColumns().indexOf(columns.get(0));
                final int relativeIndex = DecisionTableUIModelMapperHelper.getOutputEntryIndex(dtable, index);
                final int relativeOldIndex = DecisionTableUIModelMapperHelper.getOutputEntryIndex(dtable, oldIndex);
                final List<Integer> uiColumnIndexesToMove = columns.stream().map(c -> uiModel.getColumns().indexOf(c)).collect(Collectors.toList());
                final List<Integer> outputClauseIndexesToMove = uiColumnIndexesToMove.stream().map(i -> DecisionTableUIModelMapperHelper.getOutputEntryIndex(dtable, i)).collect(Collectors.toList());
                moveClauses(relativeIndex, relativeOldIndex, dtable.getOutput(), outputClauseIndexesToMove);
                CommandUtils.moveComponentWidths(index, oldIndex, dtable.getComponentWidths(), uiColumnIndexesToMove);
                final List<List<LiteralExpression>> decisionRulesOutputEntries = dtable.getRule().stream().map(DecisionRule::getOutputEntry).collect(Collectors.toList());
                updateDecisionRules(relativeIndex, relativeOldIndex, decisionRulesOutputEntries, outputClauseIndexesToMove);
                return GraphCommandResultBuilder.SUCCESS;
            } else if (section == DecisionTableSection.ANNOTATION_CLAUSES) {
                final int oldIndex = uiModel.getColumns().indexOf(columns.get(0));
                final int relativeIndex = DecisionTableUIModelMapperHelper.getAnnotationEntryIndex(dtable, index);
                final int relativeOldIndex = DecisionTableUIModelMapperHelper.getAnnotationEntryIndex(dtable, oldIndex);
                final List<Integer> uiColumnIndexesToMove = columns.stream().map(c -> uiModel.getColumns().indexOf(c)).collect(Collectors.toList());
                final List<Integer> annotationClauseIndexesToMove = uiColumnIndexesToMove.stream().map(i -> DecisionTableUIModelMapperHelper.getAnnotationEntryIndex(dtable, i)).collect(Collectors.toList());
                moveClauses(relativeIndex, relativeOldIndex, dtable.getAnnotations(), annotationClauseIndexesToMove);
                CommandUtils.moveComponentWidths(index, oldIndex, dtable.getComponentWidths(), uiColumnIndexesToMove);
                final List<List<RuleAnnotationClauseText>> decisionRulesAnnotationEntries = dtable.getRule().stream().map(DecisionRule::getAnnotationEntry).collect(Collectors.toList());
                updateDecisionRules(relativeIndex, relativeOldIndex, decisionRulesAnnotationEntries, annotationClauseIndexesToMove);
                return GraphCommandResultBuilder.SUCCESS;
            } else {
                return GraphCommandResultBuilder.failed();
            }
        }

        private <T> void moveClauses(final int relativeIndex, final int relativeOldIndex, final List<T> clauses, final List<Integer> clauseIndexesToMove) {
            final List<T> clausesToMove = clauseIndexesToMove.stream().map(clauses::get).collect(Collectors.toList());
            clauses.removeAll(clausesToMove);
            if (relativeIndex < relativeOldIndex) {
                clauses.addAll(relativeIndex, clausesToMove);
            } else if (relativeIndex > relativeOldIndex) {
                clauses.addAll(relativeIndex - clausesToMove.size() + 1, clausesToMove);
            }
        }

        private <T> void updateDecisionRules(final int relativeIndex, final int relativeOldIndex, final List<List<T>> clauses, final List<Integer> clauseIndexesToMove) {
            clauses.forEach(row -> moveClauses(relativeIndex, relativeOldIndex, row, clauseIndexesToMove));
        }
    };
}
Also used : DMNGridData(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData) DecisionTableUIModelMapperHelper(org.kie.workbench.common.dmn.client.editors.expressions.types.dtable.DecisionTableUIModelMapperHelper) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) VetoExecutionCommand(org.kie.workbench.common.dmn.client.commands.VetoExecutionCommand) CanvasCommandResultBuilder(org.kie.workbench.common.stunner.core.client.command.CanvasCommandResultBuilder) GridColumn(org.uberfire.ext.wires.core.grids.client.model.GridColumn) AbstractCanvasCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AbstractCanvasCommand) ArrayList(java.util.ArrayList) CommandUtils(org.kie.workbench.common.dmn.client.commands.util.CommandUtils) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) AbstractGraphCommand(org.kie.workbench.common.stunner.core.graph.command.impl.AbstractGraphCommand) Command(org.kie.workbench.common.stunner.core.command.Command) GraphCommandResultBuilder(org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder) VetoUndoCommand(org.kie.workbench.common.dmn.client.commands.VetoUndoCommand) CommandResult(org.kie.workbench.common.stunner.core.command.CommandResult) DecisionTableSection(org.kie.workbench.common.dmn.client.editors.expressions.types.dtable.DecisionTableUIModelMapperHelper.DecisionTableSection) CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) Collectors(java.util.stream.Collectors) AbstractCanvasGraphCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AbstractCanvasGraphCommand) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests) List(java.util.List) RuleAnnotationClauseText(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) DecisionTableSection(org.kie.workbench.common.dmn.client.editors.expressions.types.dtable.DecisionTableUIModelMapperHelper.DecisionTableSection) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) AbstractGraphCommand(org.kie.workbench.common.stunner.core.graph.command.impl.AbstractGraphCommand) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) ArrayList(java.util.ArrayList) List(java.util.List)

Example 55 with LiteralExpression

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

the class AddRelationColumnCommand method newGraphCommand.

@Override
protected Command<GraphCommandExecutionContext, RuleViolation> newGraphCommand(final AbstractCanvasHandler handler) {
    return new AbstractGraphCommand() {

        @Override
        protected CommandResult<RuleViolation> check(final GraphCommandExecutionContext gce) {
            return GraphCommandResultBuilder.SUCCESS;
        }

        @Override
        public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext gce) {
            relation.getComponentWidths().add(uiColumnIndex, null);
            final int iiIndex = uiColumnIndex - RelationUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT;
            relation.getColumn().add(iiIndex, informationItem);
            informationItem.getName().setValue(name);
            relation.getRow().forEach(row -> {
                final LiteralExpression le = new LiteralExpression();
                final HasExpression hasExpression = HasExpression.wrap(row, le);
                row.getExpression().add(iiIndex, hasExpression);
                le.setParent(row);
            });
            informationItem.setParent(relation);
            return GraphCommandResultBuilder.SUCCESS;
        }

        @Override
        public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext gce) {
            relation.getComponentWidths().remove(uiColumnIndex);
            final int columnIndex = relation.getColumn().indexOf(informationItem);
            relation.getRow().forEach(row -> row.getExpression().remove(columnIndex));
            relation.getColumn().remove(informationItem);
            return GraphCommandResultBuilder.SUCCESS;
        }
    };
}
Also used : HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) AbstractGraphCommand(org.kie.workbench.common.stunner.core.graph.command.impl.AbstractGraphCommand) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation)

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