use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionRule 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;
}
use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionRule 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;
}
use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionRule 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;
}
use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionRule 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;
}
Aggregations