Search in sources :

Example 26 with DecisionRule

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;
}
Also used : Description(org.kie.workbench.common.dmn.api.property.dmn.Description) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) RuleAnnotationClauseText(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests)

Example 27 with DecisionRule

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;
}
Also used : RuleAnnotationClause(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) InputClause(org.kie.workbench.common.dmn.api.definition.model.InputClause)

Example 28 with DecisionRule

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) {
    };
}
Also used : Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) DMNGridData(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) Before(org.junit.Before)

Example 29 with DecisionRule

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);
}
Also used : DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) AddDecisionRuleCommand(org.kie.workbench.common.dmn.client.commands.expressions.types.dtable.AddDecisionRuleCommand) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) Test(org.junit.Test)

Example 30 with DecisionRule

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());
}
Also used : GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) Test(org.junit.Test)

Aggregations

DecisionRule (org.kie.workbench.common.dmn.api.definition.model.DecisionRule)51 Test (org.junit.Test)28 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)19 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)19 UnaryTests (org.kie.workbench.common.dmn.api.definition.model.UnaryTests)17 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)16 RuleAnnotationClauseText (org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText)16 DecisionTable (org.kie.workbench.common.dmn.api.definition.model.DecisionTable)14 OutputClause (org.kie.workbench.common.dmn.api.definition.model.OutputClause)14 InputClause (org.kie.workbench.common.dmn.api.definition.model.InputClause)13 RuleAnnotationClause (org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause)12 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)12 List (java.util.List)9 BaseGridRow (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow)9 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)7 CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)7 Before (org.junit.Before)5 HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)5 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)5 Definitions (org.kie.workbench.common.dmn.api.definition.model.Definitions)5