Coverage Report - org.kuali.rice.kim.api.identity.email.EntityEmail
 
Classes in this File Line Coverage Branch Coverage Complexity
EntityEmail
95%
41/43
100%
2/2
1.195
EntityEmail$1
N/A
N/A
1.195
EntityEmail$Builder
96%
53/55
75%
6/8
1.195
EntityEmail$Constants
50%
1/2
N/A
1.195
EntityEmail$Elements
0%
0/1
N/A
1.195
 
 1  
 package org.kuali.rice.kim.api.identity.email;
 2  
 
 3  
 import org.apache.commons.lang.StringUtils;
 4  
 import org.apache.commons.lang.builder.EqualsBuilder;
 5  
 import org.apache.commons.lang.builder.HashCodeBuilder;
 6  
 import org.apache.commons.lang.builder.ToStringBuilder;
 7  
 import org.kuali.rice.core.api.CoreConstants;
 8  
 import org.kuali.rice.core.api.mo.ModelBuilder;
 9  
 import org.kuali.rice.core.api.mo.ModelObjectComplete;
 10  
 import org.kuali.rice.kim.api.KimConstants;
 11  
 import org.kuali.rice.kim.api.identity.Type;
 12  
 
 13  
 import javax.xml.bind.Element;
 14  
 import javax.xml.bind.annotation.XmlAccessType;
 15  
 import javax.xml.bind.annotation.XmlAccessorType;
 16  
 import javax.xml.bind.annotation.XmlAnyElement;
 17  
 import javax.xml.bind.annotation.XmlElement;
 18  
 import javax.xml.bind.annotation.XmlRootElement;
 19  
 import javax.xml.bind.annotation.XmlType;
 20  
 import java.io.Serializable;
 21  
 import java.util.Collection;
 22  
 
 23  21
 @XmlRootElement(name = EntityEmail.Constants.ROOT_ELEMENT_NAME)
 24  
 @XmlAccessorType(XmlAccessType.NONE)
 25  
 @XmlType(name = EntityEmail.Constants.TYPE_NAME, propOrder = {
 26  
     EntityEmail.Elements.ID,
 27  
     EntityEmail.Elements.ENTITY_TYPE_CODE,
 28  
     EntityEmail.Elements.ENTITY_ID,
 29  
     EntityEmail.Elements.EMAIL_TYPE,
 30  
     EntityEmail.Elements.EMAIL_ADDRESS,
 31  
     EntityEmail.Elements.EMAIL_ADDRESS_UNMASKED,
 32  
     EntityEmail.Elements.SUPPRESS_EMAIL,
 33  
     EntityEmail.Elements.DEFAULT_VALUE,
 34  
     EntityEmail.Elements.ACTIVE,
 35  
     CoreConstants.CommonElements.VERSION_NUMBER,
 36  
     CoreConstants.CommonElements.OBJECT_ID,
 37  
     CoreConstants.CommonElements.FUTURE_ELEMENTS
 38  
 })
 39  13
 public class EntityEmail implements ModelObjectComplete, EntityEmailContract{
 40  
     
 41  
     @XmlElement(name = Elements.ID, required = false)
 42  
     private final String id;
 43  
     @XmlElement(name = Elements.ENTITY_TYPE_CODE, required = false)
 44  
     private final String entityTypeCode;
 45  
     @XmlElement(name = Elements.ENTITY_ID, required = false)
 46  
     private final String entityId;
 47  
     @XmlElement(name = Elements.EMAIL_TYPE, required = false)
 48  
     private final Type emailType;
 49  
     @XmlElement(name = Elements.EMAIL_ADDRESS, required = false)
 50  
     private final String emailAddress;
 51  
     @XmlElement(name = Elements.EMAIL_ADDRESS_UNMASKED, required = false)
 52  
     private final String emailAddressUnmasked;
 53  
     @XmlElement(name = Elements.SUPPRESS_EMAIL, required = false)
 54  
     private final boolean suppressEmail;
 55  
     @XmlElement(name = Elements.DEFAULT_VALUE, required = false)
 56  
     private final boolean defaultValue;
 57  
     @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
 58  
     private final Long versionNumber;
 59  
     @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
 60  
     private final String objectId;
 61  
     @XmlElement(name = Elements.ACTIVE, required = false)
 62  
     private final boolean active;
 63  23
     @SuppressWarnings("unused")
 64  
     @XmlAnyElement
 65  
     private final Collection<Element> _futureElements = null;
 66  
 
 67  
     /**
 68  
      * Private constructor used only by JAXB.
 69  
      * 
 70  
      */
 71  10
     private EntityEmail() {
 72  10
         this.id = null;
 73  10
         this.entityId = null;
 74  10
         this.entityTypeCode = null;
 75  10
         this.emailType = null;
 76  10
         this.emailAddress = null;
 77  10
         this.emailAddressUnmasked = null;
 78  10
         this.suppressEmail = false;
 79  10
         this.defaultValue = false;
 80  10
         this.versionNumber = null;
 81  10
         this.objectId = null;
 82  10
         this.active = false;
 83  10
     }
 84  
 
 85  13
     private EntityEmail(Builder builder) {
 86  13
         this.id = builder.getId();
 87  13
         this.entityId = builder.getEntityId();
 88  13
         this.entityTypeCode = builder.getEntityTypeCode();
 89  13
         this.emailType = (builder.getEmailType() != null) ? builder.getEmailType().build() : null;
 90  13
         this.emailAddress = builder.getEmailAddress();
 91  13
         this.emailAddressUnmasked = builder.getEmailAddressUnmasked();
 92  13
         this.suppressEmail = builder.isSuppressEmail();
 93  13
         this.defaultValue = builder.isDefaultValue();
 94  13
         this.versionNumber = builder.getVersionNumber();
 95  13
         this.objectId = builder.getObjectId();
 96  13
         this.active = builder.isActive();
 97  13
     }
 98  
 
 99  
     @Override
 100  
     public String getId() {
 101  7
         return this.id;
 102  
     }
 103  
 
 104  
     @Override
 105  
     public String getEntityId() {
 106  7
         return this.entityId;
 107  
     }
 108  
 
 109  
     @Override
 110  
     public String getEntityTypeCode() {
 111  7
         return this.entityTypeCode;
 112  
     }
 113  
 
 114  
     @Override
 115  
     public Type getEmailType() {
 116  21
         return this.emailType;
 117  
     }
 118  
 
 119  
     @Override
 120  
     public String getEmailAddress() {
 121  2
         return this.emailAddress;
 122  
     }
 123  
 
 124  
     @Override
 125  
     public String getEmailAddressUnmasked() {
 126  7
         return this.emailAddressUnmasked;
 127  
     }
 128  
 
 129  
     @Override
 130  
     public boolean isSuppressEmail() {
 131  7
         return this.suppressEmail;
 132  
     }
 133  
 
 134  
     @Override
 135  
     public boolean isDefaultValue() {
 136  7
         return this.defaultValue;
 137  
     }
 138  
 
 139  
     @Override
 140  
     public Long getVersionNumber() {
 141  7
         return this.versionNumber;
 142  
     }
 143  
 
 144  
     @Override
 145  
     public String getObjectId() {
 146  7
         return this.objectId;
 147  
     }
 148  
 
 149  
     @Override
 150  
     public boolean isActive() {
 151  7
         return this.active;
 152  
     }
 153  
 
 154  
     @Override
 155  
     public int hashCode() {
 156  0
         return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 157  
     }
 158  
 
 159  
     @Override
 160  
     public boolean equals(Object object) {
 161  11
         return EqualsBuilder.reflectionEquals(object, this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 162  
     }
 163  
 
 164  
     @Override
 165  
     public String toString() {
 166  0
         return ToStringBuilder.reflectionToString(this);
 167  
     }
 168  
 
 169  
 
 170  
     /**
 171  
      * A builder which can be used to construct {@link EntityEmail} instances.  Enforces the constraints of the {@link org.kuali.rice.kim.api.identity.email.EntityEmailContract}.
 172  
      * 
 173  
      */
 174  5
     public final static class Builder
 175  
         implements Serializable, ModelBuilder, EntityEmailContract
 176  
     {
 177  
 
 178  
         private String id;
 179  
         private String entityId;
 180  
         private String entityTypeCode;
 181  
         private Type.Builder emailType;
 182  
         private String emailAddressUnmasked;
 183  
         private boolean suppressEmail;
 184  
         private boolean defaultValue;
 185  
         private Long versionNumber;
 186  
         private String objectId;
 187  
         private boolean active;
 188  
 
 189  11
         private Builder() {
 190  
 
 191  11
         }
 192  
 
 193  
         public static Builder create() {
 194  11
             return new Builder();
 195  
         }
 196  
 
 197  
         public static Builder create(EntityEmailContract contract) {
 198  8
             if (contract == null) {
 199  0
                 throw new IllegalArgumentException("contract was null");
 200  
             }
 201  8
             Builder builder = create();
 202  8
             builder.setId(contract.getId());
 203  8
             builder.setEntityId(contract.getEntityId());
 204  8
             builder.setEntityTypeCode(contract.getEntityTypeCode());
 205  8
             builder.setSuppressEmail(contract.isSuppressEmail());
 206  8
             if (contract.getEmailType() != null) {
 207  7
                 builder.setEmailType(Type.Builder.create(contract.getEmailType()));
 208  
             }
 209  8
             builder.setEmailAddress(contract.getEmailAddressUnmasked());
 210  8
             builder.setDefaultValue(contract.isDefaultValue());
 211  8
             builder.setVersionNumber(contract.getVersionNumber());
 212  8
             builder.setObjectId(contract.getObjectId());
 213  8
             builder.setActive(contract.isActive());
 214  8
             return builder;
 215  
         }
 216  
 
 217  
         public EntityEmail build() {
 218  13
             return new EntityEmail(this);
 219  
         }
 220  
 
 221  
         @Override
 222  
         public String getId() {
 223  13
             return this.id;
 224  
         }
 225  
 
 226  
         @Override
 227  
         public String getEntityTypeCode() {
 228  13
             return this.entityTypeCode;
 229  
         }
 230  
 
 231  
         @Override
 232  
         public String getEntityId() {
 233  13
             return this.entityId;
 234  
         }
 235  
 
 236  
         @Override
 237  
         public Type.Builder getEmailType() {
 238  24
             return this.emailType;
 239  
         }
 240  
 
 241  
         @Override
 242  
         public String getEmailAddress() {
 243  13
             if (isSuppressEmail()) {
 244  0
                 return KimConstants.RestrictedMasks.RESTRICTED_DATA_MASK;
 245  
             }
 246  13
             return this.emailAddressUnmasked;
 247  
         }
 248  
 
 249  
         @Override
 250  
         public String getEmailAddressUnmasked() {
 251  13
             return this.emailAddressUnmasked;
 252  
         }
 253  
 
 254  
         @Override
 255  
         public boolean isSuppressEmail() {
 256  26
             return this.suppressEmail;
 257  
         }
 258  
 
 259  
         @Override
 260  
         public boolean isDefaultValue() {
 261  21
             return this.defaultValue;
 262  
         }
 263  
 
 264  
         @Override
 265  
         public Long getVersionNumber() {
 266  13
             return this.versionNumber;
 267  
         }
 268  
 
 269  
         @Override
 270  
         public String getObjectId() {
 271  13
             return this.objectId;
 272  
         }
 273  
 
 274  
         @Override
 275  
         public boolean isActive() {
 276  21
             return this.active;
 277  
         }
 278  
 
 279  
         public void setId(String id) {
 280  9
             if (StringUtils.isWhitespace(id)) {
 281  1
                 throw new IllegalArgumentException("id is blank");
 282  
             }
 283  8
             this.id = id;
 284  8
         }
 285  
 
 286  
         public void setEntityTypeCode(String entityTypeCode) {
 287  8
             this.entityTypeCode = entityTypeCode;
 288  8
         }
 289  
 
 290  
         public void setEntityId(String entityId) {
 291  8
             this.entityId = entityId;
 292  8
         }
 293  
 
 294  
         public void setEmailType(Type.Builder emailType) {
 295  7
             this.emailType = emailType;
 296  7
         }
 297  
 
 298  
         public void setEmailAddress(String emailAddress) {
 299  8
             this.emailAddressUnmasked = emailAddress;
 300  8
         }
 301  
 
 302  
         private void setSuppressEmail(boolean suppressEmail) {
 303  8
             this.suppressEmail = suppressEmail;
 304  8
         }
 305  
 
 306  
         public void setDefaultValue(boolean defaultValue) {
 307  8
             this.defaultValue = defaultValue;
 308  8
         }
 309  
 
 310  
         public void setVersionNumber(Long versionNumber) {
 311  8
             this.versionNumber = versionNumber;
 312  8
         }
 313  
 
 314  
         public void setObjectId(String objectId) {
 315  8
             this.objectId = objectId;
 316  8
         }
 317  
 
 318  
         public void setActive(boolean active) {
 319  8
             this.active = active;
 320  8
         }
 321  
 
 322  
     }
 323  
 
 324  
 
 325  
     /**
 326  
      * Defines some internal constants used on this class.
 327  
      * 
 328  
      */
 329  0
     static class Constants {
 330  
 
 331  
         final static String ROOT_ELEMENT_NAME = "entityEmail";
 332  
         final static String TYPE_NAME = "EntityEmailType";
 333  1
         final static String[] HASH_CODE_EQUALS_EXCLUDE = new String[] {CoreConstants.CommonElements.FUTURE_ELEMENTS };
 334  
 
 335  
     }
 336  
 
 337  
 
 338  
     /**
 339  
      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
 340  
      * 
 341  
      */
 342  0
     static class Elements {
 343  
 
 344  
         final static String ID = "id";
 345  
         final static String ENTITY_TYPE_CODE = "entityTypeCode";
 346  
         final static String ENTITY_ID = "entityId";
 347  
         final static String EMAIL_TYPE = "emailType";
 348  
         final static String EMAIL_ADDRESS = "emailAddress";
 349  
         final static String EMAIL_ADDRESS_UNMASKED = "emailAddressUnmasked";
 350  
         final static String SUPPRESS_EMAIL = "suppressEmail";
 351  
         final static String DEFAULT_VALUE = "defaultValue";
 352  
         final static String ACTIVE = "active";
 353  
 
 354  
     }
 355  
 
 356  
 }