replacePropertiesIfEmpty(policy, "failure_retries", "final_failure_retries");
replacePropertiesIfEmpty(policy, "failure_exception", "final_failure_exception");
replacePropertiesIfEmpty(policy, "failure_guard", "final_failure_guard");
+ // Again special case for payload, should remove it if it's there but empty
+ // otherwise policy crashes
+ JsonElement payloadElem = policy.getAsJsonObject().get("payload");
+ if (payloadElem != null && payloadElem.isJsonPrimitive() && payloadElem.getAsString().isEmpty()) {
+ policy.getAsJsonObject().remove("payload");
+ }
}
return policyJson;
}
* @return The Yaml as string
*/
public static String createPolicyPayloadYamlLegacy(JsonElement operationalPolicyJsonElement) {
- JsonElement opPolicy = fulfillPoliciesTreeField(
- removeAllQuotes(reworkPayloadAttributes(operationalPolicyJsonElement.getAsJsonObject().deepCopy())));
- Map<?, ?> jsonMap = createMap(opPolicy);
DumperOptions options = new DumperOptions();
options.setDefaultScalarStyle(ScalarStyle.PLAIN);
options.setIndent(2);
options.setPrettyFlow(true);
// Policy can't support { } in the yaml
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
- return (new Yaml(options)).dump(jsonMap);
+ return (new Yaml(options)).dump(createMap(fulfillPoliciesTreeField(
+ removeAllQuotes(reworkPayloadAttributes(operationalPolicyJsonElement.getAsJsonObject().deepCopy())))));
}
/**
* @param loop The parent loop object
*/
public static void preloadConfiguration(JsonObject configurationsJson, Loop loop) {
- if (configurationsJson.entrySet().isEmpty()) {
+ if (configurationsJson != null && configurationsJson.entrySet().isEmpty()) {
JsonObject controlLoopName = new JsonObject();
controlLoopName.addProperty("controlLoopName",
loop != null ? loop.getName() : "Empty (NO loop loaded yet)");