use of org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText in project kie-wb-common by kiegroup.
the class RuleAnnotationClauseTextConverterTest method testWbFromDMNWhenIsNull.
@Test
public void testWbFromDMNWhenIsNull() {
final RuleAnnotationClauseText converted = RuleAnnotationClauseTextConverter.wbFromDMN(null);
assertNull(converted);
}
use of org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText in project kie-wb-common by kiegroup.
the class MoveColumnsCommandTest method setUp.
@Before
public void setUp() {
this.dtable = new DecisionTable();
this.uiModel = new DMNGridData();
dtable.getInput().add(inputClauseOne);
dtable.getInput().add(inputClauseTwo);
dtable.getInput().add(inputClauseThree);
dtable.getOutput().add(outputClauseOne);
dtable.getOutput().add(outputClauseTwo);
dtable.getOutput().add(outputClauseThree);
dtable.getAnnotations().add(annotationClauseOne);
dtable.getAnnotations().add(annotationClauseTwo);
dtable.getAnnotations().add(annotationClauseThree);
dtable.getRule().add(new DecisionRule() {
{
getInputEntry().add(new UnaryTests());
getInputEntry().add(new UnaryTests());
getInputEntry().add(new UnaryTests());
getOutputEntry().add(new LiteralExpression());
getOutputEntry().add(new LiteralExpression());
getOutputEntry().add(new LiteralExpression());
getAnnotationEntry().add(new RuleAnnotationClauseText());
getAnnotationEntry().add(new RuleAnnotationClauseText());
getAnnotationEntry().add(new RuleAnnotationClauseText());
}
});
uiModel.appendColumn(uiRowNumberColumn);
uiModel.appendColumn(uiInputClauseColumnOne);
uiModel.appendColumn(uiInputClauseColumnTwo);
uiModel.appendColumn(uiInputClauseColumnThree);
uiModel.appendColumn(uiOutputClauseColumnOne);
uiModel.appendColumn(uiOutputClauseColumnTwo);
uiModel.appendColumn(uiOutputClauseColumnThree);
uiModel.appendColumn(uiRuleAnnotationClauseColumnOne);
uiModel.appendColumn(uiRuleAnnotationClauseColumnTwo);
uiModel.appendColumn(uiRuleAnnotationClauseColumnThree);
doReturn(0).when(uiRowNumberColumn).getIndex();
doReturn(1).when(uiInputClauseColumnOne).getIndex();
doReturn(2).when(uiInputClauseColumnTwo).getIndex();
doReturn(3).when(uiInputClauseColumnThree).getIndex();
doReturn(4).when(uiOutputClauseColumnOne).getIndex();
doReturn(5).when(uiOutputClauseColumnTwo).getIndex();
doReturn(6).when(uiOutputClauseColumnThree).getIndex();
doReturn(7).when(uiRuleAnnotationClauseColumnOne).getIndex();
doReturn(8).when(uiRuleAnnotationClauseColumnTwo).getIndex();
doReturn(9).when(uiRuleAnnotationClauseColumnThree).getIndex();
}
use of org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText in project kie-wb-common by kiegroup.
the class DecisionTableEditorDefinitionEnricher method enrich.
@Override
public void enrich(final Optional<String> nodeUUID, final HasExpression hasExpression, final Optional<DecisionTable> expression) {
expression.ifPresent(dtable -> {
dtable.setHitPolicy(HitPolicy.UNIQUE);
dtable.setPreferredOrientation(DecisionTableOrientation.RULE_AS_ROW);
final InputClause inputClause = new InputClause();
final InputClauseLiteralExpression literalExpression = new InputClauseLiteralExpression();
literalExpression.getText().setValue(DecisionTableDefaultValueUtilities.getNewInputClauseName(dtable));
inputClause.setInputExpression(literalExpression);
dtable.getInput().add(inputClause);
final RuleAnnotationClause ruleAnnotationClause = new RuleAnnotationClause();
ruleAnnotationClause.getName().setValue(DecisionTableDefaultValueUtilities.getNewRuleAnnotationClauseName(dtable));
dtable.getAnnotations().add(ruleAnnotationClause);
final DecisionRule decisionRule = new DecisionRule();
final UnaryTests decisionRuleUnaryTest = new UnaryTests();
decisionRuleUnaryTest.getText().setValue(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_UNARY_TEST_TEXT);
decisionRule.getInputEntry().add(decisionRuleUnaryTest);
buildOutputClausesByDataType(hasExpression, dtable, decisionRule);
final RuleAnnotationClauseText ruleAnnotationEntry = new RuleAnnotationClauseText();
ruleAnnotationEntry.getText().setValue(DecisionTableDefaultValueUtilities.RULE_DESCRIPTION);
decisionRule.getAnnotationEntry().add(ruleAnnotationEntry);
dtable.getRule().add(decisionRule);
// Setup parent relationships
inputClause.setParent(dtable);
decisionRule.setParent(dtable);
literalExpression.setParent(inputClause);
decisionRuleUnaryTest.setParent(decisionRule);
ruleAnnotationEntry.setParent(dtable);
if (nodeUUID.isPresent()) {
enrichInputClauses(nodeUUID.get(), dtable);
} else {
enrichOutputClauses(dtable);
}
});
}
use of org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText in project kie-wb-common by kiegroup.
the class DecisionRuleFactory method makeDecisionRule.
public static DecisionRule makeDecisionRule(final DecisionTable dtable) {
final DecisionRule rule = new DecisionRule();
for (int ie = 0; ie < dtable.getInput().size(); ie++) {
final UnaryTests ut = new UnaryTests();
ut.getText().setValue(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_UNARY_TEST_TEXT);
rule.getInputEntry().add(ut);
ut.setParent(rule);
}
for (int oe = 0; oe < dtable.getOutput().size(); oe++) {
final LiteralExpression le = new LiteralExpression();
le.getText().setValue(DecisionTableDefaultValueUtilities.OUTPUT_CLAUSE_EXPRESSION_TEXT);
rule.getOutputEntry().add(le);
le.setParent(rule);
}
for (int index = 0; index < dtable.getAnnotations().size(); index++) {
final RuleAnnotationClauseText ruleAnnotationClauseText = new RuleAnnotationClauseText();
ruleAnnotationClauseText.getText().setValue(DecisionTableDefaultValueUtilities.RULE_ANNOTATION_CLAUSE_EXPRESSION_TEXT);
rule.getAnnotationEntry().add(ruleAnnotationClauseText);
ruleAnnotationClauseText.setParent(rule);
}
rule.setParent(dtable);
return rule;
}
use of org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText 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));
}
};
}
Aggregations