Search in sources :

Example 36 with RuleViolation

use of org.kie.workbench.common.stunner.core.rule.RuleViolation in project kie-wb-common by kiegroup.

the class AddDecisionRuleCommand 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.getRule().add(uiRowIndex, rule);
            for (int ie = 0; ie < dtable.getInput().size(); ie++) {
                final UnaryTests ut = new UnaryTests();
                ut.setText(AddInputClauseCommand.INPUT_CLAUSE_DEFAULT_VALUE);
                rule.getInputEntry().add(ut);
            }
            for (int oe = 0; oe < dtable.getOutput().size(); oe++) {
                final LiteralExpression le = new LiteralExpression();
                le.setText(AddOutputClauseCommand.OUTPUT_CLAUSE_DEFAULT_VALUE);
                rule.getOutputEntry().add(le);
            }
            final Description d = new Description();
            d.setValue(DESCRIPTION_DEFAULT_VALUE);
            rule.setDescription(d);
            return GraphCommandResultBuilder.SUCCESS;
        }

        @Override
        public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context) {
            dtable.getRule().remove(rule);
            return GraphCommandResultBuilder.SUCCESS;
        }
    };
}
Also used : Description(org.kie.workbench.common.dmn.api.property.dmn.Description) LiteralExpression(org.kie.workbench.common.dmn.api.definition.v1_1.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) UnaryTests(org.kie.workbench.common.dmn.api.definition.v1_1.UnaryTests)

Example 37 with RuleViolation

use of org.kie.workbench.common.stunner.core.rule.RuleViolation in project kie-wb-common by kiegroup.

the class AddInputClauseCommand 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) {
            final int clauseIndex = uiColumnIndex - DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT;
            dtable.getInput().add(clauseIndex, inputClause);
            dtable.getRule().forEach(rule -> {
                final UnaryTests ut = new UnaryTests();
                ut.setText(INPUT_CLAUSE_DEFAULT_VALUE);
                rule.getInputEntry().add(clauseIndex, ut);
            });
            return GraphCommandResultBuilder.SUCCESS;
        }

        @Override
        public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context) {
            final int clauseIndex = dtable.getInput().indexOf(inputClause);
            dtable.getRule().forEach(rule -> rule.getInputEntry().remove(clauseIndex));
            dtable.getInput().remove(inputClause);
            return GraphCommandResultBuilder.SUCCESS;
        }
    };
}
Also used : 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) UnaryTests(org.kie.workbench.common.dmn.api.definition.v1_1.UnaryTests)

Example 38 with RuleViolation

use of org.kie.workbench.common.stunner.core.rule.RuleViolation in project kie-wb-common by kiegroup.

the class DeleteRelationColumnCommand 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) {
            final int iiIndex = uiColumnIndex - RelationUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT;
            relation.getRow().forEach(row -> row.getExpression().remove(iiIndex));
            relation.getColumn().remove(iiIndex);
            return GraphCommandResultBuilder.SUCCESS;
        }

        @Override
        public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext gce) {
            final int iiIndex = uiColumnIndex - RelationUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT;
            relation.getColumn().add(iiIndex, oldInformationItem);
            IntStream.range(0, relation.getRow().size()).forEach(rowIndex -> {
                final Expression value = oldColumnData.get(rowIndex);
                relation.getRow().get(rowIndex).getExpression().add(iiIndex, value);
            });
            return GraphCommandResultBuilder.SUCCESS;
        }
    };
}
Also used : Expression(org.kie.workbench.common.dmn.api.definition.v1_1.Expression) 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 39 with RuleViolation

use of org.kie.workbench.common.stunner.core.rule.RuleViolation in project kie-wb-common by kiegroup.

the class AddInputClauseCommandTest method testGraphCommandUndoJustLastInputClauseColumn.

@Test
public void testGraphCommandUndoJustLastInputClauseColumn() throws Exception {
    makeCommand(DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT);
    final String ruleOneOldInput = "old rule 1";
    final String ruleTwoOldInput = "old rule 2";
    dtable.getInput().add(new InputClause());
    addRuleWithInputClauseValues(ruleOneOldInput);
    addRuleWithInputClauseValues(ruleTwoOldInput);
    assertEquals(1, dtable.getInput().size());
    final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
    assertEquals(GraphCommandResultBuilder.SUCCESS, graphCommand.execute(graphCommandExecutionContext));
    assertEquals(GraphCommandResultBuilder.SUCCESS, graphCommand.undo(graphCommandExecutionContext));
    assertEquals(1, dtable.getInput().size());
    // first rule
    assertEquals(1, dtable.getRule().get(0).getInputEntry().size());
    assertEquals(ruleOneOldInput, dtable.getRule().get(0).getInputEntry().get(0).getText());
    // second rule
    assertEquals(1, dtable.getRule().get(1).getInputEntry().size());
    assertEquals(ruleTwoOldInput, dtable.getRule().get(1).getInputEntry().get(0).getText());
}
Also used : GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) InputClause(org.kie.workbench.common.dmn.api.definition.v1_1.InputClause) Test(org.junit.Test)

Example 40 with RuleViolation

use of org.kie.workbench.common.stunner.core.rule.RuleViolation in project kie-wb-common by kiegroup.

the class AddInputClauseCommandTest method testGraphCommandExecuteExistingNotAffected.

@Test
public void testGraphCommandExecuteExistingNotAffected() throws Exception {
    makeCommand(DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT);
    final String ruleOneOldInput = "old rule 1";
    final String ruleTwoOldInput = "old rule 2";
    dtable.getInput().add(new InputClause());
    addRuleWithInputClauseValues(ruleOneOldInput);
    addRuleWithInputClauseValues(ruleTwoOldInput);
    assertEquals(1, dtable.getInput().size());
    // Graph command will insert new InputClause at index 0 of the InputEntries
    final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
    assertEquals(GraphCommandResultBuilder.SUCCESS, graphCommand.execute(graphCommandExecutionContext));
    assertEquals(2, dtable.getInput().size());
    // first rule
    assertEquals(2, dtable.getRule().get(0).getInputEntry().size());
    assertEquals(ruleOneOldInput, dtable.getRule().get(0).getInputEntry().get(1).getText());
    assertEquals(AddInputClauseCommand.INPUT_CLAUSE_DEFAULT_VALUE, dtable.getRule().get(0).getInputEntry().get(0).getText());
    // second rule
    assertEquals(2, dtable.getRule().get(1).getInputEntry().size());
    assertEquals(ruleTwoOldInput, dtable.getRule().get(1).getInputEntry().get(1).getText());
    assertEquals(AddInputClauseCommand.INPUT_CLAUSE_DEFAULT_VALUE, dtable.getRule().get(1).getInputEntry().get(0).getText());
}
Also used : GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) InputClause(org.kie.workbench.common.dmn.api.definition.v1_1.InputClause) Test(org.junit.Test)

Aggregations

RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)122 Test (org.junit.Test)81 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)59 Node (org.kie.workbench.common.stunner.core.graph.Node)27 Edge (org.kie.workbench.common.stunner.core.graph.Edge)26 RuleViolations (org.kie.workbench.common.stunner.core.rule.RuleViolations)21 LiteralExpression (org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression)18 RuleEvaluationContext (org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext)18 InformationItem (org.kie.workbench.common.dmn.api.definition.v1_1.InformationItem)16 DefaultRuleViolations (org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations)16 RuleSet (org.kie.workbench.common.stunner.core.rule.RuleSet)15 ContainmentRuleViolation (org.kie.workbench.common.stunner.core.rule.violations.ContainmentRuleViolation)15 GraphCommandResultBuilder (org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder)13 DecisionRule (org.kie.workbench.common.dmn.api.definition.v1_1.DecisionRule)12 AbstractGraphCommand (org.kie.workbench.common.stunner.core.graph.command.impl.AbstractGraphCommand)11 List (org.kie.workbench.common.dmn.api.definition.v1_1.List)10 Collection (java.util.Collection)8 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)8 CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)8 Binding (org.kie.workbench.common.dmn.api.definition.v1_1.Binding)7