use of org.kie.workbench.common.dmn.api.definition.model.InputClause 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);
});
}
use of org.kie.workbench.common.dmn.api.definition.model.InputClause 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.InputClause in project kie-wb-common by kiegroup.
the class DecisionTableGrid method addInputClause.
void addInputClause(final int index) {
getExpression().get().ifPresent(dtable -> {
final InputClause clause = new InputClause();
final CommandResult<CanvasViolation> result = sessionCommandManager.execute((AbstractCanvasHandler) sessionManager.getCurrentSession().getCanvasHandler(), new AddInputClauseCommand(dtable, clause, model, () -> makeInputClauseColumn(index, clause), index, uiModelMapper, () -> resize(BaseExpressionGrid.RESIZE_EXISTING), () -> resize(BaseExpressionGrid.RESIZE_EXISTING_MINIMUM)));
if (!CommandUtils.isError(result)) {
selectHeaderCell(0, index, false, false);
CellContextUtilities.editSelectedCell(this);
}
});
}
use of org.kie.workbench.common.dmn.api.definition.model.InputClause in project kie-wb-common by kiegroup.
the class DecisionTableGrid method doAfterHeaderInputClauseSelectionChange.
protected void doAfterHeaderInputClauseSelectionChange(final DecisionTable dtable, final int uiHeaderColumnIndex) {
final int icIndex = DecisionTableUIModelMapperHelper.getInputEntryIndex(dtable, uiHeaderColumnIndex);
final InputClause inputClause = dtable.getInput().get(icIndex);
fireDomainObjectSelectionEvent(inputClause);
}
use of org.kie.workbench.common.dmn.api.definition.model.InputClause in project kie-wb-common by kiegroup.
the class InputClausePropertyConverter method wbFromDMN.
public static InputClause wbFromDMN(final org.kie.dmn.model.api.InputClause dmn) {
final Id id = new Id(dmn.getId());
final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
final InputClauseLiteralExpression inputExpression = InputClauseLiteralExpressionPropertyConverter.wbFromDMN(dmn.getInputExpression());
final InputClauseUnaryTests inputValues = InputClauseUnaryTestsPropertyConverter.wbFromDMN(dmn.getInputValues());
final InputClause result = new InputClause(id, description, inputExpression, inputValues);
if (inputExpression != null) {
inputExpression.setParent(result);
}
if (inputValues != null) {
inputValues.setParent(result);
}
return result;
}
Aggregations