Search in sources :

Example 1 with RuleAnnotationClause

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

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

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

the class DecisionTableDefaultValueUtilitiesTest method testGetNewRuleAnnotationClauseNameWithExistingAnnotationClause.

@Test
public void testGetNewRuleAnnotationClauseNameWithExistingAnnotationClause() {
    final RuleAnnotationClause ruleAnnotationClause1 = new RuleAnnotationClause();
    dtable.getAnnotations().add(ruleAnnotationClause1);
    ruleAnnotationClause1.getName().setValue("something");
    final RuleAnnotationClause ruleAnnotationClause2 = new RuleAnnotationClause();
    dtable.getAnnotations().add(ruleAnnotationClause2);
    ruleAnnotationClause2.getName().setValue(DecisionTableDefaultValueUtilities.getNewRuleAnnotationClauseName(dtable));
    assertThat(ruleAnnotationClause2.getName().getValue()).isEqualTo(DecisionTableDefaultValueUtilities.RULE_ANNOTATION_CLAUSE_PREFIX + "1");
}
Also used : RuleAnnotationClause(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause) Test(org.junit.Test)

Example 4 with RuleAnnotationClause

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

the class DecisionTablePropertyConverter method wbFromDMN.

public static DecisionTable wbFromDMN(final JSITDecisionTable dmn) {
    final Id id = IdPropertyConverter.wbFromDMN(dmn.getId());
    final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
    final QName typeRef = QNamePropertyConverter.wbFromDMN(dmn.getTypeRef());
    final DecisionTable result = new DecisionTable();
    result.setId(id);
    result.setDescription(description);
    result.setTypeRef(typeRef);
    final List<JSITRuleAnnotationClause> jsiRuleAnnotationClauses = dmn.getAnnotation();
    if (jsiRuleAnnotationClauses.isEmpty()) {
        final RuleAnnotationClause ruleAnnotationClause = new RuleAnnotationClause();
        ruleAnnotationClause.setParent(result);
        result.getAnnotations().add(ruleAnnotationClause);
    } else {
        for (int i = 0; i < jsiRuleAnnotationClauses.size(); i++) {
            final JSITRuleAnnotationClause ruleAnnotationClause = Js.uncheckedCast(jsiRuleAnnotationClauses.get(i));
            final RuleAnnotationClause converted = RuleAnnotationClausePropertyConverter.wbFromDMN(ruleAnnotationClause);
            if (Objects.nonNull(converted)) {
                converted.setParent(result);
                result.getAnnotations().add(converted);
            }
        }
    }
    final List<JSITInputClause> jsiInputClauses = dmn.getInput();
    for (int i = 0; i < jsiInputClauses.size(); i++) {
        final JSITInputClause input = Js.uncheckedCast(jsiInputClauses.get(i));
        final InputClause inputClauseConverted = InputClausePropertyConverter.wbFromDMN(input);
        if (Objects.nonNull(inputClauseConverted)) {
            inputClauseConverted.setParent(result);
            result.getInput().add(inputClauseConverted);
        }
    }
    final List<JSITOutputClause> jsiOutputClauses = dmn.getOutput();
    for (int i = 0; i < jsiOutputClauses.size(); i++) {
        final JSITOutputClause output = Js.uncheckedCast(jsiOutputClauses.get(i));
        final OutputClause outputClauseConverted = OutputClausePropertyConverter.wbFromDMN(output);
        if (Objects.nonNull(outputClauseConverted)) {
            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(BuiltInType.UNDEFINED.asQName());
    }
    final List<JSITDecisionRule> jsiDecisionRules = dmn.getRule();
    for (int i = 0; i < jsiDecisionRules.size(); i++) {
        final JSITDecisionRule dr = Js.uncheckedCast(jsiDecisionRules.get(i));
        final DecisionRule decisionRuleConverted = DecisionRulePropertyConverter.wbFromDMN(dr);
        if (Objects.nonNull(decisionRuleConverted)) {
            decisionRuleConverted.setParent(result);
        }
        result.getRule().add(decisionRuleConverted);
    }
    // JSITHitPolicy is a String JSO so convert into the real type
    final String hitPolicy = Js.uncheckedCast(dmn.getHitPolicy());
    if (Objects.nonNull(hitPolicy)) {
        result.setHitPolicy(HitPolicy.fromValue(hitPolicy));
    }
    // JSITBuiltinAggregator is a String JSO so convert into the real type
    final String aggregation = Js.uncheckedCast(dmn.getAggregation());
    if (Objects.nonNull(aggregation)) {
        result.setAggregation(BuiltinAggregator.fromValue(aggregation));
    }
    // JSITDecisionTableOrientation is a String JSO so convert into the real type
    final String orientation = Js.uncheckedCast(dmn.getPreferredOrientation());
    if (Objects.nonNull(orientation)) {
        result.setPreferredOrientation(DecisionTableOrientation.fromValue(orientation));
    }
    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) JSITInputClause(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInputClause) JSITRuleAnnotationClause(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITRuleAnnotationClause) RuleAnnotationClause(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause) JSITDecisionRule(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionRule) JSITOutputClause(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITOutputClause) JSITDecisionRule(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionRule) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) JSITOutputClause(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITOutputClause) JSITDecisionTable(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionTable) DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) JSITRuleAnnotationClause(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITRuleAnnotationClause) JSITInputClause(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInputClause) InputClause(org.kie.workbench.common.dmn.api.definition.model.InputClause)

Example 5 with RuleAnnotationClause

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

the class RuleAnnotationClausePropertyConverter method wbFromDMN.

public static RuleAnnotationClause wbFromDMN(final JSITRuleAnnotationClause dmn) {
    final RuleAnnotationClause result = new RuleAnnotationClause();
    result.setName(new Name(dmn.getName()));
    return result;
}
Also used : JSITRuleAnnotationClause(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITRuleAnnotationClause) RuleAnnotationClause(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause) Name(org.kie.workbench.common.dmn.api.property.dmn.Name)

Aggregations

RuleAnnotationClause (org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause)18 DecisionRule (org.kie.workbench.common.dmn.api.definition.model.DecisionRule)9 InputClause (org.kie.workbench.common.dmn.api.definition.model.InputClause)9 Test (org.junit.Test)8 OutputClause (org.kie.workbench.common.dmn.api.definition.model.OutputClause)8 DecisionTable (org.kie.workbench.common.dmn.api.definition.model.DecisionTable)5 RuleAnnotationClauseText (org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText)4 JSITRuleAnnotationClause (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITRuleAnnotationClause)3 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)3 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)3 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)3 Before (org.junit.Before)2 UnaryTests (org.kie.workbench.common.dmn.api.definition.model.UnaryTests)2 Description (org.kie.workbench.common.dmn.api.property.dmn.Description)2 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)2 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)2 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)2 JSITDecisionRule (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionRule)2 JSITDecisionTable (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionTable)2 JSITInputClause (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInputClause)2