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.
78 * @param severity the severity
79 * @param errorCode the error code
80 * @param errorText the error text
81 * @param disposition the disposition
82 * @param category the category
84 public ErrorObject(String severity, String errorCode, String errorText, String disposition, String category) {
85 this(severity, Status.INTERNAL_SERVER_ERROR, errorCode, errorText, disposition, category);
89 * Instantiates a new error object.
91 * @param severity the severity
92 * @param httpResponseCode the http response code
93 * @param errorCode the error code
94 * @param errorText the error text
95 * @param disposition the disposition
96 * @param category the category
98 public ErrorObject(String severity, Integer httpResponseCode, String errorCode, String errorText,
99 String disposition, String category) {
101 this.severity = severity;
102 this.setHTTPResponseCode(httpResponseCode);
103 this.setErrorCode(errorCode);
104 this.setErrorText(errorText);
105 this.setDisposition(disposition);
106 this.setCategory(category);
107 this.setAaiElsErrorCode(AaiElsErrorCode.UNKNOWN_ERROR);
111 * Instantiates a new error object.
113 * @param severity the severity
114 * @param httpResponseCode the http response code
115 * @param errorCode the error code
116 * @param errorText the error text
117 * @param disposition the disposition
118 * @param category the category
120 public ErrorObject(String severity, Status httpResponseCode, String errorCode, String errorText, String disposition,
123 this.severity = severity;
124 this.setHTTPResponseCode(httpResponseCode);
125 this.setErrorCode(errorCode);
126 this.setErrorText(errorText);
127 this.setDisposition(disposition);
128 this.setCategory(category);
129 this.setAaiElsErrorCode(AaiElsErrorCode.UNKNOWN_ERROR);
133 * Gets the disposition.
135 * @return the disposition
137 public String getDisposition() {
142 * Sets the disposition.
144 * @param disposition the new disposition
146 public void setDisposition(String disposition) {
147 this.disposition = disposition;
153 * @return the category
155 public String getCategory() {
162 * @param category the new category
164 public void setCategory(String category) {
165 this.category = category;
171 * @return the severity
173 public String getSeverity() {
180 * @param severity the new severity
182 public void setSeverity(String severity) {
183 this.severity = severity;
187 * Gets the error code.
189 * @return the error code
191 public String getErrorCode() {
196 * Sets the error code.
198 * @param errorCode the new error code
200 public void setErrorCode(String errorCode) {
201 this.errorCode = errorCode;
205 * Gets the HTTP response code.
207 * @return the HTTP response code
209 public Status getHTTPResponseCode() {
210 return httpResponseCode;
214 * Sets the HTTP response code.
216 * @param httpResponseCode the new HTTP response code
218 public void setHTTPResponseCode(Integer httpResponseCode) {
219 this.httpResponseCode = Status.fromStatusCode(httpResponseCode);
220 if (this.httpResponseCode == null) {
221 throw new IllegalArgumentException(
222 "setHTTPResponseCode was passed an invalid Integer value, fix error.properties or your code "
228 * Sets the HTTP response code.
230 * @param httpResponseCode the new HTTP response code
232 public void setHTTPResponseCode(String httpResponseCode) {
233 this.httpResponseCode = Status.fromStatusCode(Integer.valueOf(httpResponseCode));
234 if (this.httpResponseCode == null) {
235 throw new IllegalArgumentException(
236 "setHTTPResponseCode was passed an invalid String value, fix error.properties or your code "
242 * Sets the REST error code.
244 * @param restErrorCode the new REST error code
246 public void setRESTErrorCode(String restErrorCode) {
247 this.restErrorCode = restErrorCode;
251 * Gets the REST error code.
253 * @return the REST error code
255 public String getRESTErrorCode() {
256 return this.restErrorCode;
260 * Sets the HTTP response code.
262 * @param httpResponseCode the new HTTP response code
264 public void setHTTPResponseCode(Status httpResponseCode) {
265 this.httpResponseCode = httpResponseCode;
266 if (this.httpResponseCode == null) {
267 throw new IllegalArgumentException(
268 "setHTTPResponseCode was passed an invalid String value, fix error.properties or your code "
274 * Gets the error text.
276 * @return the error text
278 public String getErrorText() {
283 * Sets the error text.
285 * @param errorText the new error text
287 public void setErrorText(String errorText) {
288 this.errorText = errorText;
294 * @return the details
296 public String getDetails() {
303 * @param details the new details
305 public void setDetails(String details) {
306 this.details = details == null ? "" : details;
309 * Sets the aai els error code.
311 * @param elsErrorCode the new code
313 public void setAaiElsErrorCode(String elsErrorCode) {
314 aaiElsErrorCode = elsErrorCode;
317 * Gets the aai els error code.
321 public String getAaiElsErrorCode() {
322 return (aaiElsErrorCode);
325 * Gets the error code string. This is also the string
326 * configured in Nagios to alert on
328 * @return the error code string
330 // Get the X.Y.Z representation of the error code
331 public String getErrorCodeString() {
332 String prefix = null;
333 switch (disposition) {
341 return prefix + disposition + "." + category + "." + errorCode;
345 * Gets the severity Code. This is also the string
346 * configured in Nagios to alert on
348 * @return the severity
350 // Get the numerical value of severity
351 public String getSeverityCode(String severity) {
352 String severityCode = "";
371 public String toString() {
372 return "ErrorObject [errorCode=" + errorCode + ", errorText=" + errorText + ", restErrorCode=" + restErrorCode
373 + ", httpResponseCode=" + httpResponseCode + ", severity=" + severity + ", disposition=" + disposition
374 + ", category=" + category + "]";