View Javadoc

1   /*
2    * Copyright 2007-2008 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.bo.entity.impl;
17  
18  import java.util.LinkedHashMap;
19  
20  import javax.persistence.Column;
21  import javax.persistence.Entity;
22  import javax.persistence.FetchType;
23  import javax.persistence.Id;
24  import javax.persistence.JoinColumn;
25  import javax.persistence.ManyToOne;
26  import javax.persistence.Table;
27  import javax.persistence.Transient;
28  
29  import org.kuali.rice.kim.bo.entity.KimEntityName;
30  import org.kuali.rice.kim.bo.entity.KimEntityPrivacyPreferences;
31  import org.kuali.rice.kim.bo.entity.dto.KimEntityDefaultInfo;
32  import org.kuali.rice.kim.bo.reference.EntityNameType;
33  import org.kuali.rice.kim.bo.reference.impl.EntityNameTypeImpl;
34  import org.kuali.rice.kim.service.KIMServiceLocator;
35  import org.kuali.rice.kim.util.KimCommonUtils;
36  import org.kuali.rice.kim.util.KimConstants;
37  
38  /**
39   * @author Kuali Rice Team (rice.collab@kuali.org)
40   */
41  @Entity
42  @Table(name = "KRIM_ENTITY_NM_T")
43  public class KimEntityNameImpl extends KimDefaultableEntityDataBase implements KimEntityName {
44  
45  	private static final long serialVersionUID = 1L;
46  
47  	@Id
48  	@Column(name = "ENTITY_NM_ID")
49  	protected String entityNameId;
50  
51  	@Column(name = "ENTITY_ID")
52  	protected String entityId;
53  
54  	@Column(name = "NM_TYP_CD")
55  	protected String nameTypeCode ;
56  
57  	@Column(name = "FIRST_NM")
58  	protected String firstName;
59  
60  	@Column(name = "MIDDLE_NM")
61  	protected String middleName;
62  
63  	@Column(name = "LAST_NM")
64  	protected String lastName;
65  
66  	@Column(name = "TITLE_NM")
67  	protected String title;
68  
69  	@Column(name = "SUFFIX_NM")
70  	protected String suffix;
71  	
72  	@ManyToOne(targetEntity=EntityNameTypeImpl.class, fetch = FetchType.EAGER, cascade = {})
73  	@JoinColumn(name = "NM_TYP_CD", insertable = false, updatable = false)
74  	protected EntityNameType entityNameType;
75  	
76  	@Transient
77  	protected Boolean suppressName;
78  	
79  
80  	/**
81  	 * @see org.kuali.rice.kim.bo.entity.KimEntityName#getEntityNameId()
82  	 */
83  	public String getEntityNameId() {
84  		return entityNameId;
85  	}
86  
87  	/**
88  	 * @see org.kuali.rice.kim.bo.entity.KimEntityName#getFirstName()
89  	 */
90  	public String getFirstName() {
91  	    if (isSuppressName()) {
92              return KimConstants.RESTRICTED_DATA_MASK;
93          }
94  		return firstName;
95  	}
96  
97  	/**
98  	 * @see org.kuali.rice.kim.bo.entity.KimEntityName#getLastName()
99  	 */
100 	public String getLastName() {
101 	    if (isSuppressName()) {
102             return KimConstants.RESTRICTED_DATA_MASK;
103         }
104 		return lastName;
105 	}
106 
107 	/**
108 	 * @see org.kuali.rice.kim.bo.entity.KimEntityName#getMiddleName()
109 	 */
110 	public String getMiddleName() {
111 	    if (isSuppressName()) {
112             return KimConstants.RESTRICTED_DATA_MASK;
113         }
114 		return middleName;
115 	}
116 
117 	/**
118 	 * @see org.kuali.rice.kim.bo.entity.KimEntityName#getNameTypeCode()
119 	 */
120 	public String getNameTypeCode() {
121 		return nameTypeCode;
122 	}
123 
124 	/**
125 	 * @see org.kuali.rice.kim.bo.entity.KimEntityName#getSuffix()
126 	 */
127 	public String getSuffix() {
128 	    if (isSuppressName()) {
129             return KimConstants.RESTRICTED_DATA_MASK;
130         }
131 		return suffix;
132 	}
133 
134 	/**
135 	 * @see org.kuali.rice.kim.bo.entity.KimEntityName#getTitle()
136 	 */
137 	public String getTitle() {
138 	    if (isSuppressName()) {
139             return KimConstants.RESTRICTED_DATA_MASK;
140         }
141 		return title;
142 	}
143 
144 	public void setFirstName(String firstName) {
145 		this.firstName = firstName;
146 	}
147 
148 	public void setLastName(String lastName) {
149 		this.lastName = lastName;
150 	}
151 
152 	public void setMiddleName(String middleName) {
153 		this.middleName = middleName;
154 	}
155 
156 	public void setNameTypeCode(String nameTypeCode) {
157 		this.nameTypeCode = nameTypeCode;
158 	}
159 
160 	public void setSuffix(String suffix) {
161 		this.suffix = suffix;
162 	}
163 
164 	public void setTitle(String title) {
165 		this.title = title;
166 	}
167 
168 	/**
169 	 * This default implementation formats the name as LAST, FIRST MIDDLE.
170 	 * 
171 	 * @see org.kuali.rice.kim.bo.entity.KimEntityName#getFormattedName()
172 	 */
173 	public String getFormattedName() {
174 	    if (isSuppressName()) {
175             return KimConstants.RESTRICTED_DATA_MASK;
176         }
177 		return getLastName() + ", " + getFirstName() + (getMiddleName()==null?"":" " + getMiddleName());
178 	}
179 	
180 	/**
181 	 * @see org.kuali.rice.kns.bo.BusinessObjectBase#toStringMapper()
182 	 */
183 	@SuppressWarnings("unchecked")
184 	@Override
185 	protected LinkedHashMap toStringMapper() {
186 		LinkedHashMap m = new LinkedHashMap();
187 		m.put( "entityNameId", entityNameId );
188 		m.put( "firstName", getFirstName() );
189 		m.put( "lastName", getLastName() );
190 		return m;
191 	}
192 
193 	public String getEntityId() {
194 		return this.entityId;
195 	}
196 
197 	public void setEntityId(String entityId) {
198 		this.entityId = entityId;
199 	}
200 
201 	public EntityNameType getEntityNameType() {
202 		return this.entityNameType;
203 	}
204 
205 	public void setEntityNameType(EntityNameType entityNameType) {
206 		this.entityNameType = entityNameType;
207 	}
208 
209 	public void setEntityNameId(String entityNameId) {
210 		this.entityNameId = entityNameId;
211 	}
212 
213     /**
214      * @see org.kuali.rice.kim.bo.entity.KimEntityName#getFirstNameUnmasked()
215      */
216     public String getFirstNameUnmasked() {
217         return this.firstName;
218     }
219 
220     /**
221      * @see org.kuali.rice.kim.bo.entity.KimEntityName#getFormattedNameUnmasked()
222      */
223     public String getFormattedNameUnmasked() {
224         return this.lastName + ", " + this.firstName + (this.middleName==null?"":" " + this.middleName);
225     }
226 
227     /**
228      * @see org.kuali.rice.kim.bo.entity.KimEntityName#getLastNameUnmasked()
229      */
230     public String getLastNameUnmasked() {
231         return this.lastName;
232     }
233 
234     /**
235      * @see org.kuali.rice.kim.bo.entity.KimEntityName#getMiddleNameUnmasked()
236      */
237     public String getMiddleNameUnmasked() {
238         return this.middleName;
239     }
240 
241     /**
242      * @see org.kuali.rice.kim.bo.entity.KimEntityName#getSuffixUnmasked()
243      */
244     public String getSuffixUnmasked() {
245         return this.suffix;
246     }
247 
248     /**
249      * @see org.kuali.rice.kim.bo.entity.KimEntityName#getTitleUnmasked()
250      */
251     public String getTitleUnmasked() {
252         return this.title;
253     }
254 
255     public boolean isSuppressName() {
256         if (suppressName != null) {
257             return suppressName.booleanValue();
258         }
259         KimEntityPrivacyPreferences privacy = KIMServiceLocator.getIdentityService().getEntityPrivacyPreferences(getEntityId());
260 
261         suppressName = false;
262         if (privacy != null) {
263             suppressName = privacy.isSuppressName();
264         } 
265         return suppressName.booleanValue();
266     }
267 }