Search in sources :

Example 1 with JSITOutputClause

use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITOutputClause in project kie-wb-common by kiegroup.

the class OutputClausePropertyConverter method wbFromDMN.

public static OutputClause wbFromDMN(final JSITOutputClause dmn) {
    final Id id = IdPropertyConverter.wbFromDMN(dmn.getId());
    final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
    final OutputClauseUnaryTests outputValues = OutputClauseUnaryTestsPropertyConverter.wbFromDMN(dmn.getOutputValues());
    final OutputClauseLiteralExpression defaultOutputEntry = OutputClauseLiteralExpressionPropertyConverter.wbFromDMN(dmn.getDefaultOutputEntry());
    final QName typeRef = QNamePropertyConverter.wbFromDMN(dmn.getTypeRef());
    final OutputClause result = new OutputClause();
    result.setId(id);
    result.setName(dmn.getName());
    result.setDescription(description);
    result.setOutputValues(outputValues);
    result.setDefaultOutputEntry(defaultOutputEntry);
    result.setTypeRef(typeRef);
    if (Objects.nonNull(outputValues)) {
        outputValues.setParent(result);
    }
    if (Objects.nonNull(defaultOutputEntry)) {
        defaultOutputEntry.setParent(result);
    }
    return result;
}
Also used : JSITOutputClause(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITOutputClause) OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) Description(org.kie.workbench.common.dmn.api.property.dmn.Description) OutputClauseLiteralExpression(org.kie.workbench.common.dmn.api.definition.model.OutputClauseLiteralExpression) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) OutputClauseUnaryTests(org.kie.workbench.common.dmn.api.definition.model.OutputClauseUnaryTests)

Example 2 with JSITOutputClause

use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITOutputClause in project kie-wb-common by kiegroup.

the class OutputClausePropertyConverter method dmnFromWB.

public static JSITOutputClause dmnFromWB(final OutputClause wb) {
    final JSITOutputClause result = new JSITOutputClause();
    result.setId(wb.getId().getValue());
    result.setName(wb.getName());
    final Optional<String> description = Optional.ofNullable(DescriptionPropertyConverter.dmnFromWB(wb.getDescription()));
    description.ifPresent(result::setDescription);
    final JSITUnaryTests outputValues = OutputClauseUnaryTestsPropertyConverter.dmnFromWB(wb.getOutputValues());
    if (Objects.nonNull(outputValues) && StringUtils.nonEmpty(outputValues.getText())) {
        result.setOutputValues(outputValues);
    }
    final JSITLiteralExpression defaultOutputEntry = OutputClauseLiteralExpressionPropertyConverter.dmnFromWB(wb.getDefaultOutputEntry());
    if (Objects.nonNull(defaultOutputEntry) && StringUtils.nonEmpty(defaultOutputEntry.getText())) {
        result.setDefaultOutputEntry(defaultOutputEntry);
    }
    QNamePropertyConverter.setDMNfromWB(wb.getTypeRef(), result::setTypeRef);
    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) JSITOutputClause(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITOutputClause)

Example 3 with JSITOutputClause

use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITOutputClause 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 4 with JSITOutputClause

use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITOutputClause in project kie-wb-common by kiegroup.

the class DecisionTablePropertyConverter method dmnFromWB.

public static JSITDecisionTable dmnFromWB(final DecisionTable wb) {
    final JSITDecisionTable result = new JSITDecisionTable();
    result.setId(wb.getId().getValue());
    final Optional<String> description = Optional.ofNullable(DescriptionPropertyConverter.dmnFromWB(wb.getDescription()));
    description.ifPresent(result::setDescription);
    QNamePropertyConverter.setDMNfromWB(wb.getTypeRef(), result::setTypeRef);
    for (final RuleAnnotationClause annotation : wb.getAnnotations()) {
        final JSITRuleAnnotationClause converted = RuleAnnotationClausePropertyConverter.dmnFromWB(annotation);
        result.addAnnotation(converted);
    }
    for (InputClause input : wb.getInput()) {
        final JSITInputClause c = InputClausePropertyConverter.dmnFromWB(input);
        result.addInput(c);
    }
    for (OutputClause input : wb.getOutput()) {
        final JSITOutputClause c = OutputClausePropertyConverter.dmnFromWB(input);
        result.addOutput(c);
    }
    if (result.getOutput().size() == 1) {
        final JSITOutputClause at = Js.uncheckedCast(result.getOutput().get(0));
        // DROOLS-3281
        at.setName(null);
        // DROOLS-5178
        at.setTypeRef(null);
    }
    for (DecisionRule dr : wb.getRule()) {
        final JSITDecisionRule c = DecisionRulePropertyConverter.dmnFromWB(dr);
        result.addRule(c);
    }
    if (Objects.nonNull(wb.getHitPolicy())) {
        switch(wb.getHitPolicy()) {
            case ANY:
                result.setHitPolicy(Js.uncheckedCast(JSITHitPolicy.ANY.value()));
                break;
            case COLLECT:
                result.setHitPolicy(Js.uncheckedCast(JSITHitPolicy.COLLECT.value()));
                break;
            case FIRST:
                result.setHitPolicy(Js.uncheckedCast(JSITHitPolicy.FIRST.value()));
                break;
            case UNIQUE:
                result.setHitPolicy(Js.uncheckedCast(JSITHitPolicy.UNIQUE.value()));
                break;
            case PRIORITY:
                result.setHitPolicy(Js.uncheckedCast(JSITHitPolicy.PRIORITY.value()));
                break;
            case RULE_ORDER:
                result.setHitPolicy(Js.uncheckedCast(JSITHitPolicy.RULE_ORDER.value()));
                break;
            case OUTPUT_ORDER:
                result.setHitPolicy(Js.uncheckedCast(JSITHitPolicy.OUTPUT_ORDER.value()));
                break;
        }
    }
    if (Objects.nonNull(wb.getAggregation())) {
        final String wbBuiltinAggregator = wb.getAggregation().value();
        result.setAggregation(Js.uncheckedCast(wbBuiltinAggregator));
    }
    if (Objects.nonNull(wb.getPreferredOrientation())) {
        final String wbPreferredOrientation = wb.getPreferredOrientation().value();
        result.setPreferredOrientation(Js.uncheckedCast(wbPreferredOrientation));
    }
    result.setOutputLabel(wb.getOutputLabel());
    return result;
}
Also used : OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) JSITOutputClause(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITOutputClause) 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) JSITDecisionTable(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionTable) JSITOutputClause(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITOutputClause) 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) JSITDecisionRule(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionRule) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule)

Aggregations

JSITOutputClause (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITOutputClause)4 OutputClause (org.kie.workbench.common.dmn.api.definition.model.OutputClause)3 DecisionRule (org.kie.workbench.common.dmn.api.definition.model.DecisionRule)2 InputClause (org.kie.workbench.common.dmn.api.definition.model.InputClause)2 RuleAnnotationClause (org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause)2 Description (org.kie.workbench.common.dmn.api.property.dmn.Description)2 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)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 JSITRuleAnnotationClause (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITRuleAnnotationClause)2 DecisionTable (org.kie.workbench.common.dmn.api.definition.model.DecisionTable)1 OutputClauseLiteralExpression (org.kie.workbench.common.dmn.api.definition.model.OutputClauseLiteralExpression)1 OutputClauseUnaryTests (org.kie.workbench.common.dmn.api.definition.model.OutputClauseUnaryTests)1 JSITLiteralExpression (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITLiteralExpression)1 JSITUnaryTests (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITUnaryTests)1