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