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.impl.identity.email;
17  
18  import javax.persistence.Column;
19  import javax.persistence.Convert;
20  import javax.persistence.MappedSuperclass;
21  import javax.persistence.Transient;
22  
23  import org.kuali.rice.kim.api.KimApiConstants;
24  import org.kuali.rice.kim.api.identity.email.EntityEmailContract;
25  import org.kuali.rice.kim.api.identity.privacy.EntityPrivacyPreferences;
26  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
27  import org.kuali.rice.krad.bo.DataObjectBase;
28  import org.kuali.rice.krad.data.jpa.converters.BooleanYNConverter;
29  
30  /**
31   * @author Kuali Rice Team (rice.collab@kuali.org)
32   */
33  @MappedSuperclass
34  public abstract class EntityEmailBase extends DataObjectBase implements EntityEmailContract {
35      private static final long serialVersionUID = 1L;
36  
37      @Column(name = "ENTITY_ID")
38      private String entityId;
39      
40      @Column(name = "ENT_TYP_CD")
41      private String entityTypeCode;
42      
43      @Column(name = "EMAIL_TYP_CD")
44      private String emailTypeCode;
45      
46      @Column(name = "EMAIL_ADDR")
47      private String emailAddress;
48  
49      @Transient
50      private boolean suppressEmail;
51      
52      @Convert(converter=BooleanYNConverter.class)
53      @Column(name = "ACTV_IND")
54      private boolean active;
55      
56      @Convert(converter=BooleanYNConverter.class)
57      @Column(name = "DFLT_IND")
58      private boolean defaultValue;
59  
60      @Override
61      public boolean isSuppressEmail() {
62          try {
63              EntityPrivacyPreferences privacy = KimApiServiceLocator.getIdentityService().getEntityPrivacyPreferences(
64                      getEntityId());
65              if (privacy != null) {
66                  this.suppressEmail = privacy.isSuppressEmail();
67              } else {
68                  this.suppressEmail = false;
69              }
70          } catch (NullPointerException e) {
71              return false;
72          } catch (ClassCastException c) {
73              return false;
74          }
75          return this.suppressEmail;
76      }
77  
78      @Override
79      public String getEmailAddressUnmasked() {
80          return this.emailAddress;
81      }
82  
83      @Override
84      public String getEmailAddress() {
85          if (isSuppressEmail()) {
86              return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK;
87          }
88  
89          return this.emailAddress;
90      }
91  
92      @Override
93      public String getEntityId() {
94          return entityId;
95      }
96  
97      public void setEntityId(String entityId) {
98          this.entityId = entityId;
99      }
100 
101     @Override
102     public String getEntityTypeCode() {
103         return entityTypeCode;
104     }
105 
106     public void setEntityTypeCode(String entityTypeCode) {
107         this.entityTypeCode = entityTypeCode;
108     }
109 
110     public String getEmailTypeCode() {
111         return emailTypeCode;
112     }
113 
114     public void setEmailTypeCode(String emailTypeCode) {
115         this.emailTypeCode = emailTypeCode;
116     }
117 
118     public void setEmailAddress(String emailAddress) {
119         this.emailAddress = emailAddress;
120     }
121 
122     public boolean getSuppressEmail() {
123         return suppressEmail;
124     }
125 
126     public void setSuppressEmail(boolean suppressEmail) {
127         this.suppressEmail = suppressEmail;
128     }
129 
130     public boolean getActive() {
131         return active;
132     }
133 
134     @Override
135     public boolean isActive() {
136         return active;
137     }
138 
139     public void setActive(boolean active) {
140         this.active = active;
141     }
142 
143     public boolean getDefaultValue() {
144         return defaultValue;
145     }
146 
147     @Override
148     public boolean isDefaultValue() {
149         return defaultValue;
150     }
151 
152     public void setDefaultValue(boolean defaultValue) {
153         this.defaultValue = defaultValue;
154     }
155 
156 }