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;
41 private String aaiElsErrorCode = AaiElsErrorCode.UNKNOWN_ERROR;
44 * Instantiates a new error object.
46 public ErrorObject() {
51 * Creates an error object
53 * @param disposition the disposition
54 * @param category the category
55 * @param severity the severity
56 * @param httpResponseCode the http response code
57 * @param restErrorCode the rest error code
58 * @param errorCode the error code
59 * @param errorText the error text
61 public ErrorObject(String disposition, String category, String severity, Integer httpResponseCode,
62 String restErrorCode, String errorCode, String errorText) {
64 this.setDisposition(disposition);
65 this.setCategory(category);
66 this.severity = severity;
67 this.setHTTPResponseCode(httpResponseCode);
68 this.setRESTErrorCode(restErrorCode);
69 this.setErrorCode(errorCode);
70 this.setErrorText(errorText);
71 this.setAaiElsErrorCode(AaiElsErrorCode.UNKNOWN_ERROR);
77 * Instantiates a new error object.
79 * @param severity the severity
80 * @param errorCode the error code
81 * @param errorText the error text
82 * @param disposition the disposition
83 * @param category the category
85 public ErrorObject(String severity, String errorCode, String errorText, String disposition, String category) {
86 this(severity, Status.INTERNAL_SERVER_ERROR, errorCode, errorText, disposition, category);
90 * Instantiates a new error object.
92 * @param severity the severity
93 * @param httpResponseCode the http response code
94 * @param errorCode the error code
95 * @param errorText the error text
96 * @param disposition the disposition
97 * @param category the category
99 public ErrorObject(String severity, Integer httpResponseCode, String errorCode, String errorText,
100 String disposition, String category) {
102 this.severity = severity;
103 this.setHTTPResponseCode(httpResponseCode);
104 this.setErrorCode(errorCode);
105 this.setErrorText(errorText);
106 this.setDisposition(disposition);
107 this.setCategory(category);
108 this.setAaiElsErrorCode(AaiElsErrorCode.UNKNOWN_ERROR);
112 * Instantiates a new error object.
114 * @param severity the severity
115 * @param httpResponseCode the http response code
116 * @param errorCode the error code
117 * @param errorText the error text
118 * @param disposition the disposition
119 * @param category the category
121 public ErrorObject(String severity, Status httpResponseCode, String errorCode, String errorText, String disposition,
124 this.severity = severity;
125 this.setHTTPResponseCode(httpResponseCode);
126 this.setErrorCode(errorCode);
127 this.setErrorText(errorText);
128 this.setDisposition(disposition);
129 this.setCategory(category);
130 this.setAaiElsErrorCode(AaiElsErrorCode.UNKNOWN_ERROR);
134 * Gets the disposition.
136 * @return the disposition
138 public String getDisposition() {
143 * Sets the disposition.
145 * @param disposition the new disposition
147 public void setDisposition(String disposition) {
148 this.disposition = disposition;
154 * @return the category
156 public String getCategory() {
163 * @param category the new category
165 public void setCategory(String category) {
166 this.category = category;
172 * @return the severity
174 public String getSeverity() {
181 * @param severity the new severity
183 public void setSeverity(String severity) {
184 this.severity = severity;
188 * Gets the error code.
190 * @return the error code
192 public String getErrorCode() {
197 * Sets the error code.
199 * @param errorCode the new error code
201 public void setErrorCode(String errorCode) {
202 this.errorCode = errorCode;
206 * Gets the HTTP response code.
208 * @return the HTTP response code
210 public Status getHTTPResponseCode() {
211 return httpResponseCode;
215 * Sets the HTTP response code.
217 * @param httpResponseCode the new HTTP response code
219 public void setHTTPResponseCode(Integer httpResponseCode) {
220 this.httpResponseCode = Status.fromStatusCode(httpResponseCode);
221 if (this.httpResponseCode == null) {
222 throw new IllegalArgumentException(
223 "setHTTPResponseCode was passed an invalid Integer value, fix error.properties or your code "
229 * Sets the HTTP response code.
231 * @param httpResponseCode the new HTTP response code
233 public void setHTTPResponseCode(String httpResponseCode) {
234 this.httpResponseCode = Status.fromStatusCode(Integer.valueOf(httpResponseCode));
235 if (this.httpResponseCode == null) {
236 throw new IllegalArgumentException(
237 "setHTTPResponseCode was passed an invalid String value, fix error.properties or your code "
243 * Sets the REST error code.
245 * @param restErrorCode the new REST error code
247 public void setRESTErrorCode(String restErrorCode) {
248 this.restErrorCode = restErrorCode;
252 * Gets the REST error code.
254 * @return the REST error code
256 public String getRESTErrorCode() {
257 return this.restErrorCode;
261 * Sets the HTTP response code.
263 * @param httpResponseCode the new HTTP response code
265 public void setHTTPResponseCode(Status httpResponseCode) {
266 this.httpResponseCode = httpResponseCode;
267 if (this.httpResponseCode == null) {
268 throw new IllegalArgumentException(
269 "setHTTPResponseCode was passed an invalid String value, fix error.properties or your code "
275 * Gets the error text.
277 * @return the error text
279 public String getErrorText() {
284 * Sets the error text.
286 * @param errorText the new error text
288 public void setErrorText(String errorText) {
289 this.errorText = errorText;
295 * @return the details
297 public String getDetails() {
304 * @param details the new details
306 public void setDetails(String details) {
307 this.details = details == null ? "" : details;
311 * Sets the aai els error code.
313 * @param elsErrorCode the new code
315 public void setAaiElsErrorCode(String elsErrorCode) {
316 aaiElsErrorCode = elsErrorCode;
320 * Gets the aai els error code.
324 public String getAaiElsErrorCode() {
325 return (aaiElsErrorCode);
329 * Gets the error code string. This is also the string
330 * configured in Nagios to alert on
332 * @return the error code string
334 // Get the X.Y.Z representation of the error code
335 public String getErrorCodeString() {
336 String prefix = null;
337 switch (disposition) {
345 return prefix + disposition + "." + category + "." + errorCode;
349 * Gets the severity Code. This is also the string
350 * configured in Nagios to alert on
352 * @return the severity
354 // Get the numerical value of severity
355 public String getSeverityCode(String severity) {
356 String severityCode = "";
375 public String toString() {
376 return "ErrorObject [errorCode=" + errorCode + ", errorText=" + errorText + ", restErrorCode=" + restErrorCode
377 + ", httpResponseCode=" + httpResponseCode + ", severity=" + severity + ", disposition=" + disposition
378 + ", category=" + category + "]";