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