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