use of org.kie.workbench.common.dmn.api.definition.model.DecisionRule in project kie-wb-common by kiegroup.
the class DecisionRulePropertyConverter method wbFromDMN.
public static DecisionRule wbFromDMN(final org.kie.dmn.model.api.DecisionRule dmn) {
final Id id = new Id(dmn.getId());
final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
final DecisionRule result = new DecisionRule();
result.setId(id);
if (!(dmn instanceof org.kie.dmn.model.v1_1.TDecisionRule)) {
for (final org.kie.dmn.model.api.RuleAnnotation ruleAnnotation : dmn.getAnnotationEntry()) {
final RuleAnnotationClauseText annotationEntryConverted = RuleAnnotationClauseTextConverter.wbFromDMN(ruleAnnotation);
if (annotationEntryConverted != null) {
annotationEntryConverted.setParent(result);
}
result.getAnnotationEntry().add(annotationEntryConverted);
}
}
if (result.getAnnotationEntry().isEmpty()) {
// If it's empty, then there is none RuleAnnotation and the description was not converted yet to RuleAnnotation.
final RuleAnnotationClauseText annotationEntryText = new RuleAnnotationClauseText();
annotationEntryText.getText().setValue(description.getValue());
annotationEntryText.setParent(result);
result.getAnnotationEntry().add(annotationEntryText);
}
for (final org.kie.dmn.model.api.UnaryTests ie : dmn.getInputEntry()) {
final UnaryTests inputEntryConverted = UnaryTestsPropertyConverter.wbFromDMN(ie);
if (inputEntryConverted != null) {
inputEntryConverted.setParent(result);
}
result.getInputEntry().add(inputEntryConverted);
}
for (final org.kie.dmn.model.api.LiteralExpression oe : dmn.getOutputEntry()) {
final LiteralExpression outputEntryConverted = LiteralExpressionPropertyConverter.wbFromDMN(oe);
if (outputEntryConverted != null) {
outputEntryConverted.setParent(result);
}
result.getOutputEntry().add(outputEntryConverted);
}
return result;
}
use of org.kie.workbench.common.dmn.api.definition.model.DecisionRule in project kie-wb-common by kiegroup.
the class DecisionTablePropertyConverter method dmnFromWB.
public static org.kie.dmn.model.api.DecisionTable dmnFromWB(final DecisionTable wb) {
final org.kie.dmn.model.api.DecisionTable result = new org.kie.dmn.model.v1_2.TDecisionTable();
result.setId(wb.getId().getValue());
result.setDescription(DescriptionPropertyConverter.dmnFromWB(wb.getDescription()));
QNamePropertyConverter.setDMNfromWB(wb.getTypeRef(), result::setTypeRef);
for (final RuleAnnotationClause annotation : wb.getAnnotations()) {
final org.kie.dmn.model.api.RuleAnnotationClause converted = RuleAnnotationClauseConverter.dmnFromWB(annotation);
if (converted != null) {
converted.setParent(result);
}
result.getAnnotation().add(converted);
}
for (InputClause input : wb.getInput()) {
final org.kie.dmn.model.api.InputClause c = InputClausePropertyConverter.dmnFromWB(input);
if (c != null) {
c.setParent(result);
}
result.getInput().add(c);
}
for (OutputClause input : wb.getOutput()) {
final org.kie.dmn.model.api.OutputClause c = OutputClausePropertyConverter.dmnFromWB(input);
if (c != null) {
c.setParent(result);
}
result.getOutput().add(c);
}
if (result.getOutput().size() == 1) {
final org.kie.dmn.model.api.OutputClause outputClause = result.getOutput().get(0);
// DROOLS-3281
outputClause.setName(null);
// DROOLS-5178
outputClause.setTypeRef(null);
}
for (DecisionRule dr : wb.getRule()) {
final org.kie.dmn.model.api.DecisionRule c = DecisionRulePropertyConverter.dmnFromWB(dr);
if (c != null) {
c.setParent(result);
}
result.getRule().add(c);
}
if (wb.getHitPolicy() != null) {
result.setHitPolicy(org.kie.dmn.model.api.HitPolicy.fromValue(wb.getHitPolicy().value()));
}
if (wb.getAggregation() != null) {
result.setAggregation(org.kie.dmn.model.api.BuiltinAggregator.fromValue(wb.getAggregation().value()));
}
if (wb.getPreferredOrientation() != null) {
result.setPreferredOrientation(org.kie.dmn.model.api.DecisionTableOrientation.fromValue(wb.getPreferredOrientation().value()));
}
result.setOutputLabel(wb.getOutputLabel());
return result;
}
use of org.kie.workbench.common.dmn.api.definition.model.DecisionRule in project kie-wb-common by kiegroup.
the class CommandUtilsTest method setUp.
@Before
public void setUp() {
decisionRuleOne = new DecisionRule();
decisionRuleTwo = new DecisionRule();
decisionRuleThree = new DecisionRule();
decisionRuleOne.setId(new Id("1"));
decisionRuleTwo.setId(new Id("2"));
decisionRuleThree.setId(new Id("3"));
allRows.clear();
allRows.add(decisionRuleOne);
allRows.add(decisionRuleTwo);
allRows.add(decisionRuleThree);
rowsToMove.clear();
gridData = new DMNGridData();
gridWidget = new BaseGrid<Expression>(gridLayer, gridData, renderer, sessionManager, sessionCommandManager, canvasCommandFactory, refreshFormPropertiesEvent, domainObjectSelectionEvent, cellEditorControls, translationService) {
};
}
use of org.kie.workbench.common.dmn.api.definition.model.DecisionRule in project kie-wb-common by kiegroup.
the class DecisionTableGridTest method testDuplicateDecisionRule.
@Test
@SuppressWarnings("unchecked")
public void testDuplicateDecisionRule() {
setupGrid(makeHasNameForDecision(), 0);
final DecisionTable dtable = grid.getExpression().get().get();
assertThat(dtable.getRule().size()).isEqualTo(1);
final DecisionRule rule0 = dtable.getRule().get(0);
assertThat(rule0.getInputEntry().size()).isEqualTo(1);
assertThat(rule0.getOutputEntry().size()).isEqualTo(1);
rule0.getInputEntry().get(0).getText().setValue("input");
rule0.getOutputEntry().get(0).getText().setValue("output");
rule0.getDescription().setValue("description");
grid.duplicateDecisionRule(0);
verify(sessionCommandManager).execute(eq(canvasHandler), addDecisionRuleCommandCaptor.capture());
final AddDecisionRuleCommand addDecisionRuleCommand = addDecisionRuleCommandCaptor.getValue();
addDecisionRuleCommand.execute(canvasHandler);
assertThat(dtable.getRule().size()).isEqualTo(2);
final DecisionRule rule1 = dtable.getRule().get(1);
assertThat(rule1.getInputEntry().size()).isEqualTo(1);
assertThat(rule1.getOutputEntry().size()).isEqualTo(1);
assertThat(rule0.getInputEntry().get(0).getText().getValue()).isEqualTo("input");
assertThat(rule0.getOutputEntry().get(0).getText().getValue()).isEqualTo("output");
assertThat(rule0.getDescription().getValue()).isEqualTo("description");
assertThat(rule1.getInputEntry().get(0).getText().getValue()).isEqualTo("input");
assertThat(rule1.getOutputEntry().get(0).getText().getValue()).isEqualTo("output");
assertThat(rule1.getDescription().getValue()).isEqualTo("description");
verifyCommandExecuteOperation(BaseExpressionGrid.RESIZE_EXISTING);
}
use of org.kie.workbench.common.dmn.api.definition.model.DecisionRule in project kie-wb-common by kiegroup.
the class AddInputClauseCommandTest method testGraphCommandExecute.
@Test
public void testGraphCommandExecute() throws Exception {
makeCommand(DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT);
dtable.getRule().add(new DecisionRule());
dtable.getRule().add(new DecisionRule());
assertEquals(0, dtable.getInput().size());
final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
assertEquals(GraphCommandResultBuilder.SUCCESS, graphCommand.execute(graphCommandExecutionContext));
// one new input column
assertEquals(1, dtable.getInput().size());
assertEquals(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_PREFIX + "1", dtable.getInput().get(0).getInputExpression().getText().getValue());
// first rule
final List<UnaryTests> inputEntriesRuleOne = dtable.getRule().get(0).getInputEntry();
assertEquals(1, inputEntriesRuleOne.size());
assertEquals(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_UNARY_TEST_TEXT, inputEntriesRuleOne.get(0).getText().getValue());
assertEquals(dtable.getRule().get(0), inputEntriesRuleOne.get(0).getParent());
// second rule
final List<UnaryTests> inputEntriesRuleTwo = dtable.getRule().get(1).getInputEntry();
assertEquals(1, inputEntriesRuleTwo.size());
assertEquals(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_UNARY_TEST_TEXT, inputEntriesRuleTwo.get(0).getText().getValue());
assertEquals(dtable.getRule().get(1), inputEntriesRuleTwo.get(0).getParent());
assertEquals(dtable, inputClause.getParent());
}
Aggregations