pushing error and audit log changes for portal
[portal.git] / ecomp-portal-BE-common / src / main / java / org / onap / portalapp / portal / controller / PortalAdminController.java
index 32b28c7..4d687e4 100644 (file)
@@ -4,6 +4,8 @@
  * ===================================================================
  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
  * ===================================================================
+ *  Modification Copyright © 2020 IBM.
+ * ===================================================================
  *
  * Unless otherwise specified, all software contained herein is licensed
  * under the Apache License, Version 2.0 (the "License");
@@ -68,8 +70,9 @@ import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.EnableAspectJAutoProxy;
 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.RequestMethod;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.DeleteMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 @RestController
@@ -92,7 +95,7 @@ public class PortalAdminController extends EPRestrictedBaseController {
                this.auditService = auditService;
        }
 
-       @RequestMapping(value = { "/portalApi/portalAdmins" }, method = RequestMethod.GET, produces = "application/json")
+       @GetMapping(value = { "/portalApi/portalAdmins" }, produces = "application/json")
        public List<PortalAdmin> getPortalAdmins(HttpServletRequest request, HttpServletResponse response) {
                EPUser user = EPUserUtils.getUserSession(request);
                List<PortalAdmin> portalAdmins = null;
@@ -120,7 +123,7 @@ public class PortalAdminController extends EPRestrictedBaseController {
         * @param response 
         * @return FieldsValidator 
         */
-       @RequestMapping(value = { "/portalApi/portalAdmin" }, method = RequestMethod.POST)
+       @PostMapping(value = { "/portalApi/portalAdmin" })
        public FieldsValidator createPortalAdmin(HttpServletRequest request, @RequestBody String userId,
                        HttpServletResponse response) {
                EPUser user = EPUserUtils.getUserSession(request);
@@ -148,18 +151,11 @@ public class PortalAdminController extends EPRestrictedBaseController {
                                } catch (Exception e) {
                                        logger.error(EELFLoggerDelegate.errorLogger, "createPortalAdmin: failed for save audit log", e);
                                }
-                               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("PortalAdminController.createPortalAdmin",
-                                                               EcompAuditLog.CD_ACTIVITY_ADD_PORTAL_ADMIN, user.getOrgUserId(), userId,
-                                                               "A new Portal Admin has been added"));
-                               MDC.remove(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP);
-                               MDC.remove(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP);
-                               MDC.remove(SystemProperties.MDC_TIMER);
+                               String auditMessageInfo = EPLogUtil.formatAuditLogMessage("PortalAdminController.createPortalAdmin",
+                                                       EcompAuditLog.CD_ACTIVITY_ADD_PORTAL_ADMIN, user.getOrgUserId(), userId,
+                                                       "A new Portal Admin has been added");           
+                       
+                               EPLogUtil.logAuditMessage(logger, auditMessageInfo);
                        }
                }
                EcompPortalUtils.logAndSerializeObject(logger, "/portalAdmin", "POST result =", response.getStatus());
@@ -167,7 +163,7 @@ public class PortalAdminController extends EPRestrictedBaseController {
                return fieldsValidator;
        }
 
-       @RequestMapping(value = { "/portalApi/portalAdmin/{userInfo}" }, method = RequestMethod.DELETE)
+       @DeleteMapping(value = { "/portalApi/portalAdmin/{userInfo}" })
        public FieldsValidator deletePortalAdmin(HttpServletRequest request, @PathVariable("userInfo") String userInfo,
                        HttpServletResponse response) {
 
@@ -205,19 +201,12 @@ public class PortalAdminController extends EPRestrictedBaseController {
                                auditLog.setActivityCode(EcompAuditLog.CD_ACTIVITY_DELETE_PORTAL_ADMIN);
                                auditLog.setAffectedRecordId(sbcid);
                                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("PortalAdminController.deletePortalAdmin",
-                                                               EcompAuditLog.CD_ACTIVITY_DELETE_PORTAL_ADMIN, user.getOrgUserId(), sbcid,
-                                                               "A Portal Admin has been deleted"));
-                               MDC.remove(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP);
-                               MDC.remove(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP);
-                               MDC.remove(SystemProperties.MDC_TIMER);
+                               String auditMessageInfo = EPLogUtil.formatAuditLogMessage("PortalAdminController.deletePortalAdmin",
+                                               EcompAuditLog.CD_ACTIVITY_DELETE_PORTAL_ADMIN, user.getOrgUserId(), sbcid,
+                                               "A Portal Admin has been deleted");             
+               
+                               EPLogUtil.logAuditMessage(logger, auditMessageInfo);
+                       
                        }
                }
                EcompPortalUtils.logAndSerializeObject(logger, "/portalAdmin", "DELETE result =", response.getStatus());
@@ -225,8 +214,8 @@ public class PortalAdminController extends EPRestrictedBaseController {
                return fieldsValidator;
        }
 
-       @RequestMapping(value = {
-                       "/portalApi/adminAppsRoles/{appId}" }, method = RequestMethod.GET, produces = "application/json")
+       @GetMapping(value = {
+                       "/portalApi/adminAppsRoles/{appId}" }, produces = "application/json")
        public List<EPRole> getRolesByApp(HttpServletRequest request, @PathVariable("appId") Long appId,
                        HttpServletResponse response) {
                EPUser user = EPUserUtils.getUserSession(request);