Replaced all tabs with spaces in java and pom.xml
[so.git] / mso-api-handlers / mso-api-handler-common / src / main / java / org / onap / so / apihandlerinfra / exceptions / ApiException.java
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;
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 String getMessageID() {
53         return messageID;
54     }
55
56     public int getHttpResponseCode() {
57         return httpResponseCode;
58     }
59
60     public ErrorLoggerInfo getErrorLoggerInfo() {
61         return errorLoggerInfo;
62     }
63
64
65     public List<String> getVariables() {
66         return variables;
67     }
68
69     public static class Builder<T extends Builder<T>> {
70         private String message;
71         private Throwable cause = null;
72         private int httpResponseCode;
73         private String messageID;
74         private ErrorLoggerInfo errorLoggerInfo = null;
75
76         private List<String> variables = null;
77
78         public Builder(String message, int httpResponseCode, String messageID) {
79             this.message = message;
80             this.httpResponseCode = httpResponseCode;
81             this.messageID = messageID;
82         }
83
84         public T message(String message) {
85             this.message = message;
86             return (T) this;
87         }
88
89         public T cause(Throwable cause) {
90             this.cause = cause;
91             return (T) this;
92         }
93
94         public T httpResponseCode(int httpResponseCode) {
95             this.httpResponseCode = httpResponseCode;
96             return (T) this;
97         }
98
99         public T messageID(String messageID) {
100             this.messageID = messageID;
101             return (T) this;
102         }
103
104         public T errorInfo(ErrorLoggerInfo errorLoggerInfo) {
105             this.errorLoggerInfo = errorLoggerInfo;
106             return (T) this;
107         }
108
109         public T variables(List<String> variables) {
110             this.variables = variables;
111             return (T) this;
112         }
113     }
114 }