push addional code
[sdc.git] / openecomp-be / lib / openecomp-common-lib / src / main / java / org / openecomp / sdc / common / errors / ErrorCode.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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.sdc.common.errors;
22
23 import java.io.Serializable;
24
25 public class ErrorCode implements Serializable {
26
27   private static final long serialVersionUID = 1L;
28
29   private String id;
30   private String message;
31   private ErrorCategory category;
32
33   protected ErrorCode() {
34   }
35
36   public String id() {
37     return id;
38   }
39
40   @Deprecated
41   protected void id(String id) {
42     this.id = id;
43   }
44
45   public String message() {
46     return message;
47   }
48
49   @Deprecated
50   protected void message(String message) {
51     this.message = message;
52   }
53
54   public ErrorCategory category() {
55     return category;
56   }
57
58   @Deprecated
59   protected void category(ErrorCategory category) {
60     this.category = category;
61   }
62
63   @Override
64   public String toString() {
65     return message;
66   }
67
68   public static class ErrorCodeBuilder {
69
70     private String id;
71     private String message;
72     private ErrorCategory category = ErrorCategory.APPLICATION;
73
74     public ErrorCodeBuilder withId(String id) {
75       this.id = id;
76       return this;
77     }
78
79     //todo remove later
80
81     public ErrorCodeBuilder withMessage(String message) {
82       this.message = message;
83       return this;
84     }
85
86     //todo remove later
87     public ErrorCodeBuilder withCategory(ErrorCategory category) {
88       this.category = category;
89       return this;
90     }
91
92     /**
93      * Build error code.
94      *
95      * @return the error code
96      */
97     public ErrorCode build() {
98       ErrorCode inst = new ErrorCode();
99       inst.id = id;
100       inst.message = message;
101       inst.category = category;
102       return inst;
103     }
104   }
105 }