fixing warnings from checkstyle in common-app-api
[sdc.git] / common-app-api / src / main / java / org / openecomp / sdc / exception / ResponseFormat.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.openecomp.sdc.exception;
22
23 /**
24  * Nested POJOs to express required JSON format of the error
25  *
26  * { "requestError": { "serviceException": { "messageId": "", "text": "",
27  * "variables": [] } } }
28  *
29  * @author paharoni
30  */
31
32 public class ResponseFormat {
33
34     private int status;
35     private RequestErrorWrapper requestErrorWrapper;
36
37     public ResponseFormat() {
38         super();
39     }
40
41     public ResponseFormat(int status) {
42         super();
43         this.status = status;
44     }
45
46     public void setStatus(int status) {
47         this.status = status;
48     }
49
50     public Integer getStatus() {
51         return status;
52     }
53
54     public RequestErrorWrapper getRequestError() {
55         return requestErrorWrapper;
56     }
57
58     public void setRequestError(RequestErrorWrapper requestErrorWrapper) {
59         this.requestErrorWrapper = requestErrorWrapper;
60     }
61
62     public void setPolicyException(PolicyException policyException) {
63         this.requestErrorWrapper = new RequestErrorWrapper(new RequestError());
64         requestErrorWrapper.setPolicyException(policyException);
65     }
66
67     public void setServiceException(ServiceException serviceException) {
68         this.requestErrorWrapper = new RequestErrorWrapper(new RequestError());
69         requestErrorWrapper.setServiceException(serviceException);
70     }
71
72     public void setOkResponseInfo(OkResponseInfo okResponseInfo) {
73         this.requestErrorWrapper = new RequestErrorWrapper(new RequestError());
74         requestErrorWrapper.setOkResponseInfo(okResponseInfo);
75     }
76
77     public String getFormattedMessage() {
78         if (this.requestErrorWrapper.requestError.okResponseInfo != null) {
79             return this.requestErrorWrapper.requestError.okResponseInfo.getFormattedErrorMessage();
80         }
81         if (this.requestErrorWrapper.requestError.serviceException != null) {
82             return this.requestErrorWrapper.requestError.serviceException.getFormattedErrorMessage();
83         }
84         return this.requestErrorWrapper.requestError.policyException.getFormattedErrorMessage();
85     }
86
87     public String getText() {
88         if (this.requestErrorWrapper.requestError.okResponseInfo != null) {
89             return this.requestErrorWrapper.requestError.okResponseInfo.getText();
90         }
91         if (this.requestErrorWrapper.requestError.serviceException != null) {
92             return this.requestErrorWrapper.requestError.serviceException.getText();
93         }
94         return this.requestErrorWrapper.requestError.policyException.getText();
95     }
96
97     public String[] getVariables() {
98         if (this.requestErrorWrapper.requestError.okResponseInfo != null) {
99             return this.requestErrorWrapper.requestError.okResponseInfo.getVariables();
100         }
101         if (this.requestErrorWrapper.requestError.serviceException != null) {
102             return this.requestErrorWrapper.requestError.serviceException.getVariables();
103         }
104         return this.requestErrorWrapper.requestError.policyException.getVariables();
105     }
106
107     public String getMessageId() {
108         if (this.requestErrorWrapper.requestError.okResponseInfo != null) {
109             return this.requestErrorWrapper.requestError.okResponseInfo.getMessageId();
110         }
111         if (this.requestErrorWrapper.requestError.serviceException != null) {
112             return this.requestErrorWrapper.requestError.serviceException.getMessageId();
113         }
114         return this.requestErrorWrapper.requestError.policyException.getMessageId();
115     }
116
117     public class RequestErrorWrapper {
118         private RequestError requestError;
119
120         public RequestErrorWrapper() {
121             this.requestError = new RequestError();
122         }
123
124         public RequestErrorWrapper(RequestError requestError) {
125             this.requestError = requestError;
126         }
127
128         public RequestError getRequestError() {
129             return requestError;
130         }
131
132         public void setRequestError(RequestError requestError) {
133             this.requestError = requestError;
134         }
135
136         public void setPolicyException(PolicyException policyException) {
137             requestError.setPolicyException(policyException);
138         }
139
140         public void setServiceException(ServiceException serviceException) {
141             requestError.setServiceException(serviceException);
142         }
143
144         public void setOkResponseInfo(OkResponseInfo okResponseInfo) {
145             requestError.setOkResponseInfo(okResponseInfo);
146         }
147     }
148
149     public class RequestError {
150         @SuppressWarnings("unused")
151         private PolicyException policyException;
152         @SuppressWarnings("unused")
153         private ServiceException serviceException;
154         @SuppressWarnings("unused")
155         private OkResponseInfo okResponseInfo;
156
157         public RequestError() {
158         }
159
160         public PolicyException getPolicyException() {
161             return policyException;
162         }
163
164         public ServiceException getServiceException() {
165             return serviceException;
166         }
167
168         public OkResponseInfo getOkResponseInfo() {
169             return okResponseInfo;
170         }
171
172         public void setPolicyException(PolicyException policyException) {
173             this.policyException = policyException;
174         }
175
176         public void setServiceException(ServiceException serviceException) {
177             this.serviceException = serviceException;
178         }
179
180         public void setOkResponseInfo(OkResponseInfo okResponseInfo) {
181             this.okResponseInfo = okResponseInfo;
182         }
183     }
184
185     @Override
186     public String toString() {
187         return "ResponseFormat[" + "status=" + status + ", requestErrorWrapper=" + requestErrorWrapper + ']';
188     }
189
190 }