[PORTAL-16 PORTAL-18] Widget ms; staging
[portal.git] / ecomp-portal-BE-common / src / main / java / org / openecomp / portalapp / portal / logging / logic / EPLogUtil.java
index aa86765..ebda67e 100644 (file)
-/*-\r
- * ================================================================================\r
- * ECOMP Portal\r
- * ================================================================================\r
- * Copyright (C) 2017 AT&T Intellectual Property\r
- * ================================================================================\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * \r
- *      http://www.apache.org/licenses/LICENSE-2.0\r
- * \r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- * ================================================================================\r
- */\r
-package org.openecomp.portalapp.portal.logging.logic;\r
-\r
-import static com.att.eelf.configuration.Configuration.MDC_ALERT_SEVERITY;\r
-\r
-import java.text.MessageFormat;\r
-\r
-import org.slf4j.MDC;\r
-\r
-import com.att.eelf.configuration.EELFLogger;\r
-import com.att.eelf.configuration.EELFManager;\r
-\r
-import org.openecomp.portalsdk.core.logging.format.AlarmSeverityEnum;\r
-import org.openecomp.portalsdk.core.logging.format.ErrorSeverityEnum;\r
-import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;\r
-import org.openecomp.portalsdk.core.web.support.UserUtils;\r
-import org.openecomp.portalapp.portal.logging.format.EPAppMessagesEnum;\r
-\r
-public class EPLogUtil {\r
-\r
-       // This class has no logger.  It uses loggers passed to it.\r
-       \r
-       /**\r
-        * Formats and writes a message to the error log with the class name and the\r
-        * specified parameters, using log level info, warn or error appropriate for\r
-        * the specified severity\r
-        * \r
-        * @param classLogger\r
-        *            Logger for the class where the error occurred; the logger\r
-        *            carries the class name.\r
-        * @param epMessageEnum\r
-        *            Enum carrying alarm and error severity\r
-        * @param param\r
-        *            Values used to build the message.\r
-        */\r
-       public static void logEcompError(EELFLoggerDelegate classLogger, EPAppMessagesEnum epMessageEnum, String... param) {\r
-               logEcompError(classLogger, epMessageEnum, null, param);\r
-       }\r
-       \r
-       /**\r
-        * Formats and writes a message to the error log with the class name and the\r
-        * specified parameters, using log level info, warn or error appropriate for\r
-        * the specified severity\r
-        * \r
-        * @param classLogger\r
-        *            Logger for the class where the error occurred; the logger\r
-        *            carries the class name.\r
-        * @param epMessageEnum\r
-        *            Enum carrying alarm and error severity\r
-        * @param param\r
-        *            Values used to build the message.\r
-        */\r
-       private static EELFLogger errorLogger = EELFManager.getInstance().getErrorLogger();\r
-       public static void logEcompError(EPAppMessagesEnum epMessageEnum, String... param) {\r
-               try {\r
-                       AlarmSeverityEnum alarmSeverityEnum = epMessageEnum.getAlarmSeverity();\r
-                       ErrorSeverityEnum errorSeverityEnum = epMessageEnum.getErrorSeverity();\r
-                       \r
-                       MDC.put(MDC_ALERT_SEVERITY, alarmSeverityEnum.name());\r
-                       MDC.put("ErrorCode", epMessageEnum.getErrorCode());\r
-                       MDC.put("ErrorDescription", epMessageEnum.getErrorDescription());\r
-                       MDC.put("ClassName", EPLogUtil.class.getName());\r
-                       \r
-                       String resolution = EPLogUtil.formatMessage(epMessageEnum.getDetails() + " " + epMessageEnum.getResolution(), (Object[]) param);\r
-                       if (errorSeverityEnum == ErrorSeverityEnum.WARN) {\r
-                               errorLogger.warn(resolution);\r
-                       } else if(errorSeverityEnum == ErrorSeverityEnum.INFO) {\r
-                               errorLogger.info(resolution);\r
-                       } else {\r
-                               errorLogger.error(resolution);\r
-                       }\r
-               } catch(Exception e) {\r
-                       errorLogger.error("Failed to log the error code. Details: " + UserUtils.getStackTrace(e));\r
-               } finally {\r
-                       MDC.remove("ErrorCode");\r
-                       MDC.remove("ErrorDescription");\r
-                       MDC.remove("ClassName");\r
-                       MDC.remove(MDC_ALERT_SEVERITY);\r
-               }\r
-       }\r
-\r
-       /**\r
-        * Formats and writes a message to the error log with the class name,\r
-        * throwable and the specified parameters, using log level info, warn or\r
-        * error appropriate for the specified severity\r
-        * \r
-        * @param classLogger\r
-        *            Logger for the class where the error occurred; the logger\r
-        *            carries the class name.\r
-        * @param epMessageEnum\r
-        *            Enum carrying alarm and error severity\r
-        * @param th\r
-        *            Throwable; ignored if null\r
-        * @param param\r
-        *            Array of Strings used to build the message.\r
-        */\r
-       @SuppressWarnings("static-access")\r
-       public static void logEcompError(EELFLoggerDelegate classLogger, EPAppMessagesEnum epMessageEnum, Throwable th,\r
-                       String... param) {\r
-\r
-               AlarmSeverityEnum alarmSeverityEnum = epMessageEnum.getAlarmSeverity();\r
-               ErrorSeverityEnum errorSeverityEnum = epMessageEnum.getErrorSeverity();\r
-\r
-               MDC.put(MDC_ALERT_SEVERITY, alarmSeverityEnum.name());\r
-               MDC.put("ErrorCode", epMessageEnum.getErrorCode());\r
-               MDC.put("ErrorDescription", epMessageEnum.getErrorDescription());\r
-\r
-               final String message = EPLogUtil.formatMessage(epMessageEnum.getDetails() + " " + epMessageEnum.getResolution(),\r
-                               (Object[]) param);\r
-               if (errorSeverityEnum == ErrorSeverityEnum.INFO) {\r
-                       if (th == null)\r
-                               classLogger.info(classLogger.errorLogger, message);\r
-                       else\r
-                               classLogger.info(classLogger.errorLogger, message, th);\r
-               } else if (errorSeverityEnum == ErrorSeverityEnum.WARN) {\r
-                       if (th == null)\r
-                               classLogger.warn(classLogger.errorLogger, message);\r
-                       else\r
-                               classLogger.warn(classLogger.errorLogger, message, th);\r
-               } else {\r
-                       if (th == null)\r
-                               classLogger.error(classLogger.errorLogger, message);\r
-                       else\r
-                               classLogger.error(classLogger.errorLogger, message, th);\r
-               }\r
-\r
-               // Clean up\r
-               MDC.remove(MDC_ALERT_SEVERITY);\r
-               MDC.remove("ErrorCode");\r
-               MDC.remove("ErrorDescription");\r
-       }\r
-\r
-       /**\r
-        * Builds a string using the format and parameters.\r
-        * @param message\r
-        * @param args\r
-        * @return\r
-        */\r
-       private static String formatMessage(String message, Object... args) {\r
-               StringBuilder sbFormattedMessage = new StringBuilder();\r
-               if (args != null && args.length > 0 && message != null && message != "") {\r
-                       MessageFormat mf = new MessageFormat(message);\r
-                       sbFormattedMessage.append(mf.format(args));\r
-               } else {\r
-                       sbFormattedMessage.append(message);\r
-               }\r
-               return sbFormattedMessage.toString();\r
-       }\r
-\r
-       /**\r
-        * Builds a comma-separated string of values to document a user action.\r
-        * \r
-        * @param action\r
-        * @param activity\r
-        * @param userId\r
-        * @param affectedId\r
-        * @param comment\r
-        * @return Value suitable for writing to the audit log file.\r
-        */\r
-       public static String formatAuditLogMessage(String action, String activity, String userId, String affectedId,\r
-                       String comment) {\r
-               StringBuilder auditLogMsg = new StringBuilder();\r
-               auditLogMsg.append("Click_A:[");\r
-               if (action != null && !action.equals("")) {\r
-                       auditLogMsg.append(" Action: ");\r
-                       auditLogMsg.append(action);\r
-               }\r
-\r
-               if (activity != null && !activity.equals("")) {\r
-                       auditLogMsg.append(",Activity CD: ");\r
-                       auditLogMsg.append(activity);\r
-               }\r
-\r
-               if (userId != null && !userId.equals("")) {\r
-                       auditLogMsg.append(",User ID: ");\r
-                       auditLogMsg.append(userId);\r
-               }\r
-\r
-               if (affectedId != null && !affectedId.equals("")) {\r
-                       auditLogMsg.append(",Affected ID: ");\r
-                       auditLogMsg.append(affectedId);\r
-               }\r
-\r
-               if (comment != null && !comment.equals("")) {\r
-                       auditLogMsg.append(",Comment: ");\r
-                       auditLogMsg.append(comment);\r
-               }\r
-               auditLogMsg.append("]");\r
-               return auditLogMsg.toString();\r
-       }\r
-\r
-       /**\r
-        * Builds a comma-separated string of values to document a user browser\r
-        * action.\r
-        * \r
-        * @param orgUserId\r
-        * @param action\r
-        * @param activity\r
-        * @param actionLink\r
-        * @param page\r
-        * @param function\r
-        * @param type\r
-        * @return Value suitable for writing to the audit log file.\r
-        */\r
-       public static String formatStoreAnalyticsAuditLogMessage(String orgUserId, String appName, String action, String activity,\r
-                       String actionLink, String page, String function, String type) {\r
-               StringBuilder auditLogStoreAnalyticsMsg = new StringBuilder();\r
-               auditLogStoreAnalyticsMsg.append("Click_Analytics:[");\r
-               if (orgUserId != null && !orgUserId.equals("")) {\r
-                       auditLogStoreAnalyticsMsg.append(" Organization User ID: ");\r
-                       auditLogStoreAnalyticsMsg.append(orgUserId);\r
-               }\r
-               \r
-               if (appName != null && !appName.equals("")) {\r
-                       auditLogStoreAnalyticsMsg.append(",AppName: ");\r
-                       auditLogStoreAnalyticsMsg.append(appName);\r
-               }\r
-\r
-               if (action != null && !action.equals("")) {\r
-                       auditLogStoreAnalyticsMsg.append(",Action: ");\r
-                       auditLogStoreAnalyticsMsg.append(action);\r
-               }\r
-\r
-               if (activity != null && !activity.equals("")) {\r
-                       auditLogStoreAnalyticsMsg.append(",Activity: ");\r
-                       auditLogStoreAnalyticsMsg.append(activity);\r
-               }\r
-\r
-               if (actionLink != null && !actionLink.equals("")) {\r
-                       auditLogStoreAnalyticsMsg.append(",ActionLink: ");\r
-                       auditLogStoreAnalyticsMsg.append(actionLink);\r
-               }\r
-\r
-               if (page != null && !page.equals("")) {\r
-                       auditLogStoreAnalyticsMsg.append(",Page: ");\r
-                       auditLogStoreAnalyticsMsg.append(page);\r
-               }\r
-\r
-               if (function != null && !function.equals("")) {\r
-                       auditLogStoreAnalyticsMsg.append(",Function: ");\r
-                       auditLogStoreAnalyticsMsg.append(function);\r
-               }\r
-\r
-               if (type != null && !type.equals("")) {\r
-                       auditLogStoreAnalyticsMsg.append(",Type: ");\r
-                       auditLogStoreAnalyticsMsg.append(type);\r
-               }\r
-               auditLogStoreAnalyticsMsg.append("]");\r
-               return auditLogStoreAnalyticsMsg.toString();\r
-       }\r
-\r
-}\r
+/*-
+ * ================================================================================
+ * ECOMP Portal
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ================================================================================
+ */
+package org.openecomp.portalapp.portal.logging.logic;
+
+import static com.att.eelf.configuration.Configuration.MDC_ALERT_SEVERITY;
+
+import java.text.MessageFormat;
+
+import org.openecomp.portalapp.portal.logging.format.EPAppMessagesEnum;
+import org.openecomp.portalsdk.core.logging.format.AlarmSeverityEnum;
+import org.openecomp.portalsdk.core.logging.format.ErrorSeverityEnum;
+import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.openecomp.portalsdk.core.web.support.UserUtils;
+import org.slf4j.MDC;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+public class EPLogUtil {
+
+       // This class has no logger of its own; it uses loggers passed to it.
+       private static EELFLogger errorLogger = EELFManager.getInstance().getErrorLogger();
+
+       /**
+        * Formats and writes a message to the error log with the class name and the
+        * specified parameters, using log level info, warn or error appropriate for
+        * the specified severity
+        * 
+        * @param classLogger
+        *            Logger for the class where the error occurred; the logger
+        *            carries the class name.
+        * @param epMessageEnum
+        *            Enum carrying alarm and error severity
+        * @param param
+        *            Values used to build the message.
+        */
+       public static void logEcompError(EELFLoggerDelegate classLogger, EPAppMessagesEnum epMessageEnum, String... param) {
+               logEcompError(classLogger, epMessageEnum, null, param);
+       }
+
+       /**
+        * Formats and writes a message to the error log with the class name and the
+        * specified parameters, using log level info, warn or error appropriate for
+        * the specified severity
+        * 
+        * @param classLogger
+        *            Logger for the class where the error occurred; the logger
+        *            carries the class name.
+        * @param epMessageEnum
+        *            Enum carrying alarm and error severity
+        * @param param
+        *            Values used to build the message.
+        */
+       public static void logEcompError(EPAppMessagesEnum epMessageEnum, String... param) {
+               try {
+                       AlarmSeverityEnum alarmSeverityEnum = epMessageEnum.getAlarmSeverity();
+                       ErrorSeverityEnum errorSeverityEnum = epMessageEnum.getErrorSeverity();
+
+                       MDC.put(MDC_ALERT_SEVERITY, alarmSeverityEnum.name());
+                       MDC.put("ErrorCode", epMessageEnum.getErrorCode());
+                       MDC.put("ErrorDescription", epMessageEnum.getErrorDescription());
+                       MDC.put("ClassName", EPLogUtil.class.getName());
+
+                       String resolution = EPLogUtil
+                                       .formatMessage(epMessageEnum.getDetails() + " " + epMessageEnum.getResolution(), (Object[]) param);
+                       if (errorSeverityEnum == ErrorSeverityEnum.WARN) {
+                               errorLogger.warn(resolution);
+                       } else if (errorSeverityEnum == ErrorSeverityEnum.INFO) {
+                               errorLogger.info(resolution);
+                       } else {
+                               errorLogger.error(resolution);
+                       }
+               } catch (Exception e) {
+                       errorLogger.error("Failed to log the error code. Details: " + UserUtils.getStackTrace(e));
+               } finally {
+                       MDC.remove("ErrorCode");
+                       MDC.remove("ErrorDescription");
+                       MDC.remove("ClassName");
+                       MDC.remove(MDC_ALERT_SEVERITY);
+               }
+       }
+
+       /**
+        * Formats and writes a message to the error log with the class name,
+        * throwable and the specified parameters, using log level info, warn or
+        * error appropriate for the specified severity
+        * 
+        * @param classLogger
+        *            Logger for the class where the error occurred; the logger
+        *            carries the class name.
+        * @param epMessageEnum
+        *            Enum carrying alarm and error severity
+        * @param th
+        *            Throwable; ignored if null
+        * @param param
+        *            Array of Strings used to build the message.
+        */
+       @SuppressWarnings("static-access")
+       public static void logEcompError(EELFLoggerDelegate classLogger, EPAppMessagesEnum epMessageEnum, Throwable th,
+                       String... param) {
+
+               AlarmSeverityEnum alarmSeverityEnum = epMessageEnum.getAlarmSeverity();
+               ErrorSeverityEnum errorSeverityEnum = epMessageEnum.getErrorSeverity();
+
+               MDC.put(MDC_ALERT_SEVERITY, alarmSeverityEnum.name());
+               MDC.put("ErrorCode", epMessageEnum.getErrorCode());
+               MDC.put("ErrorDescription", epMessageEnum.getErrorDescription());
+
+               final String message = EPLogUtil.formatMessage(epMessageEnum.getDetails() + " " + epMessageEnum.getResolution(),
+                               (Object[]) param);
+               if (errorSeverityEnum == ErrorSeverityEnum.INFO) {
+                       if (th == null)
+                               classLogger.info(classLogger.errorLogger, message);
+                       else
+                               classLogger.info(classLogger.errorLogger, message, th);
+               } else if (errorSeverityEnum == ErrorSeverityEnum.WARN) {
+                       if (th == null)
+                               classLogger.warn(classLogger.errorLogger, message);
+                       else
+                               classLogger.warn(classLogger.errorLogger, message, th);
+               } else {
+                       if (th == null)
+                               classLogger.error(classLogger.errorLogger, message);
+                       else
+                               classLogger.error(classLogger.errorLogger, message, th);
+               }
+
+               // Clean up
+               MDC.remove(MDC_ALERT_SEVERITY);
+               MDC.remove("ErrorCode");
+               MDC.remove("ErrorDescription");
+       }
+
+       /**
+        * Builds a string using the format and parameters.
+        * 
+        * @param message
+        * @param args
+        * @return
+        */
+       private static String formatMessage(String message, Object... args) {
+               StringBuilder sbFormattedMessage = new StringBuilder();
+               if (args != null && args.length > 0 && message != null && message != "") {
+                       MessageFormat mf = new MessageFormat(message);
+                       sbFormattedMessage.append(mf.format(args));
+               } else {
+                       sbFormattedMessage.append(message);
+               }
+               return sbFormattedMessage.toString();
+       }
+
+       /**
+        * Builds a comma-separated string of values to document a user action.
+        * 
+        * @param action
+        *            String
+        * @param activity
+        *            String
+        * @param userId
+        *            String
+        * @param affectedId
+        *            String
+        * @param comment
+        *            String
+        * @return Value suitable for writing to the audit log file.
+        */
+       public static String formatAuditLogMessage(String action, String activity, String userId, String affectedId,
+                       String comment) {
+               StringBuilder auditLogMsg = new StringBuilder();
+               auditLogMsg.append("Click_A:[");
+               if (action != null && !action.equals("")) {
+                       auditLogMsg.append(" Action: ");
+                       auditLogMsg.append(action);
+               }
+
+               if (activity != null && !activity.equals("")) {
+                       auditLogMsg.append(",Activity CD: ");
+                       auditLogMsg.append(activity);
+               }
+
+               if (userId != null && !userId.equals("")) {
+                       auditLogMsg.append(",User ID: ");
+                       auditLogMsg.append(userId);
+               }
+
+               if (affectedId != null && !affectedId.equals("")) {
+                       auditLogMsg.append(",Affected ID: ");
+                       auditLogMsg.append(affectedId);
+               }
+
+               if (comment != null && !comment.equals("")) {
+                       auditLogMsg.append(",Comment: ");
+                       auditLogMsg.append(comment);
+               }
+               auditLogMsg.append("]");
+               return auditLogMsg.toString();
+       }
+
+       /**
+        * Builds a comma-separated string of values to document a user browser
+        * action.
+        * 
+        * @param orgUserId
+        *            String
+        * @param appName
+        *            String
+        * @param action
+        *            String
+        * @param activity
+        *            String
+        * @param actionLink
+        *            String
+        * @param page
+        *            String
+        * @param function
+        *            String
+        * @param type
+        *            String
+        * @return String value suitable for writing to the audit log file.
+        */
+       public static String formatStoreAnalyticsAuditLogMessage(String orgUserId, String appName, String action,
+                       String activity, String actionLink, String page, String function, String type) {
+               StringBuilder auditLogStoreAnalyticsMsg = new StringBuilder();
+               auditLogStoreAnalyticsMsg.append("Click_Analytics:[");
+               if (orgUserId != null && !orgUserId.equals("")) {
+                       auditLogStoreAnalyticsMsg.append(" Organization User ID: ");
+                       auditLogStoreAnalyticsMsg.append(orgUserId);
+               }
+
+               if (appName != null && !appName.equals("")) {
+                       auditLogStoreAnalyticsMsg.append(",AppName: ");
+                       auditLogStoreAnalyticsMsg.append(appName);
+               }
+
+               if (action != null && !action.equals("")) {
+                       auditLogStoreAnalyticsMsg.append(",Action: ");
+                       auditLogStoreAnalyticsMsg.append(action);
+               }
+
+               if (activity != null && !activity.equals("")) {
+                       auditLogStoreAnalyticsMsg.append(",Activity: ");
+                       auditLogStoreAnalyticsMsg.append(activity);
+               }
+
+               if (actionLink != null && !actionLink.equals("")) {
+                       auditLogStoreAnalyticsMsg.append(",ActionLink: ");
+                       auditLogStoreAnalyticsMsg.append(actionLink);
+               }
+
+               if (page != null && !page.equals("")) {
+                       auditLogStoreAnalyticsMsg.append(",Page: ");
+                       auditLogStoreAnalyticsMsg.append(page);
+               }
+
+               if (function != null && !function.equals("")) {
+                       auditLogStoreAnalyticsMsg.append(",Function: ");
+                       auditLogStoreAnalyticsMsg.append(function);
+               }
+
+               if (type != null && !type.equals("")) {
+                       auditLogStoreAnalyticsMsg.append(",Type: ");
+                       auditLogStoreAnalyticsMsg.append(type);
+               }
+               auditLogStoreAnalyticsMsg.append("]");
+               return auditLogStoreAnalyticsMsg.toString();
+       }
+
+}