View Javadoc
1   /**
2    * Copyright 2005-2014 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.CascadeType;
19  import javax.persistence.Column;
20  import javax.persistence.Entity;
21  import javax.persistence.GeneratedValue;
22  import javax.persistence.Id;
23  import javax.persistence.JoinColumn;
24  import javax.persistence.ManyToOne;
25  import javax.persistence.Table;
26  
27  import org.kuali.rice.kim.api.identity.email.EntityEmail;
28  import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator;
29  
30  /**
31   * @author Kuali Rice Team (rice.collab@kuali.org)
32   */
33  @Entity
34  @Table(name = "KRIM_ENTITY_EMAIL_T")
35  public class EntityEmailBo extends EntityEmailBase {
36  
37      private static final long serialVersionUID = 1L;
38  
39      @PortableSequenceGenerator(name = "KRIM_ENTITY_EMAIL_ID_S")
40      @GeneratedValue(generator = "KRIM_ENTITY_EMAIL_ID_S")
41      @Id
42      @Column(name = "ENTITY_EMAIL_ID")
43      private String id;
44  
45      @ManyToOne(targetEntity = EntityEmailTypeBo.class, cascade = { CascadeType.REFRESH })
46      @JoinColumn(name = "EMAIL_TYP_CD", referencedColumnName = "EMAIL_TYP_CD", insertable = false, updatable = false)
47      private EntityEmailTypeBo emailType;
48  
49      public static EntityEmail to(EntityEmailBo bo) {
50          if (bo == null) {
51              return null;
52          }
53          return EntityEmail.Builder.create(bo).build();
54      }
55  
56      /**
57       * Creates a EntityEmailBo business object from an immutable representation of a EntityEmail.
58       *
59       * @param immutable an immutable EntityEmail
60       * @return a EntityEmailBo
61       */
62      public static EntityEmailBo from(EntityEmail immutable) {
63          if (immutable == null) {
64              return null;
65          }
66          EntityEmailBo bo = new EntityEmailBo();
67          bo.setId(immutable.getId());
68          bo.setActive(immutable.isActive());
69          bo.setEntityId(immutable.getEntityId());
70          bo.setEntityTypeCode(immutable.getEntityTypeCode());
71          if (immutable.getEmailType() != null) {
72              bo.setEmailTypeCode(immutable.getEmailType().getCode());
73          }
74          bo.setEmailAddress(immutable.getEmailAddressUnmasked());
75          bo.setEmailType(EntityEmailTypeBo.from(immutable.getEmailType()));
76          bo.setDefaultValue(immutable.isDefaultValue());
77          bo.setVersionNumber(immutable.getVersionNumber());
78          bo.setObjectId(immutable.getObjectId());
79          return bo;
80      }
81  
82      @Override
83      public EntityEmailTypeBo getEmailType() {
84          return this.emailType;
85      }
86  
87      public void setEmailType(EntityEmailTypeBo emailType) {
88          this.emailType = emailType;
89      }
90  
91      @Override
92      public String getId() {
93          return id;
94      }
95  
96      public void setId(String id) {
97          this.id = id;
98      }
99  }