[DMAAP-BC] Consolidate bus controller repos
[dmaap/buscontroller.git] / dmaap-bc / src / main / java / org / onap / dmaap / dbcapi / model / ApiError.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * org.onap.dmaap
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.dmaap.dbcapi.model;
22
23 import javax.xml.bind.annotation.XmlRootElement;
24 import java.io.Serializable;
25 import java.util.Objects;
26
27 @XmlRootElement
28 public class ApiError implements Serializable {
29         private int code;
30         private String message;
31         private String fields;
32
33         public ApiError() {
34                 this(0, null, null);
35         }
36
37         public ApiError(int code, String message) {
38                 this(code, message, null);
39         }
40
41         public ApiError(int code, String message, String fields) {
42                 this.code = code;
43                 this.message = message;
44                 this.fields = fields;
45         }
46
47         public int getCode() {
48                 return code;
49         }
50         public void setCode(int rc) {
51                 this.code = rc;
52         }
53         public String getMessage() {
54                 return message;
55         }
56         public void setMessage(String message) {
57                 this.message = message;
58         }
59         public String getFields() {
60                 return fields;
61         }
62         public void setFields(String fields) {
63                 this.fields = fields;
64         }
65         public String toString() {
66                 return String.format( "code=%d msg=%s fields=%s", this.code, this.message, this.fields );
67         }
68         public boolean is2xx() {
69                 
70                 return code >= 200 && code < 300;
71         }
72         public void reset() {
73                 code = 0;
74                 message = null;
75                 fields = null;
76         }
77
78         @Override
79         public boolean equals(Object o) {
80                 if (this == o) return true;
81                 if (o == null || getClass() != o.getClass()) return false;
82                 ApiError apiError = (ApiError) o;
83                 return code == apiError.code &&
84                                 Objects.equals(message, apiError.message) &&
85                                 Objects.equals(fields, apiError.fields);
86         }
87
88         @Override
89         public int hashCode() {
90                 return Objects.hash(code, message, fields);
91         }
92 }