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=========================================================
20 package org.openecomp.sdc.exception;
25 * Nested POJOs to express required JSON format of the error
27 * { "requestError": { "serviceException": { "messageId": "", "text": "", "variables": [] } } }
31 public class ResponseFormat {
35 private RequestErrorWrapper requestErrorWrapper;
37 public ResponseFormat() {
41 public ResponseFormat(int status) {
46 public Integer getStatus() {
50 public RequestErrorWrapper getRequestError() {
51 return requestErrorWrapper;
54 public void setRequestError(RequestErrorWrapper requestErrorWrapper) {
55 this.requestErrorWrapper = requestErrorWrapper;
58 public void setPolicyException(PolicyException policyException) {
59 this.requestErrorWrapper = new RequestErrorWrapper(new RequestError());
60 requestErrorWrapper.setPolicyException(policyException);
63 public void setServiceException(ServiceException serviceException) {
64 this.requestErrorWrapper = new RequestErrorWrapper(new RequestError());
65 requestErrorWrapper.setServiceException(serviceException);
68 public void setOkResponseInfo(OkResponseInfo okResponseInfo) {
69 this.requestErrorWrapper = new RequestErrorWrapper(new RequestError());
70 requestErrorWrapper.setOkResponseInfo(okResponseInfo);
73 public String getFormattedMessage() {
74 if (this.requestErrorWrapper.requestError.okResponseInfo != null) {
75 return this.requestErrorWrapper.requestError.okResponseInfo.getFormattedErrorMessage();
77 if (this.requestErrorWrapper.requestError.serviceException != null) {
78 return this.requestErrorWrapper.requestError.serviceException.getFormattedErrorMessage();
80 return this.requestErrorWrapper.requestError.policyException.getFormattedErrorMessage();
83 public String getText() {
84 if (this.requestErrorWrapper.requestError.okResponseInfo != null) {
85 return this.requestErrorWrapper.requestError.okResponseInfo.getText();
87 if (this.requestErrorWrapper.requestError.serviceException != null) {
88 return this.requestErrorWrapper.requestError.serviceException.getText();
90 return this.requestErrorWrapper.requestError.policyException.getText();
93 public String[] getVariables() {
94 if (this.requestErrorWrapper.requestError.okResponseInfo != null) {
95 return this.requestErrorWrapper.requestError.okResponseInfo.getVariables();
97 if (this.requestErrorWrapper.requestError.serviceException != null) {
98 return this.requestErrorWrapper.requestError.serviceException.getVariables();
100 return this.requestErrorWrapper.requestError.policyException.getVariables();
103 public String getMessageId() {
104 if (this.requestErrorWrapper.requestError.okResponseInfo != null) {
105 return this.requestErrorWrapper.requestError.okResponseInfo.getMessageId();
107 if (this.requestErrorWrapper.requestError.serviceException != null) {
108 return this.requestErrorWrapper.requestError.serviceException.getMessageId();
110 return this.requestErrorWrapper.requestError.policyException.getMessageId();
113 public class RequestErrorWrapper {
115 private RequestError requestError;
117 public RequestErrorWrapper() {
118 this.requestError = new RequestError();
121 public RequestErrorWrapper(RequestError requestError) {
122 this.requestError = requestError;
125 public RequestError getRequestError() {
129 public void setRequestError(RequestError requestError) {
130 this.requestError = requestError;
133 public void setPolicyException(PolicyException policyException) {
134 requestError.setPolicyException(policyException);
137 public void setServiceException(ServiceException serviceException) {
138 requestError.setServiceException(serviceException);
141 public void setOkResponseInfo(OkResponseInfo okResponseInfo) {
142 requestError.setOkResponseInfo(okResponseInfo);
146 public class RequestError {
148 @SuppressWarnings("unused")
149 private PolicyException policyException;
150 @SuppressWarnings("unused")
151 private ServiceException serviceException;
152 @SuppressWarnings("unused")
153 private OkResponseInfo okResponseInfo;
155 public PolicyException getPolicyException() {
156 return policyException;
159 public ServiceException getServiceException() {
160 return serviceException;
163 public OkResponseInfo getOkResponseInfo() {
164 return okResponseInfo;
167 public void setPolicyException(PolicyException policyException) {
168 this.policyException = policyException;
171 public void setServiceException(ServiceException serviceException) {
172 this.serviceException = serviceException;
175 public void setOkResponseInfo(OkResponseInfo okResponseInfo) {
176 this.okResponseInfo = okResponseInfo;
181 public String toString() {
182 return "ResponseFormat[" + "status=" + status + ", requestErrorWrapper=" + requestErrorWrapper + ']';