3f8cfa6aa1faf16114c9520ed49af63619cbe353
[vid.git] / vid-app-common / src / main / java / org / onap / vid / controllers / ControllersUtils.java
1 package org.onap.vid.controllers;
2
3 import org.apache.commons.lang3.exception.ExceptionUtils;
4 import org.onap.portalsdk.core.domain.User;
5 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
6 import org.onap.portalsdk.core.util.SystemProperties;
7 import org.onap.vid.model.ExceptionResponse;
8 import org.slf4j.MDC;
9
10 import javax.servlet.http.HttpServletRequest;
11 import javax.servlet.http.HttpSession;
12
13 import static com.att.eelf.configuration.Configuration.MDC_KEY_REQUEST_ID;
14 import static org.onap.vid.utils.Logging.getMethodName;
15
16 public class ControllersUtils {
17
18
19     public static String extractUserId(HttpServletRequest request) {
20         String userId = "";
21         HttpSession session = request.getSession();
22         if (session != null) {
23             User user = (User) session.getAttribute(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME));
24             if (user != null) {
25                 //userId = user.getHrid();
26                 userId = user.getLoginId();
27                 if (userId == null)
28                     userId = user.getOrgUserId();
29             }
30         }
31         return userId;
32     }
33
34     public static ExceptionResponse handleException(Exception e, EELFLoggerDelegate logger) {
35         logger.error(EELFLoggerDelegate.errorLogger, "{}: {}", getMethodName(), ExceptionUtils.getMessage(e), e);
36
37         ExceptionResponse exceptionResponse = new ExceptionResponse(e);
38         return exceptionResponse;
39     }
40 }