Catalog alignment
[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  * 
30  * @author paharoni
31  *
32  */
33
34 public class ResponseFormat {
35
36         private int status;
37         private RequestErrorWrapper requestErrorWrapper;
38
39         public ResponseFormat() {
40                 super();
41         }
42
43         public ResponseFormat(int status) {
44                 super();
45                 this.status = status;
46         }
47
48         public void setStatus(int status) {
49                 this.status = status;
50         }
51
52         public Integer getStatus() {
53                 return status;
54         }
55
56         public RequestErrorWrapper getRequestError() {
57                 return requestErrorWrapper;
58         }
59
60         public void setRequestError(RequestErrorWrapper requestErrorWrapper) {
61                 this.requestErrorWrapper = requestErrorWrapper;
62         }
63
64         public void setPolicyException(PolicyException policyException) {
65                 this.requestErrorWrapper = new RequestErrorWrapper(new RequestError());
66                 requestErrorWrapper.setPolicyException(policyException);
67         }
68
69         public void setServiceException(ServiceException serviceException) {
70                 this.requestErrorWrapper = new RequestErrorWrapper(new RequestError());
71                 requestErrorWrapper.setServiceException(serviceException);
72         }
73
74         public void setOkResponseInfo(OkResponseInfo okResponseInfo) {
75                 this.requestErrorWrapper = new RequestErrorWrapper(new RequestError());
76                 requestErrorWrapper.setOkResponseInfo(okResponseInfo);
77         }
78
79         public String getFormattedMessage() {
80                 if (this.requestErrorWrapper.requestError.okResponseInfo != null) {
81                         return this.requestErrorWrapper.requestError.okResponseInfo.getFormattedErrorMessage();
82                 }
83                 if (this.requestErrorWrapper.requestError.serviceException != null) {
84                         return this.requestErrorWrapper.requestError.serviceException.getFormattedErrorMessage();
85                 }
86                 return this.requestErrorWrapper.requestError.policyException.getFormattedErrorMessage();
87         }
88
89         public String getText() {
90                 if (this.requestErrorWrapper.requestError.okResponseInfo != null) {
91                         return this.requestErrorWrapper.requestError.okResponseInfo.getText();
92                 }
93                 if (this.requestErrorWrapper.requestError.serviceException != null) {
94                         return this.requestErrorWrapper.requestError.serviceException.getText();
95                 }
96                 return this.requestErrorWrapper.requestError.policyException.getText();
97         }
98
99         public String[] getVariables() {
100                 if (this.requestErrorWrapper.requestError.okResponseInfo != null) {
101                         return this.requestErrorWrapper.requestError.okResponseInfo.getVariables();
102                 }
103                 if (this.requestErrorWrapper.requestError.serviceException != null) {
104                         return this.requestErrorWrapper.requestError.serviceException.getVariables();
105                 }
106                 return this.requestErrorWrapper.requestError.policyException.getVariables();
107         }
108
109         public String getMessageId() {
110                 if (this.requestErrorWrapper.requestError.okResponseInfo != null) {
111                         return this.requestErrorWrapper.requestError.okResponseInfo.getMessageId();
112                 }
113                 if (this.requestErrorWrapper.requestError.serviceException != null) {
114                         return this.requestErrorWrapper.requestError.serviceException.getMessageId();
115                 }
116                 return this.requestErrorWrapper.requestError.policyException.getMessageId();
117         }
118
119         public class RequestErrorWrapper {
120                 private RequestError requestError;
121
122                 public RequestErrorWrapper() {
123                         this.requestError = new RequestError();
124                 }
125
126                 public RequestErrorWrapper(RequestError requestError) {
127                         this.requestError = requestError;
128                 }
129
130                 public RequestError getRequestError() {
131                         return requestError;
132                 }
133
134                 public void setRequestError(RequestError requestError) {
135                         this.requestError = requestError;
136                 }
137
138                 public void setPolicyException(PolicyException policyException) {
139                         requestError.setPolicyException(policyException);
140                 }
141
142                 public void setServiceException(ServiceException serviceException) {
143                         requestError.setServiceException(serviceException);
144                 }
145
146                 public void setOkResponseInfo(OkResponseInfo okResponseInfo) {
147                         requestError.setOkResponseInfo(okResponseInfo);
148                 }
149         }
150
151         public class RequestError {
152                 @SuppressWarnings("unused")
153                 private PolicyException policyException;
154                 @SuppressWarnings("unused")
155                 private ServiceException serviceException;
156                 @SuppressWarnings("unused")
157                 private OkResponseInfo okResponseInfo;
158
159                 public RequestError() {
160                 }
161
162                 public PolicyException getPolicyException() {
163                         return policyException;
164                 }
165
166                 public ServiceException getServiceException() {
167                         return serviceException;
168                 }
169
170                 public OkResponseInfo getOkResponseInfo() {
171                         return okResponseInfo;
172                 }
173
174                 public void setPolicyException(PolicyException policyException) {
175                         this.policyException = policyException;
176                 }
177
178                 public void setServiceException(ServiceException serviceException) {
179                         this.serviceException = serviceException;
180                 }
181
182                 public void setOkResponseInfo(OkResponseInfo okResponseInfo) {
183                         this.okResponseInfo = okResponseInfo;
184                 }
185         }
186
187         @Override
188         public String toString() {
189                 return "ResponseFormat[" + "status=" + status + ", requestErrorWrapper=" + requestErrorWrapper + ']';
190         }
191         
192 }