ab2ce106907548f61893f31009d36665dfbe4003
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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.onap.so.apihandlerinfra.exceptions;
22
23
24 import java.util.List;
25 import org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo;
26
27 public abstract class ApiException extends Exception {
28     /**
29     * 
30     */
31     private static final long serialVersionUID = 683162058616691134L;
32     private int httpResponseCode = 500;
33     private String messageID;
34     private ErrorLoggerInfo errorLoggerInfo;
35
36     private List<String> variables;
37
38     public ApiException(Builder builder) {
39         super(builder.message, builder.cause);
40
41         this.httpResponseCode = builder.httpResponseCode;
42         this.messageID = builder.messageID;
43         this.variables = builder.variables;
44         this.errorLoggerInfo = builder.errorLoggerInfo;
45         this.variables = builder.variables;
46     }
47
48     public ApiException(String message, Throwable cause) {
49         super(message, cause);
50     }
51
52     public ApiException(String message, int httpResponseCode) {
53         super(message);
54         this.httpResponseCode = httpResponseCode;
55     }
56
57     public ApiException(String message) {
58         super(message);
59     }
60
61     public String getMessageID() {
62         return messageID;
63     }
64
65     public int getHttpResponseCode() {
66         return httpResponseCode;
67     }
68
69     public ErrorLoggerInfo getErrorLoggerInfo() {
70         return errorLoggerInfo;
71     }
72
73
74     public List<String> getVariables() {
75         return variables;
76     }
77
78     public static class Builder<T extends Builder<T>> {
79         private String message;
80         private Throwable cause = null;
81         private int httpResponseCode;
82         private String messageID;
83         private ErrorLoggerInfo errorLoggerInfo = null;
84
85         private List<String> variables = null;
86
87         public Builder(String message, int httpResponseCode, String messageID) {
88             this.message = message;
89             this.httpResponseCode = httpResponseCode;
90             this.messageID = messageID;
91         }
92
93         public T message(String message) {
94             this.message = message;
95             return (T) this;
96         }
97
98         public T cause(Throwable cause) {
99             this.cause = cause;
100             return (T) this;
101         }
102
103         public T httpResponseCode(int httpResponseCode) {
104             this.httpResponseCode = httpResponseCode;
105             return (T) this;
106         }
107
108         public T messageID(String messageID) {
109             this.messageID = messageID;
110             return (T) this;
111         }
112
113         public T errorInfo(ErrorLoggerInfo errorLoggerInfo) {
114             this.errorLoggerInfo = errorLoggerInfo;
115             return (T) this;
116         }
117
118         public T variables(List<String> variables) {
119             this.variables = variables;
120             return (T) this;
121         }
122     }
123 }