pushing error and audit log changes for portal
[portal.git] / ecomp-portal-BE-common / src / main / java / org / onap / portalapp / portal / controller / RoleManageController.java
index 4d2abb8..70cca1f 100644 (file)
@@ -7,10 +7,10 @@
  * Modifications Copyright (c) 2019 Samsung 
  * ===================================================================
  * Modifications Copyright (c) 2020 IBM
- * ===================================================================
- * 
+ * =================================================================== 
+ *
  * Unless otherwise specified, all software contained herein is licensed
- * under the Apache License, Version 2.0 (the "License");
+ * under the Apache License, Version 2.0 (the "License"); 
  * you may not use this software except in compliance with the License.
  * You may obtain a copy of the License at
  * 
@@ -97,10 +97,8 @@ import org.springframework.context.annotation.EnableAspectJAutoProxy;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.servlet.ModelAndView;
 import com.fasterxml.jackson.databind.DeserializationFeature;
@@ -260,21 +258,13 @@ public class RoleManageController extends EPRestrictedBaseController {
                                                                "Deleted role for app:" + app.getId() + " and role:'" + roleId + "'",
                                                                PortalConstants.AUDIT_LOG_COMMENT_SIZE));
                                                auditService.logActivity(auditLog, null);
-                                               MDC.put(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP,
-                                                               EPEELFLoggerAdvice.getCurrentDateTimeUTC());
-                                               MDC.put(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP,
-                                                               EPEELFLoggerAdvice.getCurrentDateTimeUTC());
-                                               EcompPortalUtils.calculateDateTimeDifferenceForLog(
-                                                               MDC.get(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP),
-                                                               MDC.get(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP));
-                                               logger.info(EELFLoggerDelegate.auditLogger,
-                                                               EPLogUtil.formatAuditLogMessage("RoleManageController.removeRole",
-                                                                               EcompAuditLog.CD_ACTIVITY_EXTERNAL_AUTH_DELETE_ROLE,
-                                                                               String.valueOf(requestedUser.getId()), requestedUser.getOrgUserId(),
-                                                                               roleId.toString()));
-                                               MDC.remove(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP);
-                                               MDC.remove(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP);
-                                               MDC.remove(SystemProperties.MDC_TIMER);
+                                               String auditMessageInfo = EPLogUtil.formatAuditLogMessage("RoleManageController.removeRole",
+                                                               EcompAuditLog.CD_ACTIVITY_EXTERNAL_AUTH_DELETE_ROLE,
+                                                               String.valueOf(requestedUser.getId()), requestedUser.getOrgUserId(),
+                                                               roleId.toString());             
+                               
+                                               EPLogUtil.logAuditMessage(logger, auditMessageInfo);
+                                               
                                        } else {
                                                restCallStatus = "Remove Role failed";
                                                responseMap.put("error", externalRequestFieldsValidator.getDetailMessage());
@@ -381,19 +371,11 @@ public class RoleManageController extends EPRestrictedBaseController {
                                                                PortalConstants.AUDIT_LOG_COMMENT_SIZE));
                                                auditLog.setAffectedRecordId(user.getOrgUserId());
                                                auditService.logActivity(auditLog, null);
-                                               MDC.put(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP,
-                                                               EPEELFLoggerAdvice.getCurrentDateTimeUTC());
-                                               MDC.put(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP,
-                                                               EPEELFLoggerAdvice.getCurrentDateTimeUTC());
-                                               EcompPortalUtils.calculateDateTimeDifferenceForLog(
-                                                               MDC.get(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP),
-                                                               MDC.get(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP));
-                                               logger.info(EELFLoggerDelegate.auditLogger,
-                                                               EPLogUtil.formatAuditLogMessage("RoleManageController.saveRole", activityCode,
-                                                                               String.valueOf(user.getId()), user.getOrgUserId(), role.getName()));
-                                               MDC.remove(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP);
-                                               MDC.remove(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP);
-                                               MDC.remove(SystemProperties.MDC_TIMER);
+                                               String auditMessageInfo = EPLogUtil.formatAuditLogMessage("RoleManageController.saveRole", activityCode,
+                                                               String.valueOf(user.getId()), user.getOrgUserId(), role.getName());             
+                               
+                                               EPLogUtil.logAuditMessage(logger, auditMessageInfo);
+                                               
                                                responseMap.put("status", "Success");
                                                responseMap.put("role", domainRole);
                                        } else {
@@ -575,16 +557,10 @@ public class RoleManageController extends EPRestrictedBaseController {
                                "saveRoleFunction role for app:" + app.getId() + " and function:'" + code + "'",
                                PortalConstants.AUDIT_LOG_COMMENT_SIZE));
                auditService.logActivity(auditLog, null);
-               MDC.put(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP, EPEELFLoggerAdvice.getCurrentDateTimeUTC());
-               MDC.put(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP, EPEELFLoggerAdvice.getCurrentDateTimeUTC());
-               EcompPortalUtils.calculateDateTimeDifferenceForLog(MDC.get(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP),
-                               MDC.get(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP));
-               logger.info(EELFLoggerDelegate.auditLogger,
-                               EPLogUtil.formatAuditLogMessage("RoleManageController.saveRoleFunction", activityCode,
-                                               String.valueOf(requestedUser.getId()), requestedUser.getOrgUserId(), code));
-               MDC.remove(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP);
-               MDC.remove(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP);
-               MDC.remove(SystemProperties.MDC_TIMER);
+               String auditMessageInfo = EPLogUtil.formatAuditLogMessage("RoleManageController.saveRoleFunction", activityCode,
+                               String.valueOf(requestedUser.getId()), requestedUser.getOrgUserId(), code);             
+
+               EPLogUtil.logAuditMessage(logger, auditMessageInfo);
        }
 
        private void addIfTypeActionDoesNotExits(CentralV2RoleFunction domainRoleFunction) {
@@ -647,21 +623,12 @@ public class RoleManageController extends EPRestrictedBaseController {
                                                                                                + domainRoleFunction.getCode() + "'",
                                                                                PortalConstants.AUDIT_LOG_COMMENT_SIZE));
                                                auditService.logActivity(auditLog, null);
-                                               MDC.put(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP,
-                                                               EPEELFLoggerAdvice.getCurrentDateTimeUTC());
-                                               MDC.put(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP,
-                                                               EPEELFLoggerAdvice.getCurrentDateTimeUTC());
-                                               EcompPortalUtils.calculateDateTimeDifferenceForLog(
-                                                               MDC.get(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP),
-                                                               MDC.get(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP));
-                                               logger.info(EELFLoggerDelegate.auditLogger,
-                                                               EPLogUtil.formatAuditLogMessage("RoleManageController.removeRoleFunction",
-                                                                               EcompAuditLog.CD_ACTIVITY_EXTERNAL_AUTH_DELETE_FUNCTION,
-                                                                               String.valueOf(user.getId()), user.getOrgUserId(),
-                                                                               domainRoleFunction.getCode()));
-                                               MDC.remove(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP);
-                                               MDC.remove(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP);
-                                               MDC.remove(SystemProperties.MDC_TIMER);
+                                               String auditMessageInfo = EPLogUtil.formatAuditLogMessage("RoleManageController.removeRoleFunction",
+                                                               EcompAuditLog.CD_ACTIVITY_EXTERNAL_AUTH_DELETE_FUNCTION,
+                                                               String.valueOf(user.getId()), user.getOrgUserId(),
+                                                               domainRoleFunction.getCode());          
+
+                                               EPLogUtil.logAuditMessage(logger, auditMessageInfo);
                                                logger.info(EELFLoggerDelegate.auditLogger,
                                                                "Remove role function " + domainRoleFunction.getName());
                                        }