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.name;
17  
18  import javax.persistence.Cacheable;
19  import javax.persistence.CascadeType;
20  import javax.persistence.Column;
21  import javax.persistence.Entity;
22  import javax.persistence.GeneratedValue;
23  import javax.persistence.Id;
24  import javax.persistence.JoinColumn;
25  import javax.persistence.ManyToOne;
26  import javax.persistence.Table;
27  
28  import org.kuali.rice.kim.api.identity.name.EntityName;
29  import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator;
30  
31  @Entity
32  @Cacheable(false)
33  @Table(name = "KRIM_ENTITY_NM_T")
34  public class EntityNameBo extends EntityNameBase {
35  
36      private static final long serialVersionUID = -1449221117942310530L;
37  
38      @PortableSequenceGenerator(name = "KRIM_ENTITY_NM_ID_S")
39      @GeneratedValue(generator = "KRIM_ENTITY_NM_ID_S")
40      @Id
41      @Column(name = "ENTITY_NM_ID")
42      private String id;
43  
44      @ManyToOne(targetEntity = EntityNameTypeBo.class, cascade = { CascadeType.REFRESH })
45      @JoinColumn(name = "NM_TYP_CD", referencedColumnName = "ENT_NM_TYP_CD", insertable = false, updatable = false)
46      private EntityNameTypeBo nameType;
47  
48      public static EntityName to(EntityNameBo bo) {
49          if (bo == null) {
50              return null;
51          }
52          return EntityName.Builder.create(bo).build();
53      }
54  
55      /**
56       * Creates a EntityNameBo business object from an immutable representation of a EntityName.
57       *
58       * @param immutable an immutable EntityName
59       * @return a EntityNameBo
60       */
61      public static EntityNameBo from(EntityName immutable) {
62          if (immutable == null) {
63              return null;
64          }
65          EntityNameBo bo = new EntityNameBo();
66          bo.setId(immutable.getId());
67          bo.setActive(immutable.isActive());
68          bo.setEntityId(immutable.getEntityId());
69          bo.setNameType(EntityNameTypeBo.from(immutable.getNameType()));
70          if (immutable.getNameType() != null) {
71              bo.setNameCode(immutable.getNameType().getCode());
72          }
73          bo.setFirstName(immutable.getFirstNameUnmasked());
74          bo.setLastName(immutable.getLastNameUnmasked());
75          bo.setMiddleName(immutable.getMiddleNameUnmasked());
76          bo.setNamePrefix(immutable.getNamePrefixUnmasked());
77          bo.setNameTitle(immutable.getNameTitleUnmasked());
78          bo.setNameSuffix(immutable.getNameSuffixUnmasked());
79          bo.setNoteMessage(immutable.getNoteMessage());
80          bo.setNameChangedDate(immutable.getNameChangedDate());
81          bo.setDefaultValue(immutable.isDefaultValue());
82          bo.setVersionNumber(immutable.getVersionNumber());
83          bo.setObjectId(immutable.getObjectId());
84          return bo;
85      }
86  
87      @Override
88      public EntityNameTypeBo getNameType() {
89          return this.nameType;
90      }
91  
92      public void setNameType(EntityNameTypeBo nameType) {
93          this.nameType = nameType;
94      }
95  
96      @Override
97      public String getId() {
98          return id;
99      }
100 
101     public void setId(String id) {
102         this.id = id;
103     }
104 }