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 jakarta.ws.rs.core.Response;
24 import java.io.Serial;
26 import lombok.ToString;
27 import org.onap.policy.models.errors.concepts.ErrorResponse;
28 import org.onap.policy.models.errors.concepts.ErrorResponseInfo;
29 import org.onap.policy.models.errors.concepts.ErrorResponseUtils;
32 * This class is a base automation composition run time exception from which all automation composition run time
33 * exceptions are sub classes.
37 public class AutomationCompositionRuntimeException extends RuntimeException implements ErrorResponseInfo {
40 private static final long serialVersionUID = -8507246953751956974L;
42 // The error response of the exception
43 private final ErrorResponse errorResponse = new ErrorResponse();
45 // The object on which the exception was thrown
46 private final transient Object object;
49 * Instantiates a new automation composition runtime exception.
51 * @param statusCode the return code for the exception
52 * @param message the message on the exception
54 public AutomationCompositionRuntimeException(final Response.Status statusCode, final String message) {
55 this(statusCode, message, null);
59 * Instantiates a new automation composition runtime exception.
61 * @param statusCode the return code for the exception
62 * @param message the message on the exception
63 * @param object the object that the exception was thrown on
65 public AutomationCompositionRuntimeException(final Response.Status statusCode, final String message,
66 final Object object) {
69 errorResponse.setResponseCode(statusCode);
70 ErrorResponseUtils.getExceptionMessages(errorResponse, this);
74 * Instantiates a new automation composition runtime exception.
76 * @param statusCode the return code for the exception
77 * @param message the message on the exception
78 * @param exception the exception that caused this automation composition exception
80 public AutomationCompositionRuntimeException(final Response.Status statusCode, final String message,
81 final Exception exception) {
82 this(statusCode, message, exception, null);
86 * Instantiates a new model runtime exception from an AutomationCompositionException instance.
88 * @param exception the exception that caused this automation composition exception
90 public AutomationCompositionRuntimeException(final AutomationCompositionException exception) {
91 super(exception.getMessage(), exception);
92 this.object = exception.getObject();
93 errorResponse.setResponseCode(exception.getErrorResponse().getResponseCode());
94 ErrorResponseUtils.getExceptionMessages(errorResponse, this);
98 * Instantiates a new automation composition runtime exception.
100 * @param statusCode the return code for the exception
101 * @param message the message on the exception
102 * @param exception the exception that caused this automation composition exception
103 * @param object the object that the exception was thrown on
105 public AutomationCompositionRuntimeException(final Response.Status statusCode, final String message,
106 final Exception exception, final Object object) {
107 super(message, exception);
108 this.object = object;
109 errorResponse.setResponseCode(statusCode);
110 ErrorResponseUtils.getExceptionMessages(errorResponse, this);