View Javadoc

1   /**
2    * Copyright 2005-2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kim.api.identity.name;
17  
18  import java.io.Serializable;
19  import java.text.SimpleDateFormat;
20  import java.util.Collection;
21  import java.util.Date;
22  import javax.xml.bind.annotation.XmlAccessType;
23  import javax.xml.bind.annotation.XmlAccessorType;
24  import javax.xml.bind.annotation.XmlAnyElement;
25  import javax.xml.bind.annotation.XmlElement;
26  import javax.xml.bind.annotation.XmlRootElement;
27  import javax.xml.bind.annotation.XmlSchemaType;
28  import javax.xml.bind.annotation.XmlType;
29  import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
30  
31  import org.apache.commons.lang.StringUtils;
32  import org.joda.time.DateTime;
33  import org.kuali.rice.core.api.CoreConstants;
34  import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
35  import org.kuali.rice.core.api.mo.ModelBuilder;
36  import org.kuali.rice.kim.api.KimConstants;
37  import org.kuali.rice.kim.api.identity.CodedAttribute;
38  import org.kuali.rice.core.api.util.jaxb.DateTimeAdapter;
39  import org.w3c.dom.Element;
40  
41  import javax.xml.bind.annotation.XmlAccessType;
42  import javax.xml.bind.annotation.XmlAccessorType;
43  import javax.xml.bind.annotation.XmlAnyElement;
44  import javax.xml.bind.annotation.XmlElement;
45  import javax.xml.bind.annotation.XmlRootElement;
46  import javax.xml.bind.annotation.XmlType;
47  import java.io.Serializable;
48  import java.util.Collection;
49  
50  @XmlRootElement(name = EntityName.Constants.ROOT_ELEMENT_NAME)
51  @XmlAccessorType(XmlAccessType.NONE)
52  @XmlType(name = EntityName.Constants.TYPE_NAME, propOrder = {
53      EntityName.Elements.ID,
54      EntityName.Elements.ENTITY_ID,
55      EntityName.Elements.NAME_TYPE,
56      EntityName.Elements.NAME_PREFIX,
57      EntityName.Elements.NAME_TITLE,
58      EntityName.Elements.FIRST_NAME,
59      EntityName.Elements.MIDDLE_NAME,
60      EntityName.Elements.LAST_NAME,
61      EntityName.Elements.NAME_SUFFIX,
62      EntityName.Elements.COMPOSITE_NAME,
63      EntityName.Elements.NAME_PREFIX_UNMASKED,
64      EntityName.Elements.NAME_TITLE_UNMASKED,
65      EntityName.Elements.FIRST_NAME_UNMASKED,
66      EntityName.Elements.MIDDLE_NAME_UNMASKED,
67      EntityName.Elements.LAST_NAME_UNMASKED,
68      EntityName.Elements.NAME_SUFFIX_UNMASKED,
69      EntityName.Elements.COMPOSITE_NAME_UNMASKED,
70      EntityName.Elements.NOTE_MESSAGE,
71      EntityName.Elements.NAME_CHANGED_DATE,
72      EntityName.Elements.SUPPRESS_NAME,
73      EntityName.Elements.DEFAULT_VALUE,
74      EntityName.Elements.ACTIVE,
75      CoreConstants.CommonElements.VERSION_NUMBER,
76      CoreConstants.CommonElements.OBJECT_ID,
77      CoreConstants.CommonElements.FUTURE_ELEMENTS
78  })
79  public final class EntityName extends AbstractDataTransferObject
80      implements EntityNameContract
81  {
82  
83      @XmlElement(name = Elements.NAME_SUFFIX, required = false)
84      private final String nameSuffix;
85      @XmlElement(name = Elements.ENTITY_ID, required = false)
86      private final String entityId;
87      @XmlElement(name = Elements.NAME_TYPE, required = false)
88      private final CodedAttribute nameType;
89      @XmlElement(name = Elements.FIRST_NAME, required = false)
90      private final String firstName;
91      @XmlElement(name = Elements.FIRST_NAME_UNMASKED, required = false)
92      private final String firstNameUnmasked;
93      @XmlElement(name = Elements.MIDDLE_NAME, required = false)
94      private final String middleName;
95      @XmlElement(name = Elements.MIDDLE_NAME_UNMASKED, required = false)
96      private final String middleNameUnmasked;
97      @XmlElement(name = Elements.LAST_NAME, required = false)
98      private final String lastName;
99      @XmlElement(name = Elements.LAST_NAME_UNMASKED, required = false)
100     private final String lastNameUnmasked;
101     @XmlElement(name = Elements.NAME_PREFIX, required = false)
102     private final String namePrefix;
103     @XmlElement(name = Elements.NAME_PREFIX_UNMASKED, required = false)
104     private final String namePrefixUnmasked;
105     @XmlElement(name = Elements.NAME_TITLE, required = false)
106     private final String nameTitle;
107     @XmlElement(name = Elements.NAME_TITLE_UNMASKED, required = false)
108     private final String nameTitleUnmasked;
109     @XmlElement(name = Elements.NAME_SUFFIX_UNMASKED, required = false)
110     private final String nameSuffixUnmasked;
111     @XmlElement(name = Elements.COMPOSITE_NAME, required = false)
112     private final String compositeName;
113     @XmlElement(name = Elements.COMPOSITE_NAME_UNMASKED, required = false)
114     private final String compositeNameUnmasked;
115     @XmlElement(name = Elements.NOTE_MESSAGE, required = false)
116     private final String noteMessage;
117     @XmlElement(name = Elements.NAME_CHANGED_DATE, required = false)
118     @XmlJavaTypeAdapter(DateTimeAdapter.class)
119     private final DateTime nameChangedDate;
120     @XmlElement(name = Elements.SUPPRESS_NAME, required = false)
121     private final boolean suppressName;
122     @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
123     private final Long versionNumber;
124     @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
125     private final String objectId;
126     @XmlElement(name = Elements.DEFAULT_VALUE, required = false)
127     private final boolean defaultValue;
128     @XmlElement(name = Elements.ACTIVE, required = false)
129     private final boolean active;
130     @XmlElement(name = Elements.ID, required = false)
131     private final String id;
132     @SuppressWarnings("unused")
133     @XmlAnyElement
134     private final Collection<Element> _futureElements = null;
135 
136     /**
137      * Private constructor used only by JAXB.
138      * 
139      */
140     private EntityName() {
141         this.nameSuffix = null;
142         this.entityId = null;
143         this.nameType = null;
144         this.firstName = null;
145         this.firstNameUnmasked = null;
146         this.middleName = null;
147         this.middleNameUnmasked = null;
148         this.lastName = null;
149         this.lastNameUnmasked = null;
150         this.namePrefix = null;
151         this.namePrefixUnmasked = null;
152         this.nameTitle = null;
153         this.nameTitleUnmasked = null;
154         this.nameSuffixUnmasked = null;
155         this.compositeName = null;
156         this.compositeNameUnmasked = null;
157         this.noteMessage = null;
158         this.nameChangedDate = null;
159         this.suppressName = false;
160         this.versionNumber = null;
161         this.objectId = null;
162         this.defaultValue = false;
163         this.active = false;
164         this.id = null;
165     }
166 
167     private EntityName(Builder builder) {
168         this.nameSuffix = builder.getNameSuffix();
169         this.entityId = builder.getEntityId();
170         this.nameType = builder.getNameType() != null ? builder.getNameType().build() : null;
171         this.firstName = builder.getFirstName();
172         this.firstNameUnmasked = builder.getFirstNameUnmasked();
173         this.middleName = builder.getMiddleName();
174         this.middleNameUnmasked = builder.getMiddleNameUnmasked();
175         this.lastName = builder.getLastName();
176         this.lastNameUnmasked = builder.getLastNameUnmasked();
177         this.namePrefix = builder.getNamePrefix();
178         this.namePrefixUnmasked = builder.getNamePrefixUnmasked();
179         this.nameTitle = builder.getNameTitle();
180         this.nameTitleUnmasked = builder.getNameTitleUnmasked();
181         this.nameSuffixUnmasked = builder.getNameSuffixUnmasked();
182         this.compositeName = builder.getCompositeName();
183         this.compositeNameUnmasked = builder.getCompositeNameUnmasked();
184         this.noteMessage = builder.getNoteMessage();
185         this.nameChangedDate = builder.getNameChangedDate();
186         this.suppressName = builder.isSuppressName();
187         this.versionNumber = builder.getVersionNumber();
188         this.objectId = builder.getObjectId();
189         this.defaultValue = builder.isDefaultValue();
190         this.active = builder.isActive();
191         this.id = builder.getId();
192     }
193 
194     @Override
195     public String getNameSuffix() {
196         return this.nameSuffix;
197     }
198 
199     @Override
200     public String getEntityId() {
201         return this.entityId;
202     }
203 
204     @Override
205     public CodedAttribute getNameType() {
206         return this.nameType;
207     }
208 
209     @Override
210     public String getFirstName() {
211         return this.firstName;
212     }
213 
214     @Override
215     public String getFirstNameUnmasked() {
216         return this.firstNameUnmasked;
217     }
218 
219     @Override
220     public String getMiddleName() {
221         return this.middleName;
222     }
223 
224     @Override
225     public String getMiddleNameUnmasked() {
226         return this.middleNameUnmasked;
227     }
228 
229     @Override
230     public String getLastName() {
231         return this.lastName;
232     }
233 
234     @Override
235     public String getLastNameUnmasked() {
236         return this.lastNameUnmasked;
237     }
238 
239     @Override
240     public String getNamePrefix() {
241         return this.namePrefix;
242     }
243 
244     @Override
245     public String getNamePrefixUnmasked() {
246         return this.namePrefixUnmasked;
247     }
248 
249     @Override
250     public String getNameTitle() {
251         return this.nameTitle;
252     }
253 
254     @Override
255     public String getNameTitleUnmasked() {
256         return this.nameTitleUnmasked;
257     }
258 
259     @Override
260     public String getNameSuffixUnmasked() {
261         return this.nameSuffixUnmasked;
262     }
263 
264     @Override
265     public String getCompositeName() {
266         return this.compositeName;
267     }
268 
269     @Override
270     public String getCompositeNameUnmasked() {
271         return this.compositeNameUnmasked;
272     }
273 
274     @Override
275     public String getNoteMessage() {
276         return this.noteMessage;
277     }
278 
279     @Override
280     public DateTime getNameChangedDate() {
281         return this.nameChangedDate;
282     }
283 
284     @Override
285     public boolean isSuppressName() {
286         return this.suppressName;
287     }
288 
289     @Override
290     public Long getVersionNumber() {
291         return this.versionNumber;
292     }
293 
294     @Override
295     public String getObjectId() {
296         return this.objectId;
297     }
298 
299     @Override
300     public boolean isDefaultValue() {
301         return this.defaultValue;
302     }
303 
304     @Override
305     public boolean isActive() {
306         return this.active;
307     }
308 
309     @Override
310     public String getId() {
311         return this.id;
312     }
313 
314 
315     /**
316      * A builder which can be used to construct {@link EntityName} instances.  Enforces the constraints of the {@link EntityNameContract}.
317      * 
318      */
319     public final static class Builder
320         implements Serializable, ModelBuilder, EntityNameContract
321     {
322 
323         private String nameSuffix;
324         private String entityId;
325         private CodedAttribute.Builder nameType;
326         private String firstName;
327         private String middleName;
328         private String lastName;
329         private String namePrefix;
330         private String nameTitle;
331         private String noteMessage;
332         private DateTime nameChangedDate;
333         private boolean suppressName;
334         private Long versionNumber;
335         private String objectId;
336         private boolean defaultValue;
337         private boolean active;
338         private String id;
339 
340         private Builder() { }
341 
342         public static Builder create() {
343             return new Builder();
344         }
345 
346         public static Builder create(EntityNameContract contract) {
347             if (contract == null) {
348                 throw new IllegalArgumentException("contract was null");
349             }
350             Builder builder = create();
351             builder.setNameSuffix(contract.getNameSuffix());
352             builder.setEntityId(contract.getEntityId());
353             if (contract.getNameType() != null) {
354                 builder.setNameType(CodedAttribute.Builder.create(contract.getNameType()));
355             }
356             builder.setFirstName(contract.getFirstName());
357             builder.setMiddleName(contract.getMiddleName());
358             builder.setLastName(contract.getLastName());
359             builder.setNamePrefix(contract.getNamePrefix());
360             builder.setNameTitle(contract.getNameTitle());
361             builder.setNoteMessage(contract.getNoteMessage());
362             builder.setNameChangedDate(contract.getNameChangedDate());
363             builder.setSuppressName(contract.isSuppressName());
364             builder.setVersionNumber(contract.getVersionNumber());
365             builder.setObjectId(contract.getObjectId());
366             builder.setDefaultValue(contract.isDefaultValue());
367             builder.setActive(contract.isActive());
368             builder.setId(contract.getId());
369             return builder;
370         }
371 
372         public EntityName build() {
373             return new EntityName(this);
374         }
375 
376         @Override
377         public String getNameSuffix() {
378             if (isSuppressName()) {
379                 return KimConstants.RESTRICTED_DATA_MASK;
380             }
381             return this.nameSuffix;
382         }
383 
384         @Override
385         public String getEntityId() {
386             return this.entityId;
387         }
388 
389         @Override
390         public CodedAttribute.Builder getNameType() {
391             return this.nameType;
392         }
393 
394         @Override
395         public String getFirstName() {
396             if (isSuppressName()) {
397                 return KimConstants.RESTRICTED_DATA_MASK;
398             }
399             return this.firstName;
400         }
401 
402         @Override
403         public String getFirstNameUnmasked() {
404             return this.firstName;
405         }
406 
407         @Override
408         public String getMiddleName() {
409             if (isSuppressName()) {
410                 return KimConstants.RESTRICTED_DATA_MASK;
411             }
412             return this.middleName;
413         }
414 
415         @Override
416         public String getMiddleNameUnmasked() {
417             return this.middleName;
418         }
419 
420         @Override
421         public String getLastName() {
422             if (isSuppressName()) {
423                 return KimConstants.RESTRICTED_DATA_MASK;
424             }
425             return this.lastName;
426         }
427 
428         @Override
429         public String getLastNameUnmasked() {
430             return this.lastName;
431         }
432 
433         @Override
434         public String getNamePrefix() {
435             if (isSuppressName()) {
436                 return KimConstants.RESTRICTED_DATA_MASK;
437             }
438             return this.namePrefix;
439         }
440 
441         @Override
442         public String getNamePrefixUnmasked() {
443             return this.namePrefix;
444         }
445 
446         @Override
447         public String getNameTitle() {
448             if (isSuppressName()) {
449                 return KimConstants.RESTRICTED_DATA_MASK;
450             }
451             return this.nameTitle;
452         }
453 
454         @Override
455         public String getNameTitleUnmasked() {
456             return this.nameTitle;
457         }
458 
459         @Override
460         public String getNameSuffixUnmasked() {
461             return this.nameSuffix;
462         }
463 
464         @Override
465         public String getCompositeName() {
466             if (isSuppressName()) {
467                 return KimConstants.RESTRICTED_DATA_MASK;
468             }
469             return getCompositeNameUnmasked();
470         }
471 
472         @Override
473         public String getCompositeNameUnmasked() {
474             return getLastName() + ", " + getFirstName() + (getMiddleName()==null?"":" " + getMiddleName());
475         }
476 
477         @Override
478         public String getNoteMessage() {
479             return this.noteMessage;
480         }
481 
482         @Override
483         public DateTime getNameChangedDate() {
484             return this.nameChangedDate;
485         }
486 
487         @Override
488         public boolean isSuppressName() {
489             return this.suppressName;
490         }
491 
492         @Override
493         public Long getVersionNumber() {
494             return this.versionNumber;
495         }
496 
497         @Override
498         public String getObjectId() {
499             return this.objectId;
500         }
501 
502         @Override
503         public boolean isDefaultValue() {
504             return this.defaultValue;
505         }
506 
507         @Override
508         public boolean isActive() {
509             return this.active;
510         }
511 
512         @Override
513         public String getId() {
514             return this.id;
515         }
516 
517         public void setNameSuffix(String nameSuffix) {
518             this.nameSuffix = nameSuffix;
519         }
520 
521         public void setEntityId(String entityId) {
522             this.entityId = entityId;
523         }
524 
525         public void setNameType(CodedAttribute.Builder nameType) {
526             this.nameType = nameType;
527         }
528 
529         public void setFirstName(String firstName) {
530             this.firstName = firstName;
531         }
532 
533         public void setMiddleName(String middleName) {
534 
535             this.middleName = middleName;
536         }
537 
538         public void setLastName(String lastName) {
539             this.lastName = lastName;
540         }
541 
542         public void setNamePrefix(String namePrefix) {
543             this.namePrefix = namePrefix;
544         }
545 
546         public void setNameTitle(String nameTitle) {
547             this.nameTitle = nameTitle;
548         }
549 
550         public void setNoteMessage(String noteMessage) {
551             this.noteMessage = noteMessage;
552         }
553 
554         public void setNameChangedDate(DateTime nameChangedDate) {
555             this.nameChangedDate = nameChangedDate;
556         }
557 
558         private void setSuppressName(boolean suppressName) {
559             this.suppressName = suppressName;
560         }
561 
562         public void setVersionNumber(Long versionNumber) {
563             this.versionNumber = versionNumber;
564         }
565 
566         public void setObjectId(String objectId) {
567             this.objectId = objectId;
568         }
569 
570         public void setDefaultValue(boolean defaultValue) {
571             this.defaultValue = defaultValue;
572         }
573 
574         public void setActive(boolean active) {
575             this.active = active;
576         }
577 
578         public void setId(String id) {
579             if (StringUtils.isWhitespace(id)) {
580                 throw new IllegalArgumentException("id is blank");
581             }
582             this.id = id;
583         }
584 
585     }
586 
587 
588     /**
589      * Defines some internal constants used on this class.
590      * 
591      */
592     static class Constants {
593 
594         final static String ROOT_ELEMENT_NAME = "entityName";
595         final static String TYPE_NAME = "EntityNameType";
596     }
597 
598 
599     /**
600      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
601      * 
602      */
603     static class Elements {
604 
605         final static String NAME_SUFFIX = "nameSuffix";
606         final static String ENTITY_ID = "entityId";
607         final static String NAME_TYPE = "nameType";
608         final static String FIRST_NAME = "firstName";
609         final static String FIRST_NAME_UNMASKED = "firstNameUnmasked";
610         final static String MIDDLE_NAME = "middleName";
611         final static String MIDDLE_NAME_UNMASKED = "middleNameUnmasked";
612         final static String LAST_NAME = "lastName";
613         final static String LAST_NAME_UNMASKED = "lastNameUnmasked";
614         final static String NAME_PREFIX = "namePrefix";
615         final static String NAME_PREFIX_UNMASKED = "namePrefixUnmasked";
616         final static String NAME_TITLE = "nameTitle";
617         final static String NAME_TITLE_UNMASKED = "nameTitleUnmasked";
618         final static String NAME_SUFFIX_UNMASKED = "nameSuffixUnmasked";
619         final static String COMPOSITE_NAME = "compositeName";
620         final static String COMPOSITE_NAME_UNMASKED = "compositeNameUnmasked";
621         final static String NOTE_MESSAGE = "noteMessage";
622         final static String NAME_CHANGED_DATE= "nameChangedDate";
623         final static String SUPPRESS_NAME = "suppressName";
624         final static String DEFAULT_VALUE = "defaultValue";
625         final static String ACTIVE = "active";
626         final static String ID = "id";
627 
628     }
629 
630 }