Release version 1.13.7
[sdc.git] / catalog-fe / src / main / java / org / openecomp / sdc / fe / impl / Audit.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.openecomp.sdc.fe.impl;
21
22 import java.util.Map;
23 import javax.servlet.http.HttpServletRequest;
24 import org.openecomp.sdc.common.api.Constants;
25 import org.slf4j.Logger;
26
27 public class Audit {
28
29     private Audit() {
30     }
31
32     public static void error(Logger log, HttpRequestInfo requestInfo, int status) {
33         String errorMsg = "Internal Error";
34         if (requestInfo != null && requestInfo.getHeaders() != null) {
35             Map<String, String> requestHeaders = requestInfo.getHeaders();
36             errorMsg = String.format(Constants.ERROR_LOG_FORMAT, requestHeaders.get(Constants.USER_ID_HEADER),
37                 requestHeaders.get(Constants.FIRST_NAME_HEADER) + " " + requestHeaders.get(Constants.LAST_NAME_HEADER),
38                 requestHeaders.get(Constants.ORIGIN_HEADER), requestHeaders.get(Constants.ACCESS_HEADER), requestInfo.getRequestURL(), status);
39         }
40         log.error(errorMsg);
41     }
42
43     public static void error(Logger log, HttpServletRequest request, int status) {
44         String errorMsg = "Internal Error";
45         if (request != null) {
46             errorMsg = String.format(Constants.ERROR_LOG_FORMAT, request.getHeader(Constants.USER_ID_HEADER),
47                 request.getHeader(Constants.FIRST_NAME_HEADER) + " " + request.getHeader(Constants.LAST_NAME_HEADER),
48                 request.getHeader(Constants.ORIGIN_HEADER), request.getHeader(Constants.ACCESS_HEADER), request.getRequestURL(), status);
49         }
50         log.error(errorMsg);
51     }
52
53     public static void info(Logger log, HttpRequestInfo requestInfo, int status) {
54         String errorMsg = "Internal Error";
55         if (requestInfo != null && requestInfo.getHeaders() != null) {
56             Map<String, String> requestHeaders = requestInfo.getHeaders();
57             errorMsg = String.format(Constants.ERROR_LOG_FORMAT, requestHeaders.get(Constants.USER_ID_HEADER),
58                 requestHeaders.get(Constants.FIRST_NAME_HEADER) + " " + requestHeaders.get(Constants.LAST_NAME_HEADER),
59                 requestHeaders.get(Constants.ORIGIN_HEADER), requestHeaders.get(Constants.ACCESS_HEADER), requestInfo.getRequestURL(), status);
60         }
61         log.info(errorMsg);
62     }
63 }