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