Search in sources :

Example 11 with RuleAnnotationClause

use of org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause 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 12 with RuleAnnotationClause

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

the class DeleteRuleAnnotationClauseCommandTest method testNewGraphCommandUndo.

@Test
public void testNewGraphCommandUndo() {
    final int uiColumnIndex = 3;
    final int annotationClauseIndex = 2;
    final AbstractCanvasHandler handler = mock(AbstractCanvasHandler.class);
    final DeleteRuleAnnotationClauseCommand command = mock(DeleteRuleAnnotationClauseCommand.class);
    final DecisionRule rule1 = mock(DecisionRule.class);
    final DecisionRule rule2 = mock(DecisionRule.class);
    final List<DecisionRule> rules = Arrays.asList(rule1, rule2);
    final List rule1AnnotationEntries = mock(List.class);
    final List rule2AnnotationEntries = mock(List.class);
    final List annotations = mock(List.class);
    final List widths = mock(List.class);
    final GraphCommandExecutionContext context = mock(GraphCommandExecutionContext.class);
    final RuleAnnotationClause oldRuleClause = mock(RuleAnnotationClause.class);
    final GridColumn oldUiModelColumn = mock(GridColumn.class);
    final double oldUiModelColumnWidth = 123.4D;
    final RuleAnnotationClauseText deleted1 = mock(RuleAnnotationClauseText.class);
    final RuleAnnotationClauseText deleted2 = mock(RuleAnnotationClauseText.class);
    final List<RuleAnnotationClauseText> oldCommandData = Arrays.asList(deleted1, deleted2);
    doCallRealMethod().when(command).newGraphCommand(handler);
    when(command.getOldColumnData()).thenReturn(oldCommandData);
    when(command.getOldRuleClause()).thenReturn(oldRuleClause);
    when(oldUiModelColumn.getWidth()).thenReturn(oldUiModelColumnWidth);
    when(command.getOldUiModelColumn()).thenReturn(oldUiModelColumn);
    when(command.getDecisionTable()).thenReturn(decisionTable);
    when(command.getRuleAnnotationClauseIndex()).thenReturn(annotationClauseIndex);
    when(command.getUiColumnIndex()).thenReturn(uiColumnIndex);
    when(rule1.getAnnotationEntry()).thenReturn(rule1AnnotationEntries);
    when(rule2.getAnnotationEntry()).thenReturn(rule2AnnotationEntries);
    when(decisionTable.getRule()).thenReturn(rules);
    when(decisionTable.getAnnotations()).thenReturn(annotations);
    when(decisionTable.getComponentWidths()).thenReturn(widths);
    final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(handler);
    final CommandResult<RuleViolation> result = graphCommand.undo(context);
    assertEquals(GraphCommandResultBuilder.SUCCESS, result);
    verify(annotations).add(annotationClauseIndex, oldRuleClause);
    verify(rule1AnnotationEntries).add(annotationClauseIndex, deleted1);
    verify(rule2AnnotationEntries).add(annotationClauseIndex, deleted2);
}
Also used : RuleAnnotationClauseText(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) RuleAnnotationClause(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) List(java.util.List) GridColumn(org.uberfire.ext.wires.core.grids.client.model.GridColumn) Test(org.junit.Test)

Example 13 with RuleAnnotationClause

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

the class AddDecisionRuleCommandTest method testCanvasCommandExecuteInsertBelow.

@Test
public void testCanvasCommandExecuteInsertBelow() {
    // The default behaviour of tests in this class is to "insert above"
    final DecisionRule existingRule = new DecisionRule();
    final GridRow existingUiRow = new BaseGridRow();
    dtable.getRule().add(existingRule);
    uiModel.appendRow(existingUiRow);
    dtable.getInput().add(new InputClause());
    dtable.getOutput().add(new OutputClause());
    dtable.getAnnotations().add(new RuleAnnotationClause());
    makeCommand(1);
    uiModel.appendColumn(uiInputClauseColumn);
    uiModel.appendColumn(uiOutputClauseColumn);
    uiModel.appendColumn(uiRuleAnnotationClauseColumn);
    final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
    final Command<AbstractCanvasHandler, CanvasViolation> canvasCommand = command.newCanvasCommand(canvasHandler);
    graphCommand.execute(graphCommandExecutionContext);
    canvasCommand.execute(canvasHandler);
    assertEquals(2, uiModel.getRowCount());
    assertEquals(existingUiRow, uiModel.getRow(0));
    assertEquals(uiModelRow, uiModel.getRow(1));
    assertDefaultUiRowValues(1);
    verify(command).updateRowNumbers();
    verify(command).updateParentInformation();
}
Also used : OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) BaseGridRow(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) RuleAnnotationClause(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause) BaseGridRow(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow) GridRow(org.uberfire.ext.wires.core.grids.client.model.GridRow) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) InputClause(org.kie.workbench.common.dmn.api.definition.model.InputClause) Test(org.junit.Test)

Example 14 with RuleAnnotationClause

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

the class AddDecisionRuleCommandTest method testCanvasCommandAddRuleAndThenUndo.

@Test
public void testCanvasCommandAddRuleAndThenUndo() throws Exception {
    dtable.getInput().add(new InputClause());
    dtable.getOutput().add(new OutputClause());
    dtable.getAnnotations().add(new RuleAnnotationClause());
    makeCommand(0);
    final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
    graphCommand.execute(graphCommandExecutionContext);
    uiModel.appendColumn(uiInputClauseColumn);
    uiModel.appendColumn(uiOutputClauseColumn);
    uiModel.appendColumn(uiRuleAnnotationClauseColumn);
    final Command<AbstractCanvasHandler, CanvasViolation> canvasAddRuleCommand = command.newCanvasCommand(canvasHandler);
    canvasAddRuleCommand.execute(canvasHandler);
    assertEquals(1, uiModel.getRowCount());
    assertDefaultUiRowValues(0);
    canvasAddRuleCommand.undo(canvasHandler);
    assertEquals(0, uiModel.getRowCount());
    // one time in execute(), one time in undo()
    verify(canvasOperation, times(2)).execute();
    verify(command, times(2)).updateRowNumbers();
    verify(command, times(2)).updateParentInformation();
}
Also used : OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) RuleAnnotationClause(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause) InputClause(org.kie.workbench.common.dmn.api.definition.model.InputClause) Test(org.junit.Test)

Example 15 with RuleAnnotationClause

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

Aggregations

RuleAnnotationClause (org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause)18 DecisionRule (org.kie.workbench.common.dmn.api.definition.model.DecisionRule)9 InputClause (org.kie.workbench.common.dmn.api.definition.model.InputClause)9 Test (org.junit.Test)8 OutputClause (org.kie.workbench.common.dmn.api.definition.model.OutputClause)8 DecisionTable (org.kie.workbench.common.dmn.api.definition.model.DecisionTable)5 RuleAnnotationClauseText (org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText)4 JSITRuleAnnotationClause (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITRuleAnnotationClause)3 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)3 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)3 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)3 Before (org.junit.Before)2 UnaryTests (org.kie.workbench.common.dmn.api.definition.model.UnaryTests)2 Description (org.kie.workbench.common.dmn.api.property.dmn.Description)2 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)2 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)2 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)2 JSITDecisionRule (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionRule)2 JSITDecisionTable (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionTable)2 JSITInputClause (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInputClause)2