2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 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=========================================================
21 package org.openecomp.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;
42 * Instantiates a new error object.
44 public ErrorObject() {
49 * Creates an error object with the default HTTP Error Code (Status.INTERNAL_SERVER_ERROR)
51 * @param disposition the disposition
52 * @param category the category
53 * @param severity the severity
54 * @param httpResponseCode the http response code
55 * @param restErrorCode the rest error code
56 * @param errorCode the error code
57 * @param errorText the error text
59 public ErrorObject(String disposition, String category, String severity, Integer httpResponseCode, String restErrorCode, String errorCode, String errorText) {
61 this.setDisposition(disposition);
62 this.setCategory(category);
63 this.severity = severity;
64 this.setHTTPResponseCode(httpResponseCode);
65 this.setRESTErrorCode(restErrorCode);
66 this.setErrorCode(errorCode);
67 this.setErrorText(errorText);
73 * Instantiates a new error object.
75 * @param severity the severity
76 * @param errorCode the error code
77 * @param errorText the error text
78 * @param disposition the disposition
79 * @param category the category
81 public ErrorObject(String severity, String errorCode, String errorText, String disposition, String category) {
82 this(severity, Status.INTERNAL_SERVER_ERROR, errorCode, errorText, disposition, category);
86 * Instantiates a new error object.
88 * @param severity the severity
89 * @param httpResponseCode the http response code
90 * @param errorCode the error code
91 * @param errorText the error text
92 * @param disposition the disposition
93 * @param category the category
95 public ErrorObject(String severity, Integer httpResponseCode, String errorCode, String errorText, String disposition, String category) {
97 this.severity = severity;
98 this.setHTTPResponseCode(httpResponseCode);
99 this.setErrorCode(errorCode);
100 this.setErrorText(errorText);
101 this.setDisposition(disposition);
102 this.setCategory(category);
106 * Instantiates a new error object.
108 * @param severity the severity
109 * @param httpResponseCode the http response code
110 * @param errorCode the error code
111 * @param errorText the error text
112 * @param disposition the disposition
113 * @param category the category
115 public ErrorObject(String severity, Status httpResponseCode, String errorCode, String errorText, String disposition, String category) {
117 this.severity = severity;
118 this.setHTTPResponseCode(httpResponseCode);
119 this.setErrorCode(errorCode);
120 this.setErrorText(errorText);
121 this.setDisposition(disposition);
122 this.setCategory(category);
126 * Gets the disposition.
128 * @return the disposition
130 public String getDisposition() {
135 * Sets the disposition.
137 * @param disposition the new disposition
139 public void setDisposition(String disposition) {
140 this.disposition = disposition;
146 * @return the category
148 public String getCategory() {
155 * @param category the new category
157 public void setCategory(String category) {
158 this.category = category;
164 * @return the severity
166 public String getSeverity() {
173 * @param severity the new severity
175 public void setSeverity(String severity) {
176 this.severity = severity;
180 * Gets the error code.
182 * @return the error code
184 public String getErrorCode() {
189 * Sets the error code.
191 * @param errorCode the new error code
193 public void setErrorCode(String errorCode) {
194 this.errorCode = errorCode;
198 * Gets the HTTP response code.
200 * @return the HTTP response code
202 public Status getHTTPResponseCode() {
203 return httpResponseCode;
207 * Sets the HTTP response code.
209 * @param httpResponseCode the new HTTP response code
211 public void setHTTPResponseCode(Integer httpResponseCode) {
212 this.httpResponseCode = Status.fromStatusCode(httpResponseCode);
213 if (this.httpResponseCode == null) {
214 throw new IllegalArgumentException("setHTTPResponseCode was passed an invalid Integer value, fix error.properties or your code "+httpResponseCode);
219 * Sets the HTTP response code.
221 * @param httpResponseCode the new HTTP response code
223 public void setHTTPResponseCode(String httpResponseCode) {
224 this.httpResponseCode = Status.fromStatusCode(Integer.valueOf(httpResponseCode));
225 if (this.httpResponseCode == null) {
226 throw new IllegalArgumentException("setHTTPResponseCode was passed an invalid String value, fix error.properties or your code "+httpResponseCode);
231 * Sets the REST error code.
233 * @param restErrorCode the new REST error code
235 public void setRESTErrorCode(String restErrorCode) {
236 this.restErrorCode = restErrorCode;
240 * Gets the REST error code.
242 * @return the REST error code
244 public String getRESTErrorCode() {
245 return this.restErrorCode;
249 * Sets the HTTP response code.
251 * @param httpResponseCode the new HTTP response code
253 public void setHTTPResponseCode(Status httpResponseCode) {
254 this.httpResponseCode = httpResponseCode;
255 if (this.httpResponseCode == null) {
256 throw new IllegalArgumentException("setHTTPResponseCode was passed an invalid String value, fix error.properties or your code "+httpResponseCode);
261 * Gets the error text.
263 * @return the error text
265 public String getErrorText() {
270 * Sets the error text.
272 * @param errorText the new error text
274 public void setErrorText(String errorText) {
275 this.errorText = errorText;
279 * Gets the error code string. This is also the string
280 * configured in Nagios to alert on
282 * @return the error code string
284 // Get the X.Y.Z representation of the error code
285 public String getErrorCodeString() {
286 String prefix = null;
287 switch (disposition) {
295 return prefix + disposition + "." + category + "." + errorCode;
302 public String toString() {
303 return "ErrorObject [errorCode="+ errorCode + ", errorText=" + errorText
304 + ", restErrorCode=" + restErrorCode + ", httpResponseCode="+ httpResponseCode
305 + ", severity=" + severity + ", disposition=" + disposition + ", category=" + category +"]";