Coverage Report - org.kuali.rice.kim.impl.identity.email.EntityEmailBo
 
Classes in this File Line Coverage Branch Coverage Complexity
EntityEmailBo
0%
0/28
0%
0/20
0
 
 1  
 /**
 2  
  * Copyright 2005-2011 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.Entity
 20  
 import javax.persistence.FetchType
 21  
 import javax.persistence.Id
 22  
 import javax.persistence.JoinColumn
 23  
 import javax.persistence.ManyToOne
 24  
 import javax.persistence.Table
 25  
 import javax.persistence.Transient
 26  
 import org.hibernate.annotations.Type
 27  
 import org.kuali.rice.kim.api.KimApiConstants
 28  
 import org.kuali.rice.kim.api.identity.email.EntityEmail
 29  
 import org.kuali.rice.kim.api.identity.email.EntityEmailContract
 30  
 import org.kuali.rice.kim.api.identity.privacy.EntityPrivacyPreferences
 31  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator
 32  
 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase
 33  
 
 34  
 /**
 35  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 36  
  */
 37  
 @Entity
 38  
 @Table(name = "KRIM_ENTITY_EMAIL_T")
 39  
 class EntityEmailBo extends PersistableBusinessObjectBase implements EntityEmailContract {
 40  
     private static final long serialVersionUID = 1L;
 41  
 
 42  
         @Id
 43  
         @Column(name = "ENTITY_EMAIL_ID")
 44  
         String id;
 45  
 
 46  
         @Column(name = "ENTITY_ID")
 47  
         String entityId;
 48  
 
 49  
         @Column(name = "ENT_TYP_CD")
 50  
         String entityTypeCode;
 51  
 
 52  
         @Column(name = "EMAIL_TYP_CD")
 53  
         String emailTypeCode;
 54  
 
 55  
         @Column(name = "EMAIL_ADDR")
 56  
             String emailAddress;
 57  
 
 58  
         @ManyToOne(targetEntity=EntityEmailTypeBo.class, fetch = FetchType.EAGER, cascade = [])
 59  
         @JoinColumn(name = "PHONE_TYP_CD", insertable = false, updatable = false)
 60  
         EntityEmailTypeBo emailType;
 61  
 
 62  
         @Transient
 63  
         boolean suppressEmail;
 64  
 
 65  
         @Type(type="yes_no")
 66  
         @Column(name="ACTV_IND")
 67  
         boolean active;
 68  
 
 69  
         @Type(type="yes_no")
 70  
         @Column(name="DFLT_IND")
 71  
         boolean defaultValue;
 72  
 
 73  
      /*
 74  
        * Converts a mutable EntityEmailBo to an immutable EntityEmail representation.
 75  
        * @param bo
 76  
        * @return an immutable EntityEmail
 77  
        */
 78  
       static EntityEmail to(EntityEmailBo bo) {
 79  0
         if (bo == null) { return null }
 80  0
         return EntityEmail.Builder.create(bo).build()
 81  
       }
 82  
 
 83  
       /**
 84  
        * Creates a EntityEmailBo business object from an immutable representation of a EntityEmail.
 85  
        * @param an immutable EntityEmail
 86  
        * @return a EntityEmailBo
 87  
        */
 88  
       static EntityEmailBo from(EntityEmail immutable) {
 89  0
         if (immutable == null) {return null}
 90  
 
 91  0
         EntityEmailBo bo = new EntityEmailBo()
 92  0
         bo.id = immutable.id
 93  0
         bo.active = immutable.active
 94  
 
 95  0
         bo.entityId = immutable.entityId
 96  0
         bo.entityTypeCode = immutable.entityTypeCode
 97  0
         if (immutable.emailType != null) {
 98  0
             bo.emailTypeCode = immutable.emailType.code
 99  
         }
 100  0
         bo.emailAddress = immutable.getEmailAddressUnmasked()
 101  0
         bo.emailType = EntityEmailTypeBo.from(immutable.emailType)
 102  0
         bo.defaultValue = immutable.defaultValue
 103  0
         bo.versionNumber = immutable.versionNumber
 104  0
         bo.objectId = immutable.objectId
 105  
 
 106  0
         return bo;
 107  
       }
 108  
 
 109  
         @Override
 110  
         EntityEmailTypeBo getEmailType() {
 111  0
             return this.emailType
 112  
         }
 113  
 
 114  
         public void setEmailType(EntityEmailTypeBo emailType) {
 115  0
             this.emailType = emailType
 116  
         }
 117  
 
 118  
         @Override
 119  
         boolean isSuppressEmail() {
 120  0
             if (this.suppressEmail == null) {
 121  0
                 EntityPrivacyPreferences privacy = KimApiServiceLocator.getIdentityService().getEntityPrivacyPreferences(getEntityId())
 122  0
                 if (privacy != null) {
 123  0
                    this.suppressEmail = privacy.isSuppressEmail()
 124  
                 } else {
 125  0
                    this.suppressEmail = false
 126  
                 }
 127  
             }
 128  
 
 129  0
             return this.suppressEmail;
 130  
         }
 131  
 
 132  
         @Override
 133  
         String getEmailAddressUnmasked() {
 134  0
             return this.emailAddress
 135  
         }
 136  
 
 137  
         @Override
 138  
         String getEmailAddress() {
 139  0
             if (isSuppressEmail())  {
 140  0
                 return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK
 141  
             }
 142  0
             return this.emailAddress
 143  
         }
 144  
 }