Merge "Included Policy GUI Enhancements and validations"
[policy/engine.git] / POLICY-SDK-APP / src / main / java / org / onap / policy / controller / AutoPushController.java
index d308e7e..e0388e5 100644 (file)
@@ -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;
@@ -120,7 +121,7 @@ public class AutoPushController extends RestrictedBaseController{
                try{
                        Set<String> scopes = null;
                        List<String> roles = null;
-                       data = new ArrayList<Object>();
+                       data = new ArrayList<>();
                        String userId = UserUtils.getUserSession(request).getOrgUserId();
                        Map<String, Object> model = new HashMap<>();
                        ObjectMapper mapper = new ObjectMapper();
@@ -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)
@@ -334,7 +336,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 +350,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();
@@ -359,8 +361,8 @@ public class AutoPushController extends RestrictedBaseController{
                        policyContainer = new PDPPolicyContainer(group);
                        if(removePolicyData.size() > 0){
                                for(int i = 0 ; i < removePolicyData.size(); i++){
-                                       String data = removePolicyData.get(i).toString();
-                                       this.policyContainer.removeItem(data);
+                                       String polData = removePolicyData.get(i).toString();
+                                       this.policyContainer.removeItem(polData);
                                }
                                Set<PDPPolicy> changedPolicies = new HashSet<>();
                                changedPolicies.addAll((Collection<PDPPolicy>) this.policyContainer.getItemIds());
@@ -369,6 +371,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,9 +393,9 @@ 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;
        }
 
-}
\ No newline at end of file
+}