Search in sources :

Example 16 with InputClause

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

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

the class InputClausePropertyConverter method wbFromDMN.

public static InputClause wbFromDMN(final JSITInputClause dmn) {
    final Id id = IdPropertyConverter.wbFromDMN(dmn.getId());
    final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
    final InputClauseLiteralExpression inputExpression = InputClauseLiteralExpressionPropertyConverter.wbFromDMN(dmn.getInputExpression());
    final InputClauseUnaryTests inputValues = Optional.ofNullable(InputClauseUnaryTestsPropertyConverter.wbFromDMN(dmn.getInputValues())).orElse(new InputClauseUnaryTests());
    final InputClause result = new InputClause(id, description, inputExpression, inputValues);
    if (Objects.nonNull(inputExpression)) {
        inputExpression.setParent(result);
    }
    inputValues.setParent(result);
    return result;
}
Also used : Description(org.kie.workbench.common.dmn.api.property.dmn.Description) InputClauseLiteralExpression(org.kie.workbench.common.dmn.api.definition.model.InputClauseLiteralExpression) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) InputClauseUnaryTests(org.kie.workbench.common.dmn.api.definition.model.InputClauseUnaryTests) JSITInputClause(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInputClause) InputClause(org.kie.workbench.common.dmn.api.definition.model.InputClause)

Example 18 with InputClause

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

the class AddInputClauseCommandTest method testGraphCommandExecuteInsertMiddle.

@Test
public void testGraphCommandExecuteInsertMiddle() throws Exception {
    makeCommand(DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT + 1);
    final String ruleInputOne = "rule in 1";
    final String ruleInputTwo = "rule in 2";
    dtable.getInput().add(new InputClause());
    dtable.getInput().add(new InputClause());
    addRuleWithInputClauseValues(ruleInputOne, ruleInputTwo);
    assertEquals(2, dtable.getInput().size());
    // Graph command will insert new InputClause at index 1 of the InputEntries
    final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
    assertEquals(GraphCommandResultBuilder.SUCCESS, graphCommand.execute(graphCommandExecutionContext));
    assertEquals(3, dtable.getInput().size());
    assertNotNull(dtable.getInput().get(0).getInputExpression());
    assertEquals(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_PREFIX + "1", dtable.getInput().get(1).getInputExpression().getText().getValue());
    assertNotNull(dtable.getInput().get(2).getInputExpression());
    final List<UnaryTests> ruleInputs = dtable.getRule().get(0).getInputEntry();
    // first rule
    assertEquals(3, ruleInputs.size());
    assertEquals(ruleInputOne, ruleInputs.get(0).getText().getValue());
    assertEquals(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_UNARY_TEST_TEXT, ruleInputs.get(1).getText().getValue());
    assertEquals(dtable.getRule().get(0), ruleInputs.get(1).getParent());
    assertEquals(ruleInputTwo, ruleInputs.get(2).getText().getValue());
    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) InputClause(org.kie.workbench.common.dmn.api.definition.model.InputClause) Test(org.junit.Test)

Example 19 with InputClause

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

the class AddInputClauseCommandTest method setUp.

@Before
public void setUp() throws Exception {
    this.dtable = new DecisionTable();
    this.uiModel = new DMNGridData();
    this.uiModel.appendColumn(uiRowNumberColumn);
    this.inputClause = new InputClause();
    this.uiModelMapper = new DecisionTableUIModelMapper(() -> uiModel, () -> Optional.of(dtable), listSelector, DEFAULT_HEIGHT);
    doReturn(0).when(uiRowNumberColumn).getIndex();
    doReturn(1).when(uiInputClauseColumn).getIndex();
}
Also used : 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) InputClause(org.kie.workbench.common.dmn.api.definition.model.InputClause) Before(org.junit.Before)

Example 20 with InputClause

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

the class DeleteInputClauseCommandTest method setup.

@Before
public void setup() {
    this.dtable = new DecisionTable();
    this.inputClause = new InputClause();
    this.dtable.getInput().add(inputClause);
    this.uiModel = new DMNGridData();
    this.uiModel.appendColumn(uiRowNumberColumn);
    this.uiModel.appendColumn(uiInputClauseColumn);
    this.uiModel.appendColumn(uiAnnotationClauseColumn);
    this.uiModelMapper = new DecisionTableUIModelMapper(() -> uiModel, () -> Optional.of(dtable), listSelector, DEFAULT_HEIGHT);
    makeCommand(DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT);
    doReturn(0).when(uiRowNumberColumn).getIndex();
    doReturn(1).when(uiInputClauseColumn).getIndex();
    doReturn(2).when(uiAnnotationClauseColumn).getIndex();
}
Also used : 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) InputClause(org.kie.workbench.common.dmn.api.definition.model.InputClause) Before(org.junit.Before)

Aggregations

InputClause (org.kie.workbench.common.dmn.api.definition.model.InputClause)33 Test (org.junit.Test)18 DecisionTable (org.kie.workbench.common.dmn.api.definition.model.DecisionTable)14 DecisionRule (org.kie.workbench.common.dmn.api.definition.model.DecisionRule)11 OutputClause (org.kie.workbench.common.dmn.api.definition.model.OutputClause)10 RuleAnnotationClause (org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause)10 InputClauseLiteralExpression (org.kie.workbench.common.dmn.api.definition.model.InputClauseLiteralExpression)8 UnaryTests (org.kie.workbench.common.dmn.api.definition.model.UnaryTests)8 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)8 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)8 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)7 Definitions (org.kie.workbench.common.dmn.api.definition.model.Definitions)5 ItemDefinition (org.kie.workbench.common.dmn.api.definition.model.ItemDefinition)5 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)5 Before (org.junit.Before)4 Description (org.kie.workbench.common.dmn.api.property.dmn.Description)4 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)4 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)3 RuleAnnotationClauseText (org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText)3 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)3