re base code
[sdc.git] / common-app-api / src / main / java / org / openecomp / sdc / common / log / wrappers / LoggerSdcUtilBase.java
@@ -1,40 +1,25 @@
-package org.openecomp.sdc.common.ecomplogwrapper;
-
-import static java.net.HttpURLConnection.HTTP_BAD_METHOD;
-import static java.net.HttpURLConnection.HTTP_BAD_REQUEST;
-import static java.net.HttpURLConnection.HTTP_CLIENT_TIMEOUT;
-import static java.net.HttpURLConnection.HTTP_CONFLICT;
-import static java.net.HttpURLConnection.HTTP_ENTITY_TOO_LARGE;
-import static java.net.HttpURLConnection.HTTP_FORBIDDEN;
-import static java.net.HttpURLConnection.HTTP_GONE;
-import static java.net.HttpURLConnection.HTTP_LENGTH_REQUIRED;
-import static java.net.HttpURLConnection.HTTP_NOT_ACCEPTABLE;
-import static java.net.HttpURLConnection.HTTP_NOT_FOUND;
-import static java.net.HttpURLConnection.HTTP_PAYMENT_REQUIRED;
-import static java.net.HttpURLConnection.HTTP_PRECON_FAILED;
-import static java.net.HttpURLConnection.HTTP_PROXY_AUTH;
-import static java.net.HttpURLConnection.HTTP_REQ_TOO_LONG;
-import static java.net.HttpURLConnection.HTTP_UNAUTHORIZED;
-import static java.net.HttpURLConnection.HTTP_UNSUPPORTED_TYPE;
+package org.openecomp.sdc.common.log.wrappers;
 
-import java.util.List;
-import java.util.StringTokenizer;
+import org.apache.commons.lang3.StringUtils;
+import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import javax.ws.rs.container.ContainerRequestContext;
+import java.util.List;
+import java.util.StringTokenizer;
 
-import org.openecomp.sdc.common.ecomplog.Enums.EcompLoggerErrorCode;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import static java.net.HttpURLConnection.*;
 
 /**
  * Created by dd4296 on 12/20/2017.
  *
- * base class for metric and audit ecomplog logging
+ * base class for metric and audit log logging
  * holding the specific logic for data extraction
  */
-public class EcompLoggerSdcUtilBase {
+public class LoggerSdcUtilBase {
 
-    protected static Logger log = LoggerFactory.getLogger(EcompLoggerSdcUtilBase.class.getName());
+    protected static Logger log = LoggerFactory.getLogger(LoggerSdcUtilBase.class.getName());
 
     String getRequestIDfromHeaders(List<Object> requestHeader) {
         // this method gets list of type object.
@@ -44,28 +29,29 @@ public class EcompLoggerSdcUtilBase {
     }
 
 
+
     // this method translates http error code to ECOMP Logger Error code
     // this is a naive translation and is not a result of any documented format ECOMP specification
     protected EcompLoggerErrorCode convertHttpCodeToErrorCode(int httpResponseCode) {
-        if (isSuccessError(httpResponseCode))
+        if (isSuccessError(httpResponseCode)) {
             return EcompLoggerErrorCode.SUCCESS;
+        }
 
-        if (isSchemaError(httpResponseCode))
+        if (isSchemaError(httpResponseCode)) {
             return EcompLoggerErrorCode.SCHEMA_ERROR;
-
-        if (isDataError(httpResponseCode))
+        }
+        if (isDataError(httpResponseCode)) {
             return EcompLoggerErrorCode.DATA_ERROR;
-
-        if (isPermissionsError(httpResponseCode))
+        }
+        if (isPermissionsError(httpResponseCode)) {
             return EcompLoggerErrorCode.PERMISSION_ERROR;
-
-        if (isTimeoutOrAvailabilityError(httpResponseCode))
+        }
+        if (isTimeoutOrAvailabilityError(httpResponseCode)) {
             return EcompLoggerErrorCode.AVAILABILITY_TIMEOUTS_ERROR;
-
-        if (isBusinessProcessError(httpResponseCode))
+        }
+        if (isBusinessProcessError(httpResponseCode)) {
             return EcompLoggerErrorCode.BUSINESS_PROCESS_ERROR;
-
-
+        }
         return EcompLoggerErrorCode.UNKNOWN_ERROR;
     }
 
@@ -78,9 +64,10 @@ public class EcompLoggerSdcUtilBase {
             case HTTP_CLIENT_TIMEOUT:
             case HTTP_GONE:
                 return true;
+            default:
+                return false;
         }
 
-        return false;
     }
 
     private boolean isPermissionsError(int httpResponseCode) {
@@ -125,18 +112,18 @@ public class EcompLoggerSdcUtilBase {
 
     protected String getPartnerName(String userAgent, String userId, String url) {
 
-        if (!isNullOrEmpty(userId)) {
+        if (!StringUtils.isEmpty(userId)) {
             return userId;
         }
 
         String urlUser = getUserIdFromUrl(url);
 
-        if (!isNullOrEmpty(urlUser))
+        if (!StringUtils.isEmpty(urlUser))
             return urlUser;
 
         String userAgentName = getUserIdFromUserAgent(userAgent);
 
-        if (!isNullOrEmpty(userAgentName))
+        if (!StringUtils.isEmpty(userAgentName))
             return userAgentName;
 
         return "";
@@ -187,10 +174,6 @@ public class EcompLoggerSdcUtilBase {
         return url;
     }
 
-    private boolean isNullOrEmpty(String str) {
-        return (str == null || str.isEmpty());
-    }
-
     protected String getServiceName(ContainerRequestContext requestContext) {
         return (requestContext.getUriInfo().getRequestUri().toString())
                 .replace(requestContext.getUriInfo().getBaseUri().toString(), "/");