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