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