2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.clamp.common.acm.exception;
23 import javax.ws.rs.core.Response;
25 import lombok.ToString;
26 import org.onap.policy.models.errors.concepts.ErrorResponse;
27 import org.onap.policy.models.errors.concepts.ErrorResponseInfo;
28 import org.onap.policy.models.errors.concepts.ErrorResponseUtils;
31 * This class is a base automation composition run time exception from which all automation composition run time
32 * exceptions are sub classes.
36 public class AutomationCompositionRuntimeException extends RuntimeException implements ErrorResponseInfo {
37 private static final long serialVersionUID = -8507246953751956974L;
39 // The error response of the exception
40 private final ErrorResponse errorResponse = new ErrorResponse();
42 // The object on which the exception was thrown
43 private final transient Object object;
46 * Instantiates a new automation composition runtime exception.
48 * @param statusCode the return code for the exception
49 * @param message the message on the exception
51 public AutomationCompositionRuntimeException(final Response.Status statusCode, final String message) {
52 this(statusCode, message, null);
56 * Instantiates a new automation composition runtime exception.
58 * @param statusCode the return code for the exception
59 * @param message the message on the exception
60 * @param object the object that the exception was thrown on
62 public AutomationCompositionRuntimeException(final Response.Status statusCode, final String message,
63 final Object object) {
66 errorResponse.setResponseCode(statusCode);
67 ErrorResponseUtils.getExceptionMessages(errorResponse, this);
71 * Instantiates a new automation composition runtime exception.
73 * @param statusCode the return code for the exception
74 * @param message the message on the exception
75 * @param exception the exception that caused this automation composition exception
77 public AutomationCompositionRuntimeException(final Response.Status statusCode, final String message,
78 final Exception exception) {
79 this(statusCode, message, exception, null);
83 * Instantiates a new model runtime exception from an AutomationCompositionException instance.
85 * @param exception the exception that caused this automation composition exception
87 public AutomationCompositionRuntimeException(final AutomationCompositionException exception) {
88 super(exception.getMessage(), exception);
89 this.object = exception.getObject();
90 errorResponse.setResponseCode(exception.getErrorResponse().getResponseCode());
91 ErrorResponseUtils.getExceptionMessages(errorResponse, this);
95 * Instantiates a new automation composition runtime exception.
97 * @param statusCode the return code for the exception
98 * @param message the message on the exception
99 * @param exception the exception that caused this automation composition exception
100 * @param object the object that the exception was thrown on
102 public AutomationCompositionRuntimeException(final Response.Status statusCode, final String message,
103 final Exception exception, final Object object) {
104 super(message, exception);
105 this.object = object;
106 errorResponse.setResponseCode(statusCode);
107 ErrorResponseUtils.getExceptionMessages(errorResponse, this);