001/** 002 * Copyright 2005-2015 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.name; 017 018import org.eclipse.persistence.annotations.JoinFetch; 019import org.eclipse.persistence.annotations.JoinFetchType; 020import org.kuali.rice.kim.api.identity.name.EntityName; 021import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator; 022 023import javax.persistence.Cacheable; 024import javax.persistence.CascadeType; 025import javax.persistence.Column; 026import javax.persistence.Entity; 027import javax.persistence.GeneratedValue; 028import javax.persistence.Id; 029import javax.persistence.JoinColumn; 030import javax.persistence.ManyToOne; 031import javax.persistence.NamedQuery; 032import javax.persistence.Table; 033 034@Entity 035@Cacheable(false) 036@Table(name = "KRIM_ENTITY_NM_T") 037@NamedQuery(name="EntityNameBo.findDefaultNamesForPrincipalIds", 038 query="SELECT NEW org.kuali.rice.kim.impl.identity.IdentityServiceDaoJpa.NameHolder(en, p.principalId, p.principalName, pp.suppressName) FROM EntityNameBo en, PrincipalBo p LEFT JOIN EntityPrivacyPreferencesBo pp ON pp.entityId = p.entityId WHERE en.active = true AND en.defaultValue = true AND en.entityId = p.entityId AND p.principalId IN :principalIds" 039) 040public class EntityNameBo extends EntityNameBase { 041 042 private static final long serialVersionUID = -1449221117942310530L; 043 044 @PortableSequenceGenerator(name = "KRIM_ENTITY_NM_ID_S") 045 @GeneratedValue(generator = "KRIM_ENTITY_NM_ID_S") 046 @Id 047 @Column(name = "ENTITY_NM_ID") 048 private String id; 049 050 @JoinFetch(value= JoinFetchType.OUTER) 051 @ManyToOne(targetEntity = EntityNameTypeBo.class, cascade = { CascadeType.REFRESH }) 052 @JoinColumn(name = "NM_TYP_CD", referencedColumnName = "ENT_NM_TYP_CD", insertable = false, updatable = false) 053 private EntityNameTypeBo nameType; 054 055 public static EntityName to(EntityNameBo bo) { 056 if (bo == null) { 057 return null; 058 } 059 return EntityName.Builder.create(bo).build(); 060 } 061 062 /** 063 * Creates a EntityNameBo business object from an immutable representation of a EntityName. 064 * 065 * @param immutable an immutable EntityName 066 * @return a EntityNameBo 067 */ 068 public static EntityNameBo from(EntityName immutable) { 069 if (immutable == null) { 070 return null; 071 } 072 EntityNameBo bo = new EntityNameBo(); 073 bo.setId(immutable.getId()); 074 bo.setActive(immutable.isActive()); 075 bo.setEntityId(immutable.getEntityId()); 076 bo.setNameType(EntityNameTypeBo.from(immutable.getNameType())); 077 if (immutable.getNameType() != null) { 078 bo.setNameCode(immutable.getNameType().getCode()); 079 } 080 bo.setFirstName(immutable.getFirstNameUnmasked()); 081 bo.setLastName(immutable.getLastNameUnmasked()); 082 bo.setMiddleName(immutable.getMiddleNameUnmasked()); 083 bo.setNamePrefix(immutable.getNamePrefixUnmasked()); 084 bo.setNameTitle(immutable.getNameTitleUnmasked()); 085 bo.setNameSuffix(immutable.getNameSuffixUnmasked()); 086 bo.setNoteMessage(immutable.getNoteMessage()); 087 bo.setNameChangedDate(immutable.getNameChangedDate()); 088 bo.setDefaultValue(immutable.isDefaultValue()); 089 bo.setVersionNumber(immutable.getVersionNumber()); 090 bo.setObjectId(immutable.getObjectId()); 091 return bo; 092 } 093 094 @Override 095 public EntityNameTypeBo getNameType() { 096 return this.nameType; 097 } 098 099 public void setNameType(EntityNameTypeBo nameType) { 100 this.nameType = nameType; 101 } 102 103 @Override 104 public String getId() { 105 return id; 106 } 107 108 public void setId(String id) { 109 this.id = id; 110 } 111}