Update the license for 2017-2018 license
[aai/aai-common.git] / aai-core / src / main / java / org / onap / aai / exceptions / AAIException.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *    http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.aai.exceptions;
21
22 import java.util.Collection;
23 import java.util.LinkedList;
24
25 import org.onap.aai.logging.ErrorLogHelper;
26 import org.onap.aai.logging.ErrorObject;
27 import org.onap.aai.logging.ErrorObjectNotFoundException;
28
29 public class AAIException extends Exception {
30
31         public static final String DEFAULT_EXCEPTION_CODE = "AAI_4000";
32         private static final long serialVersionUID = 1L;
33
34         private final String code;
35         private final ErrorObject errorObject;
36         private final Collection<String> templateVars;
37
38         /**
39          * Instantiates a new AAI exception.
40          */
41         public AAIException() {
42                 super();
43                 this.code = DEFAULT_EXCEPTION_CODE;
44                 this.templateVars = new LinkedList<String> ();
45
46                 try {
47                         this.errorObject = ErrorLogHelper.getErrorObject(getCode());
48                 } catch (ErrorObjectNotFoundException e) {
49                         throw new RuntimeException("Failed to instantiate AAIException with code=" + getCode()
50                                                                                  + " - update error.properties before using this exception code");
51                 }
52         }
53
54         /**
55          * Instantiates a new AAI exception.
56          *
57          * @param code the code
58          */
59         public AAIException(String code) {
60                 super();
61
62                 this.code = code;
63                 this.templateVars = new LinkedList<String> ();
64
65                 try {
66                         this.errorObject = ErrorLogHelper.getErrorObject(getCode());
67                 } catch (ErrorObjectNotFoundException e) {
68                         throw new RuntimeException("Failed to instantiate AAIException with code=" + getCode()
69                                                                                  + " - update error.properties before using this exception code");
70                 }
71         }
72         
73         /**
74          * Instantiates a new AAI exception.
75          *
76          * @param code the code
77          * @param details the details
78          */
79         public AAIException(String code, String details) {
80                 super(details);
81
82                 this.code = code;
83                 this.templateVars = new LinkedList<String> ();
84
85                 try {
86                         this.errorObject = ErrorLogHelper.getErrorObject(getCode());
87                 } catch (ErrorObjectNotFoundException e) {
88                         throw new RuntimeException("Failed to instantiate AAIException with code=" + getCode()
89                                                                                  + " - update error.properties before using this exception code");
90                 }
91         }
92
93         /**
94          * Instantiates a new AAI exception.
95          *
96          * @param code the code
97          * @param cause the cause
98          */
99         public AAIException(String code, Throwable cause) {
100                 super(cause);
101
102                 this.code = code;
103                 this.templateVars = new LinkedList<String> ();
104
105                 try {
106                         this.errorObject = ErrorLogHelper.getErrorObject(getCode());
107                 } catch (ErrorObjectNotFoundException e) {
108                         throw new RuntimeException("Failed to instantiate AAIException with code=" + getCode()
109                                                                                  + " - update error.properties before using this exception code");
110                 }
111         }
112         
113         /**
114          * Instantiates a new AAI exception.
115          *
116          * @param code the code
117          * @param cause the cause
118          * @param details the details
119          */
120         public AAIException(String code, Throwable cause, String details) {
121                 super(details, cause);
122
123                 this.code = code;
124                 this.templateVars = new LinkedList<String> ();
125
126                 try {
127                         this.errorObject = ErrorLogHelper.getErrorObject(getCode());
128                 } catch (ErrorObjectNotFoundException e) {
129                         throw new RuntimeException("Failed to instantiate AAIException with code=" + getCode()
130                                                                                  + " - update error.properties before using this exception code");
131                 }
132         }
133         
134         public String getCode() {
135                 return code;
136         }
137
138         public ErrorObject getErrorObject() {
139                 return errorObject;
140         }
141
142         public Collection<String> getTemplateVars() {
143                 return templateVars;
144         }
145 }