use of org.kie.workbench.common.dmn.api.definition.model.OutputClause in project kie-wb-common by kiegroup.
the class DecisionTablePropertyConverter method dmnFromWB.
public static JSITDecisionTable dmnFromWB(final DecisionTable wb) {
final JSITDecisionTable result = new JSITDecisionTable();
result.setId(wb.getId().getValue());
final Optional<String> description = Optional.ofNullable(DescriptionPropertyConverter.dmnFromWB(wb.getDescription()));
description.ifPresent(result::setDescription);
QNamePropertyConverter.setDMNfromWB(wb.getTypeRef(), result::setTypeRef);
for (final RuleAnnotationClause annotation : wb.getAnnotations()) {
final JSITRuleAnnotationClause converted = RuleAnnotationClausePropertyConverter.dmnFromWB(annotation);
result.addAnnotation(converted);
}
for (InputClause input : wb.getInput()) {
final JSITInputClause c = InputClausePropertyConverter.dmnFromWB(input);
result.addInput(c);
}
for (OutputClause input : wb.getOutput()) {
final JSITOutputClause c = OutputClausePropertyConverter.dmnFromWB(input);
result.addOutput(c);
}
if (result.getOutput().size() == 1) {
final JSITOutputClause at = Js.uncheckedCast(result.getOutput().get(0));
// DROOLS-3281
at.setName(null);
// DROOLS-5178
at.setTypeRef(null);
}
for (DecisionRule dr : wb.getRule()) {
final JSITDecisionRule c = DecisionRulePropertyConverter.dmnFromWB(dr);
result.addRule(c);
}
if (Objects.nonNull(wb.getHitPolicy())) {
switch(wb.getHitPolicy()) {
case ANY:
result.setHitPolicy(Js.uncheckedCast(JSITHitPolicy.ANY.value()));
break;
case COLLECT:
result.setHitPolicy(Js.uncheckedCast(JSITHitPolicy.COLLECT.value()));
break;
case FIRST:
result.setHitPolicy(Js.uncheckedCast(JSITHitPolicy.FIRST.value()));
break;
case UNIQUE:
result.setHitPolicy(Js.uncheckedCast(JSITHitPolicy.UNIQUE.value()));
break;
case PRIORITY:
result.setHitPolicy(Js.uncheckedCast(JSITHitPolicy.PRIORITY.value()));
break;
case RULE_ORDER:
result.setHitPolicy(Js.uncheckedCast(JSITHitPolicy.RULE_ORDER.value()));
break;
case OUTPUT_ORDER:
result.setHitPolicy(Js.uncheckedCast(JSITHitPolicy.OUTPUT_ORDER.value()));
break;
}
}
if (Objects.nonNull(wb.getAggregation())) {
final String wbBuiltinAggregator = wb.getAggregation().value();
result.setAggregation(Js.uncheckedCast(wbBuiltinAggregator));
}
if (Objects.nonNull(wb.getPreferredOrientation())) {
final String wbPreferredOrientation = wb.getPreferredOrientation().value();
result.setPreferredOrientation(Js.uncheckedCast(wbPreferredOrientation));
}
result.setOutputLabel(wb.getOutputLabel());
return result;
}
use of org.kie.workbench.common.dmn.api.definition.model.OutputClause in project kie-wb-common by kiegroup.
the class DecisionTableGridTest method testOutputClauseHasNameWrapperForHeaderMetaData.
@Test
@SuppressWarnings("unchecked")
public void testOutputClauseHasNameWrapperForHeaderMetaData() {
setupGrid(makeHasNameForDecision(), 0);
// More than one OutputClause column is required before the tested wrapper is instantiated.
addOutputClause(3);
final DecisionTable dtable = expression.get();
final OutputClause outputClause = dtable.getOutput().get(0);
final GridColumn.HeaderMetaData outputClauseHeaderMetaData = grid.getModel().getColumns().get(2).getHeaderMetaData().get(1);
assertThat(outputClause.getName()).isEqualTo(outputClauseHeaderMetaData.getTitle());
reset(sessionCommandManager);
extractHeaderMetaData(1, 2).setValue(new Name(NAME_NEW));
verify(sessionCommandManager).execute(eq(canvasHandler), compositeCommandCaptor.capture());
((AbstractCanvasGraphCommand) compositeCommandCaptor.getValue().getCommands().get(0)).execute(canvasHandler);
assertThat(outputClause.getName()).isEqualTo(NAME_NEW);
}
use of org.kie.workbench.common.dmn.api.definition.model.OutputClause in project kie-wb-common by kiegroup.
the class BaseDecisionTableEditorDefinitionTest method assertParentHierarchyEnrichment.
protected void assertParentHierarchyEnrichment(final DecisionTable model) {
final List<DecisionRule> rules = model.getRule();
final DecisionRule rule = rules.get(0);
final int inputClauseCount = model.getInput().size();
final List<InputClause> inputClauses = model.getInput();
assertThat(inputClauses.size()).isEqualTo(inputClauseCount);
inputClauses.forEach(inputClause -> {
assertThat(inputClause.getParent()).isEqualTo(model);
assertThat(inputClause.getInputExpression().getParent()).isEqualTo(inputClause);
});
final int outputClauseCount = model.getOutput().size();
final List<OutputClause> outputClauses = model.getOutput();
assertThat(outputClauses.size()).isEqualTo(outputClauseCount);
outputClauses.forEach(outputClause -> assertThat(outputClause.getParent()).isEqualTo(model));
assertThat(rule.getParent()).isEqualTo(model);
final List<UnaryTests> inputEntries = rule.getInputEntry();
assertThat(inputEntries.size()).isEqualTo(inputClauseCount);
inputEntries.forEach(inputEntry -> assertThat(inputEntry.getParent()).isEqualTo(rule));
final List<LiteralExpression> outputEntries = rule.getOutputEntry();
assertThat(outputEntries.size()).isEqualTo(outputClauseCount);
outputEntries.forEach(outputEntry -> assertThat(outputEntry.getParent()).isEqualTo(rule));
}
use of org.kie.workbench.common.dmn.api.definition.model.OutputClause in project kie-wb-common by kiegroup.
the class AddOutputClauseCommandTest method testGraphCommandExecuteExistingNotAffected.
@Test
public void testGraphCommandExecuteExistingNotAffected() throws Exception {
makeCommand(DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT);
final String ruleOneOldOutput = "old rule 1";
final String ruleTwoOldOutput = "old rule 2";
dtable.getOutput().add(new OutputClause());
addRuleWithOutputClauseValues(ruleOneOldOutput);
addRuleWithOutputClauseValues(ruleTwoOldOutput);
assertEquals(1, dtable.getOutput().size());
// Graph command will insert new OutputClause at index 0 of the OutputEntries
final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
assertEquals(GraphCommandResultBuilder.SUCCESS, graphCommand.execute(graphCommandExecutionContext));
assertEquals(2, dtable.getOutput().size());
assertEquals(DecisionTableDefaultValueUtilities.OUTPUT_CLAUSE_PREFIX + "1", dtable.getOutput().get(0).getName());
assertNull(dtable.getOutput().get(1).getName());
// first rule
final List<LiteralExpression> outputEntriesRuleOne = dtable.getRule().get(0).getOutputEntry();
assertEquals(2, outputEntriesRuleOne.size());
assertEquals(ruleOneOldOutput, outputEntriesRuleOne.get(1).getText().getValue());
assertEquals(DecisionTableDefaultValueUtilities.OUTPUT_CLAUSE_EXPRESSION_TEXT, outputEntriesRuleOne.get(0).getText().getValue());
assertEquals(dtable.getRule().get(0), outputEntriesRuleOne.get(0).getParent());
// second rule
final List<LiteralExpression> outputEntriesRuleTwo = dtable.getRule().get(1).getOutputEntry();
assertEquals(2, outputEntriesRuleTwo.size());
assertEquals(ruleTwoOldOutput, outputEntriesRuleTwo.get(1).getText().getValue());
assertEquals(DecisionTableDefaultValueUtilities.OUTPUT_CLAUSE_EXPRESSION_TEXT, outputEntriesRuleTwo.get(0).getText().getValue());
assertEquals(dtable.getRule().get(1), outputEntriesRuleTwo.get(0).getParent());
assertEquals(dtable, outputClause.getParent());
}
use of org.kie.workbench.common.dmn.api.definition.model.OutputClause in project kie-wb-common by kiegroup.
the class AddOutputClauseCommandTest method testGraphCommandUndoJustLastOutputClauseColumn.
@Test
public void testGraphCommandUndoJustLastOutputClauseColumn() throws Exception {
makeCommand(DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT);
final String ruleOneOldOutput = "old rule 1";
final String ruleTwoOldOutput = "old rule 2";
dtable.getOutput().add(new OutputClause());
addRuleWithOutputClauseValues(ruleOneOldOutput);
addRuleWithOutputClauseValues(ruleTwoOldOutput);
assertEquals(1, dtable.getOutput().size());
final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
assertEquals(GraphCommandResultBuilder.SUCCESS, graphCommand.execute(graphCommandExecutionContext));
assertEquals(GraphCommandResultBuilder.SUCCESS, graphCommand.undo(graphCommandExecutionContext));
assertEquals(1, dtable.getOutput().size());
// first rule
assertEquals(1, dtable.getRule().get(0).getOutputEntry().size());
assertEquals(ruleOneOldOutput, dtable.getRule().get(0).getOutputEntry().get(0).getText().getValue());
// second rule
assertEquals(1, dtable.getRule().get(1).getOutputEntry().size());
assertEquals(ruleTwoOldOutput, dtable.getRule().get(1).getOutputEntry().get(0).getText().getValue());
}
Aggregations