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=========================================================
20 package org.onap.aai.logging;
22 import javax.ws.rs.core.Response.Status;
26 * Contains the definition of all error message fields to be mapped from the Error
30 public class ErrorObject {
32 private String disposition;
33 private String category;
34 private String severity;
35 private Status httpResponseCode = Status.INTERNAL_SERVER_ERROR; // default
36 private String restErrorCode = "3002";
37 private String errorCode;
38 private String errorText;
41 * Instantiates a new error object.
43 public ErrorObject() {
48 * Creates an error object with the default HTTP Error Code (Status.INTERNAL_SERVER_ERROR)
50 * @param disposition the disposition
51 * @param category the category
52 * @param severity the severity
53 * @param httpResponseCode the http response code
54 * @param restErrorCode the rest error code
55 * @param errorCode the error code
56 * @param errorText the error text
58 public ErrorObject(String disposition, String category, String severity, Integer httpResponseCode, String restErrorCode, String errorCode, String errorText) {
60 this.setDisposition(disposition);
61 this.setCategory(category);
62 this.severity = severity;
63 this.setHTTPResponseCode(httpResponseCode);
64 this.setRESTErrorCode(restErrorCode);
65 this.setErrorCode(errorCode);
66 this.setErrorText(errorText);
72 * Instantiates a new error object.
74 * @param severity the severity
75 * @param errorCode the error code
76 * @param errorText the error text
77 * @param disposition the disposition
78 * @param category the category
80 public ErrorObject(String severity, String errorCode, String errorText, String disposition, String category) {
81 this(severity, Status.INTERNAL_SERVER_ERROR, errorCode, errorText, disposition, category);
85 * Instantiates a new error object.
87 * @param severity the severity
88 * @param httpResponseCode the http response code
89 * @param errorCode the error code
90 * @param errorText the error text
91 * @param disposition the disposition
92 * @param category the category
94 public ErrorObject(String severity, Integer httpResponseCode, String errorCode, String errorText, String disposition, String category) {
96 this.severity = severity;
97 this.setHTTPResponseCode(httpResponseCode);
98 this.setErrorCode(errorCode);
99 this.setErrorText(errorText);
100 this.setDisposition(disposition);
101 this.setCategory(category);
105 * Instantiates a new error object.
107 * @param severity the severity
108 * @param httpResponseCode the http response code
109 * @param errorCode the error code
110 * @param errorText the error text
111 * @param disposition the disposition
112 * @param category the category
114 public ErrorObject(String severity, Status httpResponseCode, String errorCode, String errorText, String disposition, String category) {
116 this.severity = severity;
117 this.setHTTPResponseCode(httpResponseCode);
118 this.setErrorCode(errorCode);
119 this.setErrorText(errorText);
120 this.setDisposition(disposition);
121 this.setCategory(category);
125 * Gets the disposition.
127 * @return the disposition
129 public String getDisposition() {
134 * Sets the disposition.
136 * @param disposition the new disposition
138 public void setDisposition(String disposition) {
139 this.disposition = disposition;
145 * @return the category
147 public String getCategory() {
154 * @param category the new category
156 public void setCategory(String category) {
157 this.category = category;
163 * @return the severity
165 public String getSeverity() {
172 * @param severity the new severity
174 public void setSeverity(String severity) {
175 this.severity = severity;
179 * Gets the error code.
181 * @return the error code
183 public String getErrorCode() {
188 * Sets the error code.
190 * @param errorCode the new error code
192 public void setErrorCode(String errorCode) {
193 this.errorCode = errorCode;
197 * Gets the HTTP response code.
199 * @return the HTTP response code
201 public Status getHTTPResponseCode() {
202 return httpResponseCode;
206 * Sets the HTTP response code.
208 * @param httpResponseCode the new HTTP response code
210 public void setHTTPResponseCode(Integer httpResponseCode) {
211 this.httpResponseCode = Status.fromStatusCode(httpResponseCode);
212 if (this.httpResponseCode == null) {
213 throw new IllegalArgumentException("setHTTPResponseCode was passed an invalid Integer value, fix error.properties or your code "+httpResponseCode);
218 * Sets the HTTP response code.
220 * @param httpResponseCode the new HTTP response code
222 public void setHTTPResponseCode(String httpResponseCode) {
223 this.httpResponseCode = Status.fromStatusCode(Integer.valueOf(httpResponseCode));
224 if (this.httpResponseCode == null) {
225 throw new IllegalArgumentException("setHTTPResponseCode was passed an invalid String value, fix error.properties or your code "+httpResponseCode);
230 * Sets the REST error code.
232 * @param restErrorCode the new REST error code
234 public void setRESTErrorCode(String restErrorCode) {
235 this.restErrorCode = restErrorCode;
239 * Gets the REST error code.
241 * @return the REST error code
243 public String getRESTErrorCode() {
244 return this.restErrorCode;
248 * Sets the HTTP response code.
250 * @param httpResponseCode the new HTTP response code
252 public void setHTTPResponseCode(Status httpResponseCode) {
253 this.httpResponseCode = httpResponseCode;
254 if (this.httpResponseCode == null) {
255 throw new IllegalArgumentException("setHTTPResponseCode was passed an invalid String value, fix error.properties or your code "+httpResponseCode);
260 * Gets the error text.
262 * @return the error text
264 public String getErrorText() {
269 * Sets the error text.
271 * @param errorText the new error text
273 public void setErrorText(String errorText) {
274 this.errorText = errorText;
278 * Gets the error code string. This is also the string
279 * configured in Nagios to alert on
281 * @return the error code string
283 // Get the X.Y.Z representation of the error code
284 public String getErrorCodeString() {
285 String prefix = null;
286 switch (disposition) {
294 return prefix + disposition + "." + category + "." + errorCode;
298 * Gets the severity Code. This is also the string
299 * configured in Nagios to alert on
301 * @return the severity
303 // Get the numerical value of severity
304 public String getSeverityCode(String severity) {
305 String severityCode = "";
324 public String toString() {
325 return "ErrorObject [errorCode="+ errorCode + ", errorText=" + errorText
326 + ", restErrorCode=" + restErrorCode + ", httpResponseCode="+ httpResponseCode
327 + ", severity=" + severity + ", disposition=" + disposition + ", category=" + category +"]";