Merge "Resolved the Sonar issues"
[policy/engine.git] / ONAP-PAP-REST / src / main / java / org / onap / policy / pap / xacml / rest / service / MetricService.java
index 864201c..66fb9ac 100644 (file)
@@ -7,9 +7,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -35,18 +35,20 @@ import org.onap.policy.xacml.api.pap.OnapPDPGroup;
 import com.att.research.xacml.api.pap.PDPPolicy;
 
 public class MetricService {
-    private static String errorMsg     = "error";
+    private static String errorMsg = "error";
+
     /*
      * This is a private constructor
      * */
-    private MetricService(){
+    private MetricService() {
 
     }
+
     public static void doGetPolicyMetrics(HttpServletResponse response) {
         Set<OnapPDPGroup> groups = new HashSet<>();
         try {
             //get the count of policies on the PDP
-            if(XACMLPapServlet.getPAPEngine()!=null){
+            if (XACMLPapServlet.getPAPEngine() != null) {
                 groups = XACMLPapServlet.getPAPEngine().getOnapPDPGroups();
             }
             int pdpCount = 0;
@@ -56,11 +58,13 @@ public class MetricService {
             }
             //get the count of policies on the PAP
             EntityManager em = null;
-            if(XACMLPapServlet.getEmf()!=null){
+            if (XACMLPapServlet.getEmf() != null) {
                 em = XACMLPapServlet.getEmf().createEntityManager();
             }
-            if (em==null){
-                PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " Error creating entity manager with persistence unit: " + XACMLPapServlet.getPersistenceUnit());
+            if (em == null) {
+                PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE +
+                        " Error creating entity manager with persistence unit: " +
+                        XACMLPapServlet.getPersistenceUnit());
                 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
                 response.addHeader(errorMsg, "Error creating entity manager with persistence unit");
                 return;
@@ -73,25 +77,26 @@ public class MetricService {
             json.put("papCount", papCount);
             json.put("pdpCount", pdpCount);
             json.put("totalCount", totalCount);
-            if (pdpCount>0 && papCount>0 && totalCount>0) {
-                PolicyLogger.info("Metrics have been found on the Policy Engine for the number of policies on the PAP and PDP.");
+            if (pdpCount > 0 && papCount > 0 && totalCount > 0) {
+                PolicyLogger
+                        .info("Metrics have been found on the Policy Engine for the number of policies on the PAP and" +
+                                " PDP.");
                 response.setStatus(HttpServletResponse.SC_OK);
                 response.addHeader("successMapKey", "success");
                 response.addHeader("operation", "getMetrics");
-                response.addHeader("metrics", json.toString() );
-                return;
-            }else{
-                String message = "The policy count on the PAP and PDP is 0.  Please check the database and file system to correct this error.";
+                response.addHeader("metrics", json.toString());
+            } else {
+                String message =
+                        "The policy count on the PAP and PDP is 0.  Please check the database and file system to " +
+                                "correct this error.";
                 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
                 response.addHeader(errorMsg, message);
-                return;
             }
         } catch (Exception e) {
             String message = XACMLErrorConstants.ERROR_DATA_ISSUE + " Error Querying the Database: " + e.getMessage();
             PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "XACMLPapServlet", " Error Querying the Database.");
             response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
             response.addHeader(errorMsg, message);
-            return;
         }
     }