Search in sources :

Example 6 with InputClauseLiteralExpression

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

the class DecisionTableEditorDefinitionEnricher method enrich.

@Override
public void enrich(final Optional<String> nodeUUID, final HasExpression hasExpression, final Optional<DecisionTable> expression) {
    expression.ifPresent(dtable -> {
        dtable.setHitPolicy(HitPolicy.UNIQUE);
        dtable.setPreferredOrientation(DecisionTableOrientation.RULE_AS_ROW);
        final InputClause inputClause = new InputClause();
        final InputClauseLiteralExpression literalExpression = new InputClauseLiteralExpression();
        literalExpression.getText().setValue(DecisionTableDefaultValueUtilities.getNewInputClauseName(dtable));
        inputClause.setInputExpression(literalExpression);
        dtable.getInput().add(inputClause);
        final RuleAnnotationClause ruleAnnotationClause = new RuleAnnotationClause();
        ruleAnnotationClause.getName().setValue(DecisionTableDefaultValueUtilities.getNewRuleAnnotationClauseName(dtable));
        dtable.getAnnotations().add(ruleAnnotationClause);
        final DecisionRule decisionRule = new DecisionRule();
        final UnaryTests decisionRuleUnaryTest = new UnaryTests();
        decisionRuleUnaryTest.getText().setValue(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_UNARY_TEST_TEXT);
        decisionRule.getInputEntry().add(decisionRuleUnaryTest);
        buildOutputClausesByDataType(hasExpression, dtable, decisionRule);
        final RuleAnnotationClauseText ruleAnnotationEntry = new RuleAnnotationClauseText();
        ruleAnnotationEntry.getText().setValue(DecisionTableDefaultValueUtilities.RULE_DESCRIPTION);
        decisionRule.getAnnotationEntry().add(ruleAnnotationEntry);
        dtable.getRule().add(decisionRule);
        // Setup parent relationships
        inputClause.setParent(dtable);
        decisionRule.setParent(dtable);
        literalExpression.setParent(inputClause);
        decisionRuleUnaryTest.setParent(decisionRule);
        ruleAnnotationEntry.setParent(dtable);
        if (nodeUUID.isPresent()) {
            enrichInputClauses(nodeUUID.get(), dtable);
        } else {
            enrichOutputClauses(dtable);
        }
    });
}
Also used : InputClauseLiteralExpression(org.kie.workbench.common.dmn.api.definition.model.InputClauseLiteralExpression) RuleAnnotationClauseText(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText) RuleAnnotationClause(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests) InputClause(org.kie.workbench.common.dmn.api.definition.model.InputClause) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule)

Example 7 with InputClauseLiteralExpression

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

the class InputClausePropertyConverter method wbFromDMN.

public static InputClause wbFromDMN(final org.kie.dmn.model.api.InputClause dmn) {
    final Id id = new Id(dmn.getId());
    final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
    final InputClauseLiteralExpression inputExpression = InputClauseLiteralExpressionPropertyConverter.wbFromDMN(dmn.getInputExpression());
    final InputClauseUnaryTests inputValues = InputClauseUnaryTestsPropertyConverter.wbFromDMN(dmn.getInputValues());
    final InputClause result = new InputClause(id, description, inputExpression, inputValues);
    if (inputExpression != null) {
        inputExpression.setParent(result);
    }
    if (inputValues != null) {
        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) InputClause(org.kie.workbench.common.dmn.api.definition.model.InputClause)

Example 8 with InputClauseLiteralExpression

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

the class InputClauseLiteralExpressionPropertyConverter method wbFromDMN.

public static InputClauseLiteralExpression wbFromDMN(final org.kie.dmn.model.api.LiteralExpression dmn) {
    if (dmn == null) {
        return null;
    }
    final Id id = new Id(dmn.getId());
    final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
    final QName typeRef = QNamePropertyConverter.wbFromDMN(dmn.getTypeRef(), dmn);
    final Text text = new Text(dmn.getText());
    final ImportedValues importedValues = ImportedValuesConverter.wbFromDMN(dmn.getImportedValues());
    final InputClauseLiteralExpression result = new InputClauseLiteralExpression(id, description, typeRef, text, importedValues);
    if (importedValues != null) {
        importedValues.setParent(result);
    }
    return result;
}
Also used : Description(org.kie.workbench.common.dmn.api.property.dmn.Description) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) ImportedValues(org.kie.workbench.common.dmn.api.definition.model.ImportedValues) InputClauseLiteralExpression(org.kie.workbench.common.dmn.api.definition.model.InputClauseLiteralExpression) Text(org.kie.workbench.common.dmn.api.property.dmn.Text) Id(org.kie.workbench.common.dmn.api.property.dmn.Id)

Example 9 with InputClauseLiteralExpression

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

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

the class DecisionTableDefaultValueUtilitiesTest method testGetNewInputClauseNameWithDeletion.

@Test
public void testGetNewInputClauseNameWithDeletion() {
    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");
    dtable.getInput().remove(inputClause1);
    final InputClause inputClause3 = new InputClause() {

        {
            setInputExpression(new InputClauseLiteralExpression());
        }
    };
    dtable.getInput().add(inputClause3);
    inputClause3.getInputExpression().getText().setValue(DecisionTableDefaultValueUtilities.getNewInputClauseName(dtable));
    assertThat(inputClause3.getInputExpression().getText().getValue()).isEqualTo(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_PREFIX + "3");
}
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)

Aggregations

InputClauseLiteralExpression (org.kie.workbench.common.dmn.api.definition.model.InputClauseLiteralExpression)10 InputClause (org.kie.workbench.common.dmn.api.definition.model.InputClause)7 Description (org.kie.workbench.common.dmn.api.property.dmn.Description)4 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)4 Test (org.junit.Test)3 UnaryTests (org.kie.workbench.common.dmn.api.definition.model.UnaryTests)3 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)3 DecisionRule (org.kie.workbench.common.dmn.api.definition.model.DecisionRule)2 ImportedValues (org.kie.workbench.common.dmn.api.definition.model.ImportedValues)2 InputClauseUnaryTests (org.kie.workbench.common.dmn.api.definition.model.InputClauseUnaryTests)2 RuleAnnotationClause (org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause)2 RuleAnnotationClauseText (org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1