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