X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=POLICY-SDK-APP%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fcontroller%2FAutoPushController.java;h=96e104656c95e3a499923fe3725347c586304cef;hb=153ec0fda79b07ca1ecf7016f1e7f4e2c792f04e;hp=50b9d6923f96516e32c98e320efe3a4514f75a36;hpb=b31eb9787fd4171325ef39d887e2c0feb58e9927;p=policy%2Fengine.git diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/AutoPushController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/AutoPushController.java index 50b9d6923..96e104656 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/AutoPushController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/AutoPushController.java @@ -52,6 +52,7 @@ import org.onap.policy.rest.adapter.AutoPushTabAdapter; import org.onap.policy.rest.dao.CommonClassDao; import org.onap.policy.rest.jpa.PolicyEntity; import org.onap.policy.rest.jpa.PolicyVersion; +import org.onap.policy.utils.PolicyUtils; import org.onap.policy.xacml.api.XACMLErrorConstants; import org.onap.policy.xacml.api.pap.OnapPDPGroup; import org.onap.policy.xacml.std.pap.StdPDPGroup; @@ -118,9 +119,9 @@ public class AutoPushController extends RestrictedBaseController{ @RequestMapping(value={"/get_AutoPushPoliciesContainerData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) public void getPolicyGroupContainerData(HttpServletRequest request, HttpServletResponse response){ try{ - Set scopes = null; - List roles = null; - data = new ArrayList(); + Set scopes; + List roles; + data = new ArrayList<>(); String userId = UserUtils.getUserSession(request).getOrgUserId(); Map model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); @@ -138,7 +139,7 @@ public class AutoPushController extends RestrictedBaseController{ scopes.add(multipleScopes[i]); } }else{ - if(!userRole.getScope().equals("")){ + if(!"".equals(userRole.getScope())){ scopes.add(userRole.getScope()); } } @@ -219,7 +220,7 @@ public class AutoPushController extends RestrictedBaseController{ // Get the current selection String selectedItem = policyId; // - assert (selectedItem != null); + assert selectedItem != null; // create the id of the target file // Our standard for file naming is: // ...xml @@ -230,7 +231,7 @@ public class AutoPushController extends RestrictedBaseController{ String id = name; if (id.endsWith(".xml")) { id = id.replace(".xml", ""); - id = id.substring(0, id.lastIndexOf(".")); + id = id.substring(0, id.lastIndexOf('.')); } // Default policy to be Root policy; user can change to deferred @@ -288,6 +289,7 @@ public class AutoPushController extends RestrictedBaseController{ updatedGroupObject.setOnapPdps(pdpGroup.getOnapPdps()); updatedGroupObject.setPipConfigs(pdpGroup.getPipConfigs()); updatedGroupObject.setStatus(pdpGroup.getStatus()); + updatedGroupObject.setOperation("push"); // replace the original set of Policies with the set from the // container (possibly modified by the user) @@ -326,6 +328,10 @@ public class AutoPushController extends RestrictedBaseController{ JsonMessage msg = new JsonMessage(mapper.writeValueAsString(groups)); JSONObject j = new JSONObject(msg); out.write(j.toString()); + // + // Why is this here? This defeats the purpose of the loop?? + // Sonar says to remove it or make it conditional + // return null; } } @@ -334,7 +340,7 @@ public class AutoPushController extends RestrictedBaseController{ request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); logger.error(e); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -348,7 +354,7 @@ public class AutoPushController extends RestrictedBaseController{ ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); - StdPDPGroup group = (StdPDPGroup)mapper.readValue(root.get("activePdpGroup").toString(), StdPDPGroup.class); + StdPDPGroup group = mapper.readValue(root.get("activePdpGroup").toString(), StdPDPGroup.class); JsonNode removePolicyData = root.get("data"); String userId = UserUtils.getUserSession(request).getOrgUserId(); @@ -369,6 +375,7 @@ public class AutoPushController extends RestrictedBaseController{ updatedGroupObject.setOnapPdps(group.getOnapPdps()); updatedGroupObject.setPipConfigs(group.getPipConfigs()); updatedGroupObject.setStatus(group.getStatus()); + updatedGroupObject.setOperation("delete"); this.container.updateGroup(updatedGroupObject); } @@ -390,7 +397,7 @@ public class AutoPushController extends RestrictedBaseController{ request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); logger.error(e); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; }