Search in sources :

Example 1 with InputClause

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

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

the class DecisionRuleFactoryTest method setup.

@Before
public void setup() {
    dtable = new DecisionTable();
    dtable.getInput().add(new InputClause());
    dtable.getInput().add(new InputClause());
    dtable.getOutput().add(new OutputClause());
    dtable.getOutput().add(new OutputClause());
    dtable.getAnnotations().add(new RuleAnnotationClause());
    dtable.getAnnotations().add(new RuleAnnotationClause());
}
Also used : OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) RuleAnnotationClause(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause) InputClause(org.kie.workbench.common.dmn.api.definition.model.InputClause) Before(org.junit.Before)

Example 3 with InputClause

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

the class DecisionTableDefaultValueUtilitiesTest method testGetNewInputClauseNameWithExistingInputClauses.

@Test
public void testGetNewInputClauseNameWithExistingInputClauses() {
    final InputClause inputClause1 = new InputClause() {

        {
            setInputExpression(new InputClauseLiteralExpression());
        }
    };
    dtable.getInput().add(inputClause1);
    inputClause1.getInputExpression().getText().setValue("input");
    final InputClause inputClause2 = new InputClause() {

        {
            setInputExpression(new InputClauseLiteralExpression());
        }
    };
    dtable.getInput().add(inputClause2);
    inputClause2.getInputExpression().getText().setValue(DecisionTableDefaultValueUtilities.getNewInputClauseName(dtable));
    assertThat(inputClause2.getInputExpression().getText().getValue()).isEqualTo(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_PREFIX + "1");
}
Also used : InputClauseLiteralExpression(org.kie.workbench.common.dmn.api.definition.model.InputClauseLiteralExpression) InputClause(org.kie.workbench.common.dmn.api.definition.model.InputClause) Test(org.junit.Test)

Example 4 with InputClause

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

the class DecisionTableDefaultValueUtilitiesTest method testGetNewInputClauseName.

@Test
public void testGetNewInputClauseName() {
    final InputClause inputClause1 = new InputClause() {

        {
            setInputExpression(new InputClauseLiteralExpression());
        }
    };
    dtable.getInput().add(inputClause1);
    inputClause1.getInputExpression().getText().setValue(DecisionTableDefaultValueUtilities.getNewInputClauseName(dtable));
    assertThat(inputClause1.getInputExpression().getText().getValue()).isEqualTo(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_PREFIX + "1");
    final InputClause inputClause2 = new InputClause() {

        {
            setInputExpression(new InputClauseLiteralExpression());
        }
    };
    dtable.getInput().add(inputClause2);
    inputClause2.getInputExpression().getText().setValue(DecisionTableDefaultValueUtilities.getNewInputClauseName(dtable));
    assertThat(inputClause2.getInputExpression().getText().getValue()).isEqualTo(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_PREFIX + "2");
}
Also used : InputClauseLiteralExpression(org.kie.workbench.common.dmn.api.definition.model.InputClauseLiteralExpression) InputClause(org.kie.workbench.common.dmn.api.definition.model.InputClause) Test(org.junit.Test)

Example 5 with InputClause

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

the class DecisionTableEditorDefinitionEnricherTest method testModelEnrichmentWhenTopLevelDecisionTableWithInputDataAndComplexCustomType.

@Test
@SuppressWarnings("unchecked")
public void testModelEnrichmentWhenTopLevelDecisionTableWithInputDataAndComplexCustomType() {
    setupGraphWithDiagram();
    setupGraphWithInputData();
    final Definitions definitions = diagram.getDefinitions();
    final String complexItemDefinitionName = "tSmurf";
    final String complexItemDefinitionPart1Name = "tDateOfBirth";
    final String complexItemDefinitionPart2Name = "tIsBlue";
    final QName complexItemDefinitionPart1TypeRef = new QName(QName.NULL_NS_URI, BuiltInType.DATE.getName());
    final QName complexItemDefinitionPart2TypeRef = new QName(QName.NULL_NS_URI, BuiltInType.BOOLEAN.getName());
    final ItemDefinition complexItemDefinition = new ItemDefinition();
    complexItemDefinition.setName(new Name(complexItemDefinitionName));
    complexItemDefinition.getItemComponent().add(new ItemDefinition() {

        {
            setName(new Name(complexItemDefinitionPart1Name));
            setTypeRef(complexItemDefinitionPart1TypeRef);
        }
    });
    complexItemDefinition.getItemComponent().add(new ItemDefinition() {

        {
            setName(new Name(complexItemDefinitionPart2Name));
            setTypeRef(complexItemDefinitionPart2TypeRef);
        }
    });
    definitions.getItemDefinition().add(complexItemDefinition);
    final QName inputData1TypeRef = new QName(QName.NULL_NS_URI, complexItemDefinitionName);
    inputData1.getVariable().setTypeRef(inputData1TypeRef);
    final Optional<DecisionTable> oModel = definition.getModelClass();
    definition.enrich(Optional.of(NODE_UUID), decision, oModel);
    final DecisionTable model = oModel.get();
    assertBasicEnrichment(model);
    final List<InputClause> input = model.getInput();
    assertThat(input.size()).isEqualTo(3);
    assertThat(input.get(0).getInputExpression()).isInstanceOf(InputClauseLiteralExpression.class);
    assertThat(input.get(0).getInputExpression().getText().getValue()).isEqualTo(INPUT_DATA_NAME_2);
    assertThat(input.get(0).getInputExpression().getTypeRef()).isEqualTo(INPUT_DATA_QNAME_2);
    assertThat(input.get(1).getInputExpression()).isInstanceOf(InputClauseLiteralExpression.class);
    assertThat(input.get(1).getInputExpression().getText().getValue()).isEqualTo(INPUT_DATA_NAME_1 + "." + complexItemDefinitionPart1Name);
    assertThat(input.get(1).getInputExpression().getTypeRef()).isEqualTo(complexItemDefinitionPart1TypeRef);
    assertThat(input.get(2).getInputExpression()).isInstanceOf(InputClauseLiteralExpression.class);
    assertThat(input.get(2).getInputExpression().getText().getValue()).isEqualTo(INPUT_DATA_NAME_1 + "." + complexItemDefinitionPart2Name);
    assertThat(input.get(2).getInputExpression().getTypeRef()).isEqualTo(complexItemDefinitionPart2TypeRef);
    assertStandardOutputClauseEnrichment(model);
    assertStandardDecisionRuleEnrichment(model);
    assertParentHierarchyEnrichment(model);
}
Also used : DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) InputClause(org.kie.workbench.common.dmn.api.definition.model.InputClause) Test(org.junit.Test)

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