use of org.kie.workbench.common.dmn.api.definition.model.InputClauseLiteralExpression in project kie-wb-common by kiegroup.
the class DecisionTableDefaultValueUtilitiesTest method testGetNewInputClauseNameWithExistingInputClauses.
@Test
public void testGetNewInputClauseNameWithExistingInputClauses() {
final InputClause inputClause1 = new InputClause() {
{
setInputExpression(new InputClauseLiteralExpression());
}
};
dtable.getInput().add(inputClause1);
inputClause1.getInputExpression().getText().setValue("input");
final InputClause inputClause2 = new InputClause() {
{
setInputExpression(new InputClauseLiteralExpression());
}
};
dtable.getInput().add(inputClause2);
inputClause2.getInputExpression().getText().setValue(DecisionTableDefaultValueUtilities.getNewInputClauseName(dtable));
assertThat(inputClause2.getInputExpression().getText().getValue()).isEqualTo(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_PREFIX + "1");
}
use of org.kie.workbench.common.dmn.api.definition.model.InputClauseLiteralExpression in project kie-wb-common by kiegroup.
the class DecisionTableDefaultValueUtilitiesTest method testGetNewInputClauseName.
@Test
public void testGetNewInputClauseName() {
final InputClause inputClause1 = new InputClause() {
{
setInputExpression(new InputClauseLiteralExpression());
}
};
dtable.getInput().add(inputClause1);
inputClause1.getInputExpression().getText().setValue(DecisionTableDefaultValueUtilities.getNewInputClauseName(dtable));
assertThat(inputClause1.getInputExpression().getText().getValue()).isEqualTo(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_PREFIX + "1");
final InputClause inputClause2 = new InputClause() {
{
setInputExpression(new InputClauseLiteralExpression());
}
};
dtable.getInput().add(inputClause2);
inputClause2.getInputExpression().getText().setValue(DecisionTableDefaultValueUtilities.getNewInputClauseName(dtable));
assertThat(inputClause2.getInputExpression().getText().getValue()).isEqualTo(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_PREFIX + "2");
}
use of org.kie.workbench.common.dmn.api.definition.model.InputClauseLiteralExpression in project kie-wb-common by kiegroup.
the class InputClauseLiteralExpressionPropertyConverter method wbFromDMN.
public static InputClauseLiteralExpression wbFromDMN(final JSITLiteralExpression dmn) {
if (Objects.isNull(dmn)) {
return null;
}
final Id id = IdPropertyConverter.wbFromDMN(dmn.getId());
final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
final QName typeRef = QNamePropertyConverter.wbFromDMN(dmn.getTypeRef());
final Text text = new Text(dmn.getText());
final ImportedValues importedValues = ImportedValuesConverter.wbFromDMN(dmn.getImportedValues());
final InputClauseLiteralExpression result = new InputClauseLiteralExpression(id, description, typeRef, text, importedValues);
if (Objects.nonNull(importedValues)) {
importedValues.setParent(result);
}
return result;
}
use of org.kie.workbench.common.dmn.api.definition.model.InputClauseLiteralExpression 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) {
dtable.getComponentWidths().add(uiColumnIndex, null);
final int clauseIndex = uiColumnIndex - DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT;
dtable.getInput().add(clauseIndex, inputClause);
final InputClauseLiteralExpression le = new InputClauseLiteralExpression();
inputClause.setInputExpression(le);
le.getText().setValue(name);
dtable.getRule().forEach(rule -> {
final UnaryTests ut = new UnaryTests();
ut.getText().setValue(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_UNARY_TEST_TEXT);
rule.getInputEntry().add(clauseIndex, ut);
ut.setParent(rule);
});
inputClause.setParent(dtable);
return GraphCommandResultBuilder.SUCCESS;
}
@Override
public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context) {
dtable.getComponentWidths().remove(uiColumnIndex);
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.dmn.api.definition.model.InputClauseLiteralExpression in project kie-wb-common by kiegroup.
the class DecisionTableEditorDefinitionEnricher method enrichInputClauses.
@SuppressWarnings("unchecked")
void enrichInputClauses(final String uuid, final DecisionTable dtable) {
final Graph<?, Node> graph = sessionManager.getCurrentSession().getCanvasHandler().getDiagram().getGraph();
final Node<?, Edge> node = graph.getNode(uuid);
if (Objects.isNull(node)) {
return;
}
// Get all Decision nodes feeding into this DecisionTable
final List<Decision> decisionSet = node.getInEdges().stream().map(Edge::getSourceNode).map(Node::getContent).filter(content -> content instanceof Definition).map(content -> (Definition) content).map(Definition::getDefinition).filter(definition -> definition instanceof Decision).map(definition -> (Decision) definition).collect(Collectors.toList());
// Get all InputData nodes feeding into this DecisionTable
final List<InputData> inputDataSet = node.getInEdges().stream().map(Edge::getSourceNode).map(Node::getContent).filter(content -> content instanceof Definition).map(content -> (Definition) content).map(Definition::getDefinition).filter(definition -> definition instanceof InputData).map(definition -> (InputData) definition).collect(Collectors.toList());
if (decisionSet.isEmpty() && inputDataSet.isEmpty()) {
return;
}
// Extract individual components of InputData TypeRefs
final Definitions definitions = dmnGraphUtils.getModelDefinitions();
final List<ClauseRequirement> inputClauseRequirements = new ArrayList<>();
decisionSet.forEach(decision -> addInputClauseRequirement(decision.getVariable().getTypeRef(), definitions, inputClauseRequirements, decision.getName().getValue()));
inputDataSet.forEach(inputData -> addInputClauseRequirement(inputData.getVariable().getTypeRef(), definitions, inputClauseRequirements, inputData.getName().getValue()));
// Add InputClause columns for each InputData TypeRef component, sorted alphabetically
dtable.getInput().clear();
dtable.getRule().stream().forEach(decisionRule -> decisionRule.getInputEntry().clear());
inputClauseRequirements.stream().sorted(Comparator.comparing(inputClauseRequirement -> inputClauseRequirement.text)).forEach(inputClauseRequirement -> {
final InputClause inputClause = new InputClause();
final InputClauseLiteralExpression literalExpression = new InputClauseLiteralExpression();
literalExpression.getText().setValue(inputClauseRequirement.text);
literalExpression.setTypeRef(inputClauseRequirement.typeRef);
inputClause.setInputExpression(literalExpression);
dtable.getInput().add(inputClause);
dtable.getRule().stream().forEach(decisionRule -> {
final UnaryTests decisionRuleUnaryTest = new UnaryTests();
decisionRuleUnaryTest.getText().setValue(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_UNARY_TEST_TEXT);
decisionRule.getInputEntry().add(decisionRuleUnaryTest);
decisionRuleUnaryTest.setParent(decisionRule);
});
inputClause.setParent(dtable);
literalExpression.setParent(inputClause);
});
}
Aggregations