diff options
author | Ofir Sonsino <os0695@att.com> | 2018-02-20 18:03:30 +0200 |
---|---|---|
committer | Ofir Sonsino <os0695@intl.att.com> | 2018-02-27 14:47:52 +0200 |
commit | efedea1c5d80532f5b1180d57c8dafce5dcb302a (patch) | |
tree | c4bdefe8758b01f31c9e91a9ded0ab989daeb5e2 /vid-app-common/src/main/java/org/onap/vid/controllers/ControllersUtils.java | |
parent | b94bd70f1595fad9546c3506393613f68504f495 (diff) |
org.onap migration
Change-Id: I5e2d01a6da21d4003c910b5fe0702b35c2089a77
Issue-ID: VID-86
Signed-off-by: Ofir Sonsino <os0695@intl.att.com>
Diffstat (limited to 'vid-app-common/src/main/java/org/onap/vid/controllers/ControllersUtils.java')
-rw-r--r-- | vid-app-common/src/main/java/org/onap/vid/controllers/ControllersUtils.java | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/controllers/ControllersUtils.java b/vid-app-common/src/main/java/org/onap/vid/controllers/ControllersUtils.java new file mode 100644 index 00000000..3f8cfa6a --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/controllers/ControllersUtils.java @@ -0,0 +1,40 @@ +package org.onap.vid.controllers; + +import org.apache.commons.lang3.exception.ExceptionUtils; +import org.onap.portalsdk.core.domain.User; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.portalsdk.core.util.SystemProperties; +import org.onap.vid.model.ExceptionResponse; +import org.slf4j.MDC; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; + +import static com.att.eelf.configuration.Configuration.MDC_KEY_REQUEST_ID; +import static org.onap.vid.utils.Logging.getMethodName; + +public class ControllersUtils { + + + public static String extractUserId(HttpServletRequest request) { + String userId = ""; + HttpSession session = request.getSession(); + if (session != null) { + User user = (User) session.getAttribute(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME)); + if (user != null) { + //userId = user.getHrid(); + userId = user.getLoginId(); + if (userId == null) + userId = user.getOrgUserId(); + } + } + return userId; + } + + public static ExceptionResponse handleException(Exception e, EELFLoggerDelegate logger) { + logger.error(EELFLoggerDelegate.errorLogger, "{}: {}", getMethodName(), ExceptionUtils.getMessage(e), e); + + ExceptionResponse exceptionResponse = new ExceptionResponse(e); + return exceptionResponse; + } +} |