2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 package org.onap.aai.logging;
24 import javax.ws.rs.core.Response.Status;
28 * Contains the definition of all error message fields to be mapped from the Error
32 public class ErrorObject {
34 private String disposition;
35 private String category;
36 private String severity;
37 private Status httpResponseCode = Status.INTERNAL_SERVER_ERROR; // default
38 private String restErrorCode = "3002";
39 private String errorCode;
40 private String errorText;
43 * Instantiates a new error object.
45 public ErrorObject() {
50 * Creates an error object with the default HTTP Error Code (Status.INTERNAL_SERVER_ERROR)
52 * @param disposition the disposition
53 * @param category the category
54 * @param severity the severity
55 * @param httpResponseCode the http response code
56 * @param restErrorCode the rest error code
57 * @param errorCode the error code
58 * @param errorText the error text
60 public ErrorObject(String disposition, String category, String severity, Integer httpResponseCode, String restErrorCode, String errorCode, String errorText) {
62 this.setDisposition(disposition);
63 this.setCategory(category);
64 this.severity = severity;
65 this.setHTTPResponseCode(httpResponseCode);
66 this.setRESTErrorCode(restErrorCode);
67 this.setErrorCode(errorCode);
68 this.setErrorText(errorText);
74 * Instantiates a new error object.
76 * @param severity the severity
77 * @param errorCode the error code
78 * @param errorText the error text
79 * @param disposition the disposition
80 * @param category the category
82 public ErrorObject(String severity, String errorCode, String errorText, String disposition, String category) {
83 this(severity, Status.INTERNAL_SERVER_ERROR, errorCode, errorText, disposition, category);
87 * Instantiates a new error object.
89 * @param severity the severity
90 * @param httpResponseCode the http response code
91 * @param errorCode the error code
92 * @param errorText the error text
93 * @param disposition the disposition
94 * @param category the category
96 public ErrorObject(String severity, Integer httpResponseCode, String errorCode, String errorText, String disposition, String category) {
98 this.severity = severity;
99 this.setHTTPResponseCode(httpResponseCode);
100 this.setErrorCode(errorCode);
101 this.setErrorText(errorText);
102 this.setDisposition(disposition);
103 this.setCategory(category);
107 * Instantiates a new error object.
109 * @param severity the severity
110 * @param httpResponseCode the http response code
111 * @param errorCode the error code
112 * @param errorText the error text
113 * @param disposition the disposition
114 * @param category the category
116 public ErrorObject(String severity, Status httpResponseCode, String errorCode, String errorText, String disposition, String category) {
118 this.severity = severity;
119 this.setHTTPResponseCode(httpResponseCode);
120 this.setErrorCode(errorCode);
121 this.setErrorText(errorText);
122 this.setDisposition(disposition);
123 this.setCategory(category);
127 * Gets the disposition.
129 * @return the disposition
131 public String getDisposition() {
136 * Sets the disposition.
138 * @param disposition the new disposition
140 public void setDisposition(String disposition) {
141 this.disposition = disposition;
147 * @return the category
149 public String getCategory() {
156 * @param category the new category
158 public void setCategory(String category) {
159 this.category = category;
165 * @return the severity
167 public String getSeverity() {
174 * @param severity the new severity
176 public void setSeverity(String severity) {
177 this.severity = severity;
181 * Gets the error code.
183 * @return the error code
185 public String getErrorCode() {
190 * Sets the error code.
192 * @param errorCode the new error code
194 public void setErrorCode(String errorCode) {
195 this.errorCode = errorCode;
199 * Gets the HTTP response code.
201 * @return the HTTP response code
203 public Status getHTTPResponseCode() {
204 return httpResponseCode;
208 * Sets the HTTP response code.
210 * @param httpResponseCode the new HTTP response code
212 public void setHTTPResponseCode(Integer httpResponseCode) {
213 this.httpResponseCode = Status.fromStatusCode(httpResponseCode);
214 if (this.httpResponseCode == null) {
215 throw new IllegalArgumentException("setHTTPResponseCode was passed an invalid Integer value, fix error.properties or your code "+httpResponseCode);
220 * Sets the HTTP response code.
222 * @param httpResponseCode the new HTTP response code
224 public void setHTTPResponseCode(String httpResponseCode) {
225 this.httpResponseCode = Status.fromStatusCode(Integer.valueOf(httpResponseCode));
226 if (this.httpResponseCode == null) {
227 throw new IllegalArgumentException("setHTTPResponseCode was passed an invalid String value, fix error.properties or your code "+httpResponseCode);
232 * Sets the REST error code.
234 * @param restErrorCode the new REST error code
236 public void setRESTErrorCode(String restErrorCode) {
237 this.restErrorCode = restErrorCode;
241 * Gets the REST error code.
243 * @return the REST error code
245 public String getRESTErrorCode() {
246 return this.restErrorCode;
250 * Sets the HTTP response code.
252 * @param httpResponseCode the new HTTP response code
254 public void setHTTPResponseCode(Status httpResponseCode) {
255 this.httpResponseCode = httpResponseCode;
256 if (this.httpResponseCode == null) {
257 throw new IllegalArgumentException("setHTTPResponseCode was passed an invalid String value, fix error.properties or your code "+httpResponseCode);
262 * Gets the error text.
264 * @return the error text
266 public String getErrorText() {
271 * Sets the error text.
273 * @param errorText the new error text
275 public void setErrorText(String errorText) {
276 this.errorText = errorText;
280 * Gets the error code string. This is also the string
281 * configured in Nagios to alert on
283 * @return the error code string
285 // Get the X.Y.Z representation of the error code
286 public String getErrorCodeString() {
287 String prefix = null;
288 switch (disposition) {
296 return prefix + disposition + "." + category + "." + errorCode;
300 * Gets the severity Code. This is also the string
301 * configured in Nagios to alert on
303 * @return the severity
305 // Get the numerical value of severity
306 public String getSeverityCode(String severity) {
307 String severityCode = "";
326 public String toString() {
327 return "ErrorObject [errorCode="+ errorCode + ", errorText=" + errorText
328 + ", restErrorCode=" + restErrorCode + ", httpResponseCode="+ httpResponseCode
329 + ", severity=" + severity + ", disposition=" + disposition + ", category=" + category +"]";