Coverage Report - org.kuali.rice.kim.api.identity.type.EntityTypeData
 
Classes in this File Line Coverage Branch Coverage Complexity
EntityTypeData
89%
49/55
95%
19/20
1.548
EntityTypeData$1
N/A
N/A
1.548
EntityTypeData$Builder
88%
56/63
90%
18/20
1.548
EntityTypeData$Constants
50%
1/2
N/A
1.548
EntityTypeData$Elements
0%
0/1
N/A
1.548
 
 1  
 package org.kuali.rice.kim.api.identity.type;
 2  
 
 3  
 import org.apache.commons.collections.CollectionUtils;
 4  
 import org.apache.commons.lang.StringUtils;
 5  
 import org.apache.commons.lang.builder.EqualsBuilder;
 6  
 import org.apache.commons.lang.builder.HashCodeBuilder;
 7  
 import org.apache.commons.lang.builder.ToStringBuilder;
 8  
 import org.kuali.rice.core.api.CoreConstants;
 9  
 import org.kuali.rice.core.api.mo.ModelBuilder;
 10  
 import org.kuali.rice.core.api.mo.ModelObjectComplete;
 11  
 import org.kuali.rice.kim.api.identity.EntityUtils;
 12  
 import org.kuali.rice.kim.api.identity.Type;
 13  
 import org.kuali.rice.kim.api.identity.TypeContract;
 14  
 import org.kuali.rice.kim.api.identity.address.EntityAddress;
 15  
 import org.kuali.rice.kim.api.identity.address.EntityAddressContract;
 16  
 import org.kuali.rice.kim.api.identity.email.EntityEmail;
 17  
 import org.kuali.rice.kim.api.identity.email.EntityEmailContract;
 18  
 import org.kuali.rice.kim.api.identity.phone.EntityPhone;
 19  
 import org.kuali.rice.kim.api.identity.phone.EntityPhoneContract;
 20  
 import org.w3c.dom.Element;
 21  
 
 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.XmlElementWrapper;
 27  
 import javax.xml.bind.annotation.XmlRootElement;
 28  
 import javax.xml.bind.annotation.XmlType;
 29  
 import java.io.Serializable;
 30  
 import java.util.ArrayList;
 31  
 import java.util.Collection;
 32  
 import java.util.List;
 33  
 
 34  0
 @XmlRootElement(name = EntityTypeData.Constants.ROOT_ELEMENT_NAME)
 35  
 @XmlAccessorType(XmlAccessType.NONE)
 36  
 @XmlType(name = EntityTypeData.Constants.TYPE_NAME, propOrder = {
 37  
     EntityTypeData.Elements.ENTITY_ID,
 38  
     EntityTypeData.Elements.ENTITY_TYPE_CODE,
 39  
     EntityTypeData.Elements.ENTITY_TYPE,
 40  
     EntityTypeData.Elements.ADDRESSES,
 41  
     EntityTypeData.Elements.EMAIL_ADDRESSES,
 42  
     EntityTypeData.Elements.PHONE_NUMBERS,
 43  
     EntityTypeData.Elements.DEFAULT_ADDRESS,
 44  
     EntityTypeData.Elements.DEFAULT_EMAIL_ADDRESS,
 45  
     EntityTypeData.Elements.DEFAULT_PHONE_NUMBER,
 46  
     CoreConstants.CommonElements.VERSION_NUMBER,
 47  
     CoreConstants.CommonElements.OBJECT_ID,
 48  
     EntityTypeData.Elements.ACTIVE,
 49  
     CoreConstants.CommonElements.FUTURE_ELEMENTS
 50  
 })
 51  3
 public final class EntityTypeData
 52  
     implements ModelObjectComplete, EntityTypeDataContract
 53  
 {
 54  
 
 55  
     @XmlElement(name = Elements.ENTITY_ID, required = true)
 56  
     private final String entityId;
 57  
     @XmlElement(name = Elements.ENTITY_TYPE_CODE, required = true)
 58  
     private final String entityTypeCode;
 59  
     @XmlElement(name = Elements.ENTITY_TYPE, required = false)
 60  
     private final Type entityType;
 61  
     @XmlElementWrapper(name = Elements.ADDRESSES, required = false)
 62  
     @XmlElement(name = Elements.ADDRESS, required = false)
 63  
     private final List<EntityAddress> addresses;
 64  
     @XmlElementWrapper(name = Elements.EMAIL_ADDRESSES, required = false)
 65  
     @XmlElement(name = Elements.EMAIL_ADDRESS, required = false)
 66  
     private final List<EntityEmail> emailAddresses;
 67  
     @XmlElementWrapper(name = Elements.PHONE_NUMBERS, required = false)
 68  
     @XmlElement(name = Elements.PHONE_NUMBER, required = false)
 69  
     private final List<EntityPhone> phoneNumbers;
 70  
     @XmlElement(name = Elements.DEFAULT_ADDRESS, required = false)
 71  
     private final EntityAddress defaultAddress;
 72  
     @XmlElement(name = Elements.DEFAULT_EMAIL_ADDRESS, required = false)
 73  
     private final EntityEmail defaultEmailAddress;
 74  
     @XmlElement(name = Elements.DEFAULT_PHONE_NUMBER, required = false)
 75  
     private final EntityPhone defaultPhoneNumber;
 76  
     @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
 77  
     private final Long versionNumber;
 78  
     @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
 79  
     private final String objectId;
 80  
     @XmlElement(name = Elements.ACTIVE, required = false)
 81  
     private final boolean active;
 82  5
     @SuppressWarnings("unused")
 83  
     @XmlAnyElement
 84  
     private final Collection<Element> _futureElements = null;
 85  
 
 86  
     /**
 87  
      * Private constructor used only by JAXB.
 88  
      */
 89  2
     private EntityTypeData() {
 90  2
         this.entityId = null;
 91  2
         this.entityTypeCode = null;
 92  2
         this.entityType = null;
 93  2
         this.addresses = null;
 94  2
         this.emailAddresses = null;
 95  2
         this.phoneNumbers = null;
 96  2
         this.defaultAddress = null;
 97  2
         this.defaultEmailAddress = null;
 98  2
         this.defaultPhoneNumber = null;
 99  2
         this.versionNumber = null;
 100  2
         this.objectId = null;
 101  2
         this.active = false;
 102  2
     }
 103  
 
 104  3
     private EntityTypeData(Builder builder) {
 105  3
         this.entityId = builder.getEntityId();
 106  3
         this.entityTypeCode = builder.getEntityTypeCode();
 107  3
         this.entityType = (builder.getEntityType() != null) ? builder.getEntityType().build() : null;
 108  3
         this.addresses = new ArrayList<EntityAddress>();
 109  3
         if (!CollectionUtils.isEmpty(builder.getAddresses())) {
 110  1
             for (EntityAddress.Builder address : builder.getAddresses()) {
 111  1
                 this.addresses.add(address.build());
 112  
             }
 113  
         }
 114  
 
 115  3
         this.emailAddresses = new ArrayList<EntityEmail>();
 116  3
         if (!CollectionUtils.isEmpty(builder.getEmailAddresses())) {
 117  1
             for (EntityEmail.Builder email : builder.getEmailAddresses()) {
 118  1
                 this.emailAddresses.add(email.build());
 119  
             }
 120  
         }
 121  3
         this.phoneNumbers = new ArrayList<EntityPhone>();
 122  3
         if (!CollectionUtils.isEmpty(builder.getPhoneNumbers())) {
 123  1
             for (EntityPhone.Builder phoneNumber : builder.getPhoneNumbers()) {
 124  1
                 this.phoneNumbers.add(phoneNumber.build());
 125  
             }
 126  
         }
 127  3
         this.defaultAddress = builder.getDefaultAddress() != null ? builder.getDefaultAddress().build() : null;
 128  3
         this.defaultEmailAddress = builder.getDefaultEmailAddress() != null ? builder.getDefaultEmailAddress().build() : null;
 129  3
         this.defaultPhoneNumber = builder.getDefaultPhoneNumber() != null ? builder.getDefaultPhoneNumber().build() : null;
 130  3
         this.versionNumber = builder.getVersionNumber();
 131  3
         this.objectId = builder.getObjectId();
 132  3
         this.active = builder.isActive();
 133  3
     }
 134  
 
 135  
     @Override
 136  
     public String getEntityId() {
 137  1
         return this.entityId;
 138  
     }
 139  
 
 140  
     @Override
 141  
     public String getEntityTypeCode() {
 142  1
         return this.entityTypeCode;
 143  
     }
 144  
 
 145  
     @Override
 146  
     public TypeContract getEntityType() {
 147  2
         return this.entityType;
 148  
     }
 149  
 
 150  
     @Override
 151  
     public List<EntityAddress> getAddresses() {
 152  1
         return this.addresses;
 153  
     }
 154  
 
 155  
     @Override
 156  
     public List<EntityEmail> getEmailAddresses() {
 157  1
         return this.emailAddresses;
 158  
     }
 159  
 
 160  
     @Override
 161  
     public List<EntityPhone> getPhoneNumbers() {
 162  1
         return this.phoneNumbers;
 163  
     }
 164  
 
 165  
     @Override
 166  
     public EntityAddressContract getDefaultAddress() {
 167  0
         return this.defaultAddress;
 168  
     }
 169  
 
 170  
     @Override
 171  
     public EntityEmail getDefaultEmailAddress() {
 172  0
         return this.defaultEmailAddress;
 173  
     }
 174  
 
 175  
     @Override
 176  
     public EntityPhoneContract getDefaultPhoneNumber() {
 177  0
         return this.defaultPhoneNumber;
 178  
     }
 179  
 
 180  
     @Override
 181  
     public Long getVersionNumber() {
 182  1
         return this.versionNumber;
 183  
     }
 184  
 
 185  
     @Override
 186  
     public String getObjectId() {
 187  1
         return this.objectId;
 188  
     }
 189  
 
 190  
     @Override
 191  
     public boolean isActive() {
 192  1
         return this.active;
 193  
     }
 194  
 
 195  
     @Override
 196  
     public int hashCode() {
 197  0
         return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 198  
     }
 199  
 
 200  
     @Override
 201  
     public boolean equals(Object object) {
 202  3
         return EqualsBuilder.reflectionEquals(object, this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 203  
     }
 204  
 
 205  
     @Override
 206  
     public String toString() {
 207  0
         return ToStringBuilder.reflectionToString(this);
 208  
     }
 209  
 
 210  
 
 211  
     /**
 212  
      * A builder which can be used to construct {@link EntityTypeData} instances.  Enforces the constraints of the {@link EntityTypeDataContract}.
 213  
      *
 214  
      */
 215  3
     public final static class Builder
 216  
         implements Serializable, ModelBuilder, EntityTypeDataContract
 217  
     {
 218  
         private String entityId;
 219  
         private String entityTypeCode;
 220  
         private Type.Builder entityType;
 221  
         private List<EntityAddress.Builder> addresses;
 222  
         private List<EntityEmail.Builder> emailAddresses;
 223  
         private List<EntityPhone.Builder> phoneNumbers;
 224  
         private Long versionNumber;
 225  
         private String objectId;
 226  
         private boolean active;
 227  
 
 228  8
         private Builder(String entityId, String entityTypeCode) {
 229  8
             setEntityId(entityId);
 230  6
             setEntityTypeCode(entityTypeCode);
 231  4
             setEntityType(Type.Builder.create(entityTypeCode));
 232  4
         }
 233  
 
 234  
         public static Builder create(String entityId, String entityTypeCode) {
 235  8
             return new Builder(entityId, entityTypeCode);
 236  
         }
 237  
 
 238  
         public static Builder create(EntityTypeDataContract contract) {
 239  2
             if (contract == null) {
 240  0
                 throw new IllegalArgumentException("contract was null");
 241  
             }
 242  2
             Builder builder = create(contract.getEntityId(), contract.getEntityTypeCode());
 243  2
             if (contract.getEntityType() != null) {
 244  2
                 builder.setEntityType(Type.Builder.create(contract.getEntityType()));
 245  
             }
 246  2
             builder.addresses = new ArrayList<EntityAddress.Builder>();
 247  2
             if (!CollectionUtils.isEmpty(contract.getAddresses())) {
 248  1
                 for (EntityAddressContract addressContract : contract.getAddresses()) {
 249  1
                     builder.addresses.add(EntityAddress.Builder.create(addressContract));
 250  
                 }
 251  
             }
 252  2
             builder.emailAddresses = new ArrayList<EntityEmail.Builder>();
 253  2
             if (!CollectionUtils.isEmpty(contract.getEmailAddresses())) {
 254  1
                 for (EntityEmailContract emailContract : contract.getEmailAddresses()) {
 255  1
                     builder.emailAddresses.add(EntityEmail.Builder.create(emailContract));
 256  
                 }
 257  
             }
 258  2
             builder.phoneNumbers = new ArrayList<EntityPhone.Builder>();
 259  2
             if (!CollectionUtils.isEmpty(contract.getPhoneNumbers())) {
 260  1
                 for (EntityPhoneContract phoneContract : contract.getPhoneNumbers()) {
 261  1
                     builder.phoneNumbers.add(EntityPhone.Builder.create(phoneContract));
 262  
                 }
 263  
             }
 264  2
             builder.setVersionNumber(contract.getVersionNumber());
 265  2
             builder.setObjectId(contract.getObjectId());
 266  2
             builder.setActive(contract.isActive());
 267  2
             return builder;
 268  
         }
 269  
 
 270  
         public EntityTypeData build() {
 271  3
             return new EntityTypeData(this);
 272  
         }
 273  
 
 274  
         @Override
 275  
         public String getEntityId() {
 276  3
             return this.entityId;
 277  
         }
 278  
 
 279  
         @Override
 280  
         public String getEntityTypeCode() {
 281  3
             return this.entityTypeCode;
 282  
         }
 283  
 
 284  
         @Override
 285  
         public Type.Builder getEntityType() {
 286  6
             return this.entityType;
 287  
         }
 288  
 
 289  
         @Override
 290  
         public List<EntityAddress.Builder> getAddresses() {
 291  4
             return this.addresses;
 292  
         }
 293  
 
 294  
         @Override
 295  
         public List<EntityEmail.Builder> getEmailAddresses() {
 296  4
             return this.emailAddresses;
 297  
         }
 298  
 
 299  
         @Override
 300  
         public List<EntityPhone.Builder> getPhoneNumbers() {
 301  4
             return this.phoneNumbers;
 302  
         }
 303  
 
 304  
         @Override
 305  
         public EntityAddress.Builder getDefaultAddress() {
 306  4
             return EntityUtils.getDefaultItem(this.addresses);
 307  
         }
 308  
 
 309  
         @Override
 310  
         public EntityEmail.Builder getDefaultEmailAddress() {
 311  4
             return EntityUtils.getDefaultItem(this.emailAddresses);
 312  
         }
 313  
 
 314  
         @Override
 315  
         public EntityPhone.Builder getDefaultPhoneNumber() {
 316  4
             return EntityUtils.getDefaultItem(this.phoneNumbers);
 317  
         }
 318  
 
 319  
         @Override
 320  
         public Long getVersionNumber() {
 321  3
             return this.versionNumber;
 322  
         }
 323  
 
 324  
         @Override
 325  
         public String getObjectId() {
 326  3
             return this.objectId;
 327  
         }
 328  
 
 329  
         @Override
 330  
         public boolean isActive() {
 331  3
             return this.active;
 332  
         }
 333  
 
 334  
         public void setEntityId(String entityId) {
 335  8
             if (StringUtils.isEmpty(entityId)) {
 336  2
                 throw new IllegalArgumentException("entityId is empty");
 337  
             }
 338  6
             this.entityId = entityId;
 339  6
         }
 340  
 
 341  
         public void setEntityTypeCode(String entityTypeCode) {
 342  6
             if (StringUtils.isEmpty(entityTypeCode)) {
 343  2
                 throw new IllegalArgumentException("entityTypeCode is empty");
 344  
             }
 345  4
             this.entityTypeCode = entityTypeCode;
 346  4
         }
 347  
 
 348  
         public void setEntityType(Type.Builder entityType) {
 349  6
             this.entityType = entityType;
 350  6
         }
 351  
 
 352  
         public void setAddresses(List addresses) {
 353  0
             this.addresses = addresses;
 354  0
         }
 355  
 
 356  
         public void setEmailAddresses(List emailAddresses) {
 357  0
             this.emailAddresses = emailAddresses;
 358  0
         }
 359  
 
 360  
         public void setPhoneNumbers(List phoneNumbers) {
 361  0
             this.phoneNumbers = phoneNumbers;
 362  0
         }
 363  
 
 364  
         public void setVersionNumber(Long versionNumber) {
 365  2
             this.versionNumber = versionNumber;
 366  2
         }
 367  
 
 368  
         public void setObjectId(String objectId) {
 369  2
             this.objectId = objectId;
 370  2
         }
 371  
 
 372  
         public void setActive(boolean active) {
 373  2
             this.active = active;
 374  2
         }
 375  
     }
 376  
 
 377  
 
 378  
     /**
 379  
      * Defines some internal constants used on this class.
 380  
      *
 381  
      */
 382  0
     static class Constants {
 383  
 
 384  
         final static String ROOT_ELEMENT_NAME = "entityTypeData";
 385  
         final static String TYPE_NAME = "EntityTypeDataType";
 386  1
         final static String[] HASH_CODE_EQUALS_EXCLUDE = new String[] {CoreConstants.CommonElements.FUTURE_ELEMENTS };
 387  
 
 388  
     }
 389  
 
 390  
 
 391  
     /**
 392  
      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
 393  
      *
 394  
      */
 395  0
     static class Elements {
 396  
 
 397  
         final static String ENTITY_ID = "entityId";
 398  
         final static String ENTITY_TYPE_CODE = "entityTypeCode";
 399  
         final static String ENTITY_TYPE = "entityType";
 400  
         final static String ADDRESSES = "addresses";
 401  
         final static String ADDRESS = "address";
 402  
         final static String EMAIL_ADDRESSES = "emailAddresses";
 403  
         final static String EMAIL_ADDRESS = "emailAddress";
 404  
         final static String PHONE_NUMBERS = "phoneNumbers";
 405  
         final static String PHONE_NUMBER = "phoneNumber";
 406  
         final static String DEFAULT_ADDRESS = "defaultAddress";
 407  
         final static String DEFAULT_EMAIL_ADDRESS = "defaultEmailAddress";
 408  
         final static String DEFAULT_PHONE_NUMBER = "defaultPhoneNumber";
 409  
         final static String ACTIVE = "active";
 410  
 
 411  
     }
 412  
 
 413  
 }