001/** 002 * Copyright 2005-2016 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.CascadeType; 019import javax.persistence.Column; 020import javax.persistence.Entity; 021import javax.persistence.GeneratedValue; 022import javax.persistence.Id; 023import javax.persistence.JoinColumn; 024import javax.persistence.ManyToOne; 025import javax.persistence.Table; 026 027import org.eclipse.persistence.annotations.JoinFetch; 028import org.eclipse.persistence.annotations.JoinFetchType; 029import org.kuali.rice.kim.api.identity.email.EntityEmail; 030import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator; 031 032/** 033 * @author Kuali Rice Team (rice.collab@kuali.org) 034 */ 035@Entity 036@Table(name = "KRIM_ENTITY_EMAIL_T") 037public class EntityEmailBo extends EntityEmailBase { 038 039 private static final long serialVersionUID = 1L; 040 041 @PortableSequenceGenerator(name = "KRIM_ENTITY_EMAIL_ID_S") 042 @GeneratedValue(generator = "KRIM_ENTITY_EMAIL_ID_S") 043 @Id 044 @Column(name = "ENTITY_EMAIL_ID") 045 private String id; 046 047 @JoinFetch(value= JoinFetchType.OUTER) 048 @ManyToOne(targetEntity = EntityEmailTypeBo.class, cascade = { CascadeType.REFRESH }) 049 @JoinColumn(name = "EMAIL_TYP_CD", referencedColumnName = "EMAIL_TYP_CD", insertable = false, updatable = false) 050 private EntityEmailTypeBo emailType; 051 052 public static EntityEmail to(EntityEmailBo bo) { 053 if (bo == null) { 054 return null; 055 } 056 return EntityEmail.Builder.create(bo).build(); 057 } 058 059 /** 060 * Creates a EntityEmailBo business object from an immutable representation of a EntityEmail. 061 * 062 * @param immutable an immutable EntityEmail 063 * @return a EntityEmailBo 064 */ 065 public static EntityEmailBo from(EntityEmail immutable) { 066 if (immutable == null) { 067 return null; 068 } 069 EntityEmailBo bo = new EntityEmailBo(); 070 bo.setId(immutable.getId()); 071 bo.setActive(immutable.isActive()); 072 bo.setEntityId(immutable.getEntityId()); 073 bo.setEntityTypeCode(immutable.getEntityTypeCode()); 074 if (immutable.getEmailType() != null) { 075 bo.setEmailTypeCode(immutable.getEmailType().getCode()); 076 } 077 bo.setEmailAddress(immutable.getEmailAddressUnmasked()); 078 bo.setEmailType(EntityEmailTypeBo.from(immutable.getEmailType())); 079 bo.setDefaultValue(immutable.isDefaultValue()); 080 bo.setVersionNumber(immutable.getVersionNumber()); 081 bo.setObjectId(immutable.getObjectId()); 082 return bo; 083 } 084 085 @Override 086 public EntityEmailTypeBo getEmailType() { 087 return this.emailType; 088 } 089 090 public void setEmailType(EntityEmailTypeBo emailType) { 091 this.emailType = emailType; 092 } 093 094 @Override 095 public String getId() { 096 return id; 097 } 098 099 public void setId(String id) { 100 this.id = id; 101 } 102}