[POLICY-122] Policy GUI Fixes
[policy/engine.git] / ECOMP-PDP-REST / src / main / java / org / openecomp / policy / pdp / rest / api / services / GetMetricsService.java
index 14812ed..5a90bfa 100644 (file)
@@ -34,12 +34,11 @@ import org.openecomp.policy.xacml.api.XACMLErrorConstants;
 import org.springframework.http.HttpStatus;
 
 public class GetMetricsService {
-       private static Logger LOGGER = FlexLogger
-                       .getLogger(GetDictionaryService.class.getName());
+       private static final Logger LOGGER = FlexLogger
+                       .getLogger(GetMetricsService.class.getName());
 
        private MetricsResponse response = null;
        private HttpStatus status = HttpStatus.BAD_REQUEST;
-       private String message = null;
        private MetricsRequestParameters metricsParameters = null;
 
        public GetMetricsService(String requestID) {
@@ -49,7 +48,7 @@ public class GetMetricsService {
                                requestUUID = UUID.fromString(requestID);
                        } catch (IllegalArgumentException e) {
                                requestUUID = UUID.randomUUID();
-                               LOGGER.info("Generated Random UUID: " + requestUUID.toString());
+                               LOGGER.info("Generated Random UUID: " + requestUUID.toString(), e);
                        }
                } else {
                        requestUUID = UUID.randomUUID();
@@ -72,20 +71,13 @@ public class GetMetricsService {
        }
 
        private void specialCheck() {
-               if (response != null) {
-                       if (response.getResponseMessage() != null
-                                       && response.getResponseMessage().contains("PE300")) {
+               if (response != null && (response.getResponseMessage() != null
+                                       && response.getResponseMessage().contains("PE300"))) {
                                status = HttpStatus.BAD_REQUEST;
-                       }
                }
        }
 
        private void run() throws PolicyException {
-               // Check Validation.
-               /*
-                * if(!getValidation()){ LOGGER.error(message); throw new
-                * PolicyException(message); }
-                */
                // Get Result.
                try {
                        status = HttpStatus.OK;
@@ -105,11 +97,12 @@ public class GetMetricsService {
                                metricsParameters.getRequestID(), "metrics");
 
                JSONObject json = null;
+               String message = null;
                if (result != null) {
                        if (result.length() > 81 && result.contains("{")) {
                                try {
                                        String responseMessage = result.substring(0, 82);
-                                       String jsonString = result.substring(result.indexOf("{"),
+                                       String jsonString = result.substring(result.indexOf('{'),
                                                        result.length());
                                        json = new JSONObject(jsonString);
 
@@ -123,9 +116,13 @@ public class GetMetricsService {
                                        metricsResponse.setPdpMetrics(pdpCount);
 
                                } catch (JsonException | IllegalStateException e) {
+                                       String jsonString = null;
+                                       if(json != null){
+                                               jsonString = json.toString();
+                                       }
                                        message = XACMLErrorConstants.ERROR_DATA_ISSUE
-                                                       + " improper JSON object : " + json.toString();
-                                       LOGGER.error(message);
+                                                       + " improper JSON object : " + jsonString;
+                                       LOGGER.error(message + e);
                                        metricsResponse.setResponseMessage(message);
                                        metricsResponse.setResponseCode(400);
                                        return metricsResponse;