2fc427db8cf5c8ada16700a500fd5efa440db65d
[policy/clamp.git] /
1 /*-
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.clamp.common.acm.exception;
22
23 import javax.ws.rs.core.Response;
24 import lombok.Getter;
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;
29
30 /**
31  * This class is a base automation composition run time exception from which all automation composition run time
32  * exceptions are sub classes.
33  */
34 @Getter
35 @ToString
36 public class AutomationCompositionRuntimeException extends RuntimeException implements ErrorResponseInfo {
37     private static final long serialVersionUID = -8507246953751956974L;
38
39     // The error response of the exception
40     private final ErrorResponse errorResponse = new ErrorResponse();
41
42     // The object on which the exception was thrown
43     private final transient Object object;
44
45     /**
46      * Instantiates a new automation composition runtime exception.
47      *
48      * @param statusCode the return code for the exception
49      * @param message the message on the exception
50      */
51     public AutomationCompositionRuntimeException(final Response.Status statusCode, final String message) {
52         this(statusCode, message, null);
53     }
54
55     /**
56      * Instantiates a new automation composition runtime exception.
57      *
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
61      */
62     public AutomationCompositionRuntimeException(final Response.Status statusCode, final String message,
63         final Object object) {
64         super(message);
65         this.object = object;
66         errorResponse.setResponseCode(statusCode);
67         ErrorResponseUtils.getExceptionMessages(errorResponse, this);
68     }
69
70     /**
71      * Instantiates a new automation composition runtime exception.
72      *
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
76      */
77     public AutomationCompositionRuntimeException(final Response.Status statusCode, final String message,
78         final Exception exception) {
79         this(statusCode, message, exception, null);
80     }
81
82     /**
83      * Instantiates a new model runtime exception from an AutomationCompositionException instance.
84      *
85      * @param exception the exception that caused this automation composition exception
86      */
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);
92     }
93
94     /**
95      * Instantiates a new automation composition runtime exception.
96      *
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
101      */
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);
108     }
109 }