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;
}
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());
}
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");
}
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;
}
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;
}
Aggregations