2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright © 2018 IBM.
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.aai.exceptions;
25 import java.util.Collection;
26 import java.util.LinkedList;
28 import org.onap.aai.logging.ErrorLogHelper;
29 import org.onap.aai.logging.ErrorObject;
30 import org.onap.aai.logging.ErrorObjectNotFoundException;
32 public class AAIException extends Exception {
34 private static final String UPDATE_ERROR_PROPERTIES_BEFORE_USING_THIS_EXCEPTION_CODE =
35 " - update error.properties before using this exception code";
36 private static final String FAILED_TO_INSTANTIATE_AAI_EXCEPTION_WITH_CODE =
37 "Failed to instantiate AAIException with code=";
38 public static final String DEFAULT_EXCEPTION_CODE = "AAI_4000";
39 private static final long serialVersionUID = 1L;
41 private final String code;
42 private final ErrorObject errorObject;
43 private final Collection<String> templateVars;
46 * Instantiates a new AAI exception.
48 public AAIException() {
50 this.code = DEFAULT_EXCEPTION_CODE;
51 this.templateVars = new LinkedList<>();
54 this.errorObject = ErrorLogHelper.getErrorObject(getCode());
55 } catch (ErrorObjectNotFoundException e) {
56 throw new RuntimeException(FAILED_TO_INSTANTIATE_AAI_EXCEPTION_WITH_CODE + getCode()
57 + UPDATE_ERROR_PROPERTIES_BEFORE_USING_THIS_EXCEPTION_CODE);
62 * Instantiates a new AAI exception.
64 * @param code the code
66 public AAIException(String code) {
70 this.templateVars = new LinkedList<>();
73 this.errorObject = ErrorLogHelper.getErrorObject(getCode());
74 } catch (ErrorObjectNotFoundException e) {
75 throw new RuntimeException(FAILED_TO_INSTANTIATE_AAI_EXCEPTION_WITH_CODE + getCode()
76 + UPDATE_ERROR_PROPERTIES_BEFORE_USING_THIS_EXCEPTION_CODE);
81 * Instantiates a new AAI exception.
83 * @param code the code
84 * @param details the details
86 public AAIException(String code, String details) {
90 this.templateVars = new LinkedList<>();
93 this.errorObject = ErrorLogHelper.getErrorObject(getCode());
94 errorObject.setDetails(details);
95 } catch (ErrorObjectNotFoundException e) {
96 throw new RuntimeException(FAILED_TO_INSTANTIATE_AAI_EXCEPTION_WITH_CODE + getCode()
97 + UPDATE_ERROR_PROPERTIES_BEFORE_USING_THIS_EXCEPTION_CODE);
102 * Instantiates a new AAI exception.
104 * @param code the code
105 * @param cause the cause
107 public AAIException(String code, Throwable cause) {
111 this.templateVars = new LinkedList<>();
114 this.errorObject = ErrorLogHelper.getErrorObject(getCode());
115 } catch (ErrorObjectNotFoundException e) {
116 throw new RuntimeException(FAILED_TO_INSTANTIATE_AAI_EXCEPTION_WITH_CODE + getCode()
117 + UPDATE_ERROR_PROPERTIES_BEFORE_USING_THIS_EXCEPTION_CODE);
122 * Instantiates a new AAI exception.
124 * @param code the code
125 * @param cause the cause
126 * @param details the details
128 public AAIException(String code, Throwable cause, String details) {
129 super(details, cause);
132 this.templateVars = new LinkedList<>();
135 this.errorObject = ErrorLogHelper.getErrorObject(getCode());
136 } catch (ErrorObjectNotFoundException e) {
137 throw new RuntimeException(FAILED_TO_INSTANTIATE_AAI_EXCEPTION_WITH_CODE + getCode()
138 + UPDATE_ERROR_PROPERTIES_BEFORE_USING_THIS_EXCEPTION_CODE);
142 public String getCode() {
146 public ErrorObject getErrorObject() {
150 public Collection<String> getTemplateVars() {