View Javadoc

1   /**
2    * Copyright 2005-2012 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 compositeName;
332         private String noteMessage;
333         private DateTime nameChangedDate;
334         private boolean suppressName;
335         private Long versionNumber;
336         private String objectId;
337         private boolean defaultValue;
338         private boolean active;
339         private String id;
340 
341         private Builder() { }
342 
343         public static Builder create() {
344             return new Builder();
345         }
346 
347         public static Builder create(EntityNameContract contract) {
348             if (contract == null) {
349                 throw new IllegalArgumentException("contract was null");
350             }
351             Builder builder = create();
352             builder.setNameSuffix(contract.getNameSuffix());
353             builder.setEntityId(contract.getEntityId());
354             if (contract.getNameType() != null) {
355                 builder.setNameType(CodedAttribute.Builder.create(contract.getNameType()));
356             }
357             builder.setFirstName(contract.getFirstName());
358             builder.setMiddleName(contract.getMiddleName());
359             builder.setLastName(contract.getLastName());
360             builder.setNamePrefix(contract.getNamePrefix());
361             builder.setNameTitle(contract.getNameTitle());
362             builder.setNoteMessage(contract.getNoteMessage());
363             builder.setNameChangedDate(contract.getNameChangedDate());
364             builder.setSuppressName(contract.isSuppressName());
365             builder.setVersionNumber(contract.getVersionNumber());
366             builder.setObjectId(contract.getObjectId());
367             builder.setDefaultValue(contract.isDefaultValue());
368             builder.setActive(contract.isActive());
369             builder.setId(contract.getId());
370             builder.setCompositeName(contract.getCompositeName());
371             return builder;
372         }
373 
374         public EntityName build() {
375             return new EntityName(this);
376         }
377 
378         @Override
379         public String getNameSuffix() {
380             if (isSuppressName()) {
381                 return KimConstants.RESTRICTED_DATA_MASK;
382             }
383             return this.nameSuffix;
384         }
385 
386         @Override
387         public String getEntityId() {
388             return this.entityId;
389         }
390 
391         @Override
392         public CodedAttribute.Builder getNameType() {
393             return this.nameType;
394         }
395 
396         @Override
397         public String getFirstName() {
398             if (isSuppressName()) {
399                 return KimConstants.RESTRICTED_DATA_MASK;
400             }
401             return this.firstName;
402         }
403 
404         @Override
405         public String getFirstNameUnmasked() {
406             return this.firstName;
407         }
408 
409         @Override
410         public String getMiddleName() {
411             if (isSuppressName()) {
412                 return KimConstants.RESTRICTED_DATA_MASK;
413             }
414             return this.middleName;
415         }
416 
417         @Override
418         public String getMiddleNameUnmasked() {
419             return this.middleName;
420         }
421 
422         @Override
423         public String getLastName() {
424             if (isSuppressName()) {
425                 return KimConstants.RESTRICTED_DATA_MASK;
426             }
427             return this.lastName;
428         }
429 
430         @Override
431         public String getLastNameUnmasked() {
432             return this.lastName;
433         }
434 
435         @Override
436         public String getNamePrefix() {
437             if (isSuppressName()) {
438                 return KimConstants.RESTRICTED_DATA_MASK;
439             }
440             return this.namePrefix;
441         }
442 
443         @Override
444         public String getNamePrefixUnmasked() {
445             return this.namePrefix;
446         }
447 
448         @Override
449         public String getNameTitle() {
450             if (isSuppressName()) {
451                 return KimConstants.RESTRICTED_DATA_MASK;
452             }
453             return this.nameTitle;
454         }
455 
456         @Override
457         public String getNameTitleUnmasked() {
458             return this.nameTitle;
459         }
460 
461         @Override
462         public String getNameSuffixUnmasked() {
463             return this.nameSuffix;
464         }
465 
466         @Override
467         public String getCompositeName() {
468             if (isSuppressName()) {
469                 return KimConstants.RESTRICTED_DATA_MASK;
470             }
471             return getCompositeNameUnmasked();
472         }
473 
474         @Override
475         public String getCompositeNameUnmasked() {
476         	if(this.compositeName == null) {
477         		setCompositeName(getLastName() + ", " + getFirstName() + (getMiddleName()==null?"":" " + getMiddleName()));
478         	}
479             return this.compositeName;
480         }
481 
482         @Override
483         public String getNoteMessage() {
484             return this.noteMessage;
485         }
486 
487         @Override
488         public DateTime getNameChangedDate() {
489             return this.nameChangedDate;
490         }
491 
492         @Override
493         public boolean isSuppressName() {
494             return this.suppressName;
495         }
496 
497         @Override
498         public Long getVersionNumber() {
499             return this.versionNumber;
500         }
501 
502         @Override
503         public String getObjectId() {
504             return this.objectId;
505         }
506 
507         @Override
508         public boolean isDefaultValue() {
509             return this.defaultValue;
510         }
511 
512         @Override
513         public boolean isActive() {
514             return this.active;
515         }
516 
517         @Override
518         public String getId() {
519             return this.id;
520         }
521 
522         public void setNameSuffix(String nameSuffix) {
523             this.nameSuffix = nameSuffix;
524         }
525 
526         public void setEntityId(String entityId) {
527             this.entityId = entityId;
528         }
529 
530         public void setNameType(CodedAttribute.Builder nameType) {
531             this.nameType = nameType;
532         }
533 
534         public void setFirstName(String firstName) {
535             this.firstName = firstName;
536         }
537 
538         public void setMiddleName(String middleName) {
539 
540             this.middleName = middleName;
541         }
542 
543         public void setLastName(String lastName) {
544             this.lastName = lastName;
545         }
546 
547         public void setNamePrefix(String namePrefix) {
548             this.namePrefix = namePrefix;
549         }
550 
551         public void setNameTitle(String nameTitle) {
552             this.nameTitle = nameTitle;
553         }
554 
555         public void setCompositeName(String compositeName) {
556         	this.compositeName = compositeName;
557         }
558         
559         public void setNoteMessage(String noteMessage) {
560             this.noteMessage = noteMessage;
561         }
562 
563         public void setNameChangedDate(DateTime nameChangedDate) {
564             this.nameChangedDate = nameChangedDate;
565         }
566 
567         private void setSuppressName(boolean suppressName) {
568             this.suppressName = suppressName;
569         }
570 
571         public void setVersionNumber(Long versionNumber) {
572             this.versionNumber = versionNumber;
573         }
574 
575         public void setObjectId(String objectId) {
576             this.objectId = objectId;
577         }
578 
579         public void setDefaultValue(boolean defaultValue) {
580             this.defaultValue = defaultValue;
581         }
582 
583         public void setActive(boolean active) {
584             this.active = active;
585         }
586 
587         public void setId(String id) {
588             if (StringUtils.isWhitespace(id)) {
589                 throw new IllegalArgumentException("id is blank");
590             }
591             this.id = id;
592         }
593 
594     }
595 
596 
597     /**
598      * Defines some internal constants used on this class.
599      * 
600      */
601     static class Constants {
602 
603         final static String ROOT_ELEMENT_NAME = "entityName";
604         final static String TYPE_NAME = "EntityNameType";
605     }
606 
607 
608     /**
609      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
610      * 
611      */
612     static class Elements {
613 
614         final static String NAME_SUFFIX = "nameSuffix";
615         final static String ENTITY_ID = "entityId";
616         final static String NAME_TYPE = "nameType";
617         final static String FIRST_NAME = "firstName";
618         final static String FIRST_NAME_UNMASKED = "firstNameUnmasked";
619         final static String MIDDLE_NAME = "middleName";
620         final static String MIDDLE_NAME_UNMASKED = "middleNameUnmasked";
621         final static String LAST_NAME = "lastName";
622         final static String LAST_NAME_UNMASKED = "lastNameUnmasked";
623         final static String NAME_PREFIX = "namePrefix";
624         final static String NAME_PREFIX_UNMASKED = "namePrefixUnmasked";
625         final static String NAME_TITLE = "nameTitle";
626         final static String NAME_TITLE_UNMASKED = "nameTitleUnmasked";
627         final static String NAME_SUFFIX_UNMASKED = "nameSuffixUnmasked";
628         final static String COMPOSITE_NAME = "compositeName";
629         final static String COMPOSITE_NAME_UNMASKED = "compositeNameUnmasked";
630         final static String NOTE_MESSAGE = "noteMessage";
631         final static String NAME_CHANGED_DATE= "nameChangedDate";
632         final static String SUPPRESS_NAME = "suppressName";
633         final static String DEFAULT_VALUE = "defaultValue";
634         final static String ACTIVE = "active";
635         final static String ID = "id";
636 
637     }
638 
639 }