Add query params options to iframe
[sdc.git] / openecomp-be / lib / openecomp-sdc-logging-lib / openecomp-sdc-logging-core / src / main / java / org / openecomp / sdc / logging / context / impl / MdcDataErrorMessage.java
1 /*
2  * Copyright © 2016-2017 European Support Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  * 
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  * 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.openecomp.sdc.logging.context.impl;
18
19 import org.openecomp.sdc.logging.types.LoggerConstants;
20 import org.slf4j.MDC;
21
22
23 public class MdcDataErrorMessage {
24
25   private final String targetEntity;
26   private final String targetServiceName;
27   private final String errorDescription;
28   private final String level;
29   private final String errorCode;
30
31   /**
32    * Instantiates a new Mdc data error message.
33    *
34    * @param targetEntity      the target entity
35    * @param targetServiceName the target service name
36    * @param errorCategory     the error category
37    * @param errorCode         the error code
38    * @param errorDescription  the error description
39    */
40   public MdcDataErrorMessage(String targetEntity, String targetServiceName, String errorCategory,
41                              String errorCode, String errorDescription) {
42     this.level = errorCategory;
43     this.errorCode = errorCode;
44     this.targetEntity = targetEntity;
45     this.targetServiceName = targetServiceName;
46     this.errorDescription = errorDescription;
47
48     this.setMdcValues();
49   }
50
51   /**
52    * Create error message and update mdc.
53    *
54    * @param targetEntity      the target entity
55    * @param targetServiceName the target service name
56    * @param level             the level
57    * @param errorCode         the error code
58    * @param errorDescription  the error description
59    */
60   public static void createErrorMessageAndUpdateMdc(String targetEntity, String targetServiceName,
61                                                     String level, String errorCode,
62                                                     String errorDescription) {
63     // don't remove this line although it seems useless
64     new MdcDataErrorMessage(targetEntity, targetServiceName, level, errorCode, errorDescription);
65   }
66
67   public void setMdcValues() {
68     MDC.put(LoggerConstants.ERROR_CATEGORY, this.level);
69     MDC.put(LoggerConstants.ERROR_CODE, this.errorCode);
70     MDC.put(LoggerConstants.TARGET_ENTITY, this.targetEntity);
71     MDC.put(LoggerConstants.TARGET_SERVICE_NAME, this.targetServiceName);
72     MDC.put(LoggerConstants.ERROR_DESCRIPTION, this.errorDescription);
73   }
74 }