|  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 |    3 |    @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 |    6 |    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 |    12 |        @SuppressWarnings("unused") | 
  |  64 |     | 
       @XmlAnyElement  | 
  |  65 |     | 
       private final Collection<Element> _futureElements = null;  | 
  |  66 |     | 
     | 
  |  67 |     | 
         | 
  |  68 |     | 
     | 
  |  69 |     | 
     | 
  |  70 |     | 
     | 
  |  71 |    6 |        private EntityEmail() { | 
  |  72 |    6 |            this.id = null;  | 
  |  73 |    6 |            this.entityId = null;  | 
  |  74 |    6 |            this.entityTypeCode = null;  | 
  |  75 |    6 |            this.emailType = null;  | 
  |  76 |    6 |            this.emailAddress = null;  | 
  |  77 |    6 |            this.emailAddressUnmasked = null;  | 
  |  78 |    6 |            this.suppressEmail = false;  | 
  |  79 |    6 |            this.defaultValue = false;  | 
  |  80 |    6 |            this.versionNumber = null;  | 
  |  81 |    6 |            this.objectId = null;  | 
  |  82 |    6 |            this.active = false;  | 
  |  83 |    6 |        }  | 
  |  84 |     | 
     | 
  |  85 |    6 |        private EntityEmail(Builder builder) { | 
  |  86 |    6 |            this.id = builder.getId();  | 
  |  87 |    6 |            this.entityId = builder.getEntityId();  | 
  |  88 |    6 |            this.entityTypeCode = builder.getEntityTypeCode();  | 
  |  89 |    6 |            this.emailType = (builder.getEmailType() != null) ? builder.getEmailType().build() : null;  | 
  |  90 |    6 |            this.emailAddress = builder.getEmailAddress();  | 
  |  91 |    6 |            this.emailAddressUnmasked = builder.getEmailAddressUnmasked();  | 
  |  92 |    6 |            this.suppressEmail = builder.isSuppressEmail();  | 
  |  93 |    6 |            this.defaultValue = builder.isDefaultValue();  | 
  |  94 |    6 |            this.versionNumber = builder.getVersionNumber();  | 
  |  95 |    6 |            this.objectId = builder.getObjectId();  | 
  |  96 |    6 |            this.active = builder.isActive();  | 
  |  97 |    6 |        }  | 
  |  98 |     | 
     | 
  |  99 |     | 
       @Override  | 
  |  100 |     | 
       public String getId() { | 
  |  101 |    2 |            return this.id;  | 
  |  102 |     | 
       }  | 
  |  103 |     | 
     | 
  |  104 |     | 
       @Override  | 
  |  105 |     | 
       public String getEntityId() { | 
  |  106 |    2 |            return this.entityId;  | 
  |  107 |     | 
       }  | 
  |  108 |     | 
     | 
  |  109 |     | 
       @Override  | 
  |  110 |     | 
       public String getEntityTypeCode() { | 
  |  111 |    2 |            return this.entityTypeCode;  | 
  |  112 |     | 
       }  | 
  |  113 |     | 
     | 
  |  114 |     | 
       @Override  | 
  |  115 |     | 
       public Type getEmailType() { | 
  |  116 |    3 |            return this.emailType;  | 
  |  117 |     | 
       }  | 
  |  118 |     | 
     | 
  |  119 |     | 
       @Override  | 
  |  120 |     | 
       public String getEmailAddress() { | 
  |  121 |    0 |            return this.emailAddress;  | 
  |  122 |     | 
       }  | 
  |  123 |     | 
     | 
  |  124 |     | 
       @Override  | 
  |  125 |     | 
       public String getEmailAddressUnmasked() { | 
  |  126 |    2 |            return this.emailAddressUnmasked;  | 
  |  127 |     | 
       }  | 
  |  128 |     | 
     | 
  |  129 |     | 
       @Override  | 
  |  130 |     | 
       public boolean isSuppressEmail() { | 
  |  131 |    2 |            return this.suppressEmail;  | 
  |  132 |     | 
       }  | 
  |  133 |     | 
     | 
  |  134 |     | 
       @Override  | 
  |  135 |     | 
       public boolean isDefaultValue() { | 
  |  136 |    2 |            return this.defaultValue;  | 
  |  137 |     | 
       }  | 
  |  138 |     | 
     | 
  |  139 |     | 
       @Override  | 
  |  140 |     | 
       public Long getVersionNumber() { | 
  |  141 |    2 |            return this.versionNumber;  | 
  |  142 |     | 
       }  | 
  |  143 |     | 
     | 
  |  144 |     | 
       @Override  | 
  |  145 |     | 
       public String getObjectId() { | 
  |  146 |    2 |            return this.objectId;  | 
  |  147 |     | 
       }  | 
  |  148 |     | 
     | 
  |  149 |     | 
       @Override  | 
  |  150 |     | 
       public boolean isActive() { | 
  |  151 |    2 |            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 |    7 |            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 |     | 
     | 
  |  172 |     | 
     | 
  |  173 |     | 
     | 
  |  174 |    4 |        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 |    7 |            private Builder() { | 
  |  190 |     | 
     | 
  |  191 |    7 |            }  | 
  |  192 |     | 
     | 
  |  193 |     | 
           public static Builder create() { | 
  |  194 |    7 |                return new Builder();  | 
  |  195 |     | 
           }  | 
  |  196 |     | 
     | 
  |  197 |     | 
           public static Builder create(EntityEmailContract contract) { | 
  |  198 |    4 |                if (contract == null) { | 
  |  199 |    0 |                    throw new IllegalArgumentException("contract was null"); | 
  |  200 |     | 
               }  | 
  |  201 |    4 |                Builder builder = create();  | 
  |  202 |    4 |                builder.setId(contract.getId());  | 
  |  203 |    4 |                builder.setEntityId(contract.getEntityId());  | 
  |  204 |    4 |                builder.setEntityTypeCode(contract.getEntityTypeCode());  | 
  |  205 |    4 |                builder.setSuppressEmail(contract.isSuppressEmail());  | 
  |  206 |    4 |                if (contract.getEmailType() != null) { | 
  |  207 |    3 |                    builder.setEmailType(Type.Builder.create(contract.getEmailType()));  | 
  |  208 |     | 
               }  | 
  |  209 |    4 |                builder.setEmailAddress(contract.getEmailAddressUnmasked());  | 
  |  210 |    4 |                builder.setDefaultValue(contract.isDefaultValue());  | 
  |  211 |    4 |                builder.setVersionNumber(contract.getVersionNumber());  | 
  |  212 |    4 |                builder.setObjectId(contract.getObjectId());  | 
  |  213 |    4 |                builder.setActive(contract.isActive());  | 
  |  214 |    4 |                return builder;  | 
  |  215 |     | 
           }  | 
  |  216 |     | 
     | 
  |  217 |     | 
           public EntityEmail build() { | 
  |  218 |    6 |                return new EntityEmail(this);  | 
  |  219 |     | 
           }  | 
  |  220 |     | 
     | 
  |  221 |     | 
           @Override  | 
  |  222 |     | 
           public String getId() { | 
  |  223 |    6 |                return this.id;  | 
  |  224 |     | 
           }  | 
  |  225 |     | 
     | 
  |  226 |     | 
           @Override  | 
  |  227 |     | 
           public String getEntityTypeCode() { | 
  |  228 |    6 |                return this.entityTypeCode;  | 
  |  229 |     | 
           }  | 
  |  230 |     | 
     | 
  |  231 |     | 
           @Override  | 
  |  232 |     | 
           public String getEntityId() { | 
  |  233 |    6 |                return this.entityId;  | 
  |  234 |     | 
           }  | 
  |  235 |     | 
     | 
  |  236 |     | 
           @Override  | 
  |  237 |     | 
           public Type.Builder getEmailType() { | 
  |  238 |    10 |                return this.emailType;  | 
  |  239 |     | 
           }  | 
  |  240 |     | 
     | 
  |  241 |     | 
           @Override  | 
  |  242 |     | 
           public String getEmailAddress() { | 
  |  243 |    6 |                if (isSuppressEmail()) { | 
  |  244 |    0 |                    return KimConstants.RestrictedMasks.RESTRICTED_DATA_MASK;  | 
  |  245 |     | 
               }  | 
  |  246 |    6 |                return this.emailAddressUnmasked;  | 
  |  247 |     | 
           }  | 
  |  248 |     | 
     | 
  |  249 |     | 
           @Override  | 
  |  250 |     | 
           public String getEmailAddressUnmasked() { | 
  |  251 |    6 |                return this.emailAddressUnmasked;  | 
  |  252 |     | 
           }  | 
  |  253 |     | 
     | 
  |  254 |     | 
           @Override  | 
  |  255 |     | 
           public boolean isSuppressEmail() { | 
  |  256 |    12 |                return this.suppressEmail;  | 
  |  257 |     | 
           }  | 
  |  258 |     | 
     | 
  |  259 |     | 
           @Override  | 
  |  260 |     | 
           public boolean isDefaultValue() { | 
  |  261 |    8 |                return this.defaultValue;  | 
  |  262 |     | 
           }  | 
  |  263 |     | 
     | 
  |  264 |     | 
           @Override  | 
  |  265 |     | 
           public Long getVersionNumber() { | 
  |  266 |    6 |                return this.versionNumber;  | 
  |  267 |     | 
           }  | 
  |  268 |     | 
     | 
  |  269 |     | 
           @Override  | 
  |  270 |     | 
           public String getObjectId() { | 
  |  271 |    6 |                return this.objectId;  | 
  |  272 |     | 
           }  | 
  |  273 |     | 
     | 
  |  274 |     | 
           @Override  | 
  |  275 |     | 
           public boolean isActive() { | 
  |  276 |    8 |                return this.active;  | 
  |  277 |     | 
           }  | 
  |  278 |     | 
     | 
  |  279 |     | 
           public void setId(String id) { | 
  |  280 |    5 |                if (StringUtils.isWhitespace(id)) { | 
  |  281 |    1 |                    throw new IllegalArgumentException("id is blank"); | 
  |  282 |     | 
               }  | 
  |  283 |    4 |                this.id = id;  | 
  |  284 |    4 |            }  | 
  |  285 |     | 
     | 
  |  286 |     | 
           public void setEntityTypeCode(String entityTypeCode) { | 
  |  287 |    4 |                this.entityTypeCode = entityTypeCode;  | 
  |  288 |    4 |            }  | 
  |  289 |     | 
     | 
  |  290 |     | 
           public void setEntityId(String entityId) { | 
  |  291 |    4 |                this.entityId = entityId;  | 
  |  292 |    4 |            }  | 
  |  293 |     | 
     | 
  |  294 |     | 
           public void setEmailType(Type.Builder emailType) { | 
  |  295 |    3 |                this.emailType = emailType;  | 
  |  296 |    3 |            }  | 
  |  297 |     | 
     | 
  |  298 |     | 
           public void setEmailAddress(String emailAddress) { | 
  |  299 |    4 |                this.emailAddressUnmasked = emailAddress;  | 
  |  300 |    4 |            }  | 
  |  301 |     | 
     | 
  |  302 |     | 
           private void setSuppressEmail(boolean suppressEmail) { | 
  |  303 |    4 |                this.suppressEmail = suppressEmail;  | 
  |  304 |    4 |            }  | 
  |  305 |     | 
     | 
  |  306 |     | 
           public void setDefaultValue(boolean defaultValue) { | 
  |  307 |    4 |                this.defaultValue = defaultValue;  | 
  |  308 |    4 |            }  | 
  |  309 |     | 
     | 
  |  310 |     | 
           public void setVersionNumber(Long versionNumber) { | 
  |  311 |    4 |                this.versionNumber = versionNumber;  | 
  |  312 |    4 |            }  | 
  |  313 |     | 
     | 
  |  314 |     | 
           public void setObjectId(String objectId) { | 
  |  315 |    4 |                this.objectId = objectId;  | 
  |  316 |    4 |            }  | 
  |  317 |     | 
     | 
  |  318 |     | 
           public void setActive(boolean active) { | 
  |  319 |    4 |                this.active = active;  | 
  |  320 |    4 |            }  | 
  |  321 |     | 
     | 
  |  322 |     | 
       }  | 
  |  323 |     | 
     | 
  |  324 |     | 
     | 
  |  325 |     | 
         | 
  |  326 |     | 
     | 
  |  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 |     | 
     | 
  |  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 |     | 
   }  |