Merge "Added Junits for POLICY-SDK-APP controllers"
[policy/engine.git] / POLICY-SDK-APP / src / main / java / org / onap / policy / controller / AutoPushController.java
index e0388e5..e5e868f 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP Policy Engine
  * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -46,12 +46,12 @@ import org.json.JSONObject;
 import org.onap.policy.common.logging.flexlogger.FlexLogger;
 import org.onap.policy.common.logging.flexlogger.Logger;
 import org.onap.policy.model.PDPGroupContainer;
-import org.onap.policy.model.PDPPolicyContainer;
 import org.onap.policy.model.Roles;
 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.rest.util.PDPPolicyContainer;
 import org.onap.policy.utils.PolicyUtils;
 import org.onap.policy.xacml.api.XACMLErrorConstants;
 import org.onap.policy.xacml.api.pap.OnapPDPGroup;
@@ -78,6 +78,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 public class AutoPushController extends RestrictedBaseController{
 
        private static final Logger logger = FlexLogger.getLogger(AutoPushController.class);
+    private static final String UTF8 = "UTF-8";
+
        
        @Autowired
        CommonClassDao commonClassDao;
@@ -119,8 +121,8 @@ 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<String> scopes = null;
-                       List<String> roles = null;
+                       Set<String> scopes;
+                       List<String> roles;
                        data = new ArrayList<>();
                        String userId = UserUtils.getUserSession(request).getOrgUserId();
                        Map<String, Object> model = new HashMap<>();
@@ -139,7 +141,7 @@ public class AutoPushController extends RestrictedBaseController{
                                                        scopes.add(multipleScopes[i]);
                                                }
                                        }else{
-                                               if(!userRole.getScope().equals("")){
+                                               if(!"".equals(userRole.getScope())){
                                                        scopes.add(userRole.getScope());
                                                }
                                        }               
@@ -220,7 +222,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:
                                        // <domain>.<filename>.<version>.xml
@@ -319,24 +321,28 @@ public class AutoPushController extends RestrictedBaseController{
                                updatedGroupObject.setPolicies(currentPoliciesInGroup);
                                this.container.updateGroup(updatedGroupObject);
 
-                               response.setCharacterEncoding("UTF-8");
+                               response.setCharacterEncoding(UTF8);
                                response.setContentType("application / json");
-                               request.setCharacterEncoding("UTF-8");
+                               request.setCharacterEncoding(UTF8);
 
                                PrintWriter out = response.getWriter();
                                refreshGroups();
                                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;
                        }
                }
                catch (Exception e){
-                       response.setCharacterEncoding("UTF-8");
-                       request.setCharacterEncoding("UTF-8");
+                       response.setCharacterEncoding(UTF8);
+                       request.setCharacterEncoding(UTF8);
                        PrintWriter out = response.getWriter();
                        logger.error(e);
-                       out.write(PolicyUtils.CATCH_EXCEPTION);;
+                       out.write(PolicyUtils.CATCH_EXCEPTION);
                }
                return null;
        }
@@ -375,9 +381,9 @@ public class AutoPushController extends RestrictedBaseController{
                                this.container.updateGroup(updatedGroupObject);
                        }
                        
-                       response.setCharacterEncoding("UTF-8");
+                       response.setCharacterEncoding(UTF8);
                        response.setContentType("application / json");
-                       request.setCharacterEncoding("UTF-8");
+                       request.setCharacterEncoding(UTF8);
 
                        PrintWriter out = response.getWriter();
                        refreshGroups();
@@ -389,11 +395,11 @@ public class AutoPushController extends RestrictedBaseController{
                        return null;
                }
                catch (Exception e){
-                       response.setCharacterEncoding("UTF-8");
-                       request.setCharacterEncoding("UTF-8");
+                       response.setCharacterEncoding(UTF8);
+                       request.setCharacterEncoding(UTF8);
                        PrintWriter out = response.getWriter();
                        logger.error(e);
-                       out.write(PolicyUtils.CATCH_EXCEPTION);;
+                       out.write(PolicyUtils.CATCH_EXCEPTION);
                }
                return null;
        }