2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 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=========================================================
21 package org.onap.aai.logging;
23 import javax.ws.rs.core.Response.Status;
27 * Contains the definition of all error message fields to be mapped from the Error
31 public class ErrorObject {
33 private String disposition;
34 private String category;
35 private String severity;
36 private Status httpResponseCode = Status.INTERNAL_SERVER_ERROR; // default
37 private String restErrorCode = "3002";
38 private String errorCode;
39 private String errorText;
40 private String details;
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,
61 String restErrorCode, String errorCode, String errorText) {
63 this.setDisposition(disposition);
64 this.setCategory(category);
65 this.severity = severity;
66 this.setHTTPResponseCode(httpResponseCode);
67 this.setRESTErrorCode(restErrorCode);
68 this.setErrorCode(errorCode);
69 this.setErrorText(errorText);
75 * Instantiates a new error object.
77 * @param severity the severity
78 * @param errorCode the error code
79 * @param errorText the error text
80 * @param disposition the disposition
81 * @param category the category
83 public ErrorObject(String severity, String errorCode, String errorText, String disposition, String category) {
84 this(severity, Status.INTERNAL_SERVER_ERROR, errorCode, errorText, disposition, category);
88 * Instantiates a new error object.
90 * @param severity the severity
91 * @param httpResponseCode the http response code
92 * @param errorCode the error code
93 * @param errorText the error text
94 * @param disposition the disposition
95 * @param category the category
97 public ErrorObject(String severity, Integer httpResponseCode, String errorCode, String errorText,
98 String disposition, String category) {
100 this.severity = severity;
101 this.setHTTPResponseCode(httpResponseCode);
102 this.setErrorCode(errorCode);
103 this.setErrorText(errorText);
104 this.setDisposition(disposition);
105 this.setCategory(category);
109 * Instantiates a new error object.
111 * @param severity the severity
112 * @param httpResponseCode the http response code
113 * @param errorCode the error code
114 * @param errorText the error text
115 * @param disposition the disposition
116 * @param category the category
118 public ErrorObject(String severity, Status httpResponseCode, String errorCode, String errorText, String disposition,
121 this.severity = severity;
122 this.setHTTPResponseCode(httpResponseCode);
123 this.setErrorCode(errorCode);
124 this.setErrorText(errorText);
125 this.setDisposition(disposition);
126 this.setCategory(category);
130 * Gets the disposition.
132 * @return the disposition
134 public String getDisposition() {
139 * Sets the disposition.
141 * @param disposition the new disposition
143 public void setDisposition(String disposition) {
144 this.disposition = disposition;
150 * @return the category
152 public String getCategory() {
159 * @param category the new category
161 public void setCategory(String category) {
162 this.category = category;
168 * @return the severity
170 public String getSeverity() {
177 * @param severity the new severity
179 public void setSeverity(String severity) {
180 this.severity = severity;
184 * Gets the error code.
186 * @return the error code
188 public String getErrorCode() {
193 * Sets the error code.
195 * @param errorCode the new error code
197 public void setErrorCode(String errorCode) {
198 this.errorCode = errorCode;
202 * Gets the HTTP response code.
204 * @return the HTTP response code
206 public Status getHTTPResponseCode() {
207 return httpResponseCode;
211 * Sets the HTTP response code.
213 * @param httpResponseCode the new HTTP response code
215 public void setHTTPResponseCode(Integer httpResponseCode) {
216 this.httpResponseCode = Status.fromStatusCode(httpResponseCode);
217 if (this.httpResponseCode == null) {
218 throw new IllegalArgumentException(
219 "setHTTPResponseCode was passed an invalid Integer value, fix error.properties or your code "
225 * Sets the HTTP response code.
227 * @param httpResponseCode the new HTTP response code
229 public void setHTTPResponseCode(String httpResponseCode) {
230 this.httpResponseCode = Status.fromStatusCode(Integer.valueOf(httpResponseCode));
231 if (this.httpResponseCode == null) {
232 throw new IllegalArgumentException(
233 "setHTTPResponseCode was passed an invalid String value, fix error.properties or your code "
239 * Sets the REST error code.
241 * @param restErrorCode the new REST error code
243 public void setRESTErrorCode(String restErrorCode) {
244 this.restErrorCode = restErrorCode;
248 * Gets the REST error code.
250 * @return the REST error code
252 public String getRESTErrorCode() {
253 return this.restErrorCode;
257 * Sets the HTTP response code.
259 * @param httpResponseCode the new HTTP response code
261 public void setHTTPResponseCode(Status httpResponseCode) {
262 this.httpResponseCode = httpResponseCode;
263 if (this.httpResponseCode == null) {
264 throw new IllegalArgumentException(
265 "setHTTPResponseCode was passed an invalid String value, fix error.properties or your code "
271 * Gets the error text.
273 * @return the error text
275 public String getErrorText() {
280 * Sets the error text.
282 * @param errorText the new error text
284 public void setErrorText(String errorText) {
285 this.errorText = errorText;
291 * @return the details
293 public String getDetails() {
300 * @param details the new details
302 public void setDetails(String details) {
303 this.details = details == null ? "" : details;
307 * Gets the error code string. This is also the string
308 * configured in Nagios to alert on
310 * @return the error code string
312 // Get the X.Y.Z representation of the error code
313 public String getErrorCodeString() {
314 String prefix = null;
315 switch (disposition) {
323 return prefix + disposition + "." + category + "." + errorCode;
327 * Gets the severity Code. This is also the string
328 * configured in Nagios to alert on
330 * @return the severity
332 // Get the numerical value of severity
333 public String getSeverityCode(String severity) {
334 String severityCode = "";
353 public String toString() {
354 return "ErrorObject [errorCode=" + errorCode + ", errorText=" + errorText + ", restErrorCode=" + restErrorCode
355 + ", httpResponseCode=" + httpResponseCode + ", severity=" + severity + ", disposition=" + disposition
356 + ", category=" + category + "]";