Coverage Report - org.kuali.rice.kim.api.entity.phone.EntityPhone
 
Classes in this File Line Coverage Branch Coverage Complexity
EntityPhone
88%
54/61
100%
2/2
1.273
EntityPhone$1
N/A
N/A
1.273
EntityPhone$Builder
93%
73/78
68%
11/16
1.273
EntityPhone$Constants
50%
1/2
N/A
1.273
EntityPhone$Elements
0%
0/1
N/A
1.273
 
 1  
 package org.kuali.rice.kim.api.entity.phone;
 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.core.api.mo.common.active.InactivatableFromTo;
 20  
 import org.kuali.rice.kim.api.KimConstants;
 21  
 import org.kuali.rice.kim.api.entity.Type;
 22  
 import org.kuali.rice.kim.api.entity.TypeContract;
 23  
 import org.w3c.dom.Element;
 24  
 
 25  3
 @XmlRootElement(name = EntityPhone.Constants.ROOT_ELEMENT_NAME)
 26  
 @XmlAccessorType(XmlAccessType.NONE)
 27  
 @XmlType(name = EntityPhone.Constants.TYPE_NAME, propOrder = {
 28  
     EntityPhone.Elements.ID,
 29  
     EntityPhone.Elements.ENTITY_TYPE_CODE,
 30  
     EntityPhone.Elements.ENTITY_ID,
 31  
     EntityPhone.Elements.PHONE_TYPE,
 32  
     EntityPhone.Elements.COUNTRY_CODE,
 33  
     EntityPhone.Elements.PHONE_NUMBER,
 34  
     EntityPhone.Elements.EXTENSION_NUMBER,
 35  
     EntityPhone.Elements.FORMATTED_PHONE_NUMBER,
 36  
     EntityPhone.Elements.COUNTRY_CODE_UNMASKED,
 37  
     EntityPhone.Elements.PHONE_NUMBER_UNMASKED,
 38  
     EntityPhone.Elements.EXTENSION_NUMBER_UNMASKED,
 39  
     EntityPhone.Elements.FORMATTED_PHONE_NUMBER_UNMASKED,
 40  
     EntityPhone.Elements.SUPPRESS_PHONE,
 41  
     EntityPhone.Elements.DEFAULT_VALUE,
 42  
     EntityPhone.Elements.ACTIVE,
 43  
     CoreConstants.CommonElements.VERSION_NUMBER,
 44  
     CoreConstants.CommonElements.OBJECT_ID,
 45  
     CoreConstants.CommonElements.FUTURE_ELEMENTS
 46  
 })
 47  6
 public final class EntityPhone
 48  
     implements ModelObjectComplete, EntityPhoneContract
 49  
 {
 50  
 
 51  
     @XmlElement(name = Elements.ID, required = false)
 52  
     private final String id;
 53  
     @XmlElement(name = Elements.ENTITY_TYPE_CODE, required = false)
 54  
     private final String entityTypeCode;
 55  
     @XmlElement(name = Elements.ENTITY_ID, required = false)
 56  
     private final String entityId;
 57  
     @XmlElement(name = Elements.PHONE_TYPE, required = false)
 58  
     private final Type phoneType;
 59  
     @XmlElement(name = Elements.PHONE_NUMBER, required = false)
 60  
     private final String phoneNumber;
 61  
     @XmlElement(name = Elements.EXTENSION_NUMBER, required = false)
 62  
     private final String extensionNumber;
 63  
     @XmlElement(name = Elements.COUNTRY_CODE, required = false)
 64  
     private final String countryCode;
 65  
     @XmlElement(name = Elements.PHONE_NUMBER_UNMASKED, required = false)
 66  
     private final String phoneNumberUnmasked;
 67  
     @XmlElement(name = Elements.EXTENSION_NUMBER_UNMASKED, required = false)
 68  
     private final String extensionNumberUnmasked;
 69  
     @XmlElement(name = Elements.COUNTRY_CODE_UNMASKED, required = false)
 70  
     private final String countryCodeUnmasked;
 71  
     @XmlElement(name = Elements.FORMATTED_PHONE_NUMBER, required = false)
 72  
     private final String formattedPhoneNumber;
 73  
     @XmlElement(name = Elements.FORMATTED_PHONE_NUMBER_UNMASKED, required = false)
 74  
     private final String formattedPhoneNumberUnmasked;
 75  
     @XmlElement(name = Elements.SUPPRESS_PHONE, required = false)
 76  
     private final boolean suppressPhone;
 77  
     @XmlElement(name = Elements.DEFAULT_VALUE, required = false)
 78  
     private final boolean defaultValue;
 79  
     @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
 80  
     private final Long versionNumber;
 81  
     @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
 82  
     private final String objectId;
 83  
     @XmlElement(name = Elements.ACTIVE, required = false)
 84  
     private final boolean active;
 85  12
     @SuppressWarnings("unused")
 86  
     @XmlAnyElement
 87  
     private final Collection<Element> _futureElements = null;
 88  
 
 89  
     /**
 90  
      * Private constructor used only by JAXB.
 91  
      *
 92  
      */
 93  6
     private EntityPhone() {
 94  6
         this.id = null;
 95  6
         this.entityId = null;
 96  6
         this.entityTypeCode = null;
 97  6
         this.phoneType = null;
 98  6
         this.phoneNumber = null;
 99  6
         this.extensionNumber = null;
 100  6
         this.countryCode = null;
 101  6
         this.phoneNumberUnmasked = null;
 102  6
         this.extensionNumberUnmasked = null;
 103  6
         this.countryCodeUnmasked = null;
 104  6
         this.formattedPhoneNumber = null;
 105  6
         this.formattedPhoneNumberUnmasked = null;
 106  6
         this.suppressPhone = false;
 107  6
         this.defaultValue = false;
 108  6
         this.versionNumber = null;
 109  6
         this.objectId = null;
 110  6
         this.active = false;
 111  6
     }
 112  
 
 113  6
     private EntityPhone(Builder builder) {
 114  6
         this.id = builder.getId();
 115  6
         this.entityId = builder.getEntityId();
 116  6
         this.entityTypeCode = builder.getEntityTypeCode();
 117  6
         this.phoneType = (builder.getPhoneType() != null) ? builder.getPhoneType().build() : null;
 118  6
         this.phoneNumber = builder.getPhoneNumber();
 119  6
         this.extensionNumber = builder.getExtensionNumber();
 120  6
         this.countryCode = builder.getCountryCode();
 121  6
         this.phoneNumberUnmasked = builder.getPhoneNumberUnmasked();
 122  6
         this.extensionNumberUnmasked = builder.getExtensionNumberUnmasked();
 123  6
         this.countryCodeUnmasked = builder.getCountryCodeUnmasked();
 124  6
         this.formattedPhoneNumber = builder.getFormattedPhoneNumber();
 125  6
         this.formattedPhoneNumberUnmasked = builder.getFormattedPhoneNumberUnmasked();
 126  6
         this.suppressPhone = builder.isSuppressPhone();
 127  6
         this.defaultValue = builder.isDefaultValue();
 128  6
         this.versionNumber = builder.getVersionNumber();
 129  6
         this.objectId = builder.getObjectId();
 130  6
         this.active = builder.isActive();
 131  6
     }
 132  
 
 133  
     @Override
 134  
     public String getId() {
 135  2
         return this.id;
 136  
     }
 137  
 
 138  
     @Override
 139  
     public String getEntityId() {
 140  2
         return this.entityId;
 141  
     }
 142  
 
 143  
     @Override
 144  
     public String getEntityTypeCode() {
 145  2
         return this.entityTypeCode;
 146  
     }
 147  
 
 148  
     @Override
 149  
     public Type getPhoneType() {
 150  3
         return this.phoneType;
 151  
     }
 152  
 
 153  
     @Override
 154  
     public String getPhoneNumber() {
 155  0
         return this.phoneNumber;
 156  
     }
 157  
 
 158  
     @Override
 159  
     public String getExtensionNumber() {
 160  0
         return this.extensionNumber;
 161  
     }
 162  
 
 163  
     @Override
 164  
     public String getCountryCode() {
 165  0
         return this.countryCode;
 166  
     }
 167  
 
 168  
     @Override
 169  
     public String getPhoneNumberUnmasked() {
 170  2
         return this.phoneNumberUnmasked;
 171  
     }
 172  
 
 173  
     @Override
 174  
     public String getExtensionNumberUnmasked() {
 175  2
         return this.extensionNumberUnmasked;
 176  
     }
 177  
 
 178  
     @Override
 179  
     public String getCountryCodeUnmasked() {
 180  2
         return this.countryCodeUnmasked;
 181  
     }
 182  
 
 183  
     @Override
 184  
     public String getFormattedPhoneNumber() {
 185  0
         return this.formattedPhoneNumber;
 186  
     }
 187  
 
 188  
     @Override
 189  
     public String getFormattedPhoneNumberUnmasked() {
 190  0
         return this.formattedPhoneNumberUnmasked;
 191  
     }
 192  
 
 193  
     @Override
 194  
     public boolean isSuppressPhone() {
 195  2
         return this.suppressPhone;
 196  
     }
 197  
 
 198  
     @Override
 199  
     public boolean isDefaultValue() {
 200  2
         return this.defaultValue;
 201  
     }
 202  
 
 203  
     @Override
 204  
     public Long getVersionNumber() {
 205  2
         return this.versionNumber;
 206  
     }
 207  
 
 208  
     @Override
 209  
     public String getObjectId() {
 210  2
         return this.objectId;
 211  
     }
 212  
 
 213  
     @Override
 214  
     public boolean isActive() {
 215  2
         return this.active;
 216  
     }
 217  
 
 218  
     @Override
 219  
     public int hashCode() {
 220  0
         return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 221  
     }
 222  
 
 223  
     @Override
 224  
     public boolean equals(Object object) {
 225  7
         return EqualsBuilder.reflectionEquals(object, this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 226  
     }
 227  
 
 228  
     @Override
 229  
     public String toString() {
 230  0
         return ToStringBuilder.reflectionToString(this);
 231  
     }
 232  
 
 233  
 
 234  
     /**
 235  
      * A builder which can be used to construct {@link EntityPhone} instances.  Enforces the constraints of the {@link EntityPhoneContract}.
 236  
      *
 237  
      */
 238  4
     public final static class Builder
 239  
         implements Serializable, ModelBuilder, EntityPhoneContract
 240  
     {
 241  
 
 242  
         private String id;
 243  
         private String entityId;
 244  
         private String entityTypeCode;
 245  
         private Type.Builder phoneType;
 246  
         //private String phoneNumber;
 247  
         //private String extensionNumber;
 248  
         //private String countryCode;
 249  
         private String phoneNumberUnmasked;
 250  
         private String extensionNumberUnmasked;
 251  
         private String countryCodeUnmasked;
 252  
         //private String formattedPhoneNumber;
 253  
         //private String formattedPhoneNumberUnmasked;
 254  
         private boolean suppressPhone;
 255  
         private boolean defaultValue;
 256  
         private Long versionNumber;
 257  
         private String objectId;
 258  
         private boolean active;
 259  
 
 260  7
         private Builder() {
 261  
 
 262  7
         }
 263  
 
 264  
         public static Builder create() {
 265  7
             return new Builder();
 266  
         }
 267  
 
 268  
         public static Builder create(EntityPhoneContract contract) {
 269  4
             if (contract == null) {
 270  0
                 throw new IllegalArgumentException("contract was null");
 271  
             }
 272  4
             Builder builder = create();
 273  4
             builder.setId(contract.getId());
 274  4
             builder.setEntityId(contract.getEntityId());
 275  4
             builder.setEntityTypeCode(contract.getEntityTypeCode());
 276  4
             builder.setSuppressPhone(contract.isSuppressPhone());
 277  4
             if (contract.getPhoneType() != null) {
 278  3
                 builder.setPhoneType(Type.Builder.create(contract.getPhoneType()));
 279  
             }
 280  4
             builder.setPhoneNumber(contract.getPhoneNumberUnmasked());
 281  4
             builder.setExtensionNumber(contract.getExtensionNumberUnmasked());
 282  4
             builder.setCountryCode(contract.getCountryCodeUnmasked());
 283  4
             builder.setDefaultValue(contract.isDefaultValue());
 284  4
             builder.setVersionNumber(contract.getVersionNumber());
 285  4
             builder.setObjectId(contract.getObjectId());
 286  4
             builder.setActive(contract.isActive());
 287  4
             return builder;
 288  
         }
 289  
 
 290  
         public EntityPhone build() {
 291  6
             return new EntityPhone(this);
 292  
         }
 293  
 
 294  
         @Override
 295  
         public String getId() {
 296  6
             return this.id;
 297  
         }
 298  
 
 299  
         @Override
 300  
         public String getEntityTypeCode() {
 301  6
             return this.entityTypeCode;
 302  
         }
 303  
 
 304  
         @Override
 305  
         public String getEntityId() {
 306  6
             return this.entityId;
 307  
         }
 308  
 
 309  
         @Override
 310  
         public Type.Builder getPhoneType() {
 311  10
             return this.phoneType;
 312  
         }
 313  
 
 314  
         @Override
 315  
         public String getPhoneNumber() {
 316  6
             if (isSuppressPhone()) {
 317  0
                 return KimConstants.RestrictedMasks.RESTRICTED_DATA_MASK_PHONE;
 318  
             }
 319  6
             return this.phoneNumberUnmasked;
 320  
         }
 321  
 
 322  
         @Override
 323  
         public String getExtensionNumber() {
 324  6
             if (isSuppressPhone()) {
 325  0
                 return KimConstants.RestrictedMasks.RESTRICTED_DATA_MASK;
 326  
             }
 327  6
             return this.extensionNumberUnmasked;
 328  
         }
 329  
 
 330  
         @Override
 331  
         public String getCountryCode() {
 332  6
             if (isSuppressPhone()) {
 333  0
                 return KimConstants.RestrictedMasks.RESTRICTED_DATA_MASK_CODE;
 334  
             }
 335  6
             return this.countryCodeUnmasked;
 336  
         }
 337  
 
 338  
         @Override
 339  
         public String getPhoneNumberUnmasked() {
 340  6
             return this.phoneNumberUnmasked;
 341  
         }
 342  
 
 343  
         @Override
 344  
         public String getExtensionNumberUnmasked() {
 345  6
             return this.extensionNumberUnmasked;
 346  
         }
 347  
 
 348  
         @Override
 349  
         public String getCountryCodeUnmasked() {
 350  6
             return this.countryCodeUnmasked;
 351  
         }
 352  
 
 353  
         @Override
 354  
         public String getFormattedPhoneNumber() {
 355  6
             if (isSuppressPhone()) {
 356  0
                 return KimConstants.RestrictedMasks.RESTRICTED_DATA_MASK;
 357  
             }
 358  6
             return this.getFormattedPhoneNumberUnmasked();
 359  
         }
 360  
 
 361  
         @Override
 362  
         public String getFormattedPhoneNumberUnmasked() {
 363  12
             StringBuffer sb = new StringBuffer( 30 );
 364  
 
 365  
             // TODO: get extension from country code table
 366  
             // TODO: append "+xxx" if country is not the default country
 367  12
             sb.append( this.phoneNumberUnmasked );
 368  12
             if ( StringUtils.isNotBlank( this.extensionNumberUnmasked) ) {
 369  8
                 sb.append( " x" );
 370  8
                 sb.append( this.extensionNumberUnmasked );
 371  
             }
 372  
 
 373  12
             return sb.toString();
 374  
         }
 375  
 
 376  
         @Override
 377  
         public boolean isSuppressPhone() {
 378  30
             return this.suppressPhone;
 379  
         }
 380  
 
 381  
         @Override
 382  
         public boolean isDefaultValue() {
 383  8
             return this.defaultValue;
 384  
         }
 385  
 
 386  
         @Override
 387  
         public Long getVersionNumber() {
 388  6
             return this.versionNumber;
 389  
         }
 390  
 
 391  
         @Override
 392  
         public String getObjectId() {
 393  6
             return this.objectId;
 394  
         }
 395  
 
 396  
         @Override
 397  
         public boolean isActive() {
 398  8
             return this.active;
 399  
         }
 400  
 
 401  
         public void setId(String id) {
 402  5
             if (StringUtils.isWhitespace(id)) {
 403  1
                 throw new IllegalArgumentException("id is blank");
 404  
             }
 405  4
             this.id = id;
 406  4
         }
 407  
 
 408  
         public void setEntityTypeCode(String entityTypeCode) {
 409  4
             this.entityTypeCode = entityTypeCode;
 410  4
         }
 411  
 
 412  
         public void setEntityId(String entityId) {
 413  4
             this.entityId = entityId;
 414  4
         }
 415  
 
 416  
         public void setPhoneType(Type.Builder phoneType) {
 417  3
             this.phoneType = phoneType;
 418  3
         }
 419  
 
 420  
         public void setPhoneNumber(String phoneNumber) {
 421  4
             this.phoneNumberUnmasked = phoneNumber;
 422  4
         }
 423  
 
 424  
         public void setExtensionNumber(String extensionNumber) {
 425  4
             this.extensionNumberUnmasked = extensionNumber;
 426  4
         }
 427  
 
 428  
         public void setCountryCode(String countryCode) {
 429  4
             this.countryCodeUnmasked = countryCode;
 430  4
         }
 431  
 
 432  
         private void setSuppressPhone(boolean suppressPhone) {
 433  4
             this.suppressPhone = suppressPhone;
 434  4
         }
 435  
 
 436  
         public void setDefaultValue(boolean defaultValue) {
 437  4
             this.defaultValue = defaultValue;
 438  4
         }
 439  
 
 440  
         public void setVersionNumber(Long versionNumber) {
 441  4
             this.versionNumber = versionNumber;
 442  4
         }
 443  
 
 444  
         public void setObjectId(String objectId) {
 445  4
             this.objectId = objectId;
 446  4
         }
 447  
 
 448  
         public void setActive(boolean active) {
 449  4
             this.active = active;
 450  4
         }
 451  
 
 452  
     }
 453  
 
 454  
 
 455  
     /**
 456  
      * Defines some internal constants used on this class.
 457  
      *
 458  
      */
 459  0
     static class Constants {
 460  
 
 461  
         final static String ROOT_ELEMENT_NAME = "entityPhone";
 462  
         final static String TYPE_NAME = "EntityPhoneType";
 463  1
         final static String[] HASH_CODE_EQUALS_EXCLUDE = new String[] {CoreConstants.CommonElements.FUTURE_ELEMENTS };
 464  
 
 465  
     }
 466  
 
 467  
 
 468  
     /**
 469  
      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
 470  
      *
 471  
      */
 472  0
     static class Elements {
 473  
 
 474  
         final static String ID = "id";
 475  
         final static String ENTITY_TYPE_CODE = "entityTypeCode";
 476  
         final static String ENTITY_ID = "entityId";
 477  
         final static String PHONE_TYPE = "phoneType";
 478  
         final static String PHONE_NUMBER = "phoneNumber";
 479  
         final static String EXTENSION_NUMBER = "extensionNumber";
 480  
         final static String COUNTRY_CODE = "countryCode";
 481  
         final static String PHONE_NUMBER_UNMASKED = "phoneNumberUnmasked";
 482  
         final static String EXTENSION_NUMBER_UNMASKED = "extensionNumberUnmasked";
 483  
         final static String COUNTRY_CODE_UNMASKED = "countryCodeUnmasked";
 484  
         final static String FORMATTED_PHONE_NUMBER = "formattedPhoneNumber";
 485  
         final static String FORMATTED_PHONE_NUMBER_UNMASKED = "formattedPhoneNumberUnmasked";
 486  
         final static String SUPPRESS_PHONE = "suppressPhone";
 487  
         final static String DEFAULT_VALUE = "defaultValue";
 488  
         final static String ACTIVE = "active";
 489  
 
 490  
     }
 491  
 
 492  
 }