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;
}
};
}
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;
}
};
}
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;
}
};
}
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());
}
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());
}
Aggregations