Skip to content

Instantly share code, notes, and snippets.

@berndruecker
Created May 10, 2022 09:31
Show Gist options
  • Save berndruecker/cad6801fe05d6c5d39af559e4077cea2 to your computer and use it in GitHub Desktop.
Save berndruecker/cad6801fe05d6c5d39af559e4077cea2 to your computer and use it in GitHub Desktop.
@Component
public class MapDmnResult implements ExecutionListener {
@Override
public void notify(DelegateExecution execution) throws Exception {
List<String> risks = new ArrayList<String>();
Set<String> riskLevels = new HashSet<String>();
Object oDMNresult = execution.getVariable("riskDMNresult");
for (Object oResult : (List<?>) oDMNresult) {
Map<?, ?> result = (Map<?, ?>) oResult;
risks.add(result.containsKey("risk") ? (String) result.get("risk") : "");
if (result.get("riskLevel") != null) {
riskLevels.add(((String) result.get("riskLevel")).toLowerCase());
}
}
String accumulatedRiskLevel = "green";
if (riskLevels.contains("rot") || riskLevels.contains("red")) {
accumulatedRiskLevel = "red";
} else if (riskLevels.contains("gelb") || riskLevels.contains("yellow")) {
accumulatedRiskLevel = "yellow";
}
execution.setVariable("risks", Variables.objectValue(risks).serializationDataFormat(SerializationDataFormats.JSON).create());
execution.setVariable("riskLevel", accumulatedRiskLevel);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment