|  1 |     | 
   package org.kuali.rice.kim.impl.identity.email  | 
  |  2 |     | 
     | 
  |  3 |     | 
   import javax.persistence.Column  | 
  |  4 |     | 
   import javax.persistence.Entity  | 
  |  5 |     | 
   import javax.persistence.FetchType  | 
  |  6 |     | 
   import javax.persistence.Id  | 
  |  7 |     | 
   import javax.persistence.JoinColumn  | 
  |  8 |     | 
   import javax.persistence.ManyToOne  | 
  |  9 |     | 
   import javax.persistence.Table  | 
  |  10 |     | 
   import javax.persistence.Transient  | 
  |  11 |     | 
   import org.hibernate.annotations.Type  | 
  |  12 |     | 
   import org.kuali.rice.kim.api.KimConstants  | 
  |  13 |     | 
   import org.kuali.rice.kim.api.identity.email.EntityEmail  | 
  |  14 |     | 
   import org.kuali.rice.kim.api.identity.email.EntityEmailContract  | 
  |  15 |     | 
   import org.kuali.rice.kim.api.identity.privacy.EntityPrivacyPreferences  | 
  |  16 |     | 
   import org.kuali.rice.kim.api.services.KimApiServiceLocator  | 
  |  17 |     | 
   import org.kuali.rice.krad.bo.PersistableBusinessObjectBase  | 
  |  18 |     | 
     | 
  |  19 |     | 
     | 
  |  20 |     | 
     | 
  |  21 |     | 
     | 
  |  22 |     | 
   @Entity  | 
  |  23 |     | 
   @Table(name = "KRIM_ENTITY_EMAIL_T")  | 
  |  24 |     | 
   class EntityEmailBo extends PersistableBusinessObjectBase implements EntityEmailContract { | 
  |  25 |     | 
       private static final long serialVersionUID = 1L;  | 
  |  26 |     | 
     | 
  |  27 |     | 
           @Id  | 
  |  28 |     | 
           @Column(name = "ENTITY_EMAIL_ID")  | 
  |  29 |     | 
           String id;  | 
  |  30 |     | 
     | 
  |  31 |     | 
           @Column(name = "ENTITY_ID")  | 
  |  32 |     | 
           String entityId;  | 
  |  33 |     | 
     | 
  |  34 |     | 
           @Column(name = "ENT_TYP_CD")  | 
  |  35 |     | 
           String entityTypeCode;  | 
  |  36 |     | 
     | 
  |  37 |     | 
           @Column(name = "EMAIL_TYP_CD")  | 
  |  38 |     | 
           String emailTypeCode;  | 
  |  39 |     | 
     | 
  |  40 |     | 
           @Column(name = "EMAIL_ADDR")  | 
  |  41 |     | 
               String emailAddress;  | 
  |  42 |     | 
     | 
  |  43 |     | 
           @ManyToOne(targetEntity=EntityEmailTypeBo.class, fetch = FetchType.EAGER, cascade = [])  | 
  |  44 |     | 
           @JoinColumn(name = "PHONE_TYP_CD", insertable = false, updatable = false)  | 
  |  45 |     | 
           EntityEmailTypeBo emailType;  | 
  |  46 |     | 
     | 
  |  47 |     | 
           @Transient  | 
  |  48 |     | 
           boolean suppressEmail;  | 
  |  49 |     | 
     | 
  |  50 |     | 
           @Type(type="yes_no")  | 
  |  51 |     | 
           @Column(name="ACTV_IND")  | 
  |  52 |     | 
           boolean active;  | 
  |  53 |     | 
     | 
  |  54 |     | 
           @Type(type="yes_no")  | 
  |  55 |     | 
           @Column(name="DFLT_IND")  | 
  |  56 |     | 
           boolean defaultValue;  | 
  |  57 |     | 
     | 
  |  58 |     | 
          | 
  |  59 |     | 
     | 
  |  60 |     | 
     | 
  |  61 |     | 
     | 
  |  62 |     | 
     | 
  |  63 |     | 
         static EntityEmail to(EntityEmailBo bo) { | 
  |  64 |    1 |            if (bo == null) { return null } | 
  |  65 |    1 |            return EntityEmail.Builder.create(bo).build()  | 
  |  66 |     | 
         }  | 
  |  67 |     | 
     | 
  |  68 |     | 
           | 
  |  69 |     | 
     | 
  |  70 |     | 
     | 
  |  71 |     | 
     | 
  |  72 |     | 
     | 
  |  73 |     | 
         static EntityEmailBo from(EntityEmail immutable) { | 
  |  74 |    1 |            if (immutable == null) {return null} | 
  |  75 |     | 
     | 
  |  76 |    1 |            EntityEmailBo bo = new EntityEmailBo()  | 
  |  77 |    1 |            bo.id = immutable.id  | 
  |  78 |    1 |            bo.active = immutable.active  | 
  |  79 |     | 
     | 
  |  80 |    1 |            bo.entityId = immutable.entityId  | 
  |  81 |    1 |            bo.entityTypeCode = immutable.entityTypeCode  | 
  |  82 |    1 |            if (immutable.emailType != null) { | 
  |  83 |    0 |                bo.emailTypeCode = immutable.emailType.code  | 
  |  84 |     | 
           }  | 
  |  85 |    1 |            bo.emailAddress = immutable.getEmailAddressUnmasked()  | 
  |  86 |    1 |            bo.emailType = EntityEmailTypeBo.from(immutable.emailType)  | 
  |  87 |    1 |            bo.defaultValue = immutable.defaultValue  | 
  |  88 |    1 |            bo.versionNumber = immutable.versionNumber  | 
  |  89 |    1 |            bo.objectId = immutable.objectId  | 
  |  90 |     | 
     | 
  |  91 |    1 |            return bo;  | 
  |  92 |     | 
         }  | 
  |  93 |     | 
     | 
  |  94 |     | 
           @Override  | 
  |  95 |     | 
           EntityEmailTypeBo getEmailType() { | 
  |  96 |    1 |                return this.emailType  | 
  |  97 |     | 
           }  | 
  |  98 |     | 
     | 
  |  99 |     | 
           public void setEmailType(EntityEmailTypeBo emailType) { | 
  |  100 |    1 |                this.emailType = emailType  | 
  |  101 |     | 
           }  | 
  |  102 |     | 
     | 
  |  103 |     | 
           @Override  | 
  |  104 |     | 
           boolean isSuppressEmail() { | 
  |  105 |    1 |                if (this.suppressEmail == null) { | 
  |  106 |    0 |                    EntityPrivacyPreferences privacy = KimApiServiceLocator.getIdentityService().getEntityPrivacyPreferences(getEntityId())  | 
  |  107 |    0 |                    if (privacy != null) { | 
  |  108 |    0 |                       this.suppressEmail = privacy.isSuppressEmail()  | 
  |  109 |     | 
                   } else { | 
  |  110 |    0 |                       this.suppressEmail = false  | 
  |  111 |     | 
                   }  | 
  |  112 |     | 
               }  | 
  |  113 |     | 
     | 
  |  114 |    1 |                return this.suppressEmail;  | 
  |  115 |     | 
           }  | 
  |  116 |     | 
     | 
  |  117 |     | 
           @Override  | 
  |  118 |     | 
           String getEmailAddressUnmasked() { | 
  |  119 |    1 |                return this.emailAddress  | 
  |  120 |     | 
           }  | 
  |  121 |     | 
     | 
  |  122 |     | 
           @Override  | 
  |  123 |     | 
           String getEmailAddress() { | 
  |  124 |    0 |                if (isSuppressEmail())  { | 
  |  125 |    0 |                    return KimConstants.RestrictedMasks.RESTRICTED_DATA_MASK  | 
  |  126 |     | 
               }  | 
  |  127 |    0 |                return this.emailAddress  | 
  |  128 |     | 
           }  | 
  |  129 |     | 
   }  |