Fix minor code smells
[aai/search-data-service.git] / src / main / java / org / onap / aai / sa / rest / AnalyzerApi.java
index 59b526f..bf6f17c 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/**
  * ============LICENSE_START=======================================================
  * org.onap.aai
  * ================================================================================
@@ -52,6 +52,8 @@ public class AnalyzerApi {
     private static Logger logger = LoggerFactory.getInstance().getLogger(IndexApi.class.getName());
     private static Logger auditLogger = LoggerFactory.getInstance().getAuditLogger(IndexApi.class.getName());
 
+    private static final String MSG_AUTHENTICATION_FAILURE = "Authentication failure.";
+
     public AnalyzerApi(@Qualifier("searchServiceApi") SearchServiceApi searchService) {
         this.searchService = searchService;
     }
@@ -61,7 +63,7 @@ public class AnalyzerApi {
             ApiUtils apiUtils) {
 
         HttpStatus responseCode = HttpStatus.INTERNAL_SERVER_ERROR;
-        String responseString = "Undefined error";
+        String responseString;
 
         // Initialize the MDC Context for logging purposes.
         ApiUtils.initMdcContext(request, headers);
@@ -72,9 +74,9 @@ public class AnalyzerApi {
 
             if (!searchService.validateRequest(headers, request, ApiUtils.Action.GET,
                     ApiUtils.SEARCH_AUTH_POLICY_NAME)) {
-                logger.warn(SearchDbMsgs.GET_ANALYZERS_FAILURE, "Authentication failure.");
+                logger.warn(SearchDbMsgs.GET_ANALYZERS_FAILURE, MSG_AUTHENTICATION_FAILURE);
                 return ResponseEntity.status(HttpStatus.FORBIDDEN).contentType(MediaType.APPLICATION_JSON)
-                        .body("Authentication failure.");
+                        .body(MSG_AUTHENTICATION_FAILURE);
             }
 
         } catch (Exception e) {
@@ -82,7 +84,7 @@ public class AnalyzerApi {
             logger.warn(SearchDbMsgs.GET_ANALYZERS_FAILURE,
                     "Unexpected authentication failure - cause: " + e.getMessage());
             return ResponseEntity.status(HttpStatus.FORBIDDEN).contentType(MediaType.APPLICATION_JSON)
-                    .body("Authentication failure.");
+                    .body(MSG_AUTHENTICATION_FAILURE);
         }
 
 
@@ -90,25 +92,24 @@ public class AnalyzerApi {
         try {
             responseString = buildAnalyzerList(ElasticSearchHttpController.getInstance().getAnalysisConfig());
             responseCode = HttpStatus.OK;
-
         } catch (Exception e) {
-
             logger.warn(SearchDbMsgs.GET_ANALYZERS_FAILURE,
                     "Unexpected failure retrieving analysis configuration - cause: " + e.getMessage());
             responseString = "Failed to retrieve analysis configuration.  Cause: " + e.getMessage();
         }
 
         // Build the HTTP response.
-        ResponseEntity response =
+        ResponseEntity<String> response =
                 ResponseEntity.status(responseCode).contentType(MediaType.APPLICATION_JSON).body(responseString);
 
         // Generate our audit log.
+        String unknownLogField = "Unknown";
         auditLogger.info(SearchDbMsgs.PROCESS_REST_REQUEST,
                 new LogFields().setField(LogLine.DefinedFields.RESPONSE_CODE, responseCode.value())
                         .setField(LogLine.DefinedFields.RESPONSE_DESCRIPTION, responseCode.value()),
-                (request != null) ? request.getMethod() : "Unknown",
-                (request != null) ? request.getRequestURL().toString() : "Unknown",
-                (request != null) ? request.getRemoteHost() : "Unknown",
+                (request != null) ? request.getMethod() : unknownLogField,
+                (request != null) ? request.getRequestURL().toString() : unknownLogField,
+                (request != null) ? request.getRemoteHost() : unknownLogField,
                 Integer.toString(response.getStatusCodeValue()));
 
         // Clear the MDC context so that no other transaction inadvertently
@@ -118,7 +119,6 @@ public class AnalyzerApi {
         return response;
     }
 
-
     /**
      * This method takes a list of analyzer objects and generates a simple json structure to enumerate them.
      *