Search in sources :

Example 6 with DecisionRule

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 JSITDecisionTable dmn) {
    final Id id = IdPropertyConverter.wbFromDMN(dmn.getId());
    final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
    final QName typeRef = QNamePropertyConverter.wbFromDMN(dmn.getTypeRef());
    final DecisionTable result = new DecisionTable();
    result.setId(id);
    result.setDescription(description);
    result.setTypeRef(typeRef);
    final List<JSITRuleAnnotationClause> jsiRuleAnnotationClauses = dmn.getAnnotation();
    if (jsiRuleAnnotationClauses.isEmpty()) {
        final RuleAnnotationClause ruleAnnotationClause = new RuleAnnotationClause();
        ruleAnnotationClause.setParent(result);
        result.getAnnotations().add(ruleAnnotationClause);
    } else {
        for (int i = 0; i < jsiRuleAnnotationClauses.size(); i++) {
            final JSITRuleAnnotationClause ruleAnnotationClause = Js.uncheckedCast(jsiRuleAnnotationClauses.get(i));
            final RuleAnnotationClause converted = RuleAnnotationClausePropertyConverter.wbFromDMN(ruleAnnotationClause);
            if (Objects.nonNull(converted)) {
                converted.setParent(result);
                result.getAnnotations().add(converted);
            }
        }
    }
    final List<JSITInputClause> jsiInputClauses = dmn.getInput();
    for (int i = 0; i < jsiInputClauses.size(); i++) {
        final JSITInputClause input = Js.uncheckedCast(jsiInputClauses.get(i));
        final InputClause inputClauseConverted = InputClausePropertyConverter.wbFromDMN(input);
        if (Objects.nonNull(inputClauseConverted)) {
            inputClauseConverted.setParent(result);
            result.getInput().add(inputClauseConverted);
        }
    }
    final List<JSITOutputClause> jsiOutputClauses = dmn.getOutput();
    for (int i = 0; i < jsiOutputClauses.size(); i++) {
        final JSITOutputClause output = Js.uncheckedCast(jsiOutputClauses.get(i));
        final OutputClause outputClauseConverted = OutputClausePropertyConverter.wbFromDMN(output);
        if (Objects.nonNull(outputClauseConverted)) {
            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(BuiltInType.UNDEFINED.asQName());
    }
    final List<JSITDecisionRule> jsiDecisionRules = dmn.getRule();
    for (int i = 0; i < jsiDecisionRules.size(); i++) {
        final JSITDecisionRule dr = Js.uncheckedCast(jsiDecisionRules.get(i));
        final DecisionRule decisionRuleConverted = DecisionRulePropertyConverter.wbFromDMN(dr);
        if (Objects.nonNull(decisionRuleConverted)) {
            decisionRuleConverted.setParent(result);
        }
        result.getRule().add(decisionRuleConverted);
    }
    // JSITHitPolicy is a String JSO so convert into the real type
    final String hitPolicy = Js.uncheckedCast(dmn.getHitPolicy());
    if (Objects.nonNull(hitPolicy)) {
        result.setHitPolicy(HitPolicy.fromValue(hitPolicy));
    }
    // JSITBuiltinAggregator is a String JSO so convert into the real type
    final String aggregation = Js.uncheckedCast(dmn.getAggregation());
    if (Objects.nonNull(aggregation)) {
        result.setAggregation(BuiltinAggregator.fromValue(aggregation));
    }
    // JSITDecisionTableOrientation is a String JSO so convert into the real type
    final String orientation = Js.uncheckedCast(dmn.getPreferredOrientation());
    if (Objects.nonNull(orientation)) {
        result.setPreferredOrientation(DecisionTableOrientation.fromValue(orientation));
    }
    result.setOutputLabel(dmn.getOutputLabel());
    return result;
}
Also used : Description(org.kie.workbench.common.dmn.api.property.dmn.Description) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) JSITInputClause(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInputClause) JSITRuleAnnotationClause(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITRuleAnnotationClause) RuleAnnotationClause(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause) JSITDecisionRule(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionRule) JSITOutputClause(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITOutputClause) JSITDecisionRule(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionRule) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) JSITOutputClause(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITOutputClause) JSITDecisionTable(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionTable) DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) JSITRuleAnnotationClause(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITRuleAnnotationClause) JSITInputClause(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInputClause) InputClause(org.kie.workbench.common.dmn.api.definition.model.InputClause)

Example 7 with DecisionRule

use of org.kie.workbench.common.dmn.api.definition.model.DecisionRule in project kie-wb-common by kiegroup.

the class AddOutputClauseCommandTest 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.getOutput().size());
    final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
    assertEquals(GraphCommandResultBuilder.SUCCESS, graphCommand.execute(graphCommandExecutionContext));
    // one new output column
    assertEquals(1, dtable.getOutput().size());
    assertEquals(DecisionTableDefaultValueUtilities.OUTPUT_CLAUSE_PREFIX + "1", dtable.getOutput().get(0).getName());
    // first rule
    final List<LiteralExpression> outputEntriesRuleOne = dtable.getRule().get(0).getOutputEntry();
    assertEquals(1, outputEntriesRuleOne.size());
    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(1, outputEntriesRuleTwo.size());
    assertEquals(DecisionTableDefaultValueUtilities.OUTPUT_CLAUSE_EXPRESSION_TEXT, outputEntriesRuleTwo.get(0).getText().getValue());
    assertEquals(dtable.getRule().get(1), outputEntriesRuleTwo.get(0).getParent());
    assertEquals(dtable, outputClause.getParent());
}
Also used : LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) Test(org.junit.Test)

Example 8 with DecisionRule

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

Example 9 with DecisionRule

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);
}
Also used : DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) BaseGridRow(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow) 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 10 with DecisionRule

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