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