Second part of onap rename
[appc.git] / appc-adapters / appc-rest-adapter / appc-rest-adapter-bundle / src / main / java / org / onap / appc / adapter / rest / impl / RequestFailedException.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
8  * =============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * 
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25
26
27 package org.onap.appc.adapter.rest.impl;
28
29 import org.glassfish.grizzly.http.util.HttpStatus;
30 import com.att.cdp.zones.model.Server;
31
32 /**
33  * This class is used to capture the exact cause and point of failure for the processing of a request. It is then used
34  * to encode the reason for the failure, status code, and anything else that needs to be captured and reported for
35  * diagnostic purposes.
36  */
37 public class RequestFailedException extends Exception {
38
39     /**
40      *
41      */
42     private static final long serialVersionUID = 1L;
43
44     /**
45      * The operation that was being requested or performed at the time of the failure.
46      */
47     private String operation;
48
49     /**
50      * A message that details the reason for the failure
51      */
52     private String reason;
53
54     /**
55      * The server that was being operated upon
56      */
57     private Server server;
58
59     /**
60      * The id of the server being operated upon if the server object is not available (such as the server was not found)
61      */
62     private String serverId;
63
64     /**
65      * The most appropriate Http Status code that reflects the error
66      */
67     private HttpStatus status;
68
69     /**
70      * 
71      */
72     public RequestFailedException() {
73         // intentionally empty
74     }
75
76     /**
77      * @param message
78      *            The error message
79      */
80     public RequestFailedException(String message) {
81         super(message);
82     }
83
84     /**
85      * Construct the request failed exception with the operation being performed, reason for the failure, http status
86      * code that is most appropriate, and the server we were processing.
87      * 
88      * @param operation
89      *            The operation being performed
90      * @param reason
91      *            The reason that the operation was failed
92      * @param status
93      *            The http status code that is most appropriate
94      * @param server
95      *            The server that we were processing
96      */
97     @SuppressWarnings("nls")
98     public RequestFailedException(String operation, String reason, HttpStatus status, Server server) {
99         super(operation + ":" + reason);
100         this.operation = operation;
101         this.reason = reason;
102         this.status = status;
103         this.server = server;
104         if (server != null) {
105             this.serverId = server.getId();
106         }
107     }
108
109     /**
110      * Construct the request failed exception with the operation being performed, reason for the failure, http status
111      * code that is most appropriate, and the server we were processing.
112      * 
113      * @param ex
114      *            The exception that we are wrapping
115      * @param operation
116      *            The operation being performed
117      * @param reason
118      *            The reason that the operation was failed
119      * @param status
120      *            The http status code that is most appropriate
121      * @param server
122      *            The server that we were processing
123      */
124     @SuppressWarnings("nls")
125     public RequestFailedException(Throwable ex, String operation, String reason, HttpStatus status, Server server) {
126         super(operation + ":" + reason, ex);
127         this.operation = operation;
128         this.reason = reason;
129         this.status = status;
130         this.server = server;
131         if (server != null) {
132             this.serverId = server.getId();
133         }
134     }
135
136     /**
137      * @param message
138      *            The error message
139      * @param cause
140      *            A nested exception
141      */
142     public RequestFailedException(String message, Throwable cause) {
143         super(message, cause);
144     }
145
146     /**
147      * @param message
148      *            The error message
149      * @param cause
150      *            A nested exception
151      * @param enableSuppression
152      *            whether or not suppression is enabled or disabled
153      * @param writableStackTrace
154      *            whether or not the stack trace should be writable
155      */
156     public RequestFailedException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
157         super(message, cause, enableSuppression, writableStackTrace);
158     }
159
160     /**
161      * @param cause
162      *            the cause (which is saved for later retrieval by the {@link #getCause()} method). (A null value is
163      *            permitted, and indicates that the cause is nonexistent or unknown.)
164      */
165     public RequestFailedException(Throwable cause) {
166         super(cause);
167     }
168
169     /**
170      * @return The operation being performed
171      */
172     public String getOperation() {
173         return operation;
174     }
175
176     /**
177      * @return The reason for the failure
178      */
179     public String getReason() {
180         return reason;
181     }
182
183     /**
184      * @return The server being operated upon
185      */
186     public Server getServer() {
187         return server;
188     }
189
190     /**
191      * @return The id of the server being operated upon
192      */
193     public String getServerId() {
194         return serverId;
195     }
196
197     /**
198      * @return The status code from the operation
199      */
200     public HttpStatus getStatus() {
201         return status;
202     }
203
204     /**
205      * @param operation
206      *            The operation being performed
207      */
208     public void setOperation(String operation) {
209         this.operation = operation;
210     }
211
212     /**
213      * @param reason
214      *            The reason for the failure
215      */
216     public void setReason(String reason) {
217         this.reason = reason;
218     }
219
220     /**
221      * @param server
222      *            The server being operated upon
223      */
224     public void setServer(Server server) {
225         this.server = server;
226         if (server != null) {
227             setServerId(server.getId());
228         }
229     }
230
231     /**
232      * @param serverId
233      *            The id of the server being operated upon
234      */
235     public void setServerId(String serverId) {
236         this.serverId = serverId;
237     }
238
239     /**
240      * @param status
241      *            The status of the request
242      */
243     public void setStatus(HttpStatus status) {
244         this.status = status;
245     }
246
247 }