diff options
author | sebdet <sebastien.determe@intl.att.com> | 2019-04-11 02:07:44 +0200 |
---|---|---|
committer | sebdet <sebastien.determe@intl.att.com> | 2019-04-11 02:07:44 +0200 |
commit | 667cb72d3ab1578afc78a77c72b65238df741cd1 (patch) | |
tree | 9d6bf794ca50561515257482475e12ca887e162b /src/main/java | |
parent | 5431f6e5c621a094c33d01b2be89762b80273434 (diff) |
Add pdp group
Add pdp group code to add/remove policies from active PDP group
Issue-ID: CLAMP-303
Change-Id: I3fcffd229bc7703231b813948aac14ce63437127
Signed-off-by: sebdet <sebastien.determe@intl.att.com>
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/org/onap/clamp/loop/Loop.java | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/src/main/java/org/onap/clamp/loop/Loop.java b/src/main/java/org/onap/clamp/loop/Loop.java index 83f938dde..0041c589e 100644 --- a/src/main/java/org/onap/clamp/loop/Loop.java +++ b/src/main/java/org/onap/clamp/loop/Loop.java @@ -29,7 +29,9 @@ import com.google.gson.JsonObject; import com.google.gson.annotations.Expose; import java.io.Serializable; +import java.util.ArrayList; import java.util.HashSet; +import java.util.List; import java.util.Set; import javax.persistence.CascadeType; @@ -259,28 +261,43 @@ public class Loop implements Serializable { return buffer.toString().replace('.', '_').replaceAll(" ", ""); } + /** + * Generates the Json that must be sent to policy to add all policies to Active + * PDP group. + * + * @return The json, payload to send + */ public String createPoliciesPayloadPdpGroup() { JsonObject jsonObject = new JsonObject(); JsonArray jsonArray = new JsonArray(); jsonObject.add("policies", jsonArray); - for (OperationalPolicy opPolicy : this.getOperationalPolicies()) { + for (String policyName : this.listPolicyNamesPdpGroup()) { JsonObject policyNode = new JsonObject(); jsonArray.add(policyNode); - policyNode.addProperty("policy-id", opPolicy.getName()); + policyNode.addProperty("policy-id", policyName); + } + return new GsonBuilder().setPrettyPrinting().create().toJson(jsonObject); + } + /** + * Generates the list of policy names that must be send/remove to/from active + * PDP group. + * + * @return A list of policy names + */ + public List<String> listPolicyNamesPdpGroup() { + List<String> policyNamesList = new ArrayList<>(); + for (OperationalPolicy opPolicy : this.getOperationalPolicies()) { + policyNamesList.add(opPolicy.getName()); for (String guardName : opPolicy.createGuardPolicyPayloads().keySet()) { - JsonObject guardPolicyNode = new JsonObject(); - jsonArray.add(guardPolicyNode); - guardPolicyNode.addProperty("policy-id", guardName); + policyNamesList.add(guardName); } } for (MicroServicePolicy microServicePolicy : this.getMicroServicePolicies()) { - JsonObject policyNode = new JsonObject(); - jsonArray.add(policyNode); - policyNode.addProperty("policy-id", microServicePolicy.getName()); + policyNamesList.add(microServicePolicy.getName()); } - return new GsonBuilder().setPrettyPrinting().create().toJson(jsonObject); + return policyNamesList; } @Override |