Sync Integ to Master
[sdc.git] / common-app-api / src / main / java / org / openecomp / sdc / be / config / ErrorInfo.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
21 package org.openecomp.sdc.be.config;
22
23 import org.openecomp.sdc.common.config.EcompErrorName;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26
27 public class ErrorInfo {
28
29         private Integer code;
30         private String message;
31         private String messageId;
32         private ErrorInfoType errorInfoType;
33
34         private static final String SVC_PREFIX = "SVC";
35         private static final String POL_PREFIX = "POL";
36
37         private static Logger log = LoggerFactory.getLogger(ErrorInfo.class.getName());
38
39         public ErrorInfo() {
40                 this.errorInfoType = ErrorInfoType.OK;
41         }
42
43         public Integer getCode() {
44                 return code;
45         }
46
47         public void setCode(Integer code) {
48                 this.code = code;
49         }
50
51         public String getMessage() {
52                 return message;
53         }
54
55         public void setMessage(String message) {
56                 this.message = message;
57         }
58
59         public String getMessageId() {
60                 return messageId;
61         }
62
63         public void setMessageId(String messageId) {
64                 // Determining the type of error
65                 if (messageId == null) {
66                         this.errorInfoType = ErrorInfoType.OK;
67                 } else if (messageId.startsWith(SVC_PREFIX)) {
68                         this.errorInfoType = ErrorInfoType.SERVICE_EXCEPTION;
69                 } else if (messageId.startsWith(POL_PREFIX)) {
70                         this.errorInfoType = ErrorInfoType.POLICY_EXCEPTION;
71                 } else {
72                         // unexpected - should it fail the startup?
73                         BeEcompErrorManager.getInstance().logErrorConfigFileFormat("Error Info",
74                                         "Could not set error info type for message id " + messageId);
75                         log.debug("Error: unexpected error message ID {}, should start with {} or {}", messageId, SVC_PREFIX,
76                                         POL_PREFIX);
77                 }
78                 this.messageId = messageId;
79         }
80
81         public ErrorInfoType getErrorInfoType() {
82                 return this.errorInfoType;
83         }
84
85         public void cloneData(ErrorInfo other) {
86                 this.code = other.getCode();
87                 this.message = other.getMessage();
88                 this.messageId = other.getMessageId();
89                 this.errorInfoType = other.errorInfoType;
90         }
91
92         @Override
93         public String toString() {
94                 return "ErrorInfo [code=" + code + ", messageId=" + messageId + ", message=" + message + "]";
95         }
96
97         public enum ErrorInfoType {
98                 OK, POLICY_EXCEPTION, SERVICE_EXCEPTION
99         }
100
101 }