1 | |
package org.kuali.rice.kim.api.identity.phone; |
2 | |
|
3 | |
import org.apache.commons.lang.StringUtils; |
4 | |
import org.apache.commons.lang.builder.EqualsBuilder; |
5 | |
import org.apache.commons.lang.builder.HashCodeBuilder; |
6 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
7 | |
import org.kuali.rice.core.api.CoreConstants; |
8 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
9 | |
import org.kuali.rice.core.api.mo.ModelObjectComplete; |
10 | |
import org.kuali.rice.kim.api.KimConstants; |
11 | |
import org.kuali.rice.kim.api.identity.Type; |
12 | |
import org.w3c.dom.Element; |
13 | |
|
14 | |
import javax.xml.bind.annotation.XmlAccessType; |
15 | |
import javax.xml.bind.annotation.XmlAccessorType; |
16 | |
import javax.xml.bind.annotation.XmlAnyElement; |
17 | |
import javax.xml.bind.annotation.XmlElement; |
18 | |
import javax.xml.bind.annotation.XmlRootElement; |
19 | |
import javax.xml.bind.annotation.XmlType; |
20 | |
import java.io.Serializable; |
21 | |
import java.util.Collection; |
22 | |
|
23 | 3 | @XmlRootElement(name = EntityPhone.Constants.ROOT_ELEMENT_NAME) |
24 | |
@XmlAccessorType(XmlAccessType.NONE) |
25 | |
@XmlType(name = EntityPhone.Constants.TYPE_NAME, propOrder = { |
26 | |
EntityPhone.Elements.ID, |
27 | |
EntityPhone.Elements.ENTITY_TYPE_CODE, |
28 | |
EntityPhone.Elements.ENTITY_ID, |
29 | |
EntityPhone.Elements.PHONE_TYPE, |
30 | |
EntityPhone.Elements.COUNTRY_CODE, |
31 | |
EntityPhone.Elements.PHONE_NUMBER, |
32 | |
EntityPhone.Elements.EXTENSION_NUMBER, |
33 | |
EntityPhone.Elements.FORMATTED_PHONE_NUMBER, |
34 | |
EntityPhone.Elements.COUNTRY_CODE_UNMASKED, |
35 | |
EntityPhone.Elements.PHONE_NUMBER_UNMASKED, |
36 | |
EntityPhone.Elements.EXTENSION_NUMBER_UNMASKED, |
37 | |
EntityPhone.Elements.FORMATTED_PHONE_NUMBER_UNMASKED, |
38 | |
EntityPhone.Elements.SUPPRESS_PHONE, |
39 | |
EntityPhone.Elements.DEFAULT_VALUE, |
40 | |
EntityPhone.Elements.ACTIVE, |
41 | |
CoreConstants.CommonElements.VERSION_NUMBER, |
42 | |
CoreConstants.CommonElements.OBJECT_ID, |
43 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
44 | |
}) |
45 | 6 | public final class EntityPhone |
46 | |
implements ModelObjectComplete, EntityPhoneContract |
47 | |
{ |
48 | |
|
49 | |
@XmlElement(name = Elements.ID, required = false) |
50 | |
private final String id; |
51 | |
@XmlElement(name = Elements.ENTITY_TYPE_CODE, required = false) |
52 | |
private final String entityTypeCode; |
53 | |
@XmlElement(name = Elements.ENTITY_ID, required = false) |
54 | |
private final String entityId; |
55 | |
@XmlElement(name = Elements.PHONE_TYPE, required = false) |
56 | |
private final Type phoneType; |
57 | |
@XmlElement(name = Elements.PHONE_NUMBER, required = false) |
58 | |
private final String phoneNumber; |
59 | |
@XmlElement(name = Elements.EXTENSION_NUMBER, required = false) |
60 | |
private final String extensionNumber; |
61 | |
@XmlElement(name = Elements.COUNTRY_CODE, required = false) |
62 | |
private final String countryCode; |
63 | |
@XmlElement(name = Elements.PHONE_NUMBER_UNMASKED, required = false) |
64 | |
private final String phoneNumberUnmasked; |
65 | |
@XmlElement(name = Elements.EXTENSION_NUMBER_UNMASKED, required = false) |
66 | |
private final String extensionNumberUnmasked; |
67 | |
@XmlElement(name = Elements.COUNTRY_CODE_UNMASKED, required = false) |
68 | |
private final String countryCodeUnmasked; |
69 | |
@XmlElement(name = Elements.FORMATTED_PHONE_NUMBER, required = false) |
70 | |
private final String formattedPhoneNumber; |
71 | |
@XmlElement(name = Elements.FORMATTED_PHONE_NUMBER_UNMASKED, required = false) |
72 | |
private final String formattedPhoneNumberUnmasked; |
73 | |
@XmlElement(name = Elements.SUPPRESS_PHONE, required = false) |
74 | |
private final boolean suppressPhone; |
75 | |
@XmlElement(name = Elements.DEFAULT_VALUE, required = false) |
76 | |
private final boolean defaultValue; |
77 | |
@XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false) |
78 | |
private final Long versionNumber; |
79 | |
@XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false) |
80 | |
private final String objectId; |
81 | |
@XmlElement(name = Elements.ACTIVE, required = false) |
82 | |
private final boolean active; |
83 | 12 | @SuppressWarnings("unused") |
84 | |
@XmlAnyElement |
85 | |
private final Collection<Element> _futureElements = null; |
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | 6 | private EntityPhone() { |
92 | 6 | this.id = null; |
93 | 6 | this.entityId = null; |
94 | 6 | this.entityTypeCode = null; |
95 | 6 | this.phoneType = null; |
96 | 6 | this.phoneNumber = null; |
97 | 6 | this.extensionNumber = null; |
98 | 6 | this.countryCode = null; |
99 | 6 | this.phoneNumberUnmasked = null; |
100 | 6 | this.extensionNumberUnmasked = null; |
101 | 6 | this.countryCodeUnmasked = null; |
102 | 6 | this.formattedPhoneNumber = null; |
103 | 6 | this.formattedPhoneNumberUnmasked = null; |
104 | 6 | this.suppressPhone = false; |
105 | 6 | this.defaultValue = false; |
106 | 6 | this.versionNumber = null; |
107 | 6 | this.objectId = null; |
108 | 6 | this.active = false; |
109 | 6 | } |
110 | |
|
111 | 6 | private EntityPhone(Builder builder) { |
112 | 6 | this.id = builder.getId(); |
113 | 6 | this.entityId = builder.getEntityId(); |
114 | 6 | this.entityTypeCode = builder.getEntityTypeCode(); |
115 | 6 | this.phoneType = (builder.getPhoneType() != null) ? builder.getPhoneType().build() : null; |
116 | 6 | this.phoneNumber = builder.getPhoneNumber(); |
117 | 6 | this.extensionNumber = builder.getExtensionNumber(); |
118 | 6 | this.countryCode = builder.getCountryCode(); |
119 | 6 | this.phoneNumberUnmasked = builder.getPhoneNumberUnmasked(); |
120 | 6 | this.extensionNumberUnmasked = builder.getExtensionNumberUnmasked(); |
121 | 6 | this.countryCodeUnmasked = builder.getCountryCodeUnmasked(); |
122 | 6 | this.formattedPhoneNumber = builder.getFormattedPhoneNumber(); |
123 | 6 | this.formattedPhoneNumberUnmasked = builder.getFormattedPhoneNumberUnmasked(); |
124 | 6 | this.suppressPhone = builder.isSuppressPhone(); |
125 | 6 | this.defaultValue = builder.isDefaultValue(); |
126 | 6 | this.versionNumber = builder.getVersionNumber(); |
127 | 6 | this.objectId = builder.getObjectId(); |
128 | 6 | this.active = builder.isActive(); |
129 | 6 | } |
130 | |
|
131 | |
@Override |
132 | |
public String getId() { |
133 | 2 | return this.id; |
134 | |
} |
135 | |
|
136 | |
@Override |
137 | |
public String getEntityId() { |
138 | 2 | return this.entityId; |
139 | |
} |
140 | |
|
141 | |
@Override |
142 | |
public String getEntityTypeCode() { |
143 | 2 | return this.entityTypeCode; |
144 | |
} |
145 | |
|
146 | |
@Override |
147 | |
public Type getPhoneType() { |
148 | 3 | return this.phoneType; |
149 | |
} |
150 | |
|
151 | |
@Override |
152 | |
public String getPhoneNumber() { |
153 | 0 | return this.phoneNumber; |
154 | |
} |
155 | |
|
156 | |
@Override |
157 | |
public String getExtensionNumber() { |
158 | 0 | return this.extensionNumber; |
159 | |
} |
160 | |
|
161 | |
@Override |
162 | |
public String getCountryCode() { |
163 | 0 | return this.countryCode; |
164 | |
} |
165 | |
|
166 | |
@Override |
167 | |
public String getPhoneNumberUnmasked() { |
168 | 2 | return this.phoneNumberUnmasked; |
169 | |
} |
170 | |
|
171 | |
@Override |
172 | |
public String getExtensionNumberUnmasked() { |
173 | 2 | return this.extensionNumberUnmasked; |
174 | |
} |
175 | |
|
176 | |
@Override |
177 | |
public String getCountryCodeUnmasked() { |
178 | 2 | return this.countryCodeUnmasked; |
179 | |
} |
180 | |
|
181 | |
@Override |
182 | |
public String getFormattedPhoneNumber() { |
183 | 0 | return this.formattedPhoneNumber; |
184 | |
} |
185 | |
|
186 | |
@Override |
187 | |
public String getFormattedPhoneNumberUnmasked() { |
188 | 0 | return this.formattedPhoneNumberUnmasked; |
189 | |
} |
190 | |
|
191 | |
@Override |
192 | |
public boolean isSuppressPhone() { |
193 | 2 | return this.suppressPhone; |
194 | |
} |
195 | |
|
196 | |
@Override |
197 | |
public boolean isDefaultValue() { |
198 | 2 | return this.defaultValue; |
199 | |
} |
200 | |
|
201 | |
@Override |
202 | |
public Long getVersionNumber() { |
203 | 2 | return this.versionNumber; |
204 | |
} |
205 | |
|
206 | |
@Override |
207 | |
public String getObjectId() { |
208 | 2 | return this.objectId; |
209 | |
} |
210 | |
|
211 | |
@Override |
212 | |
public boolean isActive() { |
213 | 2 | return this.active; |
214 | |
} |
215 | |
|
216 | |
@Override |
217 | |
public int hashCode() { |
218 | 0 | return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
219 | |
} |
220 | |
|
221 | |
@Override |
222 | |
public boolean equals(Object object) { |
223 | 7 | return EqualsBuilder.reflectionEquals(object, this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
224 | |
} |
225 | |
|
226 | |
@Override |
227 | |
public String toString() { |
228 | 0 | return ToStringBuilder.reflectionToString(this); |
229 | |
} |
230 | |
|
231 | |
|
232 | |
|
233 | |
|
234 | |
|
235 | |
|
236 | 4 | public final static class Builder |
237 | |
implements Serializable, ModelBuilder, EntityPhoneContract |
238 | |
{ |
239 | |
|
240 | |
private String id; |
241 | |
private String entityId; |
242 | |
private String entityTypeCode; |
243 | |
private Type.Builder phoneType; |
244 | |
|
245 | |
|
246 | |
|
247 | |
private String phoneNumberUnmasked; |
248 | |
private String extensionNumberUnmasked; |
249 | |
private String countryCodeUnmasked; |
250 | |
|
251 | |
|
252 | |
private boolean suppressPhone; |
253 | |
private boolean defaultValue; |
254 | |
private Long versionNumber; |
255 | |
private String objectId; |
256 | |
private boolean active; |
257 | |
|
258 | 7 | private Builder() { |
259 | |
|
260 | 7 | } |
261 | |
|
262 | |
public static Builder create() { |
263 | 7 | return new Builder(); |
264 | |
} |
265 | |
|
266 | |
public static Builder create(EntityPhoneContract contract) { |
267 | 4 | if (contract == null) { |
268 | 0 | throw new IllegalArgumentException("contract was null"); |
269 | |
} |
270 | 4 | Builder builder = create(); |
271 | 4 | builder.setId(contract.getId()); |
272 | 4 | builder.setEntityId(contract.getEntityId()); |
273 | 4 | builder.setEntityTypeCode(contract.getEntityTypeCode()); |
274 | 4 | builder.setSuppressPhone(contract.isSuppressPhone()); |
275 | 4 | if (contract.getPhoneType() != null) { |
276 | 3 | builder.setPhoneType(Type.Builder.create(contract.getPhoneType())); |
277 | |
} |
278 | 4 | builder.setPhoneNumber(contract.getPhoneNumberUnmasked()); |
279 | 4 | builder.setExtensionNumber(contract.getExtensionNumberUnmasked()); |
280 | 4 | builder.setCountryCode(contract.getCountryCodeUnmasked()); |
281 | 4 | builder.setDefaultValue(contract.isDefaultValue()); |
282 | 4 | builder.setVersionNumber(contract.getVersionNumber()); |
283 | 4 | builder.setObjectId(contract.getObjectId()); |
284 | 4 | builder.setActive(contract.isActive()); |
285 | 4 | return builder; |
286 | |
} |
287 | |
|
288 | |
public EntityPhone build() { |
289 | 6 | return new EntityPhone(this); |
290 | |
} |
291 | |
|
292 | |
@Override |
293 | |
public String getId() { |
294 | 6 | return this.id; |
295 | |
} |
296 | |
|
297 | |
@Override |
298 | |
public String getEntityTypeCode() { |
299 | 6 | return this.entityTypeCode; |
300 | |
} |
301 | |
|
302 | |
@Override |
303 | |
public String getEntityId() { |
304 | 6 | return this.entityId; |
305 | |
} |
306 | |
|
307 | |
@Override |
308 | |
public Type.Builder getPhoneType() { |
309 | 10 | return this.phoneType; |
310 | |
} |
311 | |
|
312 | |
@Override |
313 | |
public String getPhoneNumber() { |
314 | 6 | if (isSuppressPhone()) { |
315 | 0 | return KimConstants.RestrictedMasks.RESTRICTED_DATA_MASK_PHONE; |
316 | |
} |
317 | 6 | return this.phoneNumberUnmasked; |
318 | |
} |
319 | |
|
320 | |
@Override |
321 | |
public String getExtensionNumber() { |
322 | 6 | if (isSuppressPhone()) { |
323 | 0 | return KimConstants.RestrictedMasks.RESTRICTED_DATA_MASK; |
324 | |
} |
325 | 6 | return this.extensionNumberUnmasked; |
326 | |
} |
327 | |
|
328 | |
@Override |
329 | |
public String getCountryCode() { |
330 | 6 | if (isSuppressPhone()) { |
331 | 0 | return KimConstants.RestrictedMasks.RESTRICTED_DATA_MASK_CODE; |
332 | |
} |
333 | 6 | return this.countryCodeUnmasked; |
334 | |
} |
335 | |
|
336 | |
@Override |
337 | |
public String getPhoneNumberUnmasked() { |
338 | 6 | return this.phoneNumberUnmasked; |
339 | |
} |
340 | |
|
341 | |
@Override |
342 | |
public String getExtensionNumberUnmasked() { |
343 | 6 | return this.extensionNumberUnmasked; |
344 | |
} |
345 | |
|
346 | |
@Override |
347 | |
public String getCountryCodeUnmasked() { |
348 | 6 | return this.countryCodeUnmasked; |
349 | |
} |
350 | |
|
351 | |
@Override |
352 | |
public String getFormattedPhoneNumber() { |
353 | 6 | if (isSuppressPhone()) { |
354 | 0 | return KimConstants.RestrictedMasks.RESTRICTED_DATA_MASK; |
355 | |
} |
356 | 6 | return this.getFormattedPhoneNumberUnmasked(); |
357 | |
} |
358 | |
|
359 | |
@Override |
360 | |
public String getFormattedPhoneNumberUnmasked() { |
361 | 12 | StringBuffer sb = new StringBuffer( 30 ); |
362 | |
|
363 | |
|
364 | |
|
365 | 12 | sb.append( this.phoneNumberUnmasked ); |
366 | 12 | if ( StringUtils.isNotBlank( this.extensionNumberUnmasked) ) { |
367 | 8 | sb.append( " x" ); |
368 | 8 | sb.append( this.extensionNumberUnmasked ); |
369 | |
} |
370 | |
|
371 | 12 | return sb.toString(); |
372 | |
} |
373 | |
|
374 | |
@Override |
375 | |
public boolean isSuppressPhone() { |
376 | 30 | return this.suppressPhone; |
377 | |
} |
378 | |
|
379 | |
@Override |
380 | |
public boolean isDefaultValue() { |
381 | 8 | return this.defaultValue; |
382 | |
} |
383 | |
|
384 | |
@Override |
385 | |
public Long getVersionNumber() { |
386 | 6 | return this.versionNumber; |
387 | |
} |
388 | |
|
389 | |
@Override |
390 | |
public String getObjectId() { |
391 | 6 | return this.objectId; |
392 | |
} |
393 | |
|
394 | |
@Override |
395 | |
public boolean isActive() { |
396 | 8 | return this.active; |
397 | |
} |
398 | |
|
399 | |
public void setId(String id) { |
400 | 5 | if (StringUtils.isWhitespace(id)) { |
401 | 1 | throw new IllegalArgumentException("id is blank"); |
402 | |
} |
403 | 4 | this.id = id; |
404 | 4 | } |
405 | |
|
406 | |
public void setEntityTypeCode(String entityTypeCode) { |
407 | 4 | this.entityTypeCode = entityTypeCode; |
408 | 4 | } |
409 | |
|
410 | |
public void setEntityId(String entityId) { |
411 | 4 | this.entityId = entityId; |
412 | 4 | } |
413 | |
|
414 | |
public void setPhoneType(Type.Builder phoneType) { |
415 | 3 | this.phoneType = phoneType; |
416 | 3 | } |
417 | |
|
418 | |
public void setPhoneNumber(String phoneNumber) { |
419 | 4 | this.phoneNumberUnmasked = phoneNumber; |
420 | 4 | } |
421 | |
|
422 | |
public void setExtensionNumber(String extensionNumber) { |
423 | 4 | this.extensionNumberUnmasked = extensionNumber; |
424 | 4 | } |
425 | |
|
426 | |
public void setCountryCode(String countryCode) { |
427 | 4 | this.countryCodeUnmasked = countryCode; |
428 | 4 | } |
429 | |
|
430 | |
private void setSuppressPhone(boolean suppressPhone) { |
431 | 4 | this.suppressPhone = suppressPhone; |
432 | 4 | } |
433 | |
|
434 | |
public void setDefaultValue(boolean defaultValue) { |
435 | 4 | this.defaultValue = defaultValue; |
436 | 4 | } |
437 | |
|
438 | |
public void setVersionNumber(Long versionNumber) { |
439 | 4 | this.versionNumber = versionNumber; |
440 | 4 | } |
441 | |
|
442 | |
public void setObjectId(String objectId) { |
443 | 4 | this.objectId = objectId; |
444 | 4 | } |
445 | |
|
446 | |
public void setActive(boolean active) { |
447 | 4 | this.active = active; |
448 | 4 | } |
449 | |
|
450 | |
} |
451 | |
|
452 | |
|
453 | |
|
454 | |
|
455 | |
|
456 | |
|
457 | 0 | static class Constants { |
458 | |
|
459 | |
final static String ROOT_ELEMENT_NAME = "entityPhone"; |
460 | |
final static String TYPE_NAME = "EntityPhoneType"; |
461 | 1 | final static String[] HASH_CODE_EQUALS_EXCLUDE = new String[] {CoreConstants.CommonElements.FUTURE_ELEMENTS }; |
462 | |
|
463 | |
} |
464 | |
|
465 | |
|
466 | |
|
467 | |
|
468 | |
|
469 | |
|
470 | 0 | static class Elements { |
471 | |
|
472 | |
final static String ID = "id"; |
473 | |
final static String ENTITY_TYPE_CODE = "entityTypeCode"; |
474 | |
final static String ENTITY_ID = "entityId"; |
475 | |
final static String PHONE_TYPE = "phoneType"; |
476 | |
final static String PHONE_NUMBER = "phoneNumber"; |
477 | |
final static String EXTENSION_NUMBER = "extensionNumber"; |
478 | |
final static String COUNTRY_CODE = "countryCode"; |
479 | |
final static String PHONE_NUMBER_UNMASKED = "phoneNumberUnmasked"; |
480 | |
final static String EXTENSION_NUMBER_UNMASKED = "extensionNumberUnmasked"; |
481 | |
final static String COUNTRY_CODE_UNMASKED = "countryCodeUnmasked"; |
482 | |
final static String FORMATTED_PHONE_NUMBER = "formattedPhoneNumber"; |
483 | |
final static String FORMATTED_PHONE_NUMBER_UNMASKED = "formattedPhoneNumberUnmasked"; |
484 | |
final static String SUPPRESS_PHONE = "suppressPhone"; |
485 | |
final static String DEFAULT_VALUE = "defaultValue"; |
486 | |
final static String ACTIVE = "active"; |
487 | |
|
488 | |
} |
489 | |
|
490 | |
} |