1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kim.bo.impl;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.core.api.util.type.KualiDecimal;
20 import org.kuali.rice.kim.api.identity.IdentityService;
21 import org.kuali.rice.kim.api.identity.Person;
22 import org.kuali.rice.kim.api.identity.PersonService;
23 import org.kuali.rice.kim.api.identity.address.EntityAddress;
24 import org.kuali.rice.kim.api.identity.affiliation.EntityAffiliation;
25 import org.kuali.rice.kim.api.identity.affiliation.EntityAffiliationContract;
26 import org.kuali.rice.kim.api.identity.email.EntityEmailContract;
27 import org.kuali.rice.kim.api.identity.employment.EntityEmployment;
28 import org.kuali.rice.kim.api.identity.entity.EntityDefault;
29 import org.kuali.rice.kim.api.identity.external.EntityExternalIdentifier;
30 import org.kuali.rice.kim.api.identity.name.EntityName;
31 import org.kuali.rice.kim.api.identity.phone.EntityPhoneContract;
32 import org.kuali.rice.kim.api.identity.principal.Principal;
33 import org.kuali.rice.kim.api.identity.type.EntityTypeContactInfoDefault;
34 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
35 import org.kuali.rice.kim.bo.entity.impl.KimEntityDefaultInfoCacheImpl;
36 import org.kuali.rice.kim.impl.identity.employment.EntityEmploymentStatusBo;
37 import org.kuali.rice.kim.impl.identity.employment.EntityEmploymentTypeBo;
38 import org.kuali.rice.kim.util.KimCommonUtilsInternal;
39 import org.kuali.rice.kim.util.KimConstants;
40 import org.kuali.rice.krad.bo.TransientBusinessObjectBase;
41
42 import java.util.ArrayList;
43 import java.util.HashMap;
44 import java.util.List;
45 import java.util.Map;
46
47
48
49
50
51
52
53 public class PersonImpl extends TransientBusinessObjectBase implements Person {
54
55 private static final long serialVersionUID = 1L;
56
57 protected static PersonService personService;
58 protected static IdentityService identityService;
59
60 private String lookupRoleNamespaceCode;
61 private String lookupRoleName;
62
63
64 protected String principalId;
65 protected String principalName;
66 protected String entityId;
67 protected String entityTypeCode;
68
69 protected String firstName = "";
70 protected String middleName = "";
71 protected String lastName = "";
72
73 protected String name = "";
74
75 protected EntityAddress address;
76
77
78
79
80
81
82
83
84 protected String emailAddress = "";
85
86 protected String phoneNumber = "";
87
88 protected boolean suppressName = false;
89 protected boolean suppressAddress = false;
90 protected boolean suppressPhone = false;
91 protected boolean suppressPersonal = false;
92 protected boolean suppressEmail = false;
93
94 protected List<? extends EntityAffiliationContract> affiliations;
95
96 protected String campusCode = "";
97
98
99 protected Map<String,String> externalIdentifiers = null;
100
101 protected String employeeStatusCode = "";
102 protected EntityEmploymentStatusBo employeeStatus;
103 protected String employeeTypeCode = "";
104 protected EntityEmploymentTypeBo employeeType;
105 protected String primaryDepartmentCode = "";
106 protected String employeeId = "";
107
108 protected KualiDecimal baseSalaryAmount = KualiDecimal.ZERO;
109 protected boolean active = true;
110
111 public PersonImpl() {}
112
113 public PersonImpl( Principal principal, String personEntityTypeCode ) {
114 this( principal, null, personEntityTypeCode );
115 }
116
117 public PersonImpl( Principal principal, EntityDefault entity, String personEntityTypeCode ) {
118 setPrincipal( principal, entity, personEntityTypeCode );
119 }
120
121 public PersonImpl( String principalId, String personEntityTypeCode ) {
122 this( getIdentityService().getPrincipal(principalId), personEntityTypeCode );
123 }
124
125 public PersonImpl( KimEntityDefaultInfoCacheImpl p ) {
126 entityId = p.getEntityId();
127 principalId = p.getPrincipalId();
128 principalName = p.getPrincipalName();
129 entityTypeCode = p.getEntityTypeCode();
130 firstName = p.getFirstName();
131 middleName = p.getMiddleName();
132 lastName = p.getLastName();
133 name = p.getName();
134 campusCode = p.getCampusCode();
135 primaryDepartmentCode = p.getPrimaryDepartmentCode();
136 employeeId = p.getEmployeeId();
137 affiliations = new ArrayList<EntityAffiliation>( 0 );
138 externalIdentifiers = new HashMap<String,String>( 0 );
139 }
140
141
142
143
144 public void setPrincipal(Principal principal, EntityDefault entity, String personEntityTypeCode) {
145 populatePrincipalInfo( principal );
146 if ( entity == null ) {
147 entity = getIdentityService().getEntityDefault( principal.getEntityId() );
148 }
149 populateEntityInfo( entity, principal, personEntityTypeCode );
150 }
151
152
153 protected void populatePrincipalInfo( Principal principal ) {
154 entityId = principal.getEntityId();
155 principalId = principal.getPrincipalId();
156 principalName = principal.getPrincipalName();
157 active = principal.isActive();
158 }
159
160 protected void populateEntityInfo( EntityDefault entity, Principal principal, String personEntityTypeCode ) {
161 if(entity!=null){
162 populatePrivacyInfo (entity );
163 EntityTypeContactInfoDefault entityTypeContactInfoDefault = entity.getEntityType( personEntityTypeCode );
164 entityTypeCode = personEntityTypeCode;
165 populateNameInfo( personEntityTypeCode, entity, principal );
166 populateAddressInfo( entityTypeContactInfoDefault );
167 populateEmailInfo( entityTypeContactInfoDefault );
168 populatePhoneInfo( entityTypeContactInfoDefault );
169 populateAffiliationInfo( entity );
170 populateEmploymentInfo( entity );
171 populateExternalIdentifiers( entity );
172 }
173 }
174
175 protected void populateNameInfo( String entityTypeCode, EntityDefault entity, Principal principal ) {
176 if(entity!=null){
177 EntityName entityName = entity.getName();
178 if ( entityName != null ) {
179 firstName = unNullify( entityName.getFirstName());
180 middleName = unNullify( entityName.getMiddleName() );
181 lastName = unNullify( entityName.getLastName() );
182 if ( entityTypeCode.equals( KimConstants.EntityTypes.SYSTEM ) ) {
183 name = principal.getPrincipalName().toUpperCase();
184 } else {
185 name = unNullify( entityName.getCompositeName() );
186 if(name.equals("") || name == null){
187 name = lastName + ", " + firstName;
188 }
189 }
190 } else {
191 firstName = "";
192 middleName = "";
193 if ( entityTypeCode.equals( KimConstants.EntityTypes.SYSTEM ) ) {
194 name = principal.getPrincipalName().toUpperCase();
195 lastName = principal.getPrincipalName().toUpperCase();
196 } else {
197 name = "";
198 lastName = "";
199 }
200 }
201 }
202 }
203
204 protected void populatePrivacyInfo (EntityDefault entity) {
205 if(entity!=null) {
206 if (entity.getPrivacyPreferences() != null) {
207 suppressName = entity.getPrivacyPreferences().isSuppressName();
208 suppressAddress = entity.getPrivacyPreferences().isSuppressAddress();
209 suppressPhone = entity.getPrivacyPreferences().isSuppressPhone();
210 suppressPersonal = entity.getPrivacyPreferences().isSuppressPersonal();
211 suppressEmail = entity.getPrivacyPreferences().isSuppressEmail();
212 }
213 }
214 }
215
216 protected void populateAddressInfo( EntityTypeContactInfoDefault contactInfoDefault ) {
217 if(contactInfoDefault!=null){
218 EntityAddress defaultAddress = contactInfoDefault.getDefaultAddress();
219 if ( defaultAddress != null ) {
220 address = defaultAddress;
221 } else {
222 EntityAddress.Builder builder = EntityAddress.Builder.create();
223 builder.setCity("");
224 builder.setCountryCode("");
225 builder.setLine1("");
226 builder.setLine2("");
227 builder.setLine3("");
228 builder.setCity("");
229 builder.setPostalCode("");
230 builder.setStateCode("");
231 builder.setActive(true);
232 address = builder.build();
233 }
234 }
235 }
236
237 protected void populateEmailInfo( EntityTypeContactInfoDefault contactInfoDefault ) {
238 if(contactInfoDefault!=null){
239 EntityEmailContract entityEmail = contactInfoDefault.getDefaultEmailAddress();
240 if ( entityEmail != null ) {
241 emailAddress = unNullify( entityEmail.getEmailAddressUnmasked() );
242 } else {
243 emailAddress = "";
244 }
245 }
246 }
247
248 protected void populatePhoneInfo( EntityTypeContactInfoDefault contactInfoDefault ) {
249 if(contactInfoDefault!=null){
250 EntityPhoneContract entityPhone = contactInfoDefault.getDefaultPhoneNumber();
251 if ( entityPhone != null ) {
252 phoneNumber = unNullify( entityPhone.getFormattedPhoneNumberUnmasked() );
253 } else {
254 phoneNumber = "";
255 }
256 }
257 }
258
259 protected void populateAffiliationInfo(EntityDefault entity ) {
260 if(entity!=null){
261 affiliations = entity.getAffiliations();
262 EntityAffiliation defaultAffiliation = entity.getDefaultAffiliation();
263 if ( defaultAffiliation != null ) {
264 campusCode = unNullify( defaultAffiliation.getCampusCode() );
265 } else {
266 campusCode = "";
267 }
268 }
269 }
270
271 protected void populateEmploymentInfo( EntityDefault entity ) {
272 if(entity!=null){
273 EntityEmployment employmentInformation = entity.getEmployment();
274 if ( employmentInformation != null ) {
275 employeeStatusCode = unNullify( employmentInformation.getEmployeeStatus() != null ? employmentInformation.getEmployeeStatus().getCode() : null);
276 employeeTypeCode = unNullify( employmentInformation.getEmployeeType() != null ? employmentInformation.getEmployeeStatus().getCode() : null);
277 primaryDepartmentCode = unNullify( employmentInformation.getPrimaryDepartmentCode() );
278 employeeId = unNullify( employmentInformation.getEmployeeId() );
279 if ( employmentInformation.getBaseSalaryAmount() != null ) {
280 baseSalaryAmount = employmentInformation.getBaseSalaryAmount();
281 } else {
282 baseSalaryAmount = KualiDecimal.ZERO;
283 }
284 } else {
285 employeeStatusCode = "";
286 employeeTypeCode = "";
287 primaryDepartmentCode = "";
288 employeeId = "";
289 baseSalaryAmount = KualiDecimal.ZERO;
290 }
291 }
292 }
293
294 protected void populateExternalIdentifiers( EntityDefault entity ) {
295 if(entity!=null){
296 List<? extends EntityExternalIdentifier> externalIds = entity.getExternalIdentifiers();
297 externalIdentifiers = new HashMap<String,String>( externalIds.size() );
298 for ( EntityExternalIdentifier eei : externalIds ) {
299 externalIdentifiers.put( eei.getExternalIdentifierTypeCode(), eei.getExternalId() );
300 }
301 }
302 }
303
304
305 private String unNullify( String str ) {
306 if ( str == null ) {
307 return "";
308 }
309 return str;
310 }
311
312
313
314
315 public String getEntityId() {
316 return entityId;
317 }
318
319
320
321
322 public String getPrincipalId() {
323 return principalId;
324 }
325
326
327
328
329
330
331 public String getPrincipalName() {
332 return principalName;
333 }
334
335
336
337
338 public String getFirstName() {
339 if (KimCommonUtilsInternal.isSuppressName(getEntityId())){
340 return KimConstants.RESTRICTED_DATA_MASK;
341 }
342 return firstName;
343 }
344
345
346
347
348 public String getFirstNameUnmasked() {
349 return firstName;
350 }
351
352
353
354
355 public String getMiddleName() {
356 if (KimCommonUtilsInternal.isSuppressName(getEntityId())){
357 return KimConstants.RESTRICTED_DATA_MASK;
358 }
359 return middleName;
360 }
361
362
363
364
365 public String getMiddleNameUnmasked() {
366 return middleName;
367 }
368
369
370
371
372 public String getLastName() {
373 if (KimCommonUtilsInternal.isSuppressName(getEntityId())){
374 return KimConstants.RESTRICTED_DATA_MASK;
375 }
376 return lastName;
377 }
378
379
380
381
382 public String getLastNameUnmasked() {
383 return lastName;
384 }
385
386
387
388
389 public String getName() {
390 if (StringUtils.isNotBlank(getEntityId()) && KimCommonUtilsInternal.isSuppressName(getEntityId())) {
391 return KimConstants.RESTRICTED_DATA_MASK;
392 }
393 return name;
394 }
395
396 public String getNameUnmasked() {
397 return this.name;
398 }
399
400
401
402
403 public String getPhoneNumber() {
404 if (KimCommonUtilsInternal.isSuppressPhone(getEntityId())){
405 return KimConstants.RESTRICTED_DATA_MASK;
406 }
407 return phoneNumber;
408 }
409
410
411
412
413 public String getPhoneNumberUnmasked() {
414 return phoneNumber;
415 }
416
417
418
419
420 public String getEmailAddress() {
421 if (KimCommonUtilsInternal.isSuppressEmail(getEntityId())){
422 return KimConstants.RESTRICTED_DATA_MASK;
423 }
424 return emailAddress;
425 }
426
427 public String getEmailAddressUnmasked() {
428 return emailAddress;
429 }
430
431 public List<? extends EntityAffiliationContract> getAffiliations() {
432 return affiliations;
433 }
434
435
436
437
438
439
440 public boolean hasAffiliationOfType(String affiliationTypeCode) {
441 return getCampusCodesForAffiliationOfType(affiliationTypeCode).size() > 0;
442 }
443
444
445 public List<String> getCampusCodesForAffiliationOfType(String affiliationTypeCode) {
446 ArrayList<String> campusCodes = new ArrayList<String>( 3 );
447 if ( affiliationTypeCode == null ) {
448 return campusCodes;
449 }
450 for ( EntityAffiliationContract a : getAffiliations() ) {
451 if ( a.getAffiliationType().getCode().equals(affiliationTypeCode) ) {
452 campusCodes.add( a.getCampusCode() );
453 }
454 }
455 return campusCodes;
456 }
457
458
459
460
461 public String getExternalId(String externalIdentifierTypeCode) {
462 return externalIdentifiers.get( externalIdentifierTypeCode );
463 }
464
465
466
467
468
469
470 public String getCampusCode() {
471 return campusCode;
472 }
473
474
475
476
477 @SuppressWarnings("unchecked")
478 public static PersonService getPersonService() {
479 if ( personService == null ) {
480 personService = KimApiServiceLocator.getPersonService();
481 }
482 return personService;
483 }
484
485
486
487
488 public static IdentityService getIdentityService() {
489 if ( identityService == null ) {
490 identityService = KimApiServiceLocator.getIdentityService();
491 }
492 return identityService;
493 }
494
495
496
497
498 public Map<String,String> getExternalIdentifiers() {
499 return externalIdentifiers;
500 }
501
502 public String getAddressLine1() {
503 return address.getLine1();
504 }
505
506 public String getAddressLine1Unmasked() {
507 return address.getLine1Unmasked();
508 }
509
510 public String getAddressLine2() {
511 return address.getLine2();
512 }
513
514 public String getAddressLine2Unmasked() {
515 return address.getLine2Unmasked();
516 }
517
518 public String getAddressLine3() {
519 return address.getLine3();
520 }
521
522 public String getAddressLine3Unmasked() {
523 return address.getLine3Unmasked();
524 }
525
526 public String getAddressCityName() {
527 return address.getCity();
528 }
529
530 public String getAddressCityNameUnmasked() {
531 return address.getCityUnmasked();
532 }
533
534 public String getAddressStateCode() {
535 return address.getStateCode();
536 }
537
538 public String getAddressStateCodeUnmasked() {
539 return address.getStateCodeUnmasked();
540 }
541
542 public String getAddressPostalCode() {
543 return address.getPostalCode();
544 }
545
546 public String getAddressPostalCodeUnmasked() {
547 return address.getPostalCodeUnmasked();
548 }
549
550 public String getAddressCountryCode() {
551 return address.getCountryCode();
552 }
553
554 public String getAddressCountryCodeUnmasked() {
555 return address.getCountryCodeUnmasked();
556 }
557
558 public String getEmployeeStatusCode() {
559 return this.employeeStatusCode;
560 }
561
562 public String getEmployeeTypeCode() {
563 return this.employeeTypeCode;
564 }
565
566 public KualiDecimal getBaseSalaryAmount() {
567 return this.baseSalaryAmount;
568 }
569
570 public String getEmployeeId() {
571 return this.employeeId;
572 }
573
574 public String getPrimaryDepartmentCode() {
575 return this.primaryDepartmentCode;
576 }
577
578 public String getEntityTypeCode() {
579 return this.entityTypeCode;
580 }
581
582 public boolean isActive() {
583 return this.active;
584 }
585
586 public void setActive(boolean active) {
587 this.active = active;
588 }
589
590
591
592
593 public String getLookupRoleNamespaceCode() {
594 return this.lookupRoleNamespaceCode;
595 }
596
597
598
599
600 public void setLookupRoleNamespaceCode(String lookupRoleNamespaceCode) {
601 this.lookupRoleNamespaceCode = lookupRoleNamespaceCode;
602 }
603
604
605
606
607 public String getLookupRoleName() {
608 return this.lookupRoleName;
609 }
610
611
612
613
614 public void setLookupRoleName(String lookupRoleName) {
615 this.lookupRoleName = lookupRoleName;
616 }
617
618
619
620
621 public void setPrincipalName(String principalName) {
622 this.principalName = principalName;
623 }
624
625
626
627
628 public void setName(String name) {
629 this.name = name;
630 }
631
632
633
634
635
636 public EntityEmploymentStatusBo getEmployeeStatus() {
637 return this.employeeStatus;
638 }
639
640 public EntityEmploymentTypeBo getEmployeeType() {
641 return this.employeeType;
642 }
643 }