import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
-import java.util.Map.Entry;
import javax.persistence.Column;
import javax.persistence.Entity;
/**
* The constructor.
*
- * @param name
- * The name of the operational policy
- * @param loop
- * The loop that uses this operational policy
- * @param configurationsJson
- * The operational policy property in the format of json
+ * @param name The name of the operational policy
+ * @param loop The loop that uses this operational policy
+ * @param configurationsJson The operational policy property in the format of
+ * json
*/
public OperationalPolicy(String name, Loop loop, JsonObject configurationsJson) {
this.name = name;
this.loop = loop;
this.configurationsJson = configurationsJson;
+ LegacyOperationalPolicy.preloadConfiguration(this.configurationsJson, loop);
}
@Override
return loop;
}
- @Override
- public JsonObject getJsonRepresentation() {
- return configurationsJson;
- }
-
public JsonObject getConfigurationsJson() {
return configurationsJson;
}
this.configurationsJson = configurationsJson;
}
+ @Override
+ public JsonObject getJsonRepresentation() {
+ return null;
+ }
+
@Override
public int hashCode() {
final int prime = 31;
metadata.addProperty("policy-id", this.name);
operationalPolicyDetails.add("properties", LegacyOperationalPolicy
- .reworkPayloadAttributes(this.configurationsJson.get("operational_policy").deepCopy()));
+ .reworkPayloadAttributes(this.configurationsJson.get("operational_policy").deepCopy()));
Gson gson = new GsonBuilder().create();
// Now using the legacy payload fo Dublin
JsonObject payload = new JsonObject();
payload.addProperty("policy-id", this.getName());
- payload.addProperty("content", URLEncoder.encode(
- LegacyOperationalPolicy.createPolicyPayloadYamlLegacy(this.configurationsJson.get("operational_policy")),
- StandardCharsets.UTF_8.toString()));
+ payload.addProperty("content", URLEncoder.encode(LegacyOperationalPolicy.createPolicyPayloadYamlLegacy(
+ this.configurationsJson.get("operational_policy")), StandardCharsets.UTF_8.toString()));
String opPayload = new GsonBuilder().setPrettyPrinting().create().toJson(payload);
logger.info("Operational policy payload: " + opPayload);
return opPayload;
JsonElement guardsList = this.getConfigurationsJson().get("guard_policies");
if (guardsList != null) {
- for (Entry<String, JsonElement> guardElem : guardsList.getAsJsonObject().entrySet()) {
- JsonObject guard = new JsonObject();
- guard.addProperty("policy-id", guardElem.getKey());
- guard.add("content", guardElem.getValue());
- result.put(guardElem.getKey(), new GsonBuilder().create().toJson(guard));
+ for (JsonElement guardElem : guardsList.getAsJsonArray()) {
+ result.put(guardElem.getAsJsonObject().get("policy-id").getAsString(),
+ new GsonBuilder().create().toJson(guardElem));
}
}
logger.info("Guard policy payload: " + result);