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": [] } } }
32 public class ResponseFormat {
35 private RequestErrorWrapper requestErrorWrapper;
37 public ResponseFormat() {
41 public ResponseFormat(int status) {
46 public void setStatus(int status) {
50 public Integer getStatus() {
54 public RequestErrorWrapper getRequestError() {
55 return requestErrorWrapper;
58 public void setRequestError(RequestErrorWrapper requestErrorWrapper) {
59 this.requestErrorWrapper = requestErrorWrapper;
62 public void setPolicyException(PolicyException policyException) {
63 this.requestErrorWrapper = new RequestErrorWrapper(new RequestError());
64 requestErrorWrapper.setPolicyException(policyException);
67 public void setServiceException(ServiceException serviceException) {
68 this.requestErrorWrapper = new RequestErrorWrapper(new RequestError());
69 requestErrorWrapper.setServiceException(serviceException);
72 public void setOkResponseInfo(OkResponseInfo okResponseInfo) {
73 this.requestErrorWrapper = new RequestErrorWrapper(new RequestError());
74 requestErrorWrapper.setOkResponseInfo(okResponseInfo);
77 public String getFormattedMessage() {
78 if (this.requestErrorWrapper.requestError.okResponseInfo != null) {
79 return this.requestErrorWrapper.requestError.okResponseInfo.getFormattedErrorMessage();
81 if (this.requestErrorWrapper.requestError.serviceException != null) {
82 return this.requestErrorWrapper.requestError.serviceException.getFormattedErrorMessage();
84 return this.requestErrorWrapper.requestError.policyException.getFormattedErrorMessage();
87 public String getText() {
88 if (this.requestErrorWrapper.requestError.okResponseInfo != null) {
89 return this.requestErrorWrapper.requestError.okResponseInfo.getText();
91 if (this.requestErrorWrapper.requestError.serviceException != null) {
92 return this.requestErrorWrapper.requestError.serviceException.getText();
94 return this.requestErrorWrapper.requestError.policyException.getText();
97 public String[] getVariables() {
98 if (this.requestErrorWrapper.requestError.okResponseInfo != null) {
99 return this.requestErrorWrapper.requestError.okResponseInfo.getVariables();
101 if (this.requestErrorWrapper.requestError.serviceException != null) {
102 return this.requestErrorWrapper.requestError.serviceException.getVariables();
104 return this.requestErrorWrapper.requestError.policyException.getVariables();
107 public String getMessageId() {
108 if (this.requestErrorWrapper.requestError.okResponseInfo != null) {
109 return this.requestErrorWrapper.requestError.okResponseInfo.getMessageId();
111 if (this.requestErrorWrapper.requestError.serviceException != null) {
112 return this.requestErrorWrapper.requestError.serviceException.getMessageId();
114 return this.requestErrorWrapper.requestError.policyException.getMessageId();
117 public class RequestErrorWrapper {
118 private RequestError requestError;
120 public RequestErrorWrapper() {
121 this.requestError = new RequestError();
124 public RequestErrorWrapper(RequestError requestError) {
125 this.requestError = requestError;
128 public RequestError getRequestError() {
132 public void setRequestError(RequestError requestError) {
133 this.requestError = requestError;
136 public void setPolicyException(PolicyException policyException) {
137 requestError.setPolicyException(policyException);
140 public void setServiceException(ServiceException serviceException) {
141 requestError.setServiceException(serviceException);
144 public void setOkResponseInfo(OkResponseInfo okResponseInfo) {
145 requestError.setOkResponseInfo(okResponseInfo);
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;
157 public RequestError() {
160 public PolicyException getPolicyException() {
161 return policyException;
164 public ServiceException getServiceException() {
165 return serviceException;
168 public OkResponseInfo getOkResponseInfo() {
169 return okResponseInfo;
172 public void setPolicyException(PolicyException policyException) {
173 this.policyException = policyException;
176 public void setServiceException(ServiceException serviceException) {
177 this.serviceException = serviceException;
180 public void setOkResponseInfo(OkResponseInfo okResponseInfo) {
181 this.okResponseInfo = okResponseInfo;
186 public String toString() {
187 return "ResponseFormat[" + "status=" + status + ", requestErrorWrapper=" + requestErrorWrapper + ']';