Search in sources :

Example 26 with OutputClause

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

the class DecisionTablePropertyConverter method dmnFromWB.

public static JSITDecisionTable dmnFromWB(final DecisionTable wb) {
    final JSITDecisionTable result = new JSITDecisionTable();
    result.setId(wb.getId().getValue());
    final Optional<String> description = Optional.ofNullable(DescriptionPropertyConverter.dmnFromWB(wb.getDescription()));
    description.ifPresent(result::setDescription);
    QNamePropertyConverter.setDMNfromWB(wb.getTypeRef(), result::setTypeRef);
    for (final RuleAnnotationClause annotation : wb.getAnnotations()) {
        final JSITRuleAnnotationClause converted = RuleAnnotationClausePropertyConverter.dmnFromWB(annotation);
        result.addAnnotation(converted);
    }
    for (InputClause input : wb.getInput()) {
        final JSITInputClause c = InputClausePropertyConverter.dmnFromWB(input);
        result.addInput(c);
    }
    for (OutputClause input : wb.getOutput()) {
        final JSITOutputClause c = OutputClausePropertyConverter.dmnFromWB(input);
        result.addOutput(c);
    }
    if (result.getOutput().size() == 1) {
        final JSITOutputClause at = Js.uncheckedCast(result.getOutput().get(0));
        // DROOLS-3281
        at.setName(null);
        // DROOLS-5178
        at.setTypeRef(null);
    }
    for (DecisionRule dr : wb.getRule()) {
        final JSITDecisionRule c = DecisionRulePropertyConverter.dmnFromWB(dr);
        result.addRule(c);
    }
    if (Objects.nonNull(wb.getHitPolicy())) {
        switch(wb.getHitPolicy()) {
            case ANY:
                result.setHitPolicy(Js.uncheckedCast(JSITHitPolicy.ANY.value()));
                break;
            case COLLECT:
                result.setHitPolicy(Js.uncheckedCast(JSITHitPolicy.COLLECT.value()));
                break;
            case FIRST:
                result.setHitPolicy(Js.uncheckedCast(JSITHitPolicy.FIRST.value()));
                break;
            case UNIQUE:
                result.setHitPolicy(Js.uncheckedCast(JSITHitPolicy.UNIQUE.value()));
                break;
            case PRIORITY:
                result.setHitPolicy(Js.uncheckedCast(JSITHitPolicy.PRIORITY.value()));
                break;
            case RULE_ORDER:
                result.setHitPolicy(Js.uncheckedCast(JSITHitPolicy.RULE_ORDER.value()));
                break;
            case OUTPUT_ORDER:
                result.setHitPolicy(Js.uncheckedCast(JSITHitPolicy.OUTPUT_ORDER.value()));
                break;
        }
    }
    if (Objects.nonNull(wb.getAggregation())) {
        final String wbBuiltinAggregator = wb.getAggregation().value();
        result.setAggregation(Js.uncheckedCast(wbBuiltinAggregator));
    }
    if (Objects.nonNull(wb.getPreferredOrientation())) {
        final String wbPreferredOrientation = wb.getPreferredOrientation().value();
        result.setPreferredOrientation(Js.uncheckedCast(wbPreferredOrientation));
    }
    result.setOutputLabel(wb.getOutputLabel());
    return result;
}
Also used : OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) JSITOutputClause(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITOutputClause) 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) JSITDecisionTable(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionTable) JSITOutputClause(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITOutputClause) 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) JSITDecisionRule(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionRule) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule)

Example 27 with OutputClause

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

the class DecisionTableGridTest method testOutputClauseHasNameWrapperForHeaderMetaData.

@Test
@SuppressWarnings("unchecked")
public void testOutputClauseHasNameWrapperForHeaderMetaData() {
    setupGrid(makeHasNameForDecision(), 0);
    // More than one OutputClause column is required before the tested wrapper is instantiated.
    addOutputClause(3);
    final DecisionTable dtable = expression.get();
    final OutputClause outputClause = dtable.getOutput().get(0);
    final GridColumn.HeaderMetaData outputClauseHeaderMetaData = grid.getModel().getColumns().get(2).getHeaderMetaData().get(1);
    assertThat(outputClause.getName()).isEqualTo(outputClauseHeaderMetaData.getTitle());
    reset(sessionCommandManager);
    extractHeaderMetaData(1, 2).setValue(new Name(NAME_NEW));
    verify(sessionCommandManager).execute(eq(canvasHandler), compositeCommandCaptor.capture());
    ((AbstractCanvasGraphCommand) compositeCommandCaptor.getValue().getCommands().get(0)).execute(canvasHandler);
    assertThat(outputClause.getName()).isEqualTo(NAME_NEW);
}
Also used : OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) AbstractCanvasGraphCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AbstractCanvasGraphCommand) GridColumn(org.uberfire.ext.wires.core.grids.client.model.GridColumn) DMNGridColumn(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridColumn) HasName(org.kie.workbench.common.dmn.api.definition.HasName) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Test(org.junit.Test)

Example 28 with OutputClause

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

the class BaseDecisionTableEditorDefinitionTest method assertParentHierarchyEnrichment.

protected void assertParentHierarchyEnrichment(final DecisionTable model) {
    final List<DecisionRule> rules = model.getRule();
    final DecisionRule rule = rules.get(0);
    final int inputClauseCount = model.getInput().size();
    final List<InputClause> inputClauses = model.getInput();
    assertThat(inputClauses.size()).isEqualTo(inputClauseCount);
    inputClauses.forEach(inputClause -> {
        assertThat(inputClause.getParent()).isEqualTo(model);
        assertThat(inputClause.getInputExpression().getParent()).isEqualTo(inputClause);
    });
    final int outputClauseCount = model.getOutput().size();
    final List<OutputClause> outputClauses = model.getOutput();
    assertThat(outputClauses.size()).isEqualTo(outputClauseCount);
    outputClauses.forEach(outputClause -> assertThat(outputClause.getParent()).isEqualTo(model));
    assertThat(rule.getParent()).isEqualTo(model);
    final List<UnaryTests> inputEntries = rule.getInputEntry();
    assertThat(inputEntries.size()).isEqualTo(inputClauseCount);
    inputEntries.forEach(inputEntry -> assertThat(inputEntry.getParent()).isEqualTo(rule));
    final List<LiteralExpression> outputEntries = rule.getOutputEntry();
    assertThat(outputEntries.size()).isEqualTo(outputClauseCount);
    outputEntries.forEach(outputEntry -> assertThat(outputEntry.getParent()).isEqualTo(rule));
}
Also used : OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) InputClauseLiteralExpression(org.kie.workbench.common.dmn.api.definition.model.InputClauseLiteralExpression) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) InputClause(org.kie.workbench.common.dmn.api.definition.model.InputClause)

Example 29 with OutputClause

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

the class AddOutputClauseCommandTest method testGraphCommandExecuteExistingNotAffected.

@Test
public void testGraphCommandExecuteExistingNotAffected() throws Exception {
    makeCommand(DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT);
    final String ruleOneOldOutput = "old rule 1";
    final String ruleTwoOldOutput = "old rule 2";
    dtable.getOutput().add(new OutputClause());
    addRuleWithOutputClauseValues(ruleOneOldOutput);
    addRuleWithOutputClauseValues(ruleTwoOldOutput);
    assertEquals(1, dtable.getOutput().size());
    // Graph command will insert new OutputClause at index 0 of the OutputEntries
    final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
    assertEquals(GraphCommandResultBuilder.SUCCESS, graphCommand.execute(graphCommandExecutionContext));
    assertEquals(2, dtable.getOutput().size());
    assertEquals(DecisionTableDefaultValueUtilities.OUTPUT_CLAUSE_PREFIX + "1", dtable.getOutput().get(0).getName());
    assertNull(dtable.getOutput().get(1).getName());
    // first rule
    final List<LiteralExpression> outputEntriesRuleOne = dtable.getRule().get(0).getOutputEntry();
    assertEquals(2, outputEntriesRuleOne.size());
    assertEquals(ruleOneOldOutput, outputEntriesRuleOne.get(1).getText().getValue());
    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(2, outputEntriesRuleTwo.size());
    assertEquals(ruleTwoOldOutput, outputEntriesRuleTwo.get(1).getText().getValue());
    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 : 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) Test(org.junit.Test)

Example 30 with OutputClause

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

the class AddOutputClauseCommandTest method testGraphCommandUndoJustLastOutputClauseColumn.

@Test
public void testGraphCommandUndoJustLastOutputClauseColumn() throws Exception {
    makeCommand(DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT);
    final String ruleOneOldOutput = "old rule 1";
    final String ruleTwoOldOutput = "old rule 2";
    dtable.getOutput().add(new OutputClause());
    addRuleWithOutputClauseValues(ruleOneOldOutput);
    addRuleWithOutputClauseValues(ruleTwoOldOutput);
    assertEquals(1, dtable.getOutput().size());
    final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
    assertEquals(GraphCommandResultBuilder.SUCCESS, graphCommand.execute(graphCommandExecutionContext));
    assertEquals(GraphCommandResultBuilder.SUCCESS, graphCommand.undo(graphCommandExecutionContext));
    assertEquals(1, dtable.getOutput().size());
    // first rule
    assertEquals(1, dtable.getRule().get(0).getOutputEntry().size());
    assertEquals(ruleOneOldOutput, dtable.getRule().get(0).getOutputEntry().get(0).getText().getValue());
    // second rule
    assertEquals(1, dtable.getRule().get(1).getOutputEntry().size());
    assertEquals(ruleTwoOldOutput, dtable.getRule().get(1).getOutputEntry().get(0).getText().getValue());
}
Also used : OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) 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