1 package org.kuali.ole.service;
2
3 import org.kuali.ole.OLEConstants;
4 import org.kuali.ole.deliver.processor.LoanProcessor;
5 import org.kuali.ole.deliver.bo.OleLoanDocument;
6 import org.kuali.ole.deliver.bo.OleTemporaryCirculationHistory;
7 import org.kuali.ole.deliver.api.OleDeliverRequestDefinition;
8 import org.kuali.ole.deliver.bo.OleDeliverRequestBo;
9 import org.kuali.ole.ingest.pojo.OlePatron;
10 import org.kuali.ole.deliver.bo.OlePatronLoanDocument;
11 import org.kuali.ole.deliver.bo.OlePatronLoanDocuments;
12 import org.kuali.ole.deliver.bo.OleRenewalLoanDocument;
13 import org.kuali.ole.deliver.api.*;
14 import org.kuali.ole.deliver.bo.PatronBillPayment;
15 import org.kuali.ole.deliver.bo.*;
16 import org.kuali.ole.sys.context.SpringContext;
17 import org.kuali.rice.core.api.config.ConfigurationException;
18 import org.kuali.rice.core.api.criteria.CriteriaLookupService;
19 import org.kuali.rice.core.api.criteria.GenericQueryResults;
20 import org.kuali.rice.core.api.criteria.QueryByCriteria;
21 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
22 import org.kuali.rice.kim.api.identity.IdentityService;
23 import org.kuali.rice.kim.api.identity.address.EntityAddress;
24 import org.kuali.rice.kim.api.identity.email.EntityEmail;
25 import org.kuali.rice.kim.api.identity.entity.Entity;
26 import org.kuali.rice.kim.api.identity.name.EntityName;
27 import org.kuali.rice.kim.api.identity.phone.EntityPhone;
28 import org.kuali.rice.kim.api.identity.type.EntityTypeContactInfo;
29 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
30 import org.kuali.rice.kim.impl.identity.address.EntityAddressBo;
31 import org.kuali.rice.kim.impl.identity.affiliation.EntityAffiliationBo;
32 import org.kuali.rice.kim.impl.identity.email.EntityEmailBo;
33 import org.kuali.rice.kim.impl.identity.employment.EntityEmploymentBo;
34 import org.kuali.rice.kim.impl.identity.entity.EntityBo;
35 import org.kuali.rice.kim.impl.identity.name.EntityNameBo;
36 import org.kuali.rice.kim.impl.identity.phone.EntityPhoneBo;
37 import org.kuali.rice.kim.impl.identity.type.EntityTypeContactInfoBo;
38 import org.kuali.rice.kim.impl.services.KimImplServiceLocator;
39 import org.kuali.rice.kns.service.KNSServiceLocator;
40 import org.kuali.rice.krad.data.DataObjectService;
41 import org.kuali.rice.krad.data.platform.MaxValueIncrementerFactory;
42 import org.kuali.rice.krad.service.BusinessObjectService;
43 import org.kuali.rice.krad.service.KRADServiceLocator;
44 import org.kuali.rice.krad.util.ObjectUtils;
45
46 import javax.sql.DataSource;
47 import java.io.Serializable;
48 import java.text.SimpleDateFormat;
49 import java.util.*;
50
51
52
53
54 public class OlePatronServiceImpl implements OlePatronService {
55 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OlePatronServiceImpl.class);
56 private DataObjectService dataObjectService;
57 private IdentityService identityService;
58 private CriteriaLookupService criteriaLookupService;
59 private LoanProcessor loanProcessor;
60 private OlePatronHelperService olePatronHelperService;
61 private DataSource kimDataSource;
62
63 protected OlePatronHelperService getOlePatronHelperService(){
64 if(olePatronHelperService==null)
65 olePatronHelperService=GlobalResourceLoader.getService("olePatronHelperService");
66 return olePatronHelperService;
67 }
68
69
70
71
72
73 protected LoanProcessor getLoanProcessor() {
74 if(loanProcessor==null)
75 loanProcessor=new LoanProcessor();
76 return loanProcessor;
77 }
78
79
80
81
82
83 public DataObjectService getDataObjectService() {
84 if(dataObjectService == null){
85 dataObjectService = KRADServiceLocator.getDataObjectService();
86 }
87 return dataObjectService;
88 }
89
90
91
92
93 protected IdentityService getIdentityService() {
94 if (identityService == null) {
95 identityService = (IdentityService) SpringContext.getBean("kimIdentityDelegateService");
96 }
97 return identityService;
98 }
99
100
101
102
103
104 protected CriteriaLookupService getCriteriaLookupService() {
105 if(criteriaLookupService == null) {
106 criteriaLookupService = GlobalResourceLoader.getService(OLEConstants.OlePatron.CRITERIA_LOOKUP_SERVICE);
107 }
108 return criteriaLookupService;
109 }
110
111
112
113
114
115 @Override
116 public OlePatronDefinition getPatron(String patronId) {
117 LOG.debug("Inside the getPatron method");
118 Map<String, Object> criteria = new HashMap<String, Object>(4);
119 criteria.put(OLEConstants.OlePatron.PATRON_ID, patronId);
120 return OlePatronDocument.to(getDataObjectService().find(OlePatronDocument.class, patronId));
121 }
122
123
124
125
126
127 @Override
128 public OlePatronDefinition createPatron(OlePatronDefinition olePatron) {
129 LOG.debug(" Inside create patron ");
130 OlePatronDefinition savedOlePatronDefinition = new OlePatronDefinition();
131 try{
132 OlePatronDocument olePatronDocument = OlePatronDocument.from(olePatron);
133 OlePatronDocument savedPatronDocument = getDataObjectService().save(olePatronDocument);
134 savedOlePatronDefinition = OlePatronDocument.to(savedPatronDocument);
135 }catch(Exception e){
136 LOG.error("Error: while saving patron document from OlePatronDefinition"+e);
137 }
138
139 return savedOlePatronDefinition;
140 }
141
142
143
144
145
146
147 @Override
148 public OlePatronDefinition updatePatron(OlePatronDefinition olePatronDefinition) {
149 LOG.debug("Inside the updatePatron method");
150 boolean doc = false;
151 String documentNumber = "";
152 OlePatronDocument updatedPatronDocument = null;
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274 return null;
275 }
276
277
278
279
280
281
282 private void addName(EntityNameBo name, EntityBo entity) {
283 LOG.debug("Inside the addName method");
284 List<EntityNameBo> entityName = entity.getNames();
285 if (name != null) {
286
287 entityName.add(name);
288 entity.setNames(entityName);
289 }
290 }
291
292
293
294
295
296
297 @Override
298 public void addNameToEntity(EntityName name, Entity entity) {
299 LOG.debug("Inside the addNameToEntity method");
300 EntityBo entityBo = EntityBo.from(entity);
301 EntityNameBo nameBo = EntityNameBo.from(name);
302 addName(nameBo, entityBo);
303 }
304
305
306
307
308
309 @Override
310 public void addEmailToEntity(List<EntityEmail> emails, EntityTypeContactInfo entityTypeContactInfo) {
311 LOG.debug("Inside the addEmailToEntity method");
312 List<EntityEmailBo> emailBos = new ArrayList<EntityEmailBo>();
313 for (EntityEmail email : emails) {
314 emailBos.add(EntityEmailBo.from(email));
315 }
316 addEmail(emailBos, EntityTypeContactInfoBo.from(entityTypeContactInfo));
317 }
318
319
320
321
322
323
324 private void addEmail(List<EntityEmailBo> emails, EntityTypeContactInfoBo entityTypeContactInfoBo) {
325 LOG.debug("Inside the addEmail method");
326 if (emails != null) {
327 entityTypeContactInfoBo.setEmailAddresses(emails);
328 }
329 }
330
331
332
333
334
335 private void addAddress(List<EntityAddressBo> entityAddress, EntityTypeContactInfoBo entityTypeContactInfoBo) {
336 LOG.debug("Inside the addAddress method");
337 if (entityAddress != null) {
338 entityTypeContactInfoBo.setAddresses(entityAddress);
339 }
340 }
341
342
343
344
345
346 @Override
347 public void addAddressToEntity(List<OleEntityAddressDefinition> oleEntityAddress, EntityTypeContactInfo entityTypeContactInfo) {
348 List<EntityAddressBo> addrBos = new ArrayList<EntityAddressBo>();
349 List<OleEntityAddressBo> oleAddrBos = new ArrayList<OleEntityAddressBo>();
350 for (OleEntityAddressDefinition oleAddr : oleEntityAddress) {
351 EntityAddressBo address = EntityAddressBo.from(oleAddr.getEntityAddressBo());
352 OleAddressBo oleAddress = OleAddressBo.from(oleAddr.getOleAddressBo());
353
354 oleAddrBos.add(OleEntityAddressBo.from(oleAddr));
355 addrBos.add(address);
356 }
357 addAddress(addrBos, EntityTypeContactInfoBo.from(entityTypeContactInfo));
358 }
359
360
361
362
363
364 public void addPhone(List<EntityPhoneBo> entityPhone, EntityTypeContactInfoBo entityTypeContactInfoBo) {
365 LOG.debug("Inside the addPhoneToEntity method");
366 if (entityPhone != null) {
367 entityTypeContactInfoBo.setPhoneNumbers(entityPhone);
368 }
369 }
370
371
372
373
374
375 @Override
376 public void addPhoneToEntity(List<EntityPhone> entityPhone, EntityTypeContactInfo entityTypeContactInfo) {
377 LOG.debug("Inside the addPhoneToEntity method");
378 List<EntityPhoneBo> phoneBos = new ArrayList<EntityPhoneBo>();
379 for (EntityPhone phone : entityPhone) {
380 phoneBos.add(EntityPhoneBo.from(phone));
381 }
382 addPhone(phoneBos, EntityTypeContactInfoBo.from(entityTypeContactInfo));
383 }
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419 @Override
420 public EntityName updateName(EntityName name) {
421 LOG.debug("Inside the updateName method");
422 EntityNameBo entityName = EntityNameBo.from(getIdentityService().updateName(name));
423 return EntityNameBo.to(entityName);
424 }
425
426
427
428
429
430 @Override
431 public boolean inactivateName(String nameId) {
432 LOG.debug("Inside the inactivateName method");
433 EntityNameBo entityName = EntityNameBo.from(getIdentityService().inactivateName(nameId));
434 if (entityName != null) {
435 return true;
436 }
437 return false;
438 }
439
440
441
442
443
444
445 @Override
446 public boolean updateEmail(EntityEmail entityEmail) {
447 LOG.debug("Inside the updateEmail method");
448 EntityEmailBo email = EntityEmailBo.from(getIdentityService().updateEmail(entityEmail));
449 if (email != null) {
450 return true;
451 }
452 return false;
453 }
454
455
456
457
458
459 @Override
460 public boolean inactivateEmail(String emailId) {
461 LOG.debug("Inside the inactivateEmail method");
462 EntityEmailBo entityEmail = EntityEmailBo.from(getIdentityService().inactivateEmail(emailId));
463 if (entityEmail != null) {
464 return true;
465 }
466 return false;
467 }
468
469
470
471
472
473 @Override
474 public boolean updateAddress(EntityAddress entityAddress) {
475 LOG.debug("Inside the updateAddress method");
476 EntityAddressBo address = EntityAddressBo.from(getIdentityService().updateAddress(entityAddress));
477 if (address != null) {
478 return true;
479 }
480 return false;
481 }
482
483
484
485
486
487 @Override
488 public boolean inactivateAddress(String addressId) {
489 LOG.debug("Inside the inactivateAddress method");
490 EntityAddressBo entityAddress = EntityAddressBo.from(getIdentityService().inactivateAddress(addressId));
491 if (entityAddress != null) {
492 return true;
493 }
494 return false;
495 }
496
497
498
499
500
501
502 @Override
503 public boolean updatePhone(EntityPhone entityPhone) {
504 LOG.debug("Inside the updatePhone method");
505 EntityPhoneBo phone = EntityPhoneBo.from(getIdentityService().updatePhone(entityPhone));
506 if (phone != null) {
507 return true;
508 }
509 return false;
510 }
511
512
513
514
515
516
517 @Override
518 public boolean inactivatePhone(String phoneId) {
519 LOG.debug("Inside the inactivatePhone method");
520 EntityPhoneBo entityPhone = EntityPhoneBo.from(getIdentityService().inactivatePhone(phoneId));
521 if (entityPhone != null) {
522 return true;
523 }
524 return false;
525 }
526
527
528
529
530
531 @Override
532 public boolean addNoteToPatron(OlePatronNotesDefinition patronNote) {
533 LOG.debug("Inside the addNoteToPatron method");
534
535
536
537
538
539 return false;
540 }
541
542
543
544
545
546 @Override
547 public boolean updateNote(OlePatronNotesDefinition patronNote) {
548 LOG.debug("Inside the updateNote method");
549 OlePatronNotes patronNoteBo = OlePatronNotes.from(patronNote);
550 if (patronNoteBo.getOlePatronId() != null && patronNoteBo.getPatronNoteId() != null) {
551 Map<String, Object> criteria = new HashMap<String, Object>();
552 criteria.put(OLEConstants.OlePatron.PATRON_NOTE_ID, patronNote.getPatronNoteId());
553 if (getDataObjectService().find(OlePatronNotes.class, patronNote.getPatronNoteId()) != null) {
554 getDataObjectService().save(patronNoteBo);
555 return true;
556 }
557 }
558 return false;
559 }
560
561
562
563
564
565
566 @Override
567 public boolean inactivateNote(String patronNoteId) {
568 LOG.debug("Inside the inactivateNote method");
569 if (patronNoteId != null) {
570 Map<String, Object> criteria = new HashMap<String, Object>();
571 criteria.put(OLEConstants.OlePatron.PATRON_NOTE_ID, patronNoteId);
572 OlePatronNotes patronNotes = getDataObjectService().find(OlePatronNotes.class, patronNoteId);
573 patronNotes.setActive(false);
574 getDataObjectService().save(patronNotes);
575 return true;
576 }
577 return false;
578 }
579
580
581
582
583
584 @Override
585 public OlePatronQueryResults getPatrons() {
586 LOG.debug("Inside the findPatron method");
587 GenericQueryResults<OlePatronDocument> results = getCriteriaLookupService().lookup(OlePatronDocument.class, QueryByCriteria.Builder.create().build());
588 OlePatronQueryResults.Builder builder = OlePatronQueryResults.Builder.create();
589 builder.setMoreResultsAvailable(results.isMoreResultsAvailable());
590 builder.setTotalRowCount(results.getTotalRowCount());
591
592 final List<OlePatronDefinition.Builder> ims = new ArrayList<OlePatronDefinition.Builder>();
593 for (OlePatronDocument bo : results.getResults()) {
594 ims.add(OlePatronDefinition.Builder.create(bo));
595 }
596
597 builder.setResults(ims);
598 return builder.build();
599
600 }
601
602
603
604
605
606 @Override
607 public OlePatronQueryResults findPatron(QueryByCriteria queryCriteria) {
608 LOG.debug("Inside the findPatron method");
609 GenericQueryResults<OlePatronDocument> results = getCriteriaLookupService().lookup(OlePatronDocument.class, QueryByCriteria.Builder.create().build());
610 OlePatronQueryResults.Builder builder = OlePatronQueryResults.Builder.create();
611 builder.setMoreResultsAvailable(results.isMoreResultsAvailable());
612 builder.setTotalRowCount(results.getTotalRowCount());
613
614 final List<OlePatronDefinition.Builder> ims = new ArrayList<OlePatronDefinition.Builder>();
615 for (OlePatronDocument bo : results.getResults()) {
616 ims.add(OlePatronDefinition.Builder.create(bo));
617 }
618
619 builder.setResults(ims);
620 return builder.build();
621 }
622
623
624
625
626
627
628 @Override
629 public OlePatronLoanDocuments getPatronLoanedItems(String patronBarcode) {
630
631
632 List<OleLoanDocument> oleLoanDocumentList=new ArrayList<OleLoanDocument>();
633 List<OlePatronLoanDocument> olePatronLoanItemList=new ArrayList<OlePatronLoanDocument>();
634 try{
635 oleLoanDocumentList=getLoanProcessor().getPatronLoanedItemBySolr(patronBarcode);
636 OlePatronLoanDocuments olePatronLoanDocuments=convertPatronLoanDocuments(oleLoanDocumentList);
637 return olePatronLoanDocuments;
638 }
639 catch(Exception e){
640 LOG.error("Exception while getting patron loaned items-----> "+e);
641 }
642
643 return null;
644 }
645
646 public List<OleDeliverRequestDefinition> getPatronRequestItems(String patronId) {
647
648
649 List<OleDeliverRequestBo> oleDeliverRequestBos =new ArrayList<OleDeliverRequestBo>();
650 List<OleDeliverRequestDefinition> oleDeliverRequestDefinitions =new ArrayList<OleDeliverRequestDefinition>();
651 try{
652 oleDeliverRequestBos = getLoanProcessor().getPatronRequestRecords(patronId);
653 OleDeliverRequestDefinition oleDeliverRequestDefinition = new OleDeliverRequestDefinition();
654 for(OleDeliverRequestBo oleDeliverRequestBo : oleDeliverRequestBos) {
655 oleDeliverRequestDefinition = OleDeliverRequestBo.to(oleDeliverRequestBo);
656 oleDeliverRequestDefinitions.add(oleDeliverRequestDefinition);
657 }
658 return oleDeliverRequestDefinitions;
659 }
660 catch(Exception e){
661 LOG.error("Exception while getting patron requested items-----> "+e);
662 }
663
664 return null;
665 }
666
667
668
669 public OlePatronLoanDocuments performRenewalItems(OlePatronLoanDocuments olePatronLoanDocuments){
670
671 List<OleLoanDocument> oleLoanDocumentList=new ArrayList<OleLoanDocument>(0);
672 List<OleRenewalLoanDocument> oleRenewalLoanDocumentList=convertRenewalLoanDocuments(olePatronLoanDocuments);
673 try{
674
675 for(int i=0;i<oleRenewalLoanDocumentList.size();i++){
676 OleRenewalLoanDocument oleRenewalLoanDocument=oleRenewalLoanDocumentList.get(i);
677 OleLoanDocument oleLoanDocument=getLoanProcessor().getPatronRenewalItem(oleRenewalLoanDocument.getItemBarcode());
678 if(!getLoanProcessor().checkPendingRequestforItem(oleLoanDocument.getItemId())){
679 oleLoanDocument.setRenewalItemFlag(true);
680 oleLoanDocument = getLoanProcessor().addLoan(oleLoanDocument.getPatronBarcode(),oleLoanDocument.getItemId(),oleLoanDocument,null);
681 }
682 else
683 oleLoanDocument.setErrorMessage(OLEConstants.PENDING_RQST_RENEWAL_ITM_INFO+"( Title: "+oleLoanDocument.getTitle()+" , Author: "+oleLoanDocument.getAuthor()+" , Item : "+oleLoanDocument.getItemId()+" )");
684 oleLoanDocumentList.add(oleLoanDocument);
685 }
686 olePatronLoanDocuments=convertPatronLoanDocuments(oleLoanDocumentList);
687 return olePatronLoanDocuments;
688 }
689 catch(Exception e){
690 LOG.error("Exception while performing renewal---> "+e);
691 }
692 return null;
693 }
694
695
696 private OlePatronLoanDocuments convertPatronLoanDocuments(List<OleLoanDocument> oleLoanDocumentList) {
697
698
699 List<OlePatronLoanDocument> olePatronLoanItemList=new ArrayList<OlePatronLoanDocument>();
700
701 for(int i=0;i<oleLoanDocumentList.size();i++) {
702 OleLoanDocument oleLoanDocument=oleLoanDocumentList.get(i);
703 OleRenewalLoanDocument oleRenewalLoanDocument=new OleRenewalLoanDocument();
704 oleRenewalLoanDocument.setAuthor(oleLoanDocument.getAuthor());
705 oleRenewalLoanDocument.setTitle(oleLoanDocument.getTitle());
706 oleRenewalLoanDocument.setCallNumber(oleLoanDocument.getItemCallNumber());
707 oleRenewalLoanDocument.setDueDate(oleLoanDocument.getLoanDueDate());
708 oleRenewalLoanDocument.setItemBarcode(oleLoanDocument.getItemId());
709 oleRenewalLoanDocument.setLocation(oleLoanDocument.getLocation());
710
711 if(oleLoanDocument.getErrorMessage() == null){
712 oleRenewalLoanDocument.setMessageInfo(OLEConstants.RENEWAL_ITM_SUCCESS_INFO);
713 }else
714 {
715 String errMsg="";
716 if(oleLoanDocument.getErrorMessage().contains("(OR)"))
717 errMsg=oleLoanDocument.getErrorMessage().substring(0,oleLoanDocument.getErrorMessage().lastIndexOf("(OR)"));
718 else
719 errMsg= oleLoanDocument.getErrorMessage();
720 oleRenewalLoanDocument.setMessageInfo(errMsg);
721 }
722 OlePatronLoanDocument olePatronLoanDocument=OlePatronLoanDocuments.to(oleRenewalLoanDocument);
723 olePatronLoanItemList.add(olePatronLoanDocument);
724 }
725 OlePatronLoanDocuments olePatronLoanDocuments=getOlePatronLoanDocuments(olePatronLoanItemList);
726 return olePatronLoanDocuments;
727
728 }
729
730
731 private List<OleRenewalLoanDocument> convertRenewalLoanDocuments(OlePatronLoanDocuments olePatronLoanDocuments){
732
733 List<OleRenewalLoanDocument> oleRenewalLoanDocumentList=new ArrayList<OleRenewalLoanDocument>();
734 for(int i=0;i<olePatronLoanDocuments.getOlePatronLoanDocuments().size();i++){
735 OlePatronLoanDocument olePatronLoanDocument=(OlePatronLoanDocument)olePatronLoanDocuments.getOlePatronLoanDocuments().get(i);
736 OleRenewalLoanDocument oleRenewalLoanDocument=new OleRenewalLoanDocument();
737 oleRenewalLoanDocument.setItemBarcode(olePatronLoanDocument.getItemBarcode());
738 oleRenewalLoanDocument.setCallNumber(olePatronLoanDocument.getCallNumber());
739 oleRenewalLoanDocument.setDueDate(olePatronLoanDocument.getDueDate());
740 oleRenewalLoanDocument.setLocation(olePatronLoanDocument.getLocation());
741 oleRenewalLoanDocument.setTitle(olePatronLoanDocument.getTitle());
742 oleRenewalLoanDocument.setAuthor(olePatronLoanDocument.getAuthor());
743 oleRenewalLoanDocumentList.add(oleRenewalLoanDocument);
744 }
745 return oleRenewalLoanDocumentList;
746 }
747
748 private OlePatronLoanDocuments convertOlePatronLoanDocuments(List<OleRenewalLoanDocument> oleRenewalLoanDocumentList){
749 List<OlePatronLoanDocument> olePatronLoanItemList=new ArrayList<OlePatronLoanDocument>();
750 for(int i=0;i<oleRenewalLoanDocumentList.size();i++){
751 OleRenewalLoanDocument oleRenewalLoanDocument= oleRenewalLoanDocumentList.get(i);
752 OlePatronLoanDocument olePatronLoanDocument=OlePatronLoanDocuments.to(oleRenewalLoanDocument);
753 olePatronLoanItemList.add(olePatronLoanDocument);
754 }
755 OlePatronLoanDocuments olePatronLoanDocuments=getOlePatronLoanDocuments(olePatronLoanItemList);
756 return olePatronLoanDocuments;
757 }
758
759 private OlePatronLoanDocuments getOlePatronLoanDocuments(List<OlePatronLoanDocument> olePatronLoanItemList) {
760 OleRenewalLoanDocument oleRenewalLoanDocument=new OleRenewalLoanDocument();
761 if(olePatronLoanItemList.size()!=0) {
762 oleRenewalLoanDocument.setOlePatronLoanDocuments(olePatronLoanItemList);
763 OlePatronLoanDocuments olePatronLoanDocuments=OlePatronLoanDocuments.Builder.create(oleRenewalLoanDocument).build();
764 return olePatronLoanDocuments;
765 }
766
767 return null;
768
769 }
770
771
772
773 public void deletePatronBatchProgram() {
774 LOG.debug("Inside deletePatronDocument (Batch Delete Program)");
775 OlePatronDocument olePatronDocument = new OlePatronDocument();
776 SimpleDateFormat fmt = new SimpleDateFormat(OLEConstants.OlePatron.PATRON_MAINTENANCE_DATE_FORMAT);
777 OlePatron olePatron;
778 List<OlePatronDocument> patronImpls = (List<OlePatronDocument>) getDataObjectService().findMatching(OlePatronDocument.class,QueryByCriteria.Builder.create().build()).getResults();
779 for (Iterator<OlePatronDocument> patronIterator = patronImpls.iterator(); patronIterator.hasNext(); ) {
780 olePatronDocument = patronIterator.next();
781 if ((olePatronDocument.getExpirationDate() != null && fmt.format(new Date(System.currentTimeMillis())).compareTo(fmt.format(olePatronDocument.getExpirationDate())) > 0) || (olePatronDocument.getExpirationDate() == null)) {
782 List<OleLoanDocument> oleLoanDocuments = olePatronDocument.getOleLoanDocuments();
783 List<OleTemporaryCirculationHistory> oleTemporaryCirculationHistories = olePatronDocument.getOleTemporaryCirculationHistoryRecords();
784 List<OleDeliverRequestBo> oleDeliverRequestBos = olePatronDocument.getOleDeliverRequestBos();
785 Map billMap = new HashMap();
786 billMap.put(OLEConstants.OlePatron.PAY_BILL_PATRON_ID, olePatronDocument.getOlePatronId());
787 List<PatronBillPayment> patronBillPayments = (List<PatronBillPayment>) getDataObjectService().findMatching(PatronBillPayment.class, QueryByCriteria.Builder.andAttributes(billMap).build()).getResults();
788 if ((oleLoanDocuments.size() == 0 && oleTemporaryCirculationHistories.size() == 0 && oleDeliverRequestBos.size() == 0 && patronBillPayments.size() == 0)) {
789 olePatronDocument.setActiveIndicator(false);
790 getDataObjectService().save(olePatronDocument);
791 }
792 }
793 }
794 }
795
796 public DataSource getKimDataSource() {
797 if (kimDataSource == null) {
798
799
800 kimDataSource = KimImplServiceLocator.getDataSource();
801 if (kimDataSource == null) {
802 throw new ConfigurationException("Failed to locate 'kimDataSource'");
803 }
804 }
805 return kimDataSource;
806 }
807
808 public void setKimDataSource(DataSource kimDataSource) {
809 this.kimDataSource = kimDataSource;
810 }
811
812 }