349013b7b63a5e5cfd8f90f940182bfdde9e8cd7
[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 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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21  */
22 package org.onap.aai.exceptions;
23
24 import java.util.Collection;
25 import java.util.LinkedList;
26
27 import org.onap.aai.logging.ErrorLogHelper;
28 import org.onap.aai.logging.ErrorObject;
29 import org.onap.aai.logging.ErrorObjectNotFoundException;
30
31 public class AAIException extends Exception {
32
33         public static final String DEFAULT_EXCEPTION_CODE = "AAI_4000";
34         private static final long serialVersionUID = 1L;
35
36         private final String code;
37         private final ErrorObject errorObject;
38         private final Collection<String> templateVars;
39
40         /**
41          * Instantiates a new AAI exception.
42          */
43         public AAIException() {
44                 super();
45                 this.code = DEFAULT_EXCEPTION_CODE;
46                 this.templateVars = new LinkedList<String> ();
47
48                 try {
49                         this.errorObject = ErrorLogHelper.getErrorObject(getCode());
50                 } catch (ErrorObjectNotFoundException e) {
51                         throw new RuntimeException("Failed to instantiate AAIException with code=" + getCode()
52                                                                                  + " - update error.properties before using this exception code");
53                 }
54         }
55
56         /**
57          * Instantiates a new AAI exception.
58          *
59          * @param code the code
60          */
61         public AAIException(String code) {
62                 super();
63
64                 this.code = code;
65                 this.templateVars = new LinkedList<String> ();
66
67                 try {
68                         this.errorObject = ErrorLogHelper.getErrorObject(getCode());
69                 } catch (ErrorObjectNotFoundException e) {
70                         throw new RuntimeException("Failed to instantiate AAIException with code=" + getCode()
71                                                                                  + " - update error.properties before using this exception code");
72                 }
73         }
74         
75         /**
76          * Instantiates a new AAI exception.
77          *
78          * @param code the code
79          * @param details the details
80          */
81         public AAIException(String code, String details) {
82                 super(details);
83
84                 this.code = code;
85                 this.templateVars = new LinkedList<String> ();
86
87                 try {
88                         this.errorObject = ErrorLogHelper.getErrorObject(getCode());
89                 } catch (ErrorObjectNotFoundException e) {
90                         throw new RuntimeException("Failed to instantiate AAIException with code=" + getCode()
91                                                                                  + " - update error.properties before using this exception code");
92                 }
93         }
94
95         /**
96          * Instantiates a new AAI exception.
97          *
98          * @param code the code
99          * @param cause the cause
100          */
101         public AAIException(String code, Throwable cause) {
102                 super(cause);
103
104                 this.code = code;
105                 this.templateVars = new LinkedList<String> ();
106
107                 try {
108                         this.errorObject = ErrorLogHelper.getErrorObject(getCode());
109                 } catch (ErrorObjectNotFoundException e) {
110                         throw new RuntimeException("Failed to instantiate AAIException with code=" + getCode()
111                                                                                  + " - update error.properties before using this exception code");
112                 }
113         }
114         
115         /**
116          * Instantiates a new AAI exception.
117          *
118          * @param code the code
119          * @param cause the cause
120          * @param details the details
121          */
122         public AAIException(String code, Throwable cause, String details) {
123                 super(details, cause);
124
125                 this.code = code;
126                 this.templateVars = new LinkedList<String> ();
127
128                 try {
129                         this.errorObject = ErrorLogHelper.getErrorObject(getCode());
130                 } catch (ErrorObjectNotFoundException e) {
131                         throw new RuntimeException("Failed to instantiate AAIException with code=" + getCode()
132                                                                                  + " - update error.properties before using this exception code");
133                 }
134         }
135         
136         public String getCode() {
137                 return code;
138         }
139
140         public ErrorObject getErrorObject() {
141                 return errorObject;
142         }
143
144         public Collection<String> getTemplateVars() {
145                 return templateVars;
146         }
147 }