Created
May 10, 2022 09:31
-
-
Save berndruecker/cad6801fe05d6c5d39af559e4077cea2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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