Skip to content

Commit

Permalink
[#634] Add signavio transformer to correct paths when a child decisio…
Browse files Browse the repository at this point in the history
…n is used as output.
  • Loading branch information
opatrascoiu committed Feb 22, 2024
1 parent 6742aa1 commit 953c3f8
Showing 1 changed file with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@

import com.gs.dmn.DMNModelRepository;
import com.gs.dmn.ast.*;
import com.gs.dmn.feel.analysis.semantics.type.FEELTypes;
import com.gs.dmn.log.BuildLogger;
import com.gs.dmn.log.Slf4jBuildLogger;
import com.gs.dmn.runtime.Pair;
import com.gs.dmn.serialization.DMNVersion;
import com.gs.dmn.signavio.testlab.TestLab;
import com.gs.dmn.transformation.SimpleDMNTransformer;
import org.slf4j.Logger;
Expand Down Expand Up @@ -85,13 +87,41 @@ private List<String> directChildDecisionNames(TDecision decision, DMNModelReposi
if (requiredDecision != null) {
String href = requiredDecision.getHref();
TDecision child = repository.findDecisionByRef(decision, href);
result.add(child.getName());
if (isPrimitiveType(child, repository)) {
result.add(child.getName());
}
}
}

return result;
}

private boolean isPrimitiveType(TDecision decision, DMNModelRepository repository) {
TInformationItem variable = repository.variable(decision);
if (variable == null || variable.getTypeRef() == null) {
return false;
}

TItemDefinition itemDefinition = repository.lookupItemDefinition(variable.getTypeRef().getLocalPart());
while (itemDefinition != null && itemDefinition.getTypeRef() != null) {
if (isPrimitiveType(itemDefinition)) {
return true;
} else {
itemDefinition = repository.lookupItemDefinition(itemDefinition.getTypeRef().getLocalPart());
}
}
return false;
}

private boolean isPrimitiveType(TItemDefinition itemDefinition) {
if (itemDefinition == null || itemDefinition.getTypeRef() == null) {
return false;
}

String name = itemDefinition.getTypeRef().getLocalPart();
return (FEELTypes.FEEL_TYPE_NAMES.contains(name) || name.startsWith(DMNVersion.LATEST.getFeelPrefix())) && !itemDefinition.isIsCollection();
}

private void correctDecision(TDecision decision, List<String> childNames, TDecisionTable dte) {
if (childNames.isEmpty()) {
return;
Expand All @@ -107,9 +137,8 @@ private void correctDecision(TDecision decision, List<String> childNames, TDecis

private void correctRules(TDecision decision, String oldValue, String newValue, TDecisionTable dte) {
List<TDecisionRule> ruleList = dte.getRule();
for (int i=0; i<ruleList.size(); i++) {
TDecisionRule rule = ruleList.get(i);
for (TLiteralExpression outputEntry: rule.getOutputEntry()) {
for (TDecisionRule rule : ruleList) {
for (TLiteralExpression outputEntry : rule.getOutputEntry()) {
if (oldValue.equals(outputEntry.getText().trim())) {
updateLiteralExpression(outputEntry, oldValue, newValue, decision);
}
Expand Down

0 comments on commit 953c3f8

Please sign in to comment.