From eb8e3f1dd891ac98f1bbaf35a2a0679146785236 Mon Sep 17 00:00:00 2001 From: sebdet Date: Sun, 24 Jan 2021 18:12:36 +0100 Subject: Add New UI component for policies list Add new Ui components to list policies + the small refactoring of React Routes Issue-ID: POLICY-2925 Signed-off-by: sebdet Change-Id: I784d7c144a3a3af98a9d62b5d40b5172dbdaed47 Signed-off-by: sebdet --- .../policy/clamp/policy/pdpgroup/PoliciesPdpMerger.java | 15 +++++++++------ src/main/resources/clds/camel/rest/clamp-api-v2.xml | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) (limited to 'src/main') diff --git a/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PoliciesPdpMerger.java b/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PoliciesPdpMerger.java index 4b94355ee..0bd45cd33 100644 --- a/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PoliciesPdpMerger.java +++ b/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PoliciesPdpMerger.java @@ -42,19 +42,22 @@ public class PoliciesPdpMerger { * This method extract the content of a policy without knowing the key (policy Id). * This JsonElement normally contains only the policy ID then the content, * there is only one member in the Json element. + * As this is not really practical to use this method remove that + * nested Json. * * @param policyJsonElement The policy as JsonElement * @return It return the content as JsonObject */ public static JsonObject getPolicyContentOutOfJsonElement(JsonElement policyJsonElement) { - return policyJsonElement.getAsJsonObject() - .get(((String) policyJsonElement.getAsJsonObject().keySet().toArray()[0])).getAsJsonObject(); + mergeJsonElement(policyJsonElement.getAsJsonObject(), policyJsonElement.getAsJsonObject() + .remove(((String) policyJsonElement.getAsJsonObject().keySet().toArray()[0])).getAsJsonObject()); + return policyJsonElement.getAsJsonObject(); } /** * This method merges 2 JsonElement together. If the jsonToMerge is null nothign is changed. * - * @param json The initial json that will received the data + * @param json The initial json that will received the data * @param jsonToMerge The json that will be added to the first json object */ public static void mergeJsonElement(JsonObject json, JsonObject jsonToMerge) { @@ -69,16 +72,16 @@ public class PoliciesPdpMerger { * * @param jsonPoliciesList The Json containing the policies from the PEF * @param pdpGroupsJson The json containing the PDP groups info from the PEF - * @return It returns a String containing the policies list enriched with PdpGroup info + * @return It returns a JsonObject containing the policies list enriched with PdpGroup info */ - public static String mergePoliciesAndPdpGroupStates(String jsonPoliciesList, String pdpGroupsJson) { + public static JsonObject mergePoliciesAndPdpGroupStates(String jsonPoliciesList, String pdpGroupsJson) { PdpGroups pdpGroups = JsonUtils.GSON.fromJson(pdpGroupsJson, PdpGroups.class); JsonObject policiesListJson = JsonUtils.GSON.fromJson(jsonPoliciesList, JsonObject.class).get("topology_template") .getAsJsonObject(); StreamSupport.stream(policiesListJson.get("policies").getAsJsonArray().spliterator(), true) .forEach(policyJson -> enrichOnePolicy(pdpGroups, getPolicyContentOutOfJsonElement(policyJson))); - return policiesListJson.toString(); + return policiesListJson; } /** diff --git a/src/main/resources/clds/camel/rest/clamp-api-v2.xml b/src/main/resources/clds/camel/rest/clamp-api-v2.xml index 011c24a9d..e1f138b1d 100644 --- a/src/main/resources/clds/camel/rest/clamp-api-v2.xml +++ b/src/main/resources/clds/camel/rest/clamp-api-v2.xml @@ -1317,7 +1317,7 @@ - + -- cgit 1.2.3-korg