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