MS Model Input Validation
[policy/engine.git] / ONAP-PDP-REST / src / main / java / org / onap / policy / pdp / rest / api / services / PAPServices.java
index 72d8fde..57a80b5 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP-PDP-REST
  * ================================================================================
- * 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.
@@ -111,7 +111,7 @@ public class PAPServices {
         // This makes it Real-Time to change the list depending on their
         // availability.
         if (paps == null || paps.isEmpty()) {
-            String message = XACMLErrorConstants.ERROR_DATA_ISSUE + "PAPs List is Empty.";
+            String message = XACMLErrorConstants.ERROR_SYSTEM_ERROR + "PAPs List is Empty.";
             LOGGER.error(message);
             throw new PolicyException(message);
         }
@@ -215,7 +215,7 @@ public class PAPServices {
             }
             return response;
         } else {
-            response = XACMLErrorConstants.ERROR_SYSTEM_ERROR
+            response = XACMLErrorConstants.ERROR_DATA_ISSUE
                     + "Unable to get valid response from PAP(s) " + paps;
             return response;
         }
@@ -415,10 +415,10 @@ public class PAPServices {
                     + ". PEP is not Authorized for making this Request!! \n Contact Administrator for this Scope. ";
             LOGGER.error(response);
         } else if (connection.getResponseCode() == 404 && connection.getHeaderField("error") != null) {
-            if ("unknownGroupId".equals(connection.getHeaderField("error"))) {
+            if ("UnknownGroup".equals(connection.getHeaderField("error"))) {
                 response = XACMLErrorConstants.ERROR_DATA_ISSUE
                         + connection.getHeaderField("message")
-                        + " Please check the pdpGroup you are requesting to move the policy to.";
+                        + " Please check the pdpGroup you are requesting to push the policy to.";
                 LOGGER.error(response);
             } else if ("policyNotAvailableForEdit".equals(connection.getHeaderField("error"))) {
                response = XACMLErrorConstants.ERROR_DATA_ISSUE
@@ -490,13 +490,16 @@ public class PAPServices {
                 response = XACMLErrorConstants.ERROR_UNKNOWN
                         + "Could not create or update the policy for and unknown reason";
             }else{
-                response = XACMLErrorConstants.ERROR_DATA_ISSUE
-                        + "BAD REQUEST:  Error occured while attempting perform this operation.. the request may be incorrect. " + connection.getHeaderField("error");
+                response = XACMLErrorConstants.ERROR_SYSTEM_ERROR
+                        + "Error occured while attempting perform this operation.. "
+                        + "the request may be incorrect or the PAP is unreachable. " 
+                               + connection.getHeaderField("error");
             }
             LOGGER.error(response);
         } else {
-            response = XACMLErrorConstants.ERROR_DATA_ISSUE
-                    + "BAD REQUEST:  Error occured while attempting perform this operation.. the request may be incorrect.";
+            response = XACMLErrorConstants.ERROR_SYSTEM_ERROR
+                    + "Error occured while attempting perform this operation.. "
+                    + "the request may be incorrect or the PAP is unreachable.";
             LOGGER.error(response);
         }
         return response;
@@ -544,11 +547,11 @@ public class PAPServices {
                                + "\"policyName\": \""+policyName+"\","
                                + "\"clientScope\": \""+clientScope+"\","
                                + "\"pdpGroup\": \""+pdpGroup+"\"}";
-        //String response = null;
-        HttpURLConnection connection = null;
+
+               HttpURLConnection connection = null;
         responseCode = 0;
         if (paps == null || paps.isEmpty()) {
-            String message = XACMLErrorConstants.ERROR_DATA_ISSUE + "PAPs List is Empty.";
+            String message = XACMLErrorConstants.ERROR_SYSTEM_ERROR + "PAPs List is Empty.";
             LOGGER.error(message);
             throw new PolicyException(message);
         }