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