use of org.kie.workbench.common.dmn.api.definition.model.DecisionRule in project kie-wb-common by kiegroup.
the class DecisionTablePropertyConverter method wbFromDMN.
public static DecisionTable wbFromDMN(final org.kie.dmn.model.api.DecisionTable dmn) {
final Id id = new Id(dmn.getId());
final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
final QName typeRef = QNamePropertyConverter.wbFromDMN(dmn.getTypeRef(), dmn);
final DecisionTable result = new DecisionTable();
result.setId(id);
result.setDescription(description);
result.setTypeRef(typeRef);
if (!(dmn instanceof org.kie.dmn.model.v1_1.TDecisionTable)) {
if (dmn.getAnnotation().isEmpty()) {
final RuleAnnotationClause ruleAnnotationClause = new RuleAnnotationClause();
ruleAnnotationClause.setParent(result);
result.getAnnotations().add(ruleAnnotationClause);
} else {
for (final org.kie.dmn.model.api.RuleAnnotationClause ruleAnnotationClause : dmn.getAnnotation()) {
final RuleAnnotationClause converted = RuleAnnotationClauseConverter.wbFromDMN(ruleAnnotationClause);
if (converted != null) {
converted.setParent(result);
}
result.getAnnotations().add(converted);
}
}
}
for (org.kie.dmn.model.api.InputClause input : dmn.getInput()) {
final InputClause inputClauseConverted = InputClausePropertyConverter.wbFromDMN(input);
if (inputClauseConverted != null) {
inputClauseConverted.setParent(result);
}
result.getInput().add(inputClauseConverted);
}
for (org.kie.dmn.model.api.OutputClause output : dmn.getOutput()) {
final OutputClause outputClauseConverted = OutputClausePropertyConverter.wbFromDMN(output);
if (outputClauseConverted != null) {
outputClauseConverted.setParent(result);
}
result.getOutput().add(outputClauseConverted);
}
if (result.getOutput().size() == 1) {
final OutputClause outputClause = result.getOutput().get(0);
// DROOLS-3281
outputClause.setName(null);
// DROOLS-5178
outputClause.setTypeRef(null);
}
for (org.kie.dmn.model.api.DecisionRule dr : dmn.getRule()) {
final DecisionRule decisionRuleConverted = DecisionRulePropertyConverter.wbFromDMN(dr);
if (decisionRuleConverted != null) {
decisionRuleConverted.setParent(result);
}
result.getRule().add(decisionRuleConverted);
}
if (dmn.getHitPolicy() != null) {
result.setHitPolicy(HitPolicy.fromValue(dmn.getHitPolicy().value()));
}
if (dmn.getAggregation() != null) {
result.setAggregation(BuiltinAggregator.fromValue(dmn.getAggregation().value()));
}
if (dmn.getPreferredOrientation() != null) {
result.setPreferredOrientation(DecisionTableOrientation.fromValue(dmn.getPreferredOrientation().value()));
}
result.setOutputLabel(dmn.getOutputLabel());
return result;
}
use of org.kie.workbench.common.dmn.api.definition.model.DecisionRule in project kie-wb-common by kiegroup.
the class DeleteDecisionRuleCommandTest method testGraphCommandExecuteRemoveFromMiddle.
@Test
public void testGraphCommandExecuteRemoveFromMiddle() throws Exception {
final DecisionRule firstRule = mock(DecisionRule.class);
final DecisionRule lastRule = mock(DecisionRule.class);
dtable.getRule().add(0, firstRule);
dtable.getRule().add(lastRule);
uiModel.appendRow(new BaseGridRow());
uiModel.appendRow(new BaseGridRow());
makeCommand(1);
assertEquals(3, dtable.getRule().size());
final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
assertEquals(GraphCommandResultBuilder.SUCCESS, graphCommand.execute(graphCommandExecutionContext));
assertEquals(2, dtable.getRule().size());
assertEquals(firstRule, dtable.getRule().get(0));
assertEquals(lastRule, dtable.getRule().get(1));
}
use of org.kie.workbench.common.dmn.api.definition.model.DecisionRule in project kie-wb-common by kiegroup.
the class DeleteDecisionRuleCommandTest method setup.
@Before
public void setup() {
this.dtable = new DecisionTable();
this.rule = new DecisionRule();
this.dtable.getRule().add(rule);
this.uiModel = new DMNGridData();
this.uiModelRow = new BaseGridRow();
this.uiModel.appendRow(uiModelRow);
}
use of org.kie.workbench.common.dmn.api.definition.model.DecisionRule in project kie-wb-common by kiegroup.
the class DeleteOutputClauseCommandTest method testGraphCommandExecuteRemoveMiddle.
@Test
public void testGraphCommandExecuteRemoveMiddle() {
final OutputClause firstOutput = mock(OutputClause.class);
final OutputClause lastOutput = mock(OutputClause.class);
dtable.getOutput().add(0, firstOutput);
dtable.getOutput().add(lastOutput);
final LiteralExpression outputOneValue = mock(LiteralExpression.class);
final LiteralExpression outputTwoValue = mock(LiteralExpression.class);
final LiteralExpression outputThreeValue = mock(LiteralExpression.class);
final DecisionRule rule = new DecisionRule();
rule.getOutputEntry().add(outputOneValue);
rule.getOutputEntry().add(outputTwoValue);
rule.getOutputEntry().add(outputThreeValue);
dtable.getRule().add(rule);
makeCommand(DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT + dtable.getInput().size() + 1);
final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
assertEquals(GraphCommandResultBuilder.SUCCESS, graphCommand.execute(graphCommandExecutionContext));
assertEquals(2, dtable.getOutput().size());
assertEquals(firstOutput, dtable.getOutput().get(0));
assertEquals(lastOutput, dtable.getOutput().get(1));
assertEquals(2, dtable.getRule().get(0).getOutputEntry().size());
assertEquals(outputOneValue, dtable.getRule().get(0).getOutputEntry().get(0));
assertEquals(outputThreeValue, dtable.getRule().get(0).getOutputEntry().get(1));
}
use of org.kie.workbench.common.dmn.api.definition.model.DecisionRule 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();
}
Aggregations