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