1   package org.kuali.ole.patron.bo;
2   
3   import org.apache.commons.collections.CollectionUtils;
4   import org.kuali.ole.deliver.loan.bo.OleLoanDocument;
5   import org.kuali.ole.patron.api.*;
6   import org.kuali.rice.kim.api.KimConstants;
7   import org.kuali.rice.kim.api.identity.address.EntityAddress;
8   import org.kuali.rice.kim.api.identity.email.EntityEmail;
9   import org.kuali.rice.kim.api.identity.phone.EntityPhone;
10  import org.kuali.rice.kim.impl.identity.address.EntityAddressBo;
11  import org.kuali.rice.kim.impl.identity.email.EntityEmailBo;
12  import org.kuali.rice.kim.impl.identity.employment.EntityEmploymentBo;
13  import org.kuali.rice.kim.impl.identity.entity.EntityBo;
14  import org.kuali.rice.kim.impl.identity.name.EntityNameBo;
15  import org.kuali.rice.kim.impl.identity.phone.EntityPhoneBo;
16  import org.kuali.rice.kim.impl.identity.type.EntityTypeContactInfoBo;
17  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
18  
19  import java.util.*;
20  
21  
22  
23  
24  public class OlePatronDocument extends PersistableBusinessObjectBase implements OlePatronContract {
25  
26      private String olePatronId;
27      private String barcode;
28      private String borrowerType;
29      private String affiliationType;
30      private boolean activeIndicator;
31      private boolean generalBlock;
32      private String generalBlockNotes;
33      private boolean pagingPrivilege;
34      private boolean courtesyNotice;
35      private boolean deliveryPrivilege;
36      private Date expirationDate;
37      private Date activationDate;
38      private String firstName;
39      private String middleName;
40      private String lastName;
41      private String emailAddress;
42      private String phoneNumber;
43      private String borrowerTypeName;
44      private String processMessage;
45      private String invalidBarcodeNumber;
46      private Date invalidBarcodeNumEffDate;
47  
48      private List<OleLoanDocument> oleLoanDocuments = new ArrayList<OleLoanDocument>();
49      private List<EntityPhoneBo> phones = new ArrayList<EntityPhoneBo>();
50      private List<EntityAddressBo> addresses = new ArrayList<EntityAddressBo>();
51      private List<OleEntityAddressBo> oleEntityAddressBo = new ArrayList<OleEntityAddressBo>();
52      private EntityNameBo name = new EntityNameBo();
53      private List<EntityEmailBo> emails = new ArrayList<EntityEmailBo>();
54      private List<OlePatronNotes> notes = new ArrayList<OlePatronNotes>();
55      private OleBorrowerType oleBorrowerType;
56      private EntityBo entity = new EntityBo();
57  
58      private List<OlePatronAffiliation> patronAffiliations = new ArrayList<OlePatronAffiliation>();
59      private List<EntityEmploymentBo> employments =  new ArrayList<EntityEmploymentBo>();
60  
61    
62  
63  
64  
65  
66  
67  
68  
69  
70  
71      public List<EntityEmploymentBo> getEmployments() {
72          return employments;
73      }
74  
75      public void setEmployments(List<EntityEmploymentBo> employments) {
76          this.employments = employments;
77      }
78  
79      private List<OleProxyPatronDocument> oleProxyPatronDocuments = new ArrayList<OleProxyPatronDocument>();
80      private List<OlePatronDocument> olePatronDocuments = new ArrayList<OlePatronDocument>();
81      private String proxyPatronId;
82  
83  
84      
85  
86  
87  
88  
89      public static OlePatronDefinition to(OlePatronDocument bo) {
90          if (bo == null) {
91              return null;
92          }
93          return OlePatronDefinition.Builder.create(bo).build();
94      }
95  
96      
97  
98  
99  
100 
101     public static OlePatronDocument from(OlePatronDefinition immutable) {
102         return fromAndUpdate(immutable, null);
103     }
104 
105     
106 
107 
108 
109 
110 
111     static OlePatronDocument fromAndUpdate(OlePatronDefinition immutable, OlePatronDocument toUpdate) {
112         if (immutable == null) {
113             return null;
114         }
115         OlePatronDocument bo = toUpdate;
116         if (toUpdate == null) {
117             bo = new OlePatronDocument();
118         }
119         
120         bo.olePatronId = immutable.getOlePatronId();
121 
122         bo.name = new EntityNameBo();
123 
124         if (immutable.getName() != null) {
125             bo.name = EntityNameBo.from(immutable.getName());
126         }
127 
128         bo.barcode = immutable.getBarcode();
129         bo.borrowerType = immutable.getBorrowerType();
130         bo.courtesyNotice = immutable.isCourtesyNotice();
131         bo.generalBlock = immutable.isGeneralBlock();
132         bo.deliveryPrivilege = immutable.isDeliveryPrivilege();
133         bo.pagingPrivilege = immutable.isPagingPrivilege();
134         bo.expirationDate = immutable.getExpirationDate();
135         bo.activationDate = immutable.getActivationDate();
136         bo.activeIndicator = immutable.isActiveIndicator();
137         bo.generalBlockNotes = immutable.getGeneralBlockNotes();
138         bo.invalidBarcodeNumber = immutable.getInvalidBarcodeNumber();
139         bo.invalidBarcodeNumEffDate = immutable.getInvalidBarcodeNumEffDate();
140         if (immutable.getEntity() != null) {
141             bo.entity = EntityBo.from(immutable.getEntity());
142         }
143         if (CollectionUtils.isNotEmpty(immutable.getAddresses())) {
144             for (EntityAddress entityAddr : immutable.getAddresses()) {
145                 bo.addresses.add(EntityAddressBo.from(entityAddr));
146             }
147         }
148         if (CollectionUtils.isNotEmpty(immutable.getEmails())) {
149             for (EntityEmail entityEmail : immutable.getEmails()) {
150                 bo.emails.add(EntityEmailBo.from(entityEmail));
151             }
152         }
153         if (CollectionUtils.isNotEmpty(immutable.getPhones())) {
154             for (EntityPhone entityPhone : immutable.getPhones()) {
155                 bo.phones.add(EntityPhoneBo.from(entityPhone));
156             }
157         }
158 
159         if (CollectionUtils.isNotEmpty(immutable.getNotes())) {
160             for (OlePatronNotesDefinition note : immutable.getNotes()) {
161                 bo.notes.add(OlePatronNotes.from(note));
162             }
163         }
164         if (CollectionUtils.isNotEmpty(immutable.getOleEntityAddressBo())) {
165             for (OleEntityAddressDefinition address : immutable.getOleEntityAddressBo()) {
166                 bo.oleEntityAddressBo.add(OleEntityAddressBo.from(address));
167             }
168         }
169         if (CollectionUtils.isNotEmpty(immutable.getPatronAffiliations())) {
170             for (OlePatronAffiliationDefinition affiliation : immutable.getPatronAffiliations()) {
171                 bo.patronAffiliations.add(OlePatronAffiliation.from(affiliation));
172             }
173         }
174         if (CollectionUtils.isNotEmpty(immutable.getOleProxyPatronDocuments())) {
175             for (OleProxyPatronDefinition proxyPatron : immutable.getOleProxyPatronDocuments()) {
176                 bo.oleProxyPatronDocuments.add(OleProxyPatronDocument.from(proxyPatron));
177             }
178         }
179         
180 
181 
182 
183 
184         bo.versionNumber = immutable.getVersionNumber();
185         
186         EntityBo entityBo = new EntityBo();
187         entityBo.setActive(true);
188 
189         if (null != bo.getEntity()) {
190             entityBo = bo.getEntity();
191             entityBo.setActive(true);
192         }
193         entityBo.setNames(Arrays.asList(bo.getName()));
194         EntityTypeContactInfoBo entityTypeContactInfoBo = new EntityTypeContactInfoBo();
195         if(null != bo.getEntity().getEntityTypeContactInfos() && bo.getEntity().getEntityTypeContactInfos().size() > 0){
196             entityTypeContactInfoBo = bo.getEntity().getEntityTypeContactInfos().get(0);
197         }
198         entityTypeContactInfoBo.setAddresses(bo.getAddresses());
199         entityTypeContactInfoBo.setEmailAddresses(bo.getEmails());
200         entityTypeContactInfoBo.setPhoneNumbers(bo.getPhones());
201         entityTypeContactInfoBo.setEntityTypeCode(KimConstants.EntityTypes.PERSON);
202         entityBo.setEntityTypeContactInfos(Arrays.asList(entityTypeContactInfoBo));
203         bo.setEntity(entityBo);
204         return bo;
205     }
206 
207     
208 
209 
210 
211     public List<OleLoanDocument> getOleLoanDocuments() {
212         return oleLoanDocuments;
213     }
214     
215 
216 
217 
218     public void setOleLoanDocuments(List<OleLoanDocument> oleLoanDocuments) {
219         this.oleLoanDocuments = oleLoanDocuments;
220     }
221     
222 
223 
224 
225     public String getBorrowerTypeName() {
226         return oleBorrowerType.getBorrowerTypeName();
227     }
228     
229 
230 
231 
232     public EntityBo getEntity() {
233         return entity;
234     }
235     
236 
237 
238 
239     public void setEntity(EntityBo entity) {
240         this.entity = entity;
241     }
242 
243     public String getAffiliationType() {
244         return affiliationType;
245     }
246 
247     public void setAffiliationType(String affiliationType) {
248         this.affiliationType = affiliationType;
249     }
250 
251     
252 
253 
254 
255     public List<OlePatronNotes> getNotes() {
256         return notes;
257     }
258     
259 
260 
261 
262     public void setNotes(List<OlePatronNotes> notes) {
263         this.notes = notes;
264     }
265     
266 
267 
268 
269     public String getBarcode() {
270         return barcode;
271     }
272     
273 
274 
275 
276     public void setBarcode(String barcode) {
277         this.barcode = barcode;
278     }
279     
280 
281 
282 
283     public String getBorrowerType() {
284         return borrowerType;
285     }
286     
287 
288 
289 
290     public void setBorrowerType(String borrowerType) {
291         this.borrowerType = borrowerType;
292     }
293     
294 
295 
296 
297     public boolean isActiveIndicator() {
298         return activeIndicator;
299     }
300     
301 
302 
303 
304     public void setActiveIndicator(boolean activeIndicator) {
305         this.activeIndicator = activeIndicator;
306     }
307     
308 
309 
310 
311     public String getOlePatronId() {
312         return olePatronId;
313     }
314     
315 
316 
317 
318     public void setOlePatronId(String olePatronId) {
319         this.olePatronId = olePatronId;
320     }
321     
322 
323 
324 
325     public boolean isGeneralBlock() {
326         return generalBlock;
327     }
328     
329 
330 
331 
332     public void setGeneralBlock(boolean generalBlock) {
333         this.generalBlock = generalBlock;
334     }
335     
336 
337 
338 
339     public boolean isCourtesyNotice() {
340         return courtesyNotice;
341     }
342     
343 
344 
345 
346     public void setCourtesyNotice(boolean courtesyNotice) {
347         this.courtesyNotice = courtesyNotice;
348     }
349     
350 
351 
352 
353     public boolean isDeliveryPrivilege() {
354         return deliveryPrivilege;
355     }
356     
357 
358 
359 
360     public void setDeliveryPrivilege(boolean deliveryPrivilege) {
361         this.deliveryPrivilege = deliveryPrivilege;
362     }
363     
364 
365 
366 
367     public boolean isPagingPrivilege() {
368         return pagingPrivilege;
369     }
370     
371 
372 
373 
374     public void setPagingPrivilege(boolean pagingPrivilege) {
375         this.pagingPrivilege = pagingPrivilege;
376     }
377     
378 
379 
380 
381     public Date getExpirationDate() {
382         return expirationDate;
383     }
384     
385 
386 
387 
388     public void setExpirationDate(Date expirationDate) {
389         this.expirationDate = expirationDate;
390     }
391     
392 
393 
394 
395     public String getFirstName() {
396         return firstName;
397     }
398     
399 
400 
401 
402     public void setFirstName(String firstName) {
403         this.firstName = firstName;
404     }
405     
406 
407 
408 
409     public String getMiddleName() {
410         return middleName;
411     }
412     
413 
414 
415 
416     public void setMiddleName(String middleName) {
417         this.middleName = middleName;
418     }
419     
420 
421 
422 
423     public String getLastName() {
424         return lastName;
425     }
426     
427 
428 
429 
430     public void setLastName(String lastName) {
431         this.lastName = lastName;
432     }
433     
434 
435 
436 
437     public String getEmailAddress() {
438         return emailAddress;
439     }
440     
441 
442 
443 
444     public void setEmailAddress(String emailAddress) {
445         this.emailAddress = emailAddress;
446     }
447     
448 
449 
450 
451     public String getPhoneNumber() {
452         return phoneNumber;
453     }
454     
455 
456 
457 
458     public void setPhoneNumber(String phoneNumber) {
459         this.phoneNumber = phoneNumber;
460     }
461     
462 
463 
464 
465     public List<EntityPhoneBo> getPhones() {
466         return phones;
467     }
468     
469 
470 
471 
472     public void setPhones(List<EntityPhoneBo> phones) {
473         this.phones = phones;
474     }
475     
476 
477 
478 
479     public List<EntityAddressBo> getAddresses() {
480         return addresses;
481     }
482     
483 
484 
485 
486     public void setAddresses(List<EntityAddressBo> addresses) {
487         this.addresses = addresses;
488     }
489     
490 
491 
492 
493     public EntityNameBo getName() {
494         return name;
495     }
496     
497 
498 
499 
500     public void setName(EntityNameBo name) {
501         this.name = name;
502     }
503     
504 
505 
506 
507     public List<EntityEmailBo> getEmails() {
508         return emails;
509     }
510     
511 
512 
513 
514     public void setEmails(List<EntityEmailBo> emails) {
515         this.emails = emails;
516     }
517     
518 
519 
520 
521     public OleBorrowerType getOleBorrowerType() {
522         return oleBorrowerType;
523     }
524     
525 
526 
527 
528     public void setOleBorrowerType(OleBorrowerType oleBorrowerType) {
529         this.oleBorrowerType = oleBorrowerType;
530     }
531     
532 
533 
534 
535     public String getProcessMessage() {
536         return processMessage;
537     }
538     
539 
540 
541 
542     public void setProcessMessage(String processMessage) {
543         this.processMessage = processMessage;
544     }
545 
546     protected LinkedHashMap toStringMapper() {
547         LinkedHashMap toStringMap = new LinkedHashMap();
548         toStringMap.put("olePatronId", olePatronId);
549         return toStringMap;
550     }
551     
552 
553 
554 
555     @Override
556     public String getId() {
557         return this.getOlePatronId();
558     }
559     
560 
561 
562 
563     public List<OlePatronDocument> getOlePatronDocuments() {
564         return olePatronDocuments;
565     }
566     
567 
568 
569 
570     public void setOlePatronDocuments(List<OlePatronDocument> olePatronDocuments) {
571         this.olePatronDocuments = olePatronDocuments;
572     }
573     
574 
575 
576 
577     public String getProxyPatronId() {
578         return proxyPatronId;
579     }
580     
581 
582 
583 
584     public void setProxyPatronId(String proxyPatronId) {
585         this.proxyPatronId = proxyPatronId;
586     }
587     
588 
589 
590 
591     public List<OleProxyPatronDocument> getOleProxyPatronDocuments() {
592         return oleProxyPatronDocuments;
593     }
594     
595 
596 
597 
598     public void setOleProxyPatronDocuments(List<OleProxyPatronDocument> oleProxyPatronDocuments) {
599         this.oleProxyPatronDocuments = oleProxyPatronDocuments;
600     }
601     
602 
603 
604 
605     public Date getActivationDate() {
606         return activationDate;
607     }
608     
609 
610 
611 
612     public void setActivationDate(Date activationDate) {
613         this.activationDate = activationDate;
614     }
615     
616 
617 
618 
619     public String getGeneralBlockNotes() {
620         return generalBlockNotes;
621     }
622     
623 
624 
625 
626     public void setGeneralBlockNotes(String generalBlockNotes) {
627         this.generalBlockNotes = generalBlockNotes;
628     }
629     
630 
631 
632 
633     public String getInvalidBarcodeNumber() {
634         return invalidBarcodeNumber;
635     }
636     
637 
638 
639 
640     public void setInvalidBarcodeNumber(String invalidBarcodeNumber) {
641         this.invalidBarcodeNumber = invalidBarcodeNumber;
642     }
643     
644 
645 
646 
647     public Date getInvalidBarcodeNumEffDate() {
648         return invalidBarcodeNumEffDate;
649     }
650     
651 
652 
653 
654     public void setInvalidBarcodeNumEffDate(Date invalidBarcodeNumEffDate) {
655         this.invalidBarcodeNumEffDate = invalidBarcodeNumEffDate;
656     }
657     
658 
659 
660 
661     public List<OleEntityAddressBo> getOleEntityAddressBo() {
662         return oleEntityAddressBo;
663     }
664     
665 
666 
667 
668     public void setOleEntityAddressBo(List<OleEntityAddressBo> oleEntityAddressBo) {
669         this.oleEntityAddressBo = oleEntityAddressBo;
670     }
671     
672 
673 
674 
675     public List<OlePatronAffiliation> getPatronAffiliations() {
676         return patronAffiliations;
677     }
678     
679 
680 
681 
682     public void setPatronAffiliations(List<OlePatronAffiliation> patronAffiliations) {
683         this.patronAffiliations = patronAffiliations;
684     }
685 }