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.sdc.exception;
24 * Nested POJOs to express required JSON format of the error
26 * { "requestError": { "serviceException": { "messageId": "", "text": "",
27 * "variables": [] } } }
34 public class ResponseFormat {
37 private RequestErrorWrapper requestErrorWrapper;
39 public ResponseFormat() {
43 public ResponseFormat(int status) {
48 public void setStatus(int status) {
52 public Integer getStatus() {
56 public RequestErrorWrapper getRequestError() {
57 return requestErrorWrapper;
60 public void setRequestError(RequestErrorWrapper requestErrorWrapper) {
61 this.requestErrorWrapper = requestErrorWrapper;
64 public void setPolicyException(PolicyException policyException) {
65 this.requestErrorWrapper = new RequestErrorWrapper(new RequestError());
66 requestErrorWrapper.setPolicyException(policyException);
69 public void setServiceException(ServiceException serviceException) {
70 this.requestErrorWrapper = new RequestErrorWrapper(new RequestError());
71 requestErrorWrapper.setServiceException(serviceException);
74 public void setOkResponseInfo(OkResponseInfo okResponseInfo) {
75 this.requestErrorWrapper = new RequestErrorWrapper(new RequestError());
76 requestErrorWrapper.setOkResponseInfo(okResponseInfo);
79 public String getFormattedMessage() {
80 if (this.requestErrorWrapper.requestError.okResponseInfo != null) {
81 return this.requestErrorWrapper.requestError.okResponseInfo.getFormattedErrorMessage();
83 if (this.requestErrorWrapper.requestError.serviceException != null) {
84 return this.requestErrorWrapper.requestError.serviceException.getFormattedErrorMessage();
86 return this.requestErrorWrapper.requestError.policyException.getFormattedErrorMessage();
89 public String getText() {
90 if (this.requestErrorWrapper.requestError.okResponseInfo != null) {
91 return this.requestErrorWrapper.requestError.okResponseInfo.getText();
93 if (this.requestErrorWrapper.requestError.serviceException != null) {
94 return this.requestErrorWrapper.requestError.serviceException.getText();
96 return this.requestErrorWrapper.requestError.policyException.getText();
99 public String[] getVariables() {
100 if (this.requestErrorWrapper.requestError.okResponseInfo != null) {
101 return this.requestErrorWrapper.requestError.okResponseInfo.getVariables();
103 if (this.requestErrorWrapper.requestError.serviceException != null) {
104 return this.requestErrorWrapper.requestError.serviceException.getVariables();
106 return this.requestErrorWrapper.requestError.policyException.getVariables();
109 public String getMessageId() {
110 if (this.requestErrorWrapper.requestError.okResponseInfo != null) {
111 return this.requestErrorWrapper.requestError.okResponseInfo.getMessageId();
113 if (this.requestErrorWrapper.requestError.serviceException != null) {
114 return this.requestErrorWrapper.requestError.serviceException.getMessageId();
116 return this.requestErrorWrapper.requestError.policyException.getMessageId();
119 public class RequestErrorWrapper {
120 private RequestError requestError;
122 public RequestErrorWrapper() {
123 this.requestError = new RequestError();
126 public RequestErrorWrapper(RequestError requestError) {
127 this.requestError = requestError;
130 public RequestError getRequestError() {
134 public void setRequestError(RequestError requestError) {
135 this.requestError = requestError;
138 public void setPolicyException(PolicyException policyException) {
139 requestError.setPolicyException(policyException);
142 public void setServiceException(ServiceException serviceException) {
143 requestError.setServiceException(serviceException);
146 public void setOkResponseInfo(OkResponseInfo okResponseInfo) {
147 requestError.setOkResponseInfo(okResponseInfo);
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;
159 public RequestError() {
162 public PolicyException getPolicyException() {
163 return policyException;
166 public ServiceException getServiceException() {
167 return serviceException;
170 public OkResponseInfo getOkResponseInfo() {
171 return okResponseInfo;
174 public void setPolicyException(PolicyException policyException) {
175 this.policyException = policyException;
178 public void setServiceException(ServiceException serviceException) {
179 this.serviceException = serviceException;
182 public void setOkResponseInfo(OkResponseInfo okResponseInfo) {
183 this.okResponseInfo = okResponseInfo;
188 public String toString() {
189 return "ResponseFormat[" + "status=" + status + ", requestErrorWrapper=" + requestErrorWrapper + ']';