1 package org.kuali.ole.ncip.service.impl;
2
3 import org.apache.commons.lang.StringUtils;
4 import org.apache.log4j.Logger;
5 import org.kuali.ole.DataCarrierService;
6 import org.kuali.ole.OLEConstants;
7 import org.kuali.ole.OLEParameterConstants;
8 import org.kuali.ole.deliver.bo.*;
9 import org.kuali.ole.deliver.calendar.bo.OleCalendar;
10 import org.kuali.ole.deliver.calendar.service.OleCalendarService;
11 import org.kuali.ole.deliver.calendar.service.impl.OleCalendarServiceImpl;
12 import org.kuali.ole.deliver.processor.LoanProcessor;
13
14 import org.kuali.ole.deliver.service.OleDeliverRequestDocumentHelperServiceImpl;
15 import org.kuali.ole.describe.bo.OleInstanceItemType;
16 import org.kuali.ole.describe.bo.OleLocation;
17 import org.kuali.ole.describe.bo.OleLocationLevel;
18 import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
19 import org.kuali.ole.docstore.common.document.*;
20 import org.kuali.ole.docstore.common.document.HoldingsTree;
21 import org.kuali.ole.docstore.common.document.content.bib.marc.BibMarcRecord;
22 import org.kuali.ole.docstore.common.document.content.bib.marc.BibMarcRecords;
23 import org.kuali.ole.docstore.common.document.content.bib.marc.xstream.BibMarcRecordProcessor;
24 import org.kuali.ole.docstore.common.document.content.instance.*;
25 import org.kuali.ole.docstore.common.document.content.instance.Item;
26 import org.kuali.ole.docstore.common.document.content.instance.xstream.HoldingOlemlRecordProcessor;
27
28 import org.kuali.ole.docstore.common.document.content.instance.xstream.ItemOlemlRecordProcessor;
29
30 import org.kuali.ole.docstore.common.search.SearchResponse;
31 import org.kuali.ole.docstore.common.search.SearchResult;
32 import org.kuali.ole.docstore.common.search.SearchResultField;
33
34 import org.kuali.ole.docstore.model.xmlpojo.ingest.*;
35
36 import org.kuali.ole.ncip.bo.*;
37
38 import org.kuali.ole.ncip.converter.OLECheckInItemConverter;
39 import org.kuali.ole.ncip.converter.OLECheckOutItemConverter;
40 import org.kuali.ole.ncip.converter.OLERenewItemConverter;
41 import org.kuali.ole.ncip.service.OLESIAPIHelperService;
42 import org.kuali.ole.service.OleCirculationPolicyService;
43 import org.kuali.ole.service.OleCirculationPolicyServiceImpl;
44 import org.kuali.ole.sys.context.SpringContext;
45 import org.kuali.ole.util.DocstoreUtil;
46 import org.kuali.rice.core.api.config.property.ConfigContext;
47 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
48 import org.kuali.rice.kim.api.permission.PermissionService;
49 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
50 import org.kuali.rice.kim.impl.identity.address.EntityAddressBo;
51 import org.kuali.rice.kim.impl.identity.email.EntityEmailBo;
52 import org.kuali.rice.kim.impl.identity.entity.EntityBo;
53 import org.kuali.rice.kim.impl.identity.name.EntityNameBo;
54 import org.kuali.rice.kim.impl.identity.phone.EntityPhoneBo;
55 import org.kuali.rice.krad.service.BusinessObjectService;
56 import org.kuali.ole.docstore.common.document.content.instance.Location;
57 import org.kuali.rice.krad.service.KRADServiceLocator;
58 import org.kuali.rice.krad.util.GlobalVariables;
59 import org.kuali.rice.krms.api.engine.EngineResults;
60 import org.kuali.rice.krms.api.engine.ResultEvent;
61 import org.kuali.rice.krms.framework.engine.BasicRule;
62
63
64 import java.math.BigDecimal;
65 import java.sql.Timestamp;
66 import java.text.DateFormat;
67 import java.text.ParseException;
68 import java.text.SimpleDateFormat;
69 import java.util.*;
70
71
72
73
74
75
76
77
78 public class OLECirculationHelperServiceImpl {
79 private static final Logger LOG = Logger.getLogger(OLECirculationHelperServiceImpl.class);
80 private static final String DOCSTORE_URL = "docstore.url";
81 private final String CREATE_NEW_DOCSTORE_RECORD_QUERY_STRING = "docAction=ingestContent&stringContent=";
82 private BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService();
83 private LoanProcessor loanProcessor;
84 private OLECheckInItemConverter oleCheckInItemConverter = new OLECheckInItemConverter();
85 private OLECheckOutItemConverter oleCheckOutItemConverter = new OLECheckOutItemConverter();
86 private OLESIAPIHelperService oleSIAPIHelperService;
87 private OleCirculationPolicyService oleCirculationPolicyService = getOleCirculationPolicyService();
88 private DocstoreClientLocator docstoreClientLocator;
89 public OleDeliverRequestDocumentHelperServiceImpl oleDeliverRequestDocumentHelperService = new OleDeliverRequestDocumentHelperServiceImpl();
90 DocstoreUtil docstoreUtil = new DocstoreUtil();
91 private Map<String,OleBorrowerType> oleBorrowerTypeMap = getAvailableBorrowerTypes();
92
93 public DocstoreClientLocator getDocstoreClientLocator() {
94
95 if (docstoreClientLocator == null) {
96 docstoreClientLocator = SpringContext.getBean(DocstoreClientLocator.class);
97
98 }
99 return docstoreClientLocator;
100 }
101
102 public LoanProcessor getLoanProcessor(){
103 if (loanProcessor == null) {
104 loanProcessor = SpringContext.getBean(LoanProcessor.class);
105
106 }
107 return loanProcessor;
108 }
109
110
111 public OleCirculationPolicyService getOleCirculationPolicyService() {
112 if (null == oleCirculationPolicyService) {
113 oleCirculationPolicyService = new OleCirculationPolicyServiceImpl();
114 }
115 return oleCirculationPolicyService;
116 }
117
118 public BusinessObjectService getBusinessObjectService() {
119 return businessObjectService;
120 }
121
122 public void setBusinessObjectService(BusinessObjectService businessObjectService) {
123 this.businessObjectService = businessObjectService;
124 }
125
126 public OLESIAPIHelperService getOleSIAPIHelperService() {
127 if (oleSIAPIHelperService == null) {
128 oleSIAPIHelperService = SpringContext.getBean(OLESIAPIHelperService.class);
129 }
130 return oleSIAPIHelperService;
131 }
132
133 public void setOleSIAPIHelperService(OLESIAPIHelperService oleSIAPIHelperService) {
134 this.oleSIAPIHelperService = oleSIAPIHelperService;
135 }
136
137 public Map<String,OleBorrowerType> getAvailableBorrowerTypes(){
138 Map<String,OleBorrowerType> borrowerTypeMap = new HashMap<String,OleBorrowerType>();
139 List<OleBorrowerType> oleBorrowerTypeList = (List<OleBorrowerType>)businessObjectService.findAll(OleBorrowerType.class);
140 if(oleBorrowerTypeList!=null && oleBorrowerTypeList.size()>0){
141 for(OleBorrowerType oleBorrowerType : oleBorrowerTypeList){
142 borrowerTypeMap.put(oleBorrowerType.getBorrowerTypeId(),oleBorrowerType);
143 }
144 }
145 return borrowerTypeMap;
146 }
147
148 public OLELookupUser initialiseLookupUser(OlePatronDocument olePatronDocument, String agencyId) {
149 OLELookupUser oleLookupUser = new OLELookupUser();
150 oleLookupUser.setPatronId(olePatronDocument.getBarcode());
151 OlePatronEmailBo olePatronEmailBo = getDefaultEmailBo(olePatronDocument.getOlePatronId());
152 if (olePatronEmailBo != null) {
153 oleLookupUser.setPatronEmail(olePatronEmailBo);
154 }
155 OlePatronAddressBo olePatronAddressBo = getDefaultAddressBo(olePatronDocument.getOlePatronId());
156 if (olePatronAddressBo != null) {
157 oleLookupUser.setPatronAddress(olePatronAddressBo);
158 }
159 OlePatronPhoneBo olePatronPhoneBo = getDefaultPhoneBo(olePatronDocument.getOlePatronId());
160 if (olePatronPhoneBo != null) {
161 oleLookupUser.setPatronPhone(olePatronPhoneBo);
162 }
163 List<OLEUserPrivilege> oleUserPrivilegeList = getPatronPrivilege(olePatronDocument, agencyId);
164 if ( oleUserPrivilegeList!= null) {
165 oleLookupUser.setOleUserPrivileges(oleUserPrivilegeList);
166 }
167 OlePatronNameBo olePatronNameBo = getEntityNameBo(olePatronDocument.getOlePatronId());
168 if (olePatronNameBo != null) {
169 oleLookupUser.setPatronName(olePatronNameBo);
170 }
171 return oleLookupUser;
172 }
173
174 public EntityBo getEntity(String entityId) {
175 LOG.info("Inside getEntity : Entity Id : " + entityId);
176 Map<String, String> entityMap = new HashMap<>();
177 entityMap.put("id", entityId);
178 List<EntityBo> entityBoList = (List<EntityBo>) businessObjectService.findMatching(EntityBo.class, entityMap);
179 if (entityBoList.size() > 0)
180 return entityBoList.get(0);
181 return null;
182 }
183
184 public OlePatronEmailBo getDefaultEmailBo(String entityId) {
185 LOG.info("Inside getDefaultEmailBo : Entity Id : " + entityId);
186 EntityBo entityBo = getEntity(entityId);
187 OlePatronEmailBo olePatronEmailBo = null;
188 if (entityBo != null) {
189 if (entityBo.getEntityTypeContactInfos() != null && entityBo.getEntityTypeContactInfos().size() > 0)
190 if (entityBo.getEntityTypeContactInfos().get(0).getEmailAddresses() != null && entityBo.getEntityTypeContactInfos().get(0).getEmailAddresses().size() > 0) {
191 for (EntityEmailBo entityEmailBo : entityBo.getEntityTypeContactInfos().get(0).getEmailAddresses()) {
192 if (entityEmailBo.getDefaultValue()) {
193 olePatronEmailBo = new OlePatronEmailBo();
194 olePatronEmailBo.setEmailTypeCode(entityEmailBo.getEmailTypeCode());
195 olePatronEmailBo.setEmailAddress(entityEmailBo.getEmailAddress());
196 return olePatronEmailBo;
197 }
198 }
199 }
200 }
201 return null;
202 }
203
204 public OlePatronAddressBo getDefaultAddressBo(String entityId) {
205 LOG.info("Inside getDefaultAddressBo : Entity Id : " + entityId);
206 EntityBo entityBo = getEntity(entityId);
207 EntityAddressBo entityAddressBo = null;
208 OlePatronAddressBo olePatronAddressBo = null;
209 if (entityBo != null) {
210 if (entityBo.getEntityTypeContactInfos() != null && entityBo.getEntityTypeContactInfos().size() > 0)
211 if (entityBo.getEntityTypeContactInfos().get(0).getDefaultAddress() != null) {
212 entityAddressBo = entityBo.getEntityTypeContactInfos().get(0).getDefaultAddress();
213 olePatronAddressBo = new OlePatronAddressBo();
214 olePatronAddressBo.setAddressTypeCode(entityAddressBo.getAddressTypeCode());
215 olePatronAddressBo.setCity(entityAddressBo.getCity());
216 olePatronAddressBo.setCountryCode(entityAddressBo.getCountryCode());
217 olePatronAddressBo.setLine1(entityAddressBo.getLine1());
218 olePatronAddressBo.setLine2(entityAddressBo.getLine2());
219 olePatronAddressBo.setLine3(entityAddressBo.getLine3());
220 olePatronAddressBo.setPostalCode(entityAddressBo.getPostalCode());
221 olePatronAddressBo.setStateProvinceCode(entityAddressBo.getStateProvinceCode());
222 return olePatronAddressBo;
223 }
224 }
225 return null;
226 }
227
228 public OlePatronNameBo getEntityNameBo(String entityId) {
229 LOG.info("Inside getEntityNameBo : Entity Id : " + entityId);
230 EntityBo entityBo = getEntity(entityId);
231 EntityNameBo entityNameBo = null;
232 OlePatronNameBo olePatronNameBo = null;
233 if (entityBo != null) {
234 if (entityBo.getNames() != null && entityBo.getNames().size() > 0) {
235 entityNameBo = entityBo.getNames().get(0);
236 olePatronNameBo = new OlePatronNameBo();
237 olePatronNameBo.setFirstName(entityNameBo.getFirstName());
238 olePatronNameBo.setMiddleName(entityNameBo.getMiddleName());
239 olePatronNameBo.setLastName(entityNameBo.getLastName());
240 return olePatronNameBo;
241 }
242 }
243 return null;
244 }
245
246 public OlePatronPhoneBo getDefaultPhoneBo(String entityId) {
247 LOG.info("Inside getDefaultPhoneBo : Entity Id : " + entityId);
248 EntityBo entityBo = getEntity(entityId);
249 EntityPhoneBo entityPhoneBo = null;
250 OlePatronPhoneBo olePatronPhoneBo = null;
251 if (entityBo != null) {
252 if (entityBo.getEntityTypeContactInfos().get(0) != null && entityBo.getEntityTypeContactInfos().size() > 0) {
253 if (entityBo.getEntityTypeContactInfos().get(0).getDefaultPhoneNumber() != null) {
254 entityPhoneBo = entityBo.getEntityTypeContactInfos().get(0).getDefaultPhoneNumber();
255 olePatronPhoneBo = new OlePatronPhoneBo();
256 olePatronPhoneBo.setPhoneTypeCode(entityPhoneBo.getPhoneTypeCode());
257 olePatronPhoneBo.setPhoneNumber(entityPhoneBo.getPhoneNumber());
258 return olePatronPhoneBo;
259 }
260 }
261 }
262 return null;
263 }
264
265 public List<OLEUserPrivilege> getPatronPrivilege(OlePatronDocument olePatronDocument, String agencyId) {
266 List<OLEUserPrivilege> userPrivilegeList;
267 if (olePatronDocument != null) {
268 userPrivilegeList = new ArrayList<OLEUserPrivilege>();
269 OLEUserPrivilege courtesyPrivilege = new OLEUserPrivilege();
270 courtesyPrivilege.setUserPrivilegeType(OLEConstants.COURTESY_NOTICE);
271 courtesyPrivilege.setUserPrivilegeDescription(OLEConstants.COURTESY_DESCRIPTION);
272 if (olePatronDocument.isCourtesyNotice()) {
273 courtesyPrivilege.setUserPrivilegeStatus(String.valueOf(Boolean.TRUE));
274 } else {
275 courtesyPrivilege.setUserPrivilegeStatus(String.valueOf(Boolean.FALSE));
276 }
277 userPrivilegeList.add(courtesyPrivilege);
278 OLEUserPrivilege deliverPrivilege = new OLEUserPrivilege();
279 deliverPrivilege.setUserPrivilegeType(OLEConstants.DELIVERY);
280 deliverPrivilege.setUserPrivilegeDescription(OLEConstants.DELIVERY_DESCRIPTION);
281 if (olePatronDocument.isDeliveryPrivilege()){
282 deliverPrivilege.setUserPrivilegeStatus(String.valueOf(Boolean.TRUE));
283 }else{
284 deliverPrivilege.setUserPrivilegeStatus(String.valueOf(Boolean.FALSE));
285 }
286 userPrivilegeList.add(deliverPrivilege);
287 OLEUserPrivilege pagingPrivilege = new OLEUserPrivilege();
288 pagingPrivilege.setUserPrivilegeType(OLEConstants.PAGING);
289 pagingPrivilege.setUserPrivilegeDescription(OLEConstants.PAGING_DESCRIPTION);
290 if (olePatronDocument.isPagingPrivilege()) {
291 pagingPrivilege.setUserPrivilegeStatus(String.valueOf(Boolean.TRUE));
292 }else{
293 pagingPrivilege.setUserPrivilegeStatus(String.valueOf(Boolean.FALSE));
294 }
295 userPrivilegeList.add(pagingPrivilege);
296 if (oleBorrowerTypeMap.get(olePatronDocument.getBorrowerType())!=null) {
297 olePatronDocument.setOleBorrowerType(oleBorrowerTypeMap.get(olePatronDocument.getBorrowerType()));
298 olePatronDocument.setBorrowerTypeCode(oleBorrowerTypeMap.get(olePatronDocument.getBorrowerType()).getBorrowerTypeCode());
299 OLEUserPrivilege oleProfilePrivilege = new OLEUserPrivilege();
300 oleProfilePrivilege.setUserPrivilegeType(OLEConstants.PROFILE);
301 oleProfilePrivilege.setUserPrivilegeStatus(oleBorrowerTypeMap.get(olePatronDocument.getBorrowerType()).getBorrowerTypeName());
302 oleProfilePrivilege.setUserPrivilegeDescription(OLEConstants.PROFILE_DESCRIPTION);
303 userPrivilegeList.add(oleProfilePrivilege);
304 }
305 if (agencyId != null) {
306 String itemType, itemLocation = "";
307 HashMap<String, String> agencyPropertyMap = getAgencyPropertyMap(agencyId);
308 itemType = agencyPropertyMap.get(OLEConstants.ITEM_TYPE);
309 itemLocation = agencyPropertyMap.get(OLEConstants.ITEM_LOCATION);
310 OLEUserPrivilege oleUserPrivilege = new OLEUserPrivilege();
311 oleUserPrivilege.setUserPrivilegeType(OLEConstants.STATUS);
312 oleUserPrivilege.setUserPrivilegeDescription(OLEConstants.STATUS_DESCRIPTION);
313 oleUserPrivilege.setUserPrivilegeStatus(OLEConstants.OK);
314 if (olePatronDocument.isGeneralBlock() || isPatronExpired(olePatronDocument) || !olePatronDocument.isActiveIndicator() || isPatronActivated(olePatronDocument) || !isAbleToCheckOut(olePatronDocument.getOlePatronId(), olePatronDocument.getBorrowerTypeCode(), itemType, itemLocation))
315 oleUserPrivilege.setUserPrivilegeStatus(OLEConstants.BLOCKED);
316 userPrivilegeList.add(oleUserPrivilege);
317 }
318 return userPrivilegeList;
319 }
320 return null;
321 }
322
323 public boolean isPatronExpired(OlePatronDocument olePatronDocument) {
324
325 SimpleDateFormat fmt = new SimpleDateFormat(OLEConstants.OleDeliverRequest.DATE_FORMAT);
326 Date expirationDate = olePatronDocument.getExpirationDate();
327 if (expirationDate != null) {
328 if ((fmt.format(expirationDate)).compareTo(fmt.format(new Date(System.currentTimeMillis()))) > 0) {
329 return false;
330 } else {
331 return true;
332 }
333 }else{
334 return false;
335 }
336 }
337
338 public boolean isPatronActivated(OlePatronDocument olePatronDocument) {
339
340 SimpleDateFormat fmt = new SimpleDateFormat(OLEConstants.OleDeliverRequest.DATE_FORMAT);
341 Date activationDate = olePatronDocument.getActivationDate();
342 if (activationDate != null) {
343 if ((fmt.format(activationDate)).compareTo(fmt.format(new Date(System.currentTimeMillis()))) <= 0) {
344 return false;
345 } else {
346 return true;
347 }
348 } else {
349 return false;
350 }
351 }
352
353 public boolean isAbleToCheckOut(String patronId, String borrowerType, String itemType, String itemLocation) {
354 LOG.info("Inside isAbleToCheckOut method . Patron Id : " +patronId + " Borrower Type : " + borrowerType + " ItemType : "+itemType + " Item Location : " + itemLocation);
355 boolean allowed = true;
356 Long startTime = System.currentTimeMillis();
357 String agendaName = OLEConstants.CHECK_OUT_AGENDA_NM;
358 HashMap<String, Object> termValues = new HashMap<String, Object>();
359 List<FeeType> feeTypeList = oleCirculationPolicyService.getPatronBillPayment(patronId);
360 Integer overdueFineAmt = 0;
361 Integer replacementFeeAmt = 0;
362 for (FeeType feeType : feeTypeList) {
363 overdueFineAmt += feeType.getOleFeeType().getFeeTypeName().equalsIgnoreCase(OLEConstants.OVERDUE_FINE) ? feeType.getFeeAmount().intValue() : 0;
364 replacementFeeAmt += feeType.getOleFeeType().getFeeTypeName().equalsIgnoreCase(OLEConstants.REPLACEMENT_FEE) ? feeType.getFeeAmount().intValue() : 0;
365 }
366 String[] locationArray = itemLocation.split("['/']");
367 List<String> locationList = Arrays.asList(locationArray);
368 for (String value : locationList) {
369 Map<String, String> requestMap = new HashMap<>();
370 requestMap.put(OLEConstants.LOCATION_CODE, value);
371 List<OleLocation> oleLocations = (List<OleLocation>) businessObjectService.findMatching(OleLocation.class, requestMap);
372 if (oleLocations != null && oleLocations.size() > 0) {
373 String locationLevelId = oleLocations.get(0).getLevelId();
374 requestMap.clear();
375 requestMap.put(OLEConstants.LEVEL_ID, locationLevelId);
376 List<OleLocationLevel> oleLocationLevels = (List<OleLocationLevel>) businessObjectService.findMatching(OleLocationLevel.class, requestMap);
377 if (oleLocationLevels != null && oleLocationLevels.size() > 0) {
378 OleLocationLevel oleLocationLevel = new OleLocationLevel();
379 oleLocationLevel = oleLocationLevels.get(0);
380 if (oleLocationLevel.getLevelCode().equals(OLEConstants.OLEBatchProcess.LOCATION_LEVEL_CAMPUS)) {
381 termValues.put(OLEConstants.ITEM_CAMPUS, value);
382 } else if (oleLocationLevel.getLevelCode().equals(OLEConstants.OLEBatchProcess.LOCATION_LEVEL_INSTITUTION)) {
383 termValues.put(OLEConstants.ITEM_INSTITUTION, value);
384 } else if (oleLocationLevel.getLevelCode().equals(OLEConstants.OLEBatchProcess.LOCATION_LEVEL_COLLECTION)) {
385 termValues.put(OLEConstants.ITEM_COLLECTION, value);
386 } else if (oleLocationLevel.getLevelCode().equals(OLEConstants.OLEBatchProcess.LOCATION_LEVEL_LIBRARY)) {
387 termValues.put(OLEConstants.ITEM_LIBRARY, value);
388 } else if (oleLocationLevel.getLevelCode().equals(OLEConstants.OLEBatchProcess.LOCATION_LEVEL_SHELVING)) {
389 termValues.put(OLEConstants.ITEM_SHELVING, value);
390 }
391 }
392 }
393 }
394 termValues.put(OLEConstants.BORROWER_TYPE, borrowerType);
395 termValues.put(OLEConstants.ITEM_TYPE, itemType);
396
397 termValues.put(OLEConstants.OVERDUE_FINE_AMT, overdueFineAmt);
398 termValues.put(OLEConstants.REPLACEMENT_FEE_AMT, replacementFeeAmt);
399 termValues.put(OLEConstants.ALL_CHARGES, overdueFineAmt + replacementFeeAmt);
400
401
402 DataCarrierService dataCarrierService = GlobalResourceLoader.getService(OLEConstants.DATA_CARRIER_SERVICE);
403 String itemId = "";
404 dataCarrierService.removeData(patronId+itemId);
405 dataCarrierService.addData(OLEConstants.GROUP_ID, "100");
406 HashMap keyLoanMap=new HashMap();
407 keyLoanMap=oleCirculationPolicyService.getLoanedKeyMap(patronId,false);
408 List<Integer> listOfOverDueDays =(List<Integer>)keyLoanMap.get(OLEConstants.LIST_OF_OVERDUE_DAYS);
409 dataCarrierService.addData(OLEConstants.LIST_OVERDUE_DAYS, listOfOverDueDays);
410
411 dataCarrierService.addData(OLEConstants.LIST_RECALLED_OVERDUE_DAYS, (List<Integer>) keyLoanMap.get(OLEConstants.LIST_RECALLED_OVERDUE_DAYS));
412 termValues.put(OLEConstants.PATRON_ID_POLICY, patronId);
413 termValues.put(OLEConstants.ITEM_ID_POLICY, "");
414 try {
415 EngineResults engineResults = getLoanProcessor().getEngineResults(agendaName, termValues);
416 dataCarrierService.removeData(patronId+itemId);
417 List<ResultEvent> allResults = engineResults.getAllResults();
418 for (Iterator<ResultEvent> resultEventIterator = allResults.iterator(); resultEventIterator.hasNext(); ) {
419 ResultEvent resultEvent = resultEventIterator.next();
420 if (resultEvent.getSource() instanceof BasicRule) {
421 BasicRule basicRule = (BasicRule) resultEvent.getSource();
422 if (resultEvent.getType().equals(OLEConstants.RULE_EVALUATED) && ((basicRule.getName().equals(OLENCIPConstants.CHECK_REPLACEMENT_FEE_AMT) && resultEvent.getResult())
423 || (basicRule.getName().equals(OLENCIPConstants.CHECK_ALL_OVERDUE_FINE_AMT) && resultEvent.getResult()) || (basicRule.getName().equals(OLENCIPConstants.CHECK_OVERALL_CHARGES) && resultEvent.getResult()))) {
424
425 allowed = false;
426 break;
427 }
428 }
429 }
430 List<String> errorMessage = (List<String>) engineResults.getAttribute(OLEConstants.ERROR_ACTION);
431 if (errorMessage != null && errorMessage.size() > 0) {
432 allowed = false;
433 }
434 } catch (Exception e) {
435 LOG.info("Exception Occured while evaluating the KRMS rules");
436 LOG.error(e, e);
437 }
438 Long endTime =System.currentTimeMillis();
439 Long timeDifference = endTime-startTime;
440 LOG.info("Time taken for the krms fro getting the patron status " + timeDifference);
441 return allowed;
442 }
443
444 public String checkOutItem(String patronId, String operatorId, String itemBarcode) {
445 LOG.info("In Check Out Item . Patron Barcode : "+patronId + " OperatorId : " +operatorId + "Item Barcode : "+itemBarcode);
446 OlePatronDocument olePatronDocument = null;
447 Map<String, String> patronMap = new HashMap<String, String>();
448 patronMap.put(OLEConstants.BARCODE, patronId);
449 List<OlePatronDocument> olePatronDocumentList = (List<OlePatronDocument>) businessObjectService.findMatching(OlePatronDocument.class, patronMap);
450 if (olePatronDocumentList.size() > 0) {
451 olePatronDocument = olePatronDocumentList.get(0);
452 } else {
453 OLECheckOutItem oleCheckOutItem = new OLECheckOutItem();
454 oleCheckOutItem.setCode("002");
455 oleCheckOutItem.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.NO_PATRON_INFO));
456 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.NO_PATRON_INFO));
457 return oleCheckOutItemConverter.generateCheckOutItemXml(oleCheckOutItem);
458 }
459 OleLoanDocument oleLoanDocument;
460 try {
461 oleLoanDocument = getLoanProcessor().getLoanDocument(olePatronDocument.getBarcode(), null, true, false);
462 oleLoanDocument.setLoanOperatorId(operatorId);
463 Map<String, String> circulationDeskDetailMaps = new HashMap<String, String>();
464 circulationDeskDetailMaps.put(OLENCIPConstants.OPERATOR_ID, operatorId);
465 List<OleCirculationDeskDetail> oleCirculationDeskDetailLists = (List<OleCirculationDeskDetail>) businessObjectService.findMatching(OleCirculationDeskDetail.class, circulationDeskDetailMaps);
466 if (oleCirculationDeskDetailLists != null && oleCirculationDeskDetailLists.size() > 0) {
467 for (OleCirculationDeskDetail oleCirculationDeskDetail : oleCirculationDeskDetailLists) {
468 if (oleCirculationDeskDetail.isDefaultLocation()) {
469 String circulationDeskId = oleCirculationDeskDetail.getCirculationDeskId();
470 oleLoanDocument.setCirculationLocationId(circulationDeskId);
471 Map<String, String> circulationMap = new HashMap<String, String>();
472 circulationMap.put(OLEConstants.CIRCULATION_DESK_ID, circulationDeskId);
473 List<OleCirculationDesk> oleCirculationDeskList = (List<OleCirculationDesk>) businessObjectService.findMatching(OleCirculationDesk.class, circulationMap);
474 if (oleCirculationDeskList.size() > 0)
475 oleLoanDocument.setOleCirculationDesk(oleCirculationDeskList.get(0));
476 break;
477 }
478 }
479 } else {
480 OLECheckOutItem oleCheckOutItem = new OLECheckOutItem();
481 oleCheckOutItem.setCode("026");
482 oleCheckOutItem.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.CIRCULATION_DESK_NOT_MAPPED_OPERATOR));
483 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.CIRCULATION_DESK_NOT_MAPPED_OPERATOR));
484 return oleCheckOutItemConverter.generateCheckOutItemXml(oleCheckOutItem);
485 }
486 if (oleLoanDocument.getErrorMessage() == null || (oleLoanDocument.getErrorMessage() != null && oleLoanDocument.getErrorMessage().isEmpty())) {
487 if (olePatronDocument != null) {
488 oleLoanDocument.setLoanOperatorId(operatorId);
489 oleLoanDocument = getLoanProcessor().addLoan(olePatronDocument.getBarcode(), itemBarcode, oleLoanDocument, operatorId);
490 if (oleLoanDocument.getErrorMessage() == null || (oleLoanDocument.getErrorMessage() != null && oleLoanDocument.getErrorMessage().isEmpty())) {
491 OLECheckOutItem oleCheckOutItem = new OLECheckOutItem();
492 oleCheckOutItem.setDueDate(oleLoanDocument.getLoanDueDate() != null ? oleLoanDocument.getLoanDueDate().toString() : "");
493 oleCheckOutItem.setRenewalCount(oleLoanDocument.getNumberOfRenewals());
494 oleCheckOutItem.setUserType(oleLoanDocument.getBorrowerTypeName());
495 oleCheckOutItem.setBarcode(oleLoanDocument.getItemId());
496 oleCheckOutItem.setPatronId(oleLoanDocument.getPatronId());
497 oleCheckOutItem.setPatronBarcode(patronId);
498 if (oleLoanDocument.getOleItem() != null && oleLoanDocument.getOleItem().getItemType() != null) {
499 oleCheckOutItem.setItemType(oleLoanDocument.getOleItem().getItemType().getCodeValue());
500 }
501 oleCheckOutItem.setCode("030");
502 oleCheckOutItem.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.SUCCESSFULLEY_LOANED));
503 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.SUCCESSFULLEY_LOANED));
504 return oleCheckOutItemConverter.generateCheckOutItemXml(oleCheckOutItem);
505
506 } else {
507 if (oleLoanDocument.getOleItem() != null && oleLoanDocument.getOleItem().getLocation() == null) {
508 OLECheckOutItem oleCheckOutItem = new OLECheckOutItem();
509 oleCheckOutItem.setCode("028");
510 oleCheckOutItem.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.INVAL_LOC));
511 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.INVAL_LOC));
512 return oleCheckOutItemConverter.generateCheckOutItemXml(oleCheckOutItem);
513 } else if (oleLoanDocument.getOleItem() != null && oleLoanDocument.getOleItem().getItemStatus() != null &&
514 oleLoanDocument.getOleItem().getItemStatus().getCodeValue() != null && oleLoanDocument.getOleItem().getItemStatus().getCodeValue().equalsIgnoreCase("LOANED")) {
515
516 OLECheckOutItem oleCheckOutItem = new OLECheckOutItem();
517 oleCheckOutItem.setCode("100");
518 oleCheckOutItem.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.ITEM_IN_LOAN));
519 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.ITEM_IN_LOAN));
520 return oleCheckOutItemConverter.generateCheckOutItemXml(oleCheckOutItem);
521 } else {
522 OLECheckOutItem oleCheckOutItem = new OLECheckOutItem();
523 oleCheckOutItem.setCode("500");
524 oleCheckOutItem.setMessage(oleLoanDocument.getErrorMessage());
525 LOG.info(oleLoanDocument.getErrorMessage());
526 return oleCheckOutItemConverter.generateCheckOutItemXml(oleCheckOutItem);
527 }
528 }
529 } else {
530 OLECheckOutItem oleCheckOutItem = new OLECheckOutItem();
531 oleCheckOutItem.setCode("500");
532 oleCheckOutItem.setMessage(oleLoanDocument.getErrorMessage());
533 LOG.info(oleLoanDocument.getErrorMessage());
534 return oleCheckOutItemConverter.generateCheckOutItemXml(oleCheckOutItem);
535 }
536 } else {
537 OLECheckOutItem oleCheckOutItem = new OLECheckOutItem();
538 oleCheckOutItem.setCode("500");
539 oleCheckOutItem.setMessage(oleLoanDocument.getErrorMessage());
540 LOG.info(oleLoanDocument.getErrorMessage());
541 return oleCheckOutItemConverter.generateCheckOutItemXml(oleCheckOutItem);
542 }
543 } catch (Exception e) {
544 OLECheckOutItem oleCheckOutItem = new OLECheckOutItem();
545 oleCheckOutItem.setCode("014");
546 oleCheckOutItem.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.ITEM_BARCODE_DOESNOT_EXISTS));
547 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.ITEM_BARCODE_DOESNOT_EXISTS));
548 LOG.error(e,e);
549 return oleCheckOutItemConverter.generateCheckOutItemXml(oleCheckOutItem);
550 }
551 }
552
553 public String checkInItem(String patronBarcode, String operatorId, String itemBarcode, String deleteIndicator) {
554 LOG.info("Inside checkInItem method .Patron barcode : " + patronBarcode + " Operator Id : " +operatorId + " Item Barcode : " + itemBarcode );
555
556 OleLoanDocument oleLoanDocument = new OleLoanDocument();
557 OLECheckInItem oleCheckInItem = new OLECheckInItem();
558 try {
559
560
561 Map<String, String> loanMap = new HashMap<String, String>();
562 loanMap.put(OLEConstants.OleDeliverRequest.ITEM_ID, itemBarcode);
563 List<OleLoanDocument> oleLoanList = (List<OleLoanDocument>) businessObjectService.findMatching(OleLoanDocument.class, loanMap);
564 if (oleLoanList.size() > 0) {
565 oleLoanDocument = oleLoanList.get(0);
566 String olePatronId = oleLoanList.get(0).getPatronId();
567 Map<String, String> patronMap = new HashMap<String, String>();
568 patronMap.put(OLEConstants.OleDeliverRequest.PATRON_ID, olePatronId);
569 List<OlePatronDocument> olePatronDocumentList = (List<OlePatronDocument>) businessObjectService.findMatching(OlePatronDocument.class, patronMap);
570 if (olePatronDocumentList.size() > 0) {
571 oleLoanDocument.setOlePatron(olePatronDocumentList.get(0));
572 oleLoanDocument.setPatronBarcode(olePatronDocumentList.get(0).getBarcode());
573 if(olePatronDocumentList.get(0).getOleBorrowerType()!=null){
574 oleLoanDocument.setBorrowerTypeCode(olePatronDocumentList.get(0).getOleBorrowerType().getBorrowerTypeCode());
575 oleLoanDocument.setBorrowerTypeName(olePatronDocumentList.get(0).getOleBorrowerType().getBorrowerTypeName());
576 }
577 }
578 }
579 Map<String, String> circulationDeskDetailMap = new HashMap<String, String>();
580 circulationDeskDetailMap.put(OLENCIPConstants.OPERATOR_ID, operatorId);
581 List<OleCirculationDeskDetail> oleCirculationDeskDetailList = (List<OleCirculationDeskDetail>) businessObjectService.findMatching(OleCirculationDeskDetail.class, circulationDeskDetailMap);
582 if (oleCirculationDeskDetailList != null && oleCirculationDeskDetailList.size() > 0) {
583 for (OleCirculationDeskDetail oleCirculationDeskDetail : oleCirculationDeskDetailList) {
584 if (oleCirculationDeskDetail.isDefaultLocation()) {
585 String circulationDeskId = oleCirculationDeskDetail.getCirculationDeskId();
586 oleLoanDocument.setCirculationLocationId(circulationDeskId);
587 Map<String, String> circulationMap = new HashMap<String, String>();
588 circulationMap.put(OLEConstants.CIRCULATION_DESK_ID, circulationDeskId);
589 List<OleCirculationDesk> oleCirculationDeskList = (List<OleCirculationDesk>) businessObjectService.findMatching(OleCirculationDesk.class, circulationMap);
590 if (oleCirculationDeskList.size() > 0)
591 oleLoanDocument.setOleCirculationDesk(oleCirculationDeskList.get(0));
592 break;
593 }
594 }
595 oleLoanDocument = getLoanProcessor().returnLoan(itemBarcode, oleLoanDocument);
596 oleCheckInItem.setAuthor(oleLoanDocument.getAuthor());
597 oleCheckInItem.setTitle(oleLoanDocument.getTitle());
598 oleCheckInItem.setCallNumber(oleLoanDocument.getItemCallNumber());
599 oleCheckInItem.setBarcode(oleLoanDocument.getPatronBarcode());
600 oleCheckInItem.setUserId(oleLoanDocument.getPatronBarcode());
601 oleCheckInItem.setUserType(oleLoanDocument.getBorrowerTypeName());
602 if (oleLoanDocument.getOleItem() != null && oleLoanDocument.getOleItem().getItemType() != null) {
603 oleCheckInItem.setItemType(oleLoanDocument.getOleItem().getItemType().getCodeValue());
604 }
605 if (oleLoanDocument.getErrorMessage() == null || (oleLoanDocument.getErrorMessage() != null && oleLoanDocument.getErrorMessage().isEmpty())) {
606 oleCheckInItem.setCode("024");
607 oleCheckInItem.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.SUCCESSFULLEY_CHECKED_IN));
608 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.SUCCESSFULLEY_CHECKED_IN));
609 if (deleteIndicator!=null && deleteIndicator.equalsIgnoreCase("y")) {
610
611 org.kuali.ole.docstore.common.document.Item item = getDocstoreClientLocator().getDocstoreClient().retrieveItem(oleLoanDocument.getItemUuid());
612 String bibId = item.getHolding().getBib().getId();
613
614 getDocstoreClientLocator().getDocstoreClient().deleteBib(bibId);
615 }
616 return oleCheckInItemConverter.generateCheckInItemXml(oleCheckInItem);
617 } else {
618 oleCheckInItem.setCode("500");
619 oleCheckInItem.setMessage(oleLoanDocument.getErrorMessage());
620 LOG.info(oleLoanDocument.getErrorMessage());
621 return oleCheckInItemConverter.generateCheckInItemXml(oleCheckInItem);
622 }
623 } else {
624 oleCheckInItem.setCode("025");
625 oleCheckInItem.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.CHECK_IN_FAILED));
626 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.CHECK_IN_FAILED));
627 return oleCheckInItemConverter.generateCheckInItemXml(oleCheckInItem);
628 }
629 } catch (Exception e) {
630 if(e.getMessage()!=null && e.getMessage().equals("")){
631 oleCheckInItem.setCode("014");
632 oleCheckInItem.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.ITEM_BARCODE_DOESNOT_EXISTS));
633 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.ITEM_BARCODE_DOESNOT_EXISTS));
634 LOG.error(e,e);
635 return oleCheckInItemConverter.generateCheckInItemXml(oleCheckInItem);
636 }
637
638 oleCheckInItem.setCode("025");
639 oleCheckInItem.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.CHECK_IN_FAILED));
640 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.CHECK_IN_FAILED));
641 return oleCheckInItemConverter.generateCheckInItemXml(oleCheckInItem);
642 }
643 }
644
645 public String acceptItem(String patronBarcode, String operatorId, String itemBarcode, String callNumber, String title, String author, String itemType, String itemLocation, String dateExpires, String requestType, String pickUpLocation) throws Exception {
646 LOG.info("Inside Accept Item . Patron Barcode " + patronBarcode + "Operator Id : " +operatorId + "Item barcode :" + itemBarcode + " Call Number : "+callNumber + "Title : "+title + " Author : " +author + "Item Type : "+ itemType + "Item Location : "+itemLocation + "Request Type :" + requestType + "Pick up Location : " + pickUpLocation );
647 OLEAcceptItem oleAcceptItem = new OLEAcceptItem();
648 String itemIdentifier = null;
649 if (docstoreUtil.isItemAvailableInDocStore(itemBarcode)) {
650 return itemIdentifier;
651 }
652 BibMarcRecord bibMarcRecord = getLoanProcessor().getBibMarcRecord(title, author);
653
654 List<BibMarcRecord> bibMarcRecordList = new ArrayList<>();
655 bibMarcRecordList.add(bibMarcRecord);
656
657 BibMarcRecords bibMarcRecords = new BibMarcRecords();
658 bibMarcRecords.setRecords(bibMarcRecordList);
659 BibMarcRecordProcessor bibMarcRecordProcessor = new BibMarcRecordProcessor();
660
661
662 Bib bib = new BibMarc();
663 bib.setStaffOnly(true);
664 bib.setCategory(org.kuali.ole.docstore.common.document.content.enums.DocCategory.WORK.getCode());
665 bib.setType(org.kuali.ole.docstore.common.document.content.enums.DocType.BIB.getCode());
666 bib.setFormat(org.kuali.ole.docstore.common.document.content.enums.DocFormat.MARC.getCode());
667 bib.setContent(bibMarcRecordProcessor.toXml(bibMarcRecords));
668 bib.setOperation(DocstoreDocument.OperationType.CREATE);
669
670
671 OleHoldings oleHoldings = new OleHoldings();
672 LocationLevel locationLevel = new LocationLevel();
673 locationLevel = getLoanProcessor().createLocationLevel(itemLocation, locationLevel);
674 Location holdingsLocation = new Location();
675 holdingsLocation.setPrimary(OLEConstants.TRUE);
676 holdingsLocation.setStatus(OLEConstants.PERMANENT);
677 holdingsLocation.setLocationLevel(locationLevel);
678 oleHoldings.setLocation(holdingsLocation);
679 oleHoldings.setStaffOnlyFlag(true);
680 Item item = new Item();
681
682 AccessInformation accessInformation = new AccessInformation();
683 accessInformation.setBarcode(itemBarcode);
684 item.setAccessInformation(accessInformation);
685 item.setStaffOnlyFlag(true);
686 ItemStatus itemStatus = new ItemStatus();
687 itemStatus.setCodeValue(OLEConstants.AVAILABLE);
688 item.setItemStatus(itemStatus);
689 ItemType type = new ItemType();
690 type.setCodeValue(itemType);
691 item.setItemType(type);
692 CallNumber itemCallNumber = new CallNumber();
693 itemCallNumber.setNumber(callNumber);
694 item.setCallNumber(itemCallNumber);
695 ShelvingScheme shelvingScheme = new ShelvingScheme();
696 shelvingScheme.setCodeValue(OLEConstants.LCC);
697 itemCallNumber.setShelvingScheme(shelvingScheme);
698
699 item.setLocation(holdingsLocation);
700 ItemOlemlRecordProcessor itemOlemlRecordProcessor = new ItemOlemlRecordProcessor();
701 org.kuali.ole.docstore.common.document.Item documentItem = new ItemOleml();
702 documentItem.setContent(itemOlemlRecordProcessor.toXML(item));
703 documentItem.setStaffOnly(true);
704 documentItem.setOperation(DocstoreDocument.OperationType.CREATE);
705 Holdings holdings = new PHoldings();
706 holdings.setStaffOnly(true);
707 HoldingOlemlRecordProcessor holdingOlemlRecordProcessor = new HoldingOlemlRecordProcessor();
708 holdings.setContent(holdingOlemlRecordProcessor.toXML(oleHoldings));
709 holdings.setOperation(DocstoreDocument.OperationType.CREATE);
710 HoldingsTree holdingsTree = new HoldingsTree();
711 holdingsTree.setHoldings(holdings);
712 holdingsTree.getItems().add(documentItem);
713 BibTree bibTree = new BibTree();
714 bibTree.setBib(bib);
715 bibTree.getHoldingsTrees().add(holdingsTree);
716 BibTrees bibTrees = new BibTrees();
717 bibTrees.getBibTrees().add(bibTree);
718 bibTrees=getDocstoreClientLocator().getDocstoreClient().processBibTrees(bibTrees);
719 Thread.sleep(200);
720 if(bibTrees!=null && bibTrees.getBibTrees()!=null && bibTrees.getBibTrees().size()>0 &&bibTrees.getBibTrees().get(0).getHoldingsTrees()!=null && bibTrees.getBibTrees().get(0).getHoldingsTrees().size()>0
721 && bibTrees.getBibTrees().get(0).getHoldingsTrees().get(0).getItems() != null && bibTrees.getBibTrees().get(0).getHoldingsTrees().get(0).getItems().size()>0 ){
722 itemIdentifier= bibTrees.getBibTrees().get(0).getHoldingsTrees().get(0).getItems().get(0).getId();
723 }else{
724 itemIdentifier="";
725 }
726 LOG.info("Item Created with identifier : " + itemIdentifier);
727 return itemIdentifier;
728 }
729
730 public HashMap<String, String> getAgencyPropertyMap(String agencyId) {
731 HashMap<String, String> agencyPropertyMap = new HashMap<String, String>();
732 agencyPropertyMap = getOleSIAPIHelperService().getAgencyPropertyMap(OLEConstants.DLVR_NMSPC, OLEConstants.DLVR_CMPNT, OLENCIPConstants.NCIPAPI_PARAMETER_NAME, agencyId, agencyPropertyMap);
733 return agencyPropertyMap;
734 }
735
736 public String renewItem(String patronBarcode, String operatorId, String itemBarcode) {
737 LOG.info("Inside Renew Item . Patron Barcode : " + patronBarcode + "Operator Id : "+ operatorId + " Item Barcode : " +itemBarcode);
738 OLERenewItem oleRenewItem = new OLERenewItem();
739 OLERenewItemConverter oleRenewItemConverter = new OLERenewItemConverter();
740 OlePatronDocument olePatronDocument = null;
741 Map<String, String> patronMap = new HashMap<String, String>();
742 patronMap.put(OLEConstants.BARCODE, patronBarcode);
743 List<OlePatronDocument> patronDocuments = (List<OlePatronDocument>) businessObjectService.findMatching(OlePatronDocument.class, patronMap);
744 if (patronDocuments.size() > 0) {
745 olePatronDocument = patronDocuments.get(0);
746 } else {
747 oleRenewItem.setCode("002");
748 oleRenewItem.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.NO_PATRON_INFO));
749 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.NO_PATRON_INFO));
750 return oleRenewItemConverter.generateRenewItemXml(oleRenewItem);
751 }
752 if (!getLoanProcessor().hasCirculationDesk(operatorId)) {
753 oleRenewItem.setCode("001");
754 oleRenewItem.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.INVALID_OPRTR_ID));
755 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.INVALID_OPRTR_ID));
756 return oleRenewItemConverter.generateRenewItemXml(oleRenewItem);
757 }
758 Map<String, String> loanMap = new HashMap<String, String>();
759 loanMap.put(OLEConstants.PATRON_ID, olePatronDocument.getOlePatronId());
760 loanMap.put(OLEConstants.OleDeliverRequest.ITEM_ID, itemBarcode);
761 List<OleLoanDocument> loanDocuments = (List<OleLoanDocument>) businessObjectService.findMatching(OleLoanDocument.class, loanMap);
762 if (loanDocuments.size() > 0) {
763 OleLoanDocument oleLoanDocument = loanDocuments.get(0);
764
765 if (patronDocuments.size() > 0) {
766 oleLoanDocument.setOlePatron(olePatronDocument);
767 oleLoanDocument.setBorrowerTypeCode(olePatronDocument.getBorrowerTypeCode());
768 oleLoanDocument.setBorrowerTypeId(olePatronDocument.getBorrowerType());
769 oleLoanDocument.setOleBorrowerType(olePatronDocument.getOleBorrowerType());
770 oleLoanDocument.setBorrowerTypeName(olePatronDocument.getBorrowerTypeName());
771 }
772 oleLoanDocument.setRenewalItemFlag(true);
773 oleLoanDocument.setErrorMessage(null);
774 if (getLoanProcessor().canOverrideLoan(operatorId)) {
775 if (!getLoanProcessor().checkPendingRequestforItem(oleLoanDocument.getItemUuid())) {
776 Timestamp currentDate = new Timestamp(System.currentTimeMillis());
777 try {
778 oleLoanDocument = getLoanProcessor().addLoan(oleLoanDocument.getPatronBarcode(), oleLoanDocument.getItemId(), oleLoanDocument, operatorId);
779 if (oleLoanDocument.getErrorMessage() == null || (oleLoanDocument.getErrorMessage() != null && oleLoanDocument.getErrorMessage().trim().isEmpty())) {
780 oleRenewItem.setCode("003");
781 oleRenewItem.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.RENEW_SUCCESS));
782 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.RENEW_SUCCESS));
783 oleRenewItem.setPastDueDate(oleLoanDocument.getPastDueDate().toString());
784 oleRenewItem.setNewDueDate(oleLoanDocument.getLoanDueDate() != null ? oleLoanDocument.getLoanDueDate().toString() : "");
785 oleRenewItem.setRenewalCount(oleLoanDocument.getNumberOfRenewals());
786 return oleRenewItemConverter.generateRenewItemXml(oleRenewItem);
787 } else {
788 oleRenewItem.setCode("500");
789 oleRenewItem.setMessage(oleLoanDocument.getErrorMessage());
790 LOG.info(oleLoanDocument.getErrorMessage());
791 return oleRenewItemConverter.generateRenewItemXml(oleRenewItem);
792
793 }
794 } catch (Exception e) {
795 LOG.error(e,e);
796 return "Exception occured while renewing an item";
797 }
798
799 } else {
800 oleRenewItem.setCode("009");
801 oleRenewItem.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.RQST_PNDNG));
802 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.RQST_PNDNG));
803 return oleRenewItemConverter.generateRenewItemXml(oleRenewItem);
804 }
805 } else {
806 oleRenewItem.setCode("010");
807 oleRenewItem.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.NO_RENEW));
808 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.NO_RENEW));
809 return oleRenewItemConverter.generateRenewItemXml(oleRenewItem);
810 }
811 } else {
812 oleRenewItem.setCode("011");
813 oleRenewItem.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.ITM_NT_LOAN));
814 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.ITM_NT_LOAN));
815 return oleRenewItemConverter.generateRenewItemXml(oleRenewItem);
816 }
817 }
818
819
820 public boolean validPatron(String patronId) {
821 boolean valid = false;
822 Map<String, String> patronMap = new HashMap<String, String>();
823 patronMap.put(OLEConstants.BARCODE, patronId);
824 List<OlePatronDocument> olePatronDocumentList = (List<OlePatronDocument>) businessObjectService.findMatching(OlePatronDocument.class, patronMap);
825 if (olePatronDocumentList.size() > 0) {
826 valid = true;
827 }
828 return valid;
829 }
830
831
832 private Map<String, String> getLocationMap(String itemLocation) {
833 Map<String, String> locationMap = new HashMap<String, String>();
834 String[] locationArray = itemLocation.split("['/']");
835 List<String> locationList = Arrays.asList(locationArray);
836 for (String value : locationList) {
837 Map<String, String> requestMap = new HashMap<>();
838 requestMap.put(OLEConstants.LOCATION_CODE, value);
839 List<OleLocation> oleLocations = (List<OleLocation>) businessObjectService.findMatching(OleLocation.class, requestMap);
840 if (oleLocations != null && oleLocations.size() > 0) {
841 String locationLevelId = oleLocations.get(0).getLevelId();
842 requestMap.clear();
843 requestMap.put(OLEConstants.LEVEL_ID, locationLevelId);
844 List<OleLocationLevel> oleLocationLevels = (List<OleLocationLevel>) businessObjectService.findMatching(OleLocationLevel.class, requestMap);
845 if (oleLocationLevels != null && oleLocationLevels.size() > 0) {
846 OleLocationLevel oleLocationLevel = new OleLocationLevel();
847 oleLocationLevel = oleLocationLevels.get(0);
848 if (oleLocationLevel.getLevelCode().equals(OLEConstants.OLEBatchProcess.LOCATION_LEVEL_CAMPUS)) {
849 locationMap.put(OLEConstants.ITEM_CAMPUS, value);
850 } else if (oleLocationLevel.getLevelCode().equals(OLEConstants.OLEBatchProcess.LOCATION_LEVEL_INSTITUTION)) {
851 locationMap.put(OLEConstants.ITEM_INSTITUTION, value);
852 } else if (oleLocationLevel.getLevelCode().equals(OLEConstants.OLEBatchProcess.LOCATION_LEVEL_COLLECTION)) {
853 locationMap.put(OLEConstants.ITEM_COLLECTION, value);
854 } else if (oleLocationLevel.getLevelCode().equals(OLEConstants.OLEBatchProcess.LOCATION_LEVEL_LIBRARY)) {
855 locationMap.put(OLEConstants.ITEM_LIBRARY, value);
856 } else if (oleLocationLevel.getLevelCode().equals(OLEConstants.OLEBatchProcess.LOCATION_LEVEL_SHELVING)) {
857 locationMap.put(OLEConstants.ITEM_SHELVING, value);
858 }
859 }
860 }
861 }
862 return locationMap;
863 }
864
865
866
867
868
869
870 public GregorianCalendar getGregorianCalendarDate(String date) {
871 if (date != null) {
872 if(date.equals("")){
873 return new GregorianCalendar(2025,1,1);
874 }
875
876 SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
877 Date parsedDate = null;
878 try{
879 try {
880 parsedDate = simpleDateFormat.parse(date);
881 } catch (ParseException e) {
882 simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
883 parsedDate = simpleDateFormat.parse(date);
884 }
885 }catch (ParseException e){
886 LOG.info("Exception occured while parsing the date : " + date);
887 }
888 Calendar cal = Calendar.getInstance();
889 cal.setTime(parsedDate);
890 int year = cal.get(Calendar.YEAR);
891 int month = cal.get(Calendar.MONTH);
892 int day = cal.get(Calendar.DAY_OF_MONTH);
893 return new GregorianCalendar(year, month, day);
894 }
895 return null;
896 }
897 }
898
899
900
901