Containerization feature of SO
[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 import org.onap.so.apihandlerinfra.logging.AlarmLoggerInfo;
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     private AlarmLoggerInfo alarmLoggerInfo;
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.alarmLoggerInfo = builder.alarmLoggerInfo;
48         this.variables = builder.variables;        
49     }
50
51     public ApiException(String message, Throwable cause) {
52          super(message, cause);
53         }
54
55         public String getMessageID() {
56         return messageID;
57     }
58
59     public int getHttpResponseCode() {
60         return httpResponseCode;
61     }
62
63     public ErrorLoggerInfo getErrorLoggerInfo() {
64         return errorLoggerInfo;
65     }
66
67     public AlarmLoggerInfo getAlarmLoggerInfo() {
68         return alarmLoggerInfo;
69     }
70
71     public List<String> getVariables() {
72         return variables;
73     }
74
75     public static class Builder<T extends Builder<T>> {
76         private String message;
77         private Throwable cause = null;
78         private int httpResponseCode;
79         private String messageID;
80         private ErrorLoggerInfo errorLoggerInfo = null;
81         private AlarmLoggerInfo alarmLoggerInfo = null;
82         private List<String> variables = null;
83         
84         public Builder(String message, int httpResponseCode, String messageID) {
85             this.message = message;
86             this.httpResponseCode = httpResponseCode;
87             this.messageID = messageID;
88         }
89
90         public T message(String message) {
91             this.message = message;
92             return (T) this;
93         }
94
95         public T cause(Throwable cause) {
96             this.cause = cause;
97             return (T) this;
98         }
99
100         public T httpResponseCode(int httpResponseCode) {
101             this.httpResponseCode = httpResponseCode;
102             return (T) this;
103         }
104
105         public T messageID(String messageID) {
106             this.messageID = messageID;
107             return (T) this;
108         }
109
110         public T errorInfo(ErrorLoggerInfo errorLoggerInfo){
111             this.errorLoggerInfo = errorLoggerInfo;
112             return (T) this;
113         }
114
115         public T alarmInfo(AlarmLoggerInfo alarmLoggerInfo){
116             this.alarmLoggerInfo = alarmLoggerInfo;
117             return (T) this;
118         }
119
120         public T variables(List<String> variables) {
121             this.variables = variables;
122             return (T) this;
123         }
124     }
125 }