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 java.sql.Timestamp;
19  
20  import javax.persistence.Column;
21  import javax.persistence.Convert;
22  import javax.persistence.MappedSuperclass;
23  import javax.persistence.Transient;
24  
25  import org.joda.time.DateTime;
26  import org.kuali.rice.kim.api.KimApiConstants;
27  import org.kuali.rice.kim.api.identity.name.EntityNameContract;
28  import org.kuali.rice.kim.api.identity.privacy.EntityPrivacyPreferences;
29  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
30  import org.kuali.rice.krad.bo.DataObjectBase;
31  import org.kuali.rice.krad.data.jpa.converters.BooleanYNConverter;
32  
33  @MappedSuperclass
34  public abstract class EntityNameBase extends DataObjectBase implements EntityNameContract {
35      private static final long serialVersionUID = 7102034794623577359L;
36  
37      @Column(name = "ENTITY_ID")
38      private String entityId;
39  
40      @Column(name = "NM_TYP_CD")
41      private String nameCode;
42  
43      @Column(name = "FIRST_NM")
44      private String firstName;
45  
46      @Column(name = "MIDDLE_NM")
47      private String middleName;
48  
49      @Column(name = "LAST_NM")
50      private String lastName;
51  
52      @Column(name = "PREFIX_NM")
53      private String namePrefix;
54  
55      @Column(name = "TITLE_NM")
56      private String nameTitle;
57  
58      @Column(name = "SUFFIX_NM")
59      private String nameSuffix;
60  
61      @Convert(converter=BooleanYNConverter.class)
62      @Column(name = "ACTV_IND")
63      private boolean active;
64  
65      @Convert(converter=BooleanYNConverter.class)
66      @Column(name = "DFLT_IND")
67      private boolean defaultValue;
68  
69      @Column(name = "NOTE_MSG")
70      private String noteMessage;
71  
72      @Column(name = "NM_CHNG_DT")
73      private Timestamp nameChangedDate;
74  
75      @Transient
76      private boolean suppressName;
77  
78  
79      @Override
80      public String getFirstName() {
81          if (isSuppressName()) {
82              return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK;
83          }
84  
85          return this.firstName;
86      }
87  
88      @Override
89      public String getMiddleName() {
90          if (isSuppressName()) {
91              return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK;
92          }
93  
94          return this.middleName;
95      }
96  
97      @Override
98      public String getLastName() {
99          if (isSuppressName()) {
100             return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK;
101         }
102 
103         return this.lastName;
104     }
105 
106     @Override
107     public String getNamePrefix() {
108         if (isSuppressName()) {
109             return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK;
110         }
111 
112         return this.namePrefix;
113     }
114 
115     @Override
116     public String getNameTitle() {
117         if (isSuppressName()) {
118             return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK;
119         }
120 
121         return this.nameTitle;
122     }
123 
124     @Override
125     public String getFirstNameUnmasked() {
126         return this.firstName;
127     }
128 
129     @Override
130     public String getMiddleNameUnmasked() {
131         return this.middleName;
132     }
133 
134     @Override
135     public String getLastNameUnmasked() {
136         return this.lastName;
137     }
138 
139     @Override
140     public String getNamePrefixUnmasked() {
141         return this.namePrefix;
142     }
143 
144     @Override
145     public String getNameTitleUnmasked() {
146         return this.nameTitle;
147     }
148 
149     @Override
150     public String getNameSuffixUnmasked() {
151         return this.nameSuffix;
152     }
153 
154     @Override
155     public String getCompositeName() {
156         if (isSuppressName()) {
157             return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK;
158         }
159 
160         return getCompositeNameUnmasked();
161     }
162 
163     @Override
164     public String getCompositeNameUnmasked() {
165         return getLastName() + ", " + getFirstName() + (getMiddleName() == null ? "" : " " + getMiddleName());
166     }
167 
168     @Override
169     public DateTime getNameChangedDate() {
170         return nameChangedDate != null ? new DateTime(nameChangedDate.getTime()) : null;
171     }
172 
173     public Timestamp getNameChangedTimestamp() {
174         return nameChangedDate;
175     }
176 
177     @Override
178     public boolean isSuppressName() {
179         try {
180             EntityPrivacyPreferences privacy = KimApiServiceLocator.getIdentityService().getEntityPrivacyPreferences(
181                     getEntityId());
182             if (privacy != null) {
183                 this.suppressName = privacy.isSuppressName();
184             } else {
185                 this.suppressName = false;
186             }
187         } catch (NullPointerException e) {
188             return false;
189         } catch (ClassCastException c) {
190             return false;
191         }
192 
193         return this.suppressName;
194     }
195 
196     @Override
197     public String getEntityId() {
198         return entityId;
199     }
200 
201     public void setEntityId(String entityId) {
202         this.entityId = entityId;
203     }
204 
205     public String getNameCode() {
206         return nameCode;
207     }
208 
209     public void setNameCode(String nameCode) {
210         this.nameCode = nameCode;
211     }
212 
213     public void setFirstName(String firstName) {
214         this.firstName = firstName;
215     }
216 
217     public void setMiddleName(String middleName) {
218         this.middleName = middleName;
219     }
220 
221     public void setLastName(String lastName) {
222         this.lastName = lastName;
223     }
224 
225     public void setNamePrefix(String namePrefix) {
226         this.namePrefix = namePrefix;
227     }
228 
229     public void setNameTitle(String nameTitle) {
230         this.nameTitle = nameTitle;
231     }
232 
233     @Override
234     public String getNameSuffix() {
235         return nameSuffix;
236     }
237 
238     public void setNameSuffix(String nameSuffix) {
239         this.nameSuffix = nameSuffix;
240     }
241 
242     public boolean getActive() {
243         return active;
244     }
245 
246     @Override
247     public boolean isActive() {
248         return active;
249     }
250 
251     public void setActive(boolean active) {
252         this.active = active;
253     }
254 
255     public boolean getDefaultValue() {
256         return defaultValue;
257     }
258 
259     @Override
260     public boolean isDefaultValue() {
261         return defaultValue;
262     }
263 
264     public void setDefaultValue(boolean defaultValue) {
265         this.defaultValue = defaultValue;
266     }
267 
268     @Override
269     public String getNoteMessage() {
270         return noteMessage;
271     }
272 
273     public void setNoteMessage(String noteMessage) {
274         this.noteMessage = noteMessage;
275     }
276 
277     public void setNameChangedDate(DateTime nameChangedDate) {
278         if ( nameChangedDate != null ) {
279             this.nameChangedDate = new Timestamp( nameChangedDate.getMillis() );
280         } else {
281             this.nameChangedDate = null;
282         }
283     }
284 
285     public void setNameChangedTimestamp(Timestamp nameChangedDate) {
286         this.nameChangedDate = nameChangedDate;
287     }
288 
289     public boolean getSuppressName() {
290         return suppressName;
291     }
292 
293     public void setSuppressName(boolean suppressName) {
294         this.suppressName = suppressName;
295     }
296 
297 }