1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.commons.ihe.xds.core.responses;
17
18 import org.apache.commons.lang3.builder.ToStringBuilder;
19 import org.apache.commons.lang3.builder.ToStringStyle;
20 import org.openehealth.ipf.commons.ihe.xds.core.XdsRuntimeException;
21 import org.openehealth.ipf.commons.ihe.xds.core.validate.XDSMetaDataException;
22
23 import javax.xml.bind.annotation.XmlAccessType;
24 import javax.xml.bind.annotation.XmlAccessorType;
25 import javax.xml.bind.annotation.XmlType;
26 import java.io.Serializable;
27
28
29
30
31
32
33 @XmlAccessorType(XmlAccessType.FIELD)
34 @XmlType(name = "ErrorInfo", propOrder = {"errorCode", "codeContext", "severity", "location", "customErrorCode"})
35 public class ErrorInfo implements Serializable {
36 private static final long serialVersionUID = 7615868122051414551L;
37
38 private ErrorCode errorCode;
39 private String codeContext;
40 private Severity severity;
41 private String location;
42
43
44 private String customErrorCode;
45
46
47
48
49
50 public ErrorInfo() {}
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66 public ErrorInfo(ErrorCode errorCode, String codeContext, Severity severity, String location, String customErrorCode) {
67 this.errorCode = errorCode;
68 this.codeContext = codeContext;
69 this.severity = severity;
70 this.location = location;
71 this.customErrorCode = customErrorCode;
72 }
73
74
75
76
77
78
79
80
81
82
83
84
85 public ErrorInfo(
86 Throwable throwable,
87 ErrorCode defaultMetaDataError,
88 ErrorCode defaultError,
89 String defaultLocation)
90 {
91 this(defaultError, throwable.getMessage(), Severity.ERROR, defaultLocation, null);
92 Throwable t = throwable;
93 while (t != null) {
94 if (t instanceof XDSMetaDataException) {
95 XDSMetaDataException metaDataException = (XDSMetaDataException) t;
96 this.errorCode = metaDataException.getValidationMessage().getErrorCode();
97 if (this.errorCode == null) {
98 this.errorCode = defaultMetaDataError;
99 }
100 this.codeContext = metaDataException.getMessage();
101 return;
102 }
103 if (t instanceof XdsRuntimeException) {
104 XdsRuntimeException exception = (XdsRuntimeException) t;
105 this.errorCode = exception.getErrorCode();
106 this.codeContext = exception.getCodeContext();
107 this.severity = exception.getSeverity();
108 this.location = exception.getLocation();
109 return;
110 }
111 t = t.getCause();
112 }
113 }
114
115
116
117
118 public ErrorCode getErrorCode() {
119 return errorCode;
120 }
121
122
123
124
125
126 public void setErrorCode(ErrorCode errorCode) {
127 this.errorCode = errorCode;
128 }
129
130
131
132
133 public String getCodeContext() {
134 return codeContext;
135 }
136
137
138
139
140
141 public void setCodeContext(String codeContext) {
142 this.codeContext = codeContext;
143 }
144
145
146
147
148 public Severity getSeverity() {
149 return severity;
150 }
151
152
153
154
155
156 public void setSeverity(Severity severity) {
157 this.severity = severity;
158 }
159
160
161
162
163 public String getLocation() {
164 return location;
165 }
166
167
168
169
170
171 public void setLocation(String location) {
172 this.location = location;
173 }
174
175
176
177
178
179 public String getCustomErrorCode() {
180 return customErrorCode;
181 }
182
183 public void setCustomErrorCode(String customErrorCode) {
184 this.customErrorCode = customErrorCode;
185 }
186
187 @Override
188 public int hashCode() {
189 final int prime = 31;
190 int result = 1;
191 result = prime * result + ((codeContext == null) ? 0 : codeContext.hashCode());
192 result = prime * result + ((errorCode == null) ? 0 : errorCode.hashCode());
193 result = prime * result + ((location == null) ? 0 : location.hashCode());
194 result = prime * result + ((severity == null) ? 0 : severity.hashCode());
195 result = prime * result + ((customErrorCode == null) ? 0 : customErrorCode.hashCode());
196 return result;
197 }
198
199 @Override
200 public boolean equals(Object obj) {
201 if (this == obj)
202 return true;
203 if (obj == null)
204 return false;
205 if (getClass() != obj.getClass())
206 return false;
207 ErrorInfo other = (ErrorInfo) obj;
208 if (codeContext == null) {
209 if (other.codeContext != null)
210 return false;
211 } else if (!codeContext.equals(other.codeContext))
212 return false;
213 if (errorCode == null) {
214 if (other.errorCode != null)
215 return false;
216 } else if (!errorCode.equals(other.errorCode))
217 return false;
218 if (location == null) {
219 if (other.location != null)
220 return false;
221 } else if (!location.equals(other.location))
222 return false;
223 if (severity == null) {
224 if (other.severity != null)
225 return false;
226 } else if (!severity.equals(other.severity))
227 return false;
228 if (customErrorCode == null) {
229 if (other.customErrorCode != null)
230 return false;
231 } else if (!customErrorCode.equals(other.customErrorCode))
232 return false;
233 return true;
234 }
235
236 @Override
237 public String toString() {
238 return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
239 }
240 }