Search in sources :

Example 1 with RuleAnnotationClauseText

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

the class DecisionRuleFactoryTest method testDuplicateDecisionRule.

@Test
public void testDuplicateDecisionRule() {
    final DecisionRule rule = DecisionRuleFactory.makeDecisionRule(dtable);
    final List<UnaryTests> inputEntries = rule.getInputEntry();
    assertThat(inputEntries.size()).isEqualTo(2);
    inputEntries.get(0).getText().setValue(INPUT_CLAUSE_TEXT_1);
    inputEntries.get(1).getText().setValue(INPUT_CLAUSE_TEXT_2);
    inputEntries.get(0).setConstraintType(ConstraintType.ENUMERATION);
    inputEntries.get(1).setConstraintType(ConstraintType.RANGE);
    final List<LiteralExpression> outputEntries = rule.getOutputEntry();
    assertThat(outputEntries.size()).isEqualTo(2);
    outputEntries.get(0).getText().setValue(OUTPUT_CLAUSE_TEXT_1);
    outputEntries.get(1).getText().setValue(OUTPUT_CLAUSE_TEXT_2);
    final List<RuleAnnotationClauseText> annotationEntries = rule.getAnnotationEntry();
    assertThat(annotationEntries.size()).isEqualTo(2);
    annotationEntries.get(0).getText().setValue(RULE_ANNOTATION_CLAUSE_TEXT_1);
    annotationEntries.get(1).getText().setValue(RULE_ANNOTATION_CLAUSE_TEXT_2);
    dtable.getRule().add(rule);
    final DecisionRule duplicate = DecisionRuleFactory.duplicateDecisionRule(0, dtable);
    final List<UnaryTests> duplicateInputEntries = duplicate.getInputEntry();
    assertThat(duplicateInputEntries.size()).isEqualTo(2);
    assertUnaryTestsText(duplicateInputEntries.get(0), INPUT_CLAUSE_TEXT_1);
    assertUnaryTestsText(duplicateInputEntries.get(1), INPUT_CLAUSE_TEXT_2);
    assertThat(duplicateInputEntries.get(0).getConstraintType()).isEqualTo(ConstraintType.ENUMERATION);
    assertThat(duplicateInputEntries.get(1).getConstraintType()).isEqualTo(ConstraintType.RANGE);
    assertUnaryTestsInstancesAreNotTheSame(inputEntries.get(0), duplicateInputEntries.get(0));
    assertUnaryTestsInstancesAreNotTheSame(inputEntries.get(1), duplicateInputEntries.get(1));
    assertThat(duplicateInputEntries).allSatisfy(unaryTests -> assertThat(unaryTests.getParent()).isEqualTo(duplicate));
    final List<LiteralExpression> duplicateOutputEntries = duplicate.getOutputEntry();
    assertThat(duplicateOutputEntries.size()).isEqualTo(2);
    assertLiteralExpressionText(duplicateOutputEntries.get(0), OUTPUT_CLAUSE_TEXT_1);
    assertLiteralExpressionText(duplicateOutputEntries.get(1), OUTPUT_CLAUSE_TEXT_2);
    assertLiteralExpressionInstancesAreNotTheSame(outputEntries.get(0), duplicateOutputEntries.get(0));
    assertLiteralExpressionInstancesAreNotTheSame(outputEntries.get(1), duplicateOutputEntries.get(1));
    assertThat(duplicateOutputEntries).allSatisfy(literalExpression -> assertThat(literalExpression.getParent()).isEqualTo(duplicate));
    final List<RuleAnnotationClauseText> duplicateRuleAnnotationClauses = duplicate.getAnnotationEntry();
    assertThat(duplicateRuleAnnotationClauses.size()).isEqualTo(2);
    assertAnnotationClauseText(duplicateRuleAnnotationClauses.get(0), RULE_ANNOTATION_CLAUSE_TEXT_1);
    assertAnnotationClauseText(duplicateRuleAnnotationClauses.get(1), RULE_ANNOTATION_CLAUSE_TEXT_2);
    assertRuleAnnotationClauseInstancesAreNotTheSame(annotationEntries.get(0), duplicateRuleAnnotationClauses.get(0));
    assertRuleAnnotationClauseInstancesAreNotTheSame(annotationEntries.get(1), duplicateRuleAnnotationClauses.get(1));
    assertThat(duplicateRuleAnnotationClauses).allSatisfy(ruleAnnotationClauseText -> assertThat(ruleAnnotationClauseText.getParent()).isEqualTo(duplicate));
    assertThat(duplicate.getParent()).isEqualTo(dtable);
}
Also used : LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) RuleAnnotationClauseText(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText) 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 2 with RuleAnnotationClauseText

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

the class RuleAnnotationClauseTextPropertyConverter method wbFromDMN.

public static RuleAnnotationClauseText wbFromDMN(final JSITRuleAnnotation dmn) {
    final RuleAnnotationClauseText result = new RuleAnnotationClauseText();
    result.setText(new Text(dmn.getText()));
    return result;
}
Also used : RuleAnnotationClauseText(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText) Text(org.kie.workbench.common.dmn.api.property.dmn.Text) RuleAnnotationClauseText(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText)

Example 3 with RuleAnnotationClauseText

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

the class DecisionRulePropertyConverter method dmnFromWB.

public static JSITDecisionRule dmnFromWB(final DecisionRule wb) {
    final JSITDecisionRule result = new JSITDecisionRule();
    result.setId(wb.getId().getValue());
    final Optional<String> description = Optional.ofNullable(DescriptionPropertyConverter.dmnFromWB(wb.getDescription()));
    description.ifPresent(result::setDescription);
    for (final RuleAnnotationClauseText ruleAnnotationClauseText : wb.getAnnotationEntry()) {
        final JSITRuleAnnotation ruleAnnotation = RuleAnnotationClauseTextPropertyConverter.dmnFromWB(ruleAnnotationClauseText);
        result.addAnnotationEntry(ruleAnnotation);
    }
    for (UnaryTests ie : wb.getInputEntry()) {
        final JSITUnaryTests inputEntryConverted = UnaryTestsPropertyConverter.dmnFromWB(ie);
        result.addInputEntry(inputEntryConverted);
    }
    for (LiteralExpression oe : wb.getOutputEntry()) {
        final JSITLiteralExpression outputEntryConverted = LiteralExpressionPropertyConverter.dmnFromWB(oe);
        result.addOutputEntry(outputEntryConverted);
    }
    return result;
}
Also used : JSITUnaryTests(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITUnaryTests) JSITLiteralExpression(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITLiteralExpression) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) JSITLiteralExpression(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITLiteralExpression) RuleAnnotationClauseText(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText) JSITDecisionRule(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionRule) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests) JSITUnaryTests(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITUnaryTests) JSITRuleAnnotation(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITRuleAnnotation)

Example 4 with RuleAnnotationClauseText

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

the class DecisionRulePropertyConverter method wbFromDMN.

public static DecisionRule wbFromDMN(final JSITDecisionRule dmn) {
    final Id id = IdPropertyConverter.wbFromDMN(dmn.getId());
    final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
    final DecisionRule result = new DecisionRule();
    result.setId(id);
    result.setDescription(description);
    final List<JSITRuleAnnotation> jsiAnnotationEntries = dmn.getAnnotationEntry();
    for (int i = 0; i < jsiAnnotationEntries.size(); i++) {
        final JSITRuleAnnotation jsiRuleAnnotation = Js.uncheckedCast(jsiAnnotationEntries.get(i));
        final RuleAnnotationClauseText ruleAnnotationClauseText = RuleAnnotationClauseTextPropertyConverter.wbFromDMN(jsiRuleAnnotation);
        if (Objects.nonNull(ruleAnnotationClauseText)) {
            ruleAnnotationClauseText.setParent(result);
            result.getAnnotationEntry().add(ruleAnnotationClauseText);
        }
    }
    if (result.getAnnotationEntry().isEmpty()) {
        final RuleAnnotationClauseText annotationEntryText = new RuleAnnotationClauseText();
        annotationEntryText.getText().setValue(description.getValue());
        annotationEntryText.setParent(result);
        result.getAnnotationEntry().add(annotationEntryText);
    }
    final List<JSITUnaryTests> jsiInputEntries = dmn.getInputEntry();
    for (int i = 0; i < jsiInputEntries.size(); i++) {
        final JSITUnaryTests jsiInputEntry = Js.uncheckedCast(jsiInputEntries.get(i));
        final UnaryTests inputEntryConverted = UnaryTestsPropertyConverter.wbFromDMN(jsiInputEntry);
        if (Objects.nonNull(inputEntryConverted)) {
            inputEntryConverted.setParent(result);
            result.getInputEntry().add(inputEntryConverted);
        }
    }
    final List<JSITLiteralExpression> jsiOutputEntries = dmn.getOutputEntry();
    for (int i = 0; i < jsiOutputEntries.size(); i++) {
        final JSITLiteralExpression jsiOutputEntry = Js.uncheckedCast(jsiOutputEntries.get(i));
        final LiteralExpression outputEntryConverted = LiteralExpressionPropertyConverter.wbFromDMN(jsiOutputEntry);
        if (Objects.nonNull(outputEntryConverted)) {
            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) JSITLiteralExpression(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITLiteralExpression) RuleAnnotationClauseText(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText) JSITDecisionRule(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionRule) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) JSITRuleAnnotation(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITRuleAnnotation) JSITUnaryTests(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITUnaryTests) JSITLiteralExpression(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITLiteralExpression) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests) JSITUnaryTests(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITUnaryTests)

Example 5 with RuleAnnotationClauseText

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

the class DecisionRulePropertyConverterTest method testDmnFromWbWithAnnotationRules.

@Test
public void testDmnFromWbWithAnnotationRules() {
    final org.kie.workbench.common.dmn.api.definition.model.DecisionRule wb = new org.kie.workbench.common.dmn.api.definition.model.DecisionRule();
    final String annotation1 = "the text one";
    final String annotation2 = "the text two";
    final RuleAnnotationClauseText ruleAnnotation1 = createWbRuleAnnotation(annotation1);
    final RuleAnnotationClauseText ruleAnnotation2 = createWbRuleAnnotation(annotation2);
    wb.getAnnotationEntry().add(ruleAnnotation1);
    wb.getAnnotationEntry().add(ruleAnnotation2);
    final org.kie.dmn.model.api.DecisionRule dmn = DecisionRulePropertyConverter.dmnFromWB(wb);
    assertEquals(2, dmn.getAnnotationEntry().size());
    assertEquals(annotation1, dmn.getAnnotationEntry().get(0).getText());
    assertEquals(annotation2, dmn.getAnnotationEntry().get(1).getText());
}
Also used : RuleAnnotationClauseText(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText) TDecisionRule(org.kie.dmn.model.v1_2.TDecisionRule) Test(org.junit.Test)

Aggregations

RuleAnnotationClauseText (org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText)25 DecisionRule (org.kie.workbench.common.dmn.api.definition.model.DecisionRule)14 UnaryTests (org.kie.workbench.common.dmn.api.definition.model.UnaryTests)12 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)11 Test (org.junit.Test)10 List (java.util.List)5 DecisionTable (org.kie.workbench.common.dmn.api.definition.model.DecisionTable)5 RuleAnnotationClause (org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause)5 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)5 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)5 Before (org.junit.Before)3 InputClause (org.kie.workbench.common.dmn.api.definition.model.InputClause)3 Text (org.kie.workbench.common.dmn.api.property.dmn.Text)3 DMNGridData (org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData)3 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)3 AbstractGraphCommand (org.kie.workbench.common.stunner.core.graph.command.impl.AbstractGraphCommand)3 OutputClause (org.kie.workbench.common.dmn.api.definition.model.OutputClause)2 Description (org.kie.workbench.common.dmn.api.property.dmn.Description)2 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)2 JSITDecisionRule (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionRule)2