[SDC-29] Amdocs OnBoard 1707 initial commit.
[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     For backward compatibility only - will be removed soon
37   */
38
39   @Override
40   public String toString() {
41     return message;
42   }
43
44   public String id() {
45     return id;
46   }
47
48   @Deprecated
49   protected void id(String id) {
50     this.id = id;
51   }
52
53   public String message() {
54     return message;
55   }
56
57   @Deprecated
58   protected void message(String message) {
59     this.message = message;
60   }
61
62   public ErrorCategory category() {
63     return category;
64   }
65
66   @Deprecated
67   protected void category(ErrorCategory category) {
68     this.category = category;
69   }
70
71   public static class ErrorCodeBuilder {
72
73     private String id;
74     private String message;
75     private ErrorCategory category = ErrorCategory.APPLICATION;
76
77     public ErrorCodeBuilder withId(String id) {
78       this.id = id;
79       return this;
80     }
81
82     //todo remove later
83
84     public ErrorCodeBuilder withMessage(String message) {
85       this.message = message;
86       return this;
87     }
88
89     //todo remove later
90     public ErrorCodeBuilder withCategory(ErrorCategory category) {
91       this.category = category;
92       return this;
93     }
94
95     /**
96      * Build error code.
97      *
98      * @return the error code
99      */
100     public ErrorCode build() {
101       ErrorCode inst = new ErrorCode();
102       inst.id = id;
103       inst.message = message;
104       inst.category = category;
105       return inst;
106     }
107   }
108 }