Skip to content

Commit 5b34b39

Browse files
Fix sonar issue
1 parent b852284 commit 5b34b39

1 file changed

Lines changed: 28 additions & 24 deletions

File tree

src/commonMain/kotlin/org/hisp/dhis/rules/engine/RuleConditionEvaluator.kt

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -124,30 +124,34 @@ internal class RuleConditionEvaluator(
124124
// IllegalArgumentException signals a rule-configuration problem (e.g. a malformed
125125
// ASSIGN target), reported like an expression error rather than an unexpected one
126126
val isConfigurationError = e is IllegalExpressionException || e is IllegalArgumentException
127-
val errorMessage: String
128-
errorMessage =
129-
if (ruleAction != null && isConfigurationError) {
130-
"Action " + ruleAction::class.simpleName +
131-
" from rule " + rule.name + " with id " + rule.uid +
132-
" executed for " + targetType.name + "(" + targetUid + ")" +
133-
" with condition (" + rule.condition + ")" +
134-
" raised an error: " + e.message
135-
} else if (ruleAction != null) {
136-
"Action " + ruleAction::class.simpleName +
137-
" from rule " + rule.name + " with id " + rule.uid +
138-
" executed for " + targetType.name + "(" + targetUid + ")" +
139-
" with condition (" + rule.condition + ")" +
140-
" raised an unexpected exception: " + e.message
141-
} else if (isConfigurationError) {
142-
"Rule " + rule.name + " with id " + rule.uid +
143-
" executed for " + targetType.name + "(" + targetUid + ")" +
144-
" with condition (" + rule.condition + ")" +
145-
" raised an error: " + e.message
146-
} else {
147-
"Rule " + rule.name + " with id " + rule.uid +
148-
" executed for " + targetType.name + "(" + targetUid + ")" +
149-
" with condition (" + rule.condition + ")" +
150-
" raised an unexpected exception: " + e.message
127+
val errorMessage =
128+
when {
129+
ruleAction != null && isConfigurationError -> {
130+
"Action " + ruleAction::class.simpleName +
131+
" from rule " + rule.name + " with id " + rule.uid +
132+
" executed for " + targetType.name + "(" + targetUid + ")" +
133+
" with condition (" + rule.condition + ")" +
134+
" raised an error: " + e.message
135+
}
136+
ruleAction != null -> {
137+
"Action " + ruleAction::class.simpleName +
138+
" from rule " + rule.name + " with id " + rule.uid +
139+
" executed for " + targetType.name + "(" + targetUid + ")" +
140+
" with condition (" + rule.condition + ")" +
141+
" raised an unexpected exception: " + e.message
142+
}
143+
isConfigurationError -> {
144+
"Rule " + rule.name + " with id " + rule.uid +
145+
" executed for " + targetType.name + "(" + targetUid + ")" +
146+
" with condition (" + rule.condition + ")" +
147+
" raised an error: " + e.message
148+
}
149+
else -> {
150+
"Rule " + rule.name + " with id " + rule.uid +
151+
" executed for " + targetType.name + "(" + targetUid + ")" +
152+
" with condition (" + rule.condition + ")" +
153+
" raised an unexpected exception: " + e.message
154+
}
151155
}
152156
log.severe(errorMessage)
153157
ruleEvaluationResults.add(errorRule(rule, errorMessage))

0 commit comments

Comments
 (0)