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