001/**
002 * Copyright 2005-2015 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.kim.impl.identity.email;
017
018import javax.persistence.Column;
019import javax.persistence.Convert;
020import javax.persistence.MappedSuperclass;
021import javax.persistence.Transient;
022
023import org.kuali.rice.kim.api.KimApiConstants;
024import org.kuali.rice.kim.api.identity.email.EntityEmailContract;
025import org.kuali.rice.kim.api.identity.privacy.EntityPrivacyPreferences;
026import org.kuali.rice.kim.api.services.KimApiServiceLocator;
027import org.kuali.rice.krad.bo.DataObjectBase;
028import org.kuali.rice.krad.data.jpa.converters.BooleanYNConverter;
029
030/**
031 * @author Kuali Rice Team (rice.collab@kuali.org)
032 */
033@MappedSuperclass
034public abstract class EntityEmailBase extends DataObjectBase implements EntityEmailContract {
035    private static final long serialVersionUID = 1L;
036
037    @Column(name = "ENTITY_ID")
038    private String entityId;
039    
040    @Column(name = "ENT_TYP_CD")
041    private String entityTypeCode;
042    
043    @Column(name = "EMAIL_TYP_CD")
044    private String emailTypeCode;
045    
046    @Column(name = "EMAIL_ADDR")
047    private String emailAddress;
048
049    @Transient
050    private boolean suppressEmail;
051    
052    @Convert(converter=BooleanYNConverter.class)
053    @Column(name = "ACTV_IND")
054    private boolean active;
055    
056    @Convert(converter=BooleanYNConverter.class)
057    @Column(name = "DFLT_IND")
058    private boolean defaultValue;
059
060    @Override
061    public boolean isSuppressEmail() {
062        try {
063            EntityPrivacyPreferences privacy = KimApiServiceLocator.getIdentityService().getEntityPrivacyPreferences(
064                    getEntityId());
065            if (privacy != null) {
066                this.suppressEmail = privacy.isSuppressEmail();
067            } else {
068                this.suppressEmail = false;
069            }
070        } catch (NullPointerException e) {
071            return false;
072        } catch (ClassCastException c) {
073            return false;
074        }
075        return this.suppressEmail;
076    }
077
078    @Override
079    public String getEmailAddressUnmasked() {
080        return this.emailAddress;
081    }
082
083    @Override
084    public String getEmailAddress() {
085        if (isSuppressEmail()) {
086            return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK;
087        }
088
089        return this.emailAddress;
090    }
091
092    @Override
093    public String getEntityId() {
094        return entityId;
095    }
096
097    public void setEntityId(String entityId) {
098        this.entityId = entityId;
099    }
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}