Search in sources :

Example 26 with UnaryTests

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

the class DecisionRulePropertyConverter method wbFromDMN.

public static DecisionRule wbFromDMN(final org.kie.dmn.model.api.DecisionRule dmn) {
    final Id id = new Id(dmn.getId());
    final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
    final DecisionRule result = new DecisionRule();
    result.setId(id);
    if (!(dmn instanceof org.kie.dmn.model.v1_1.TDecisionRule)) {
        for (final org.kie.dmn.model.api.RuleAnnotation ruleAnnotation : dmn.getAnnotationEntry()) {
            final RuleAnnotationClauseText annotationEntryConverted = RuleAnnotationClauseTextConverter.wbFromDMN(ruleAnnotation);
            if (annotationEntryConverted != null) {
                annotationEntryConverted.setParent(result);
            }
            result.getAnnotationEntry().add(annotationEntryConverted);
        }
    }
    if (result.getAnnotationEntry().isEmpty()) {
        // If it's empty, then there is none RuleAnnotation and the description was not converted yet to RuleAnnotation.
        final RuleAnnotationClauseText annotationEntryText = new RuleAnnotationClauseText();
        annotationEntryText.getText().setValue(description.getValue());
        annotationEntryText.setParent(result);
        result.getAnnotationEntry().add(annotationEntryText);
    }
    for (final org.kie.dmn.model.api.UnaryTests ie : dmn.getInputEntry()) {
        final UnaryTests inputEntryConverted = UnaryTestsPropertyConverter.wbFromDMN(ie);
        if (inputEntryConverted != null) {
            inputEntryConverted.setParent(result);
        }
        result.getInputEntry().add(inputEntryConverted);
    }
    for (final org.kie.dmn.model.api.LiteralExpression oe : dmn.getOutputEntry()) {
        final LiteralExpression outputEntryConverted = LiteralExpressionPropertyConverter.wbFromDMN(oe);
        if (outputEntryConverted != null) {
            outputEntryConverted.setParent(result);
        }
        result.getOutputEntry().add(outputEntryConverted);
    }
    return result;
}
Also used : Description(org.kie.workbench.common.dmn.api.property.dmn.Description) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) RuleAnnotationClauseText(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests)

Example 27 with UnaryTests

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

the class ItemDefinitionPropertyConverter method setUnaryTests.

static void setUnaryTests(final ItemDefinition wb, final JSITItemDefinition dmn) {
    final JSITUnaryTests dmnAllowedValues = dmn.getAllowedValues();
    final Optional<UnaryTests> wbUnaryTests = ofNullable(UnaryTestsPropertyConverter.wbFromDMN(dmnAllowedValues));
    wbUnaryTests.ifPresent(unaryTests -> {
        wb.setAllowedValues(unaryTests);
        unaryTests.setParent(wb);
    });
}
Also used : JSITUnaryTests(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITUnaryTests) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests) JSITUnaryTests(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITUnaryTests)

Example 28 with UnaryTests

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

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

the class AddInputClauseCommandTest 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.getInput().size());
    final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
    assertEquals(GraphCommandResultBuilder.SUCCESS, graphCommand.execute(graphCommandExecutionContext));
    // one new input column
    assertEquals(1, dtable.getInput().size());
    assertEquals(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_PREFIX + "1", dtable.getInput().get(0).getInputExpression().getText().getValue());
    // first rule
    final List<UnaryTests> inputEntriesRuleOne = dtable.getRule().get(0).getInputEntry();
    assertEquals(1, inputEntriesRuleOne.size());
    assertEquals(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_UNARY_TEST_TEXT, inputEntriesRuleOne.get(0).getText().getValue());
    assertEquals(dtable.getRule().get(0), inputEntriesRuleOne.get(0).getParent());
    // second rule
    final List<UnaryTests> inputEntriesRuleTwo = dtable.getRule().get(1).getInputEntry();
    assertEquals(1, inputEntriesRuleTwo.size());
    assertEquals(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_UNARY_TEST_TEXT, inputEntriesRuleTwo.get(0).getText().getValue());
    assertEquals(dtable.getRule().get(1), inputEntriesRuleTwo.get(0).getParent());
    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) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) Test(org.junit.Test)

Example 30 with UnaryTests

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

the class ItemDefinitionUpdateHandlerTest method testMakeAllowedValuesWhenDataTypeAndItemDefinitionConstraintAreEqual.

@Test
public void testMakeAllowedValuesWhenDataTypeAndItemDefinitionConstraintAreEqual() {
    final DataType dataType = mock(DataType.class);
    final ItemDefinition itemDefinition = mock(ItemDefinition.class);
    final UnaryTests expectedAllowedValues = mock(UnaryTests.class);
    final String expectedText = "(1..20)";
    final ConstraintType expectedConstraintType = ConstraintType.RANGE;
    when(itemDefinition.getAllowedValues()).thenReturn(expectedAllowedValues);
    when(expectedAllowedValues.getConstraintType()).thenReturn(expectedConstraintType);
    when(expectedAllowedValues.getText()).thenReturn(new Text(expectedText));
    when(dataType.getConstraint()).thenReturn(expectedText);
    final UnaryTests actualAllowedValues = handler.makeAllowedValues(dataType, itemDefinition);
    assertEquals(expectedAllowedValues, actualAllowedValues);
    assertEquals(expectedConstraintType, actualAllowedValues.getConstraintType());
}
Also used : ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) ConstraintType(org.kie.workbench.common.dmn.api.definition.model.ConstraintType) Text(org.kie.workbench.common.dmn.api.property.dmn.Text) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests) Test(org.junit.Test)

Aggregations

UnaryTests (org.kie.workbench.common.dmn.api.definition.model.UnaryTests)36 DecisionRule (org.kie.workbench.common.dmn.api.definition.model.DecisionRule)16 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)16 Test (org.junit.Test)15 RuleAnnotationClauseText (org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText)13 ItemDefinition (org.kie.workbench.common.dmn.api.definition.model.ItemDefinition)10 InputClause (org.kie.workbench.common.dmn.api.definition.model.InputClause)9 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)8 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)8 DecisionTable (org.kie.workbench.common.dmn.api.definition.model.DecisionTable)6 Text (org.kie.workbench.common.dmn.api.property.dmn.Text)6 ConstraintType (org.kie.workbench.common.dmn.api.definition.model.ConstraintType)5 Description (org.kie.workbench.common.dmn.api.property.dmn.Description)5 InputClauseLiteralExpression (org.kie.workbench.common.dmn.api.definition.model.InputClauseLiteralExpression)4 RuleAnnotationClause (org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause)4 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)4 DataType (org.kie.workbench.common.dmn.client.editors.types.common.DataType)4 JSITUnaryTests (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITUnaryTests)4 List (java.util.List)3 Before (org.junit.Before)3