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