Search in sources :

Example 1 with OutputClause

use of org.kie.workbench.common.dmn.api.definition.model.OutputClause 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;
}
Also used : Description(org.kie.workbench.common.dmn.api.property.dmn.Description) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) 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) DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) InputClause(org.kie.workbench.common.dmn.api.definition.model.InputClause)

Example 2 with OutputClause

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

the class DeleteOutputClauseCommandTest method setup.

@Before
public void setup() {
    this.dtable = new DecisionTable();
    this.outputClause = new OutputClause();
    this.dtable.getOutput().add(outputClause);
    this.uiModel = new DMNGridData();
    this.uiModel.appendColumn(uiRowNumberColumn);
    this.uiModel.appendColumn(uiOutputClauseColumn);
    this.uiModel.appendColumn(uiRuleAnnotationClauseColumn);
    this.uiModelMapper = new DecisionTableUIModelMapper(() -> uiModel, () -> Optional.of(dtable), listSelector, DEFAULT_HEIGHT);
    makeCommand(DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT + dtable.getInput().size());
    doReturn(0).when(uiRowNumberColumn).getIndex();
    doReturn(1).when(uiOutputClauseColumn).getIndex();
    doReturn(2).when(uiRuleAnnotationClauseColumn).getIndex();
}
Also used : OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) DecisionTableUIModelMapper(org.kie.workbench.common.dmn.client.editors.expressions.types.dtable.DecisionTableUIModelMapper) DMNGridData(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData) Before(org.junit.Before)

Example 3 with OutputClause

use of org.kie.workbench.common.dmn.api.definition.model.OutputClause 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)

Example 4 with OutputClause

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

the class DecisionTablePropertyConverterTest method testDMNFromWBMultipleOutputClauseTypeRef.

@Test
public void testDMNFromWBMultipleOutputClauseTypeRef() {
    final DecisionTable wb = new DecisionTable();
    final OutputClause wbOutputClause1 = new OutputClause();
    final OutputClause wbOutputClause2 = new OutputClause();
    wb.getId().setValue(UUID);
    wb.getDescription().setValue(DESCRIPTION);
    wb.setTypeRef(new org.kie.workbench.common.dmn.api.property.dmn.QName(NULL_NS_URI, QNAME_LOCALPART));
    wbOutputClause1.setName(NAME + "-oc1");
    wbOutputClause2.setName(NAME + "-oc2");
    wbOutputClause1.setTypeRef(new org.kie.workbench.common.dmn.api.property.dmn.QName(NULL_NS_URI, QNAME_LOCALPART + "-oc1"));
    wbOutputClause2.setTypeRef(new org.kie.workbench.common.dmn.api.property.dmn.QName(NULL_NS_URI, QNAME_LOCALPART + "-oc2"));
    wb.getOutput().add(wbOutputClause1);
    wb.getOutput().add(wbOutputClause2);
    final org.kie.dmn.model.api.DecisionTable dmn = DecisionTablePropertyConverter.dmnFromWB(wb);
    assertThat(dmn).isNotNull();
    assertThat(dmn.getId()).isNotNull();
    assertThat(dmn.getId()).isEqualTo(UUID);
    assertThat(dmn.getDescription()).isNotNull();
    assertThat(dmn.getDescription()).isEqualTo(DESCRIPTION);
    assertThat(dmn.getTypeRef()).isNotNull();
    assertThat(dmn.getTypeRef().getLocalPart()).isEqualTo(QNAME_LOCALPART);
    assertThat(dmn.getOutput()).hasSize(2);
    final org.kie.dmn.model.api.OutputClause dmnOutputClause1 = dmn.getOutput().get(0);
    final org.kie.dmn.model.api.OutputClause dmnOutputClause2 = dmn.getOutput().get(1);
    assertThat(dmnOutputClause1.getName()).isEqualTo(NAME + "-oc1");
    assertThat(dmnOutputClause2.getName()).isEqualTo(NAME + "-oc2");
    assertThat(dmnOutputClause1.getTypeRef().getLocalPart()).isEqualTo(QNAME_LOCALPART + "-oc1");
    assertThat(dmnOutputClause2.getTypeRef().getLocalPart()).isEqualTo(QNAME_LOCALPART + "-oc2");
}
Also used : TOutputClause(org.kie.dmn.model.v1_2.TOutputClause) OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) TDecisionTable(org.kie.dmn.model.v1_2.TDecisionTable) Test(org.junit.Test)

Example 5 with OutputClause

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

the class DecisionTableDefaultValueUtilitiesTest method testGetNewOutputClauseName.

@Test
public void testGetNewOutputClauseName() {
    final OutputClause outputClause1 = new OutputClause();
    dtable.getOutput().add(outputClause1);
    outputClause1.setName(DecisionTableDefaultValueUtilities.getNewOutputClauseName(dtable));
    assertThat(outputClause1.getName()).isEqualTo(DecisionTableDefaultValueUtilities.OUTPUT_CLAUSE_PREFIX + "1");
    final OutputClause outputClause2 = new OutputClause();
    dtable.getOutput().add(outputClause2);
    outputClause2.setName(DecisionTableDefaultValueUtilities.getNewOutputClauseName(dtable));
    assertThat(outputClause2.getName()).isEqualTo(DecisionTableDefaultValueUtilities.OUTPUT_CLAUSE_PREFIX + "2");
}
Also used : OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) Test(org.junit.Test)

Aggregations

OutputClause (org.kie.workbench.common.dmn.api.definition.model.OutputClause)40 Test (org.junit.Test)24 DecisionTable (org.kie.workbench.common.dmn.api.definition.model.DecisionTable)21 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)14 DecisionRule (org.kie.workbench.common.dmn.api.definition.model.DecisionRule)12 InputClause (org.kie.workbench.common.dmn.api.definition.model.InputClause)10 RuleAnnotationClause (org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause)9 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)8 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)8 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)7 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)7 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)7 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)6 Description (org.kie.workbench.common.dmn.api.property.dmn.Description)6 ContextEntry (org.kie.workbench.common.dmn.api.definition.model.ContextEntry)5 InformationItemPrimary (org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary)5 Before (org.junit.Before)4 TDecisionTable (org.kie.dmn.model.v1_2.TDecisionTable)4 TOutputClause (org.kie.dmn.model.v1_2.TOutputClause)4 HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)4