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=========================================================
22 package org.onap.aai.exceptions;
24 import java.util.Collection;
25 import java.util.LinkedList;
27 import org.onap.aai.logging.ErrorLogHelper;
28 import org.onap.aai.logging.ErrorObject;
29 import org.onap.aai.logging.ErrorObjectNotFoundException;
31 public class AAIException extends Exception {
33 private static final String UPDATE_ERROR_PROPERTIES_BEFORE_USING_THIS_EXCEPTION_CODE = " - update error.properties before using this exception code";
34 private static final String FAILED_TO_INSTANTIATE_AAI_EXCEPTION_WITH_CODE = "Failed to instantiate AAIException with code=";
35 public static final String DEFAULT_EXCEPTION_CODE = "AAI_4000";
36 private static final long serialVersionUID = 1L;
38 private final String code;
39 private final ErrorObject errorObject;
40 private final Collection<String> templateVars;
43 * Instantiates a new AAI exception.
45 public AAIException() {
47 this.code = DEFAULT_EXCEPTION_CODE;
48 this.templateVars = new LinkedList<String> ();
51 this.errorObject = ErrorLogHelper.getErrorObject(getCode());
52 } catch (ErrorObjectNotFoundException e) {
53 throw new RuntimeException(FAILED_TO_INSTANTIATE_AAI_EXCEPTION_WITH_CODE + getCode()
54 + UPDATE_ERROR_PROPERTIES_BEFORE_USING_THIS_EXCEPTION_CODE);
59 * Instantiates a new AAI exception.
61 * @param code the code
63 public AAIException(String code) {
67 this.templateVars = new LinkedList<String> ();
70 this.errorObject = ErrorLogHelper.getErrorObject(getCode());
71 } catch (ErrorObjectNotFoundException e) {
72 throw new RuntimeException(FAILED_TO_INSTANTIATE_AAI_EXCEPTION_WITH_CODE + getCode()
73 + UPDATE_ERROR_PROPERTIES_BEFORE_USING_THIS_EXCEPTION_CODE);
78 * Instantiates a new AAI exception.
80 * @param code the code
81 * @param details the details
83 public AAIException(String code, String details) {
87 this.templateVars = new LinkedList<String> ();
90 this.errorObject = ErrorLogHelper.getErrorObject(getCode());
91 errorObject.setDetails(details);
92 } catch (ErrorObjectNotFoundException e) {
93 throw new RuntimeException(FAILED_TO_INSTANTIATE_AAI_EXCEPTION_WITH_CODE + getCode()
94 + UPDATE_ERROR_PROPERTIES_BEFORE_USING_THIS_EXCEPTION_CODE);
99 * Instantiates a new AAI exception.
101 * @param code the code
102 * @param cause the cause
104 public AAIException(String code, Throwable cause) {
108 this.templateVars = new LinkedList<String> ();
111 this.errorObject = ErrorLogHelper.getErrorObject(getCode());
112 } catch (ErrorObjectNotFoundException e) {
113 throw new RuntimeException(FAILED_TO_INSTANTIATE_AAI_EXCEPTION_WITH_CODE + getCode()
114 + UPDATE_ERROR_PROPERTIES_BEFORE_USING_THIS_EXCEPTION_CODE);
119 * Instantiates a new AAI exception.
121 * @param code the code
122 * @param cause the cause
123 * @param details the details
125 public AAIException(String code, Throwable cause, String details) {
126 super(details, cause);
129 this.templateVars = new LinkedList<String> ();
132 this.errorObject = ErrorLogHelper.getErrorObject(getCode());
133 } catch (ErrorObjectNotFoundException e) {
134 throw new RuntimeException(FAILED_TO_INSTANTIATE_AAI_EXCEPTION_WITH_CODE + getCode()
135 + UPDATE_ERROR_PROPERTIES_BEFORE_USING_THIS_EXCEPTION_CODE);
139 public String getCode() {
143 public ErrorObject getErrorObject() {
147 public Collection<String> getTemplateVars() {