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