1 package org.kuali.ole.ncip.service.impl;
2
3 import org.apache.log4j.Logger;
4 import org.kuali.ole.DataCarrierService;
5 import org.kuali.ole.OLEConstants;
6 import org.kuali.ole.deliver.bo.*;
7 import org.kuali.ole.deliver.processor.LoanProcessor;
8 import org.kuali.ole.deliver.service.OleDeliverRequestDocumentHelperServiceImpl;
9 import org.kuali.ole.describe.bo.OleLocation;
10 import org.kuali.ole.describe.bo.OleLocationLevel;
11 import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
12 import org.kuali.ole.docstore.common.document.*;
13 import org.kuali.ole.docstore.common.document.HoldingsTree;
14 import org.kuali.ole.docstore.common.document.content.bib.marc.BibMarcRecord;
15 import org.kuali.ole.docstore.common.document.content.bib.marc.BibMarcRecords;
16 import org.kuali.ole.docstore.common.document.content.bib.marc.xstream.BibMarcRecordProcessor;
17 import org.kuali.ole.docstore.common.document.content.instance.*;
18 import org.kuali.ole.docstore.common.document.content.instance.Item;
19 import org.kuali.ole.docstore.common.document.content.instance.xstream.HoldingOlemlRecordProcessor;
20 import org.kuali.ole.docstore.common.document.content.instance.xstream.ItemOlemlRecordProcessor;
21 import org.kuali.ole.ncip.bo.*;
22 import org.kuali.ole.ncip.converter.OLECheckInItemConverter;
23 import org.kuali.ole.ncip.converter.OLECheckOutItemConverter;
24 import org.kuali.ole.ncip.converter.OLERenewItemConverter;
25 import org.kuali.ole.ncip.service.OLESIAPIHelperService;
26 import org.kuali.ole.service.OleCirculationPolicyService;
27 import org.kuali.ole.service.OleCirculationPolicyServiceImpl;
28 import org.kuali.ole.sys.context.SpringContext;
29 import org.kuali.ole.util.DocstoreUtil;
30 import org.kuali.rice.core.api.config.property.ConfigContext;
31 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
32 import org.kuali.rice.kim.impl.identity.address.EntityAddressBo;
33 import org.kuali.rice.kim.impl.identity.email.EntityEmailBo;
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.krad.service.BusinessObjectService;
38 import org.kuali.rice.krad.service.KRADServiceLocator;
39 import org.kuali.rice.krms.api.engine.EngineResults;
40 import org.kuali.rice.krms.api.engine.ResultEvent;
41 import org.kuali.rice.krms.framework.engine.BasicRule;
42
43 import java.sql.Timestamp;
44 import java.text.ParseException;
45 import java.text.SimpleDateFormat;
46 import java.util.*;
47
48
49
50
51
52
53
54
55 public class OLECirculationHelperServiceImpl {
56 private static final Logger LOG = Logger.getLogger(OLECirculationHelperServiceImpl.class);
57 private static final String DOCSTORE_URL = "docstore.url";
58 private final String CREATE_NEW_DOCSTORE_RECORD_QUERY_STRING = "docAction=ingestContent&stringContent=";
59 private BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService();
60 private LoanProcessor loanProcessor;
61 private OLECheckInItemConverter oleCheckInItemConverter = new OLECheckInItemConverter();
62 private OLECheckOutItemConverter oleCheckOutItemConverter = new OLECheckOutItemConverter();
63 private OLESIAPIHelperService oleSIAPIHelperService;
64 private OleCirculationPolicyService oleCirculationPolicyService = getOleCirculationPolicyService();
65 private DocstoreClientLocator docstoreClientLocator;
66 public OleDeliverRequestDocumentHelperServiceImpl oleDeliverRequestDocumentHelperService = new OleDeliverRequestDocumentHelperServiceImpl();
67 DocstoreUtil docstoreUtil = new DocstoreUtil();
68 private Map<String,OleBorrowerType> oleBorrowerTypeMap = getAvailableBorrowerTypes();
69
70 public DocstoreClientLocator getDocstoreClientLocator() {
71
72 if (docstoreClientLocator == null) {
73 docstoreClientLocator = SpringContext.getBean(DocstoreClientLocator.class);
74
75 }
76 return docstoreClientLocator;
77 }
78
79 public LoanProcessor getLoanProcessor(){
80 if (loanProcessor == null) {
81 loanProcessor = SpringContext.getBean(LoanProcessor.class);
82
83 }
84 return loanProcessor;
85 }
86
87
88 public OleCirculationPolicyService getOleCirculationPolicyService() {
89 if (null == oleCirculationPolicyService) {
90 oleCirculationPolicyService = new OleCirculationPolicyServiceImpl();
91 }
92 return oleCirculationPolicyService;
93 }
94
95 public BusinessObjectService getBusinessObjectService() {
96 return businessObjectService;
97 }
98
99 public void setBusinessObjectService(BusinessObjectService businessObjectService) {
100 this.businessObjectService = businessObjectService;
101 }
102
103 public OLESIAPIHelperService getOleSIAPIHelperService() {
104 if (oleSIAPIHelperService == null) {
105 oleSIAPIHelperService = SpringContext.getBean(OLESIAPIHelperService.class);
106 }
107 return oleSIAPIHelperService;
108 }
109
110 public void setOleSIAPIHelperService(OLESIAPIHelperService oleSIAPIHelperService) {
111 this.oleSIAPIHelperService = oleSIAPIHelperService;
112 }
113
114 public Map<String,OleBorrowerType> getAvailableBorrowerTypes(){
115 Map<String,OleBorrowerType> borrowerTypeMap = new HashMap<String,OleBorrowerType>();
116 List<OleBorrowerType> oleBorrowerTypeList = (List<OleBorrowerType>)businessObjectService.findAll(OleBorrowerType.class);
117 if(oleBorrowerTypeList!=null && oleBorrowerTypeList.size()>0){
118 for(OleBorrowerType oleBorrowerType : oleBorrowerTypeList){
119 borrowerTypeMap.put(oleBorrowerType.getBorrowerTypeId(),oleBorrowerType);
120 }
121 }
122 return borrowerTypeMap;
123 }
124
125 public OLELookupUser initialiseLookupUser(OlePatronDocument olePatronDocument, String agencyId) {
126 OLELookupUser oleLookupUser = new OLELookupUser();
127 oleLookupUser.setPatronId(olePatronDocument.getBarcode());
128 OlePatronEmailBo olePatronEmailBo = getDefaultEmailBo(olePatronDocument.getOlePatronId());
129 if (olePatronEmailBo != null) {
130 oleLookupUser.setPatronEmail(olePatronEmailBo);
131 }
132 OlePatronAddressBo olePatronAddressBo = getDefaultAddressBo(olePatronDocument.getOlePatronId());
133 if (olePatronAddressBo != null) {
134 oleLookupUser.setPatronAddress(olePatronAddressBo);
135 }
136 OlePatronPhoneBo olePatronPhoneBo = getDefaultPhoneBo(olePatronDocument.getOlePatronId());
137 if (olePatronPhoneBo != null) {
138 oleLookupUser.setPatronPhone(olePatronPhoneBo);
139 }
140 List<OLEUserPrivilege> oleUserPrivilegeList = getPatronPrivilege(olePatronDocument, agencyId);
141 if ( oleUserPrivilegeList!= null) {
142 oleLookupUser.setOleUserPrivileges(oleUserPrivilegeList);
143 }
144 OlePatronNameBo olePatronNameBo = getEntityNameBo(olePatronDocument.getOlePatronId());
145 if (olePatronNameBo != null) {
146 oleLookupUser.setPatronName(olePatronNameBo);
147 }
148 return oleLookupUser;
149 }
150
151 public EntityBo getEntity(String entityId) {
152 LOG.info("Inside getEntity : Entity Id : " + entityId);
153 Map<String, String> entityMap = new HashMap<>();
154 entityMap.put("id", entityId);
155 List<EntityBo> entityBoList = (List<EntityBo>) businessObjectService.findMatching(EntityBo.class, entityMap);
156 if (entityBoList.size() > 0)
157 return entityBoList.get(0);
158 return null;
159 }
160
161 public OlePatronEmailBo getDefaultEmailBo(String entityId) {
162 LOG.info("Inside getDefaultEmailBo : Entity Id : " + entityId);
163 EntityBo entityBo = getEntity(entityId);
164 OlePatronEmailBo olePatronEmailBo = null;
165 if (entityBo != null) {
166 if (entityBo.getEntityTypeContactInfos() != null && entityBo.getEntityTypeContactInfos().size() > 0)
167 if (entityBo.getEntityTypeContactInfos().get(0).getEmailAddresses() != null && entityBo.getEntityTypeContactInfos().get(0).getEmailAddresses().size() > 0) {
168 for (EntityEmailBo entityEmailBo : entityBo.getEntityTypeContactInfos().get(0).getEmailAddresses()) {
169 if (entityEmailBo.getDefaultValue()) {
170 olePatronEmailBo = new OlePatronEmailBo();
171 olePatronEmailBo.setEmailTypeCode(entityEmailBo.getEmailTypeCode());
172 olePatronEmailBo.setEmailAddress(entityEmailBo.getEmailAddress());
173 return olePatronEmailBo;
174 }
175 }
176 }
177 }
178 return null;
179 }
180
181 public OlePatronAddressBo getDefaultAddressBo(String entityId) {
182 LOG.info("Inside getDefaultAddressBo : Entity Id : " + entityId);
183 EntityBo entityBo = getEntity(entityId);
184 EntityAddressBo entityAddressBo = null;
185 OlePatronAddressBo olePatronAddressBo = null;
186 if (entityBo != null) {
187 if (entityBo.getEntityTypeContactInfos() != null && entityBo.getEntityTypeContactInfos().size() > 0)
188 if (entityBo.getEntityTypeContactInfos().get(0).getDefaultAddress() != null) {
189 entityAddressBo = entityBo.getEntityTypeContactInfos().get(0).getDefaultAddress();
190 olePatronAddressBo = new OlePatronAddressBo();
191 olePatronAddressBo.setAddressTypeCode(entityAddressBo.getAddressTypeCode());
192 olePatronAddressBo.setCity(entityAddressBo.getCity());
193 olePatronAddressBo.setCountryCode(entityAddressBo.getCountryCode());
194 olePatronAddressBo.setLine1(entityAddressBo.getLine1());
195 olePatronAddressBo.setLine2(entityAddressBo.getLine2());
196 olePatronAddressBo.setLine3(entityAddressBo.getLine3());
197 olePatronAddressBo.setPostalCode(entityAddressBo.getPostalCode());
198 olePatronAddressBo.setStateProvinceCode(entityAddressBo.getStateProvinceCode());
199 return olePatronAddressBo;
200 }
201 }
202 return null;
203 }
204
205 public OlePatronNameBo getEntityNameBo(String entityId) {
206 LOG.info("Inside getEntityNameBo : Entity Id : " + entityId);
207 EntityBo entityBo = getEntity(entityId);
208 EntityNameBo entityNameBo = null;
209 OlePatronNameBo olePatronNameBo = null;
210 if (entityBo != null) {
211 if (entityBo.getNames() != null && entityBo.getNames().size() > 0) {
212 entityNameBo = entityBo.getNames().get(0);
213 olePatronNameBo = new OlePatronNameBo();
214 olePatronNameBo.setFirstName(entityNameBo.getFirstName());
215 olePatronNameBo.setMiddleName(entityNameBo.getMiddleName());
216 olePatronNameBo.setLastName(entityNameBo.getLastName());
217 return olePatronNameBo;
218 }
219 }
220 return null;
221 }
222
223 public OlePatronPhoneBo getDefaultPhoneBo(String entityId) {
224 LOG.info("Inside getDefaultPhoneBo : Entity Id : " + entityId);
225 EntityBo entityBo = getEntity(entityId);
226 EntityPhoneBo entityPhoneBo = null;
227 OlePatronPhoneBo olePatronPhoneBo = null;
228 if (entityBo != null) {
229 if (entityBo.getEntityTypeContactInfos().get(0) != null && entityBo.getEntityTypeContactInfos().size() > 0) {
230 if (entityBo.getEntityTypeContactInfos().get(0).getDefaultPhoneNumber() != null) {
231 entityPhoneBo = entityBo.getEntityTypeContactInfos().get(0).getDefaultPhoneNumber();
232 olePatronPhoneBo = new OlePatronPhoneBo();
233 olePatronPhoneBo.setPhoneTypeCode(entityPhoneBo.getPhoneTypeCode());
234 olePatronPhoneBo.setPhoneNumber(entityPhoneBo.getPhoneNumber());
235 return olePatronPhoneBo;
236 }
237 }
238 }
239 return null;
240 }
241
242 public List<OLEUserPrivilege> getPatronPrivilege(OlePatronDocument olePatronDocument, String agencyId) {
243 List<OLEUserPrivilege> userPrivilegeList;
244 if (olePatronDocument != null) {
245 userPrivilegeList = new ArrayList<OLEUserPrivilege>();
246 OLEUserPrivilege courtesyPrivilege = new OLEUserPrivilege();
247 courtesyPrivilege.setUserPrivilegeType(OLEConstants.COURTESY_NOTICE);
248 courtesyPrivilege.setUserPrivilegeDescription(OLEConstants.COURTESY_DESCRIPTION);
249 if (olePatronDocument.isCourtesyNotice()) {
250 courtesyPrivilege.setUserPrivilegeStatus(String.valueOf(Boolean.TRUE));
251 } else {
252 courtesyPrivilege.setUserPrivilegeStatus(String.valueOf(Boolean.FALSE));
253 }
254 userPrivilegeList.add(courtesyPrivilege);
255 OLEUserPrivilege deliverPrivilege = new OLEUserPrivilege();
256 deliverPrivilege.setUserPrivilegeType(OLEConstants.DELIVERY);
257 deliverPrivilege.setUserPrivilegeDescription(OLEConstants.DELIVERY_DESCRIPTION);
258 if (olePatronDocument.isDeliveryPrivilege()){
259 deliverPrivilege.setUserPrivilegeStatus(String.valueOf(Boolean.TRUE));
260 }else{
261 deliverPrivilege.setUserPrivilegeStatus(String.valueOf(Boolean.FALSE));
262 }
263 userPrivilegeList.add(deliverPrivilege);
264 OLEUserPrivilege pagingPrivilege = new OLEUserPrivilege();
265 pagingPrivilege.setUserPrivilegeType(OLEConstants.PAGING);
266 pagingPrivilege.setUserPrivilegeDescription(OLEConstants.PAGING_DESCRIPTION);
267 if (olePatronDocument.isPagingPrivilege()) {
268 pagingPrivilege.setUserPrivilegeStatus(String.valueOf(Boolean.TRUE));
269 }else{
270 pagingPrivilege.setUserPrivilegeStatus(String.valueOf(Boolean.FALSE));
271 }
272 userPrivilegeList.add(pagingPrivilege);
273 if (oleBorrowerTypeMap.get(olePatronDocument.getBorrowerType())!=null) {
274 olePatronDocument.setOleBorrowerType(oleBorrowerTypeMap.get(olePatronDocument.getBorrowerType()));
275 olePatronDocument.setBorrowerTypeCode(oleBorrowerTypeMap.get(olePatronDocument.getBorrowerType()).getBorrowerTypeCode());
276 OLEUserPrivilege oleProfilePrivilege = new OLEUserPrivilege();
277 oleProfilePrivilege.setUserPrivilegeType(OLEConstants.PROFILE);
278 oleProfilePrivilege.setUserPrivilegeStatus(oleBorrowerTypeMap.get(olePatronDocument.getBorrowerType()).getBorrowerTypeName());
279 oleProfilePrivilege.setUserPrivilegeDescription(OLEConstants.PROFILE_DESCRIPTION);
280 userPrivilegeList.add(oleProfilePrivilege);
281 }
282 if (agencyId != null) {
283 String itemType, itemLocation = "";
284 HashMap<String, String> agencyPropertyMap = getAgencyPropertyMap(agencyId);
285 itemType = agencyPropertyMap.get(OLEConstants.ITEM_TYPE);
286 itemLocation = agencyPropertyMap.get(OLEConstants.ITEM_LOCATION);
287 OLEUserPrivilege oleUserPrivilege = new OLEUserPrivilege();
288 oleUserPrivilege.setUserPrivilegeType(OLEConstants.STATUS);
289 oleUserPrivilege.setUserPrivilegeDescription(OLEConstants.STATUS_DESCRIPTION);
290 oleUserPrivilege.setUserPrivilegeStatus(OLEConstants.OK);
291 if (olePatronDocument.isGeneralBlock() || isPatronExpired(olePatronDocument) || !olePatronDocument.isActiveIndicator() || isPatronActivated(olePatronDocument) || !isAbleToCheckOut(olePatronDocument.getOlePatronId(), olePatronDocument.getBorrowerTypeCode(), itemType, itemLocation))
292 oleUserPrivilege.setUserPrivilegeStatus(OLEConstants.BLOCKED);
293 userPrivilegeList.add(oleUserPrivilege);
294 }
295 return userPrivilegeList;
296 }
297 return null;
298 }
299
300 public boolean isPatronExpired(OlePatronDocument olePatronDocument) {
301
302 SimpleDateFormat fmt = new SimpleDateFormat(OLEConstants.OleDeliverRequest.DATE_FORMAT);
303 Date expirationDate = olePatronDocument.getExpirationDate();
304 if (expirationDate != null) {
305 if ((fmt.format(expirationDate)).compareTo(fmt.format(new Date(System.currentTimeMillis()))) > 0) {
306 return false;
307 } else {
308 return true;
309 }
310 }else{
311 return false;
312 }
313 }
314
315 public boolean isPatronActivated(OlePatronDocument olePatronDocument) {
316
317 SimpleDateFormat fmt = new SimpleDateFormat(OLEConstants.OleDeliverRequest.DATE_FORMAT);
318 Date activationDate = olePatronDocument.getActivationDate();
319 if (activationDate != null) {
320 if ((fmt.format(activationDate)).compareTo(fmt.format(new Date(System.currentTimeMillis()))) <= 0) {
321 return false;
322 } else {
323 return true;
324 }
325 } else {
326 return false;
327 }
328 }
329
330 public boolean isAbleToCheckOut(String patronId, String borrowerType, String itemType, String itemLocation) {
331 LOG.info("Inside isAbleToCheckOut method . Patron Id : " +patronId + " Borrower Type : " + borrowerType + " ItemType : "+itemType + " Item Location : " + itemLocation);
332 boolean allowed = true;
333 Long startTime = System.currentTimeMillis();
334 String agendaName = OLEConstants.CHECK_OUT_AGENDA_NM;
335 HashMap<String, Object> termValues = new HashMap<String, Object>();
336 List<FeeType> feeTypeList = oleCirculationPolicyService.getPatronBillPayment(patronId);
337 Integer overdueFineAmt = 0;
338 Integer replacementFeeAmt = 0;
339 for (FeeType feeType : feeTypeList) {
340 overdueFineAmt += feeType.getOleFeeType().getFeeTypeName().equalsIgnoreCase(OLEConstants.OVERDUE_FINE) ? feeType.getFeeAmount().intValue() : 0;
341 replacementFeeAmt += feeType.getOleFeeType().getFeeTypeName().equalsIgnoreCase(OLEConstants.REPLACEMENT_FEE) ? feeType.getFeeAmount().intValue() : 0;
342 }
343 String[] locationArray = itemLocation.split("['/']");
344 List<String> locationList = Arrays.asList(locationArray);
345 for (String value : locationList) {
346 Map<String, String> requestMap = new HashMap<>();
347 requestMap.put(OLEConstants.LOCATION_CODE, value);
348 List<OleLocation> oleLocations = (List<OleLocation>) businessObjectService.findMatching(OleLocation.class, requestMap);
349 if (oleLocations != null && oleLocations.size() > 0) {
350 String locationLevelId = oleLocations.get(0).getLevelId();
351 requestMap.clear();
352 requestMap.put(OLEConstants.LEVEL_ID, locationLevelId);
353 List<OleLocationLevel> oleLocationLevels = (List<OleLocationLevel>) businessObjectService.findMatching(OleLocationLevel.class, requestMap);
354 if (oleLocationLevels != null && oleLocationLevels.size() > 0) {
355 OleLocationLevel oleLocationLevel = new OleLocationLevel();
356 oleLocationLevel = oleLocationLevels.get(0);
357 if (oleLocationLevel.getLevelCode().equals(OLEConstants.OLEBatchProcess.LOCATION_LEVEL_CAMPUS)) {
358 termValues.put(OLEConstants.ITEM_CAMPUS, value);
359 } else if (oleLocationLevel.getLevelCode().equals(OLEConstants.OLEBatchProcess.LOCATION_LEVEL_INSTITUTION)) {
360 termValues.put(OLEConstants.ITEM_INSTITUTION, value);
361 } else if (oleLocationLevel.getLevelCode().equals(OLEConstants.OLEBatchProcess.LOCATION_LEVEL_COLLECTION)) {
362 termValues.put(OLEConstants.ITEM_COLLECTION, value);
363 } else if (oleLocationLevel.getLevelCode().equals(OLEConstants.OLEBatchProcess.LOCATION_LEVEL_LIBRARY)) {
364 termValues.put(OLEConstants.ITEM_LIBRARY, value);
365 } else if (oleLocationLevel.getLevelCode().equals(OLEConstants.OLEBatchProcess.LOCATION_LEVEL_SHELVING)) {
366 termValues.put(OLEConstants.ITEM_SHELVING, value);
367 }
368 }
369 }
370 }
371 termValues.put(OLEConstants.BORROWER_TYPE, borrowerType);
372 termValues.put(OLEConstants.ITEM_TYPE, itemType);
373
374 termValues.put(OLEConstants.OVERDUE_FINE_AMT, overdueFineAmt);
375 termValues.put(OLEConstants.REPLACEMENT_FEE_AMT, replacementFeeAmt);
376 termValues.put(OLEConstants.ALL_CHARGES, overdueFineAmt + replacementFeeAmt);
377
378
379 DataCarrierService dataCarrierService = GlobalResourceLoader.getService(OLEConstants.DATA_CARRIER_SERVICE);
380 String itemId = "";
381 dataCarrierService.removeData(patronId+itemId);
382 dataCarrierService.addData(OLEConstants.GROUP_ID, "100");
383 HashMap keyLoanMap=new HashMap();
384 keyLoanMap=oleCirculationPolicyService.getLoanedKeyMap(patronId,false);
385 List<Integer> listOfOverDueDays =(List<Integer>)keyLoanMap.get(OLEConstants.LIST_OF_OVERDUE_DAYS);
386 dataCarrierService.addData(OLEConstants.LIST_OVERDUE_DAYS, listOfOverDueDays);
387
388 dataCarrierService.addData(OLEConstants.LIST_RECALLED_OVERDUE_DAYS, (List<Integer>) keyLoanMap.get(OLEConstants.LIST_RECALLED_OVERDUE_DAYS));
389 termValues.put(OLEConstants.PATRON_ID_POLICY, patronId);
390 termValues.put(OLEConstants.ITEM_ID_POLICY, "");
391 try {
392 EngineResults engineResults = getLoanProcessor().getEngineResults(agendaName, termValues);
393 dataCarrierService.removeData(patronId+itemId);
394 List<ResultEvent> allResults = engineResults.getAllResults();
395 for (Iterator<ResultEvent> resultEventIterator = allResults.iterator(); resultEventIterator.hasNext(); ) {
396 ResultEvent resultEvent = resultEventIterator.next();
397 if (resultEvent.getSource() instanceof BasicRule) {
398 BasicRule basicRule = (BasicRule) resultEvent.getSource();
399 if (resultEvent.getType().equals(OLEConstants.RULE_EVALUATED) && ((basicRule.getName().equals(OLENCIPConstants.CHECK_REPLACEMENT_FEE_AMT) && resultEvent.getResult())
400 || (basicRule.getName().equals(OLENCIPConstants.CHECK_ALL_OVERDUE_FINE_AMT) && resultEvent.getResult()) || (basicRule.getName().equals(OLENCIPConstants.CHECK_OVERALL_CHARGES) && resultEvent.getResult()))) {
401
402 allowed = false;
403 break;
404 }
405 }
406 }
407 List<String> errorMessage = (List<String>) engineResults.getAttribute(OLEConstants.ERROR_ACTION);
408 if (errorMessage != null && errorMessage.size() > 0) {
409 allowed = false;
410 }
411 } catch (Exception e) {
412 LOG.info("Exception Occured while evaluating the KRMS rules");
413 LOG.error(e, e);
414 }
415 Long endTime =System.currentTimeMillis();
416 Long timeDifference = endTime-startTime;
417 LOG.info("Time taken for the krms fro getting the patron status " + timeDifference);
418 return allowed;
419 }
420
421 public String checkOutItem(String patronId, String operatorId, String itemBarcode, boolean isSIP2Request) {
422 LOG.info("In Check Out Item . Patron Barcode : "+patronId + " OperatorId : " +operatorId + "Item Barcode : "+itemBarcode);
423 OlePatronDocument olePatronDocument = null;
424 if(itemBarcode == null ||( itemBarcode!=null && itemBarcode.trim().isEmpty())){
425 OLECheckOutItem oleCheckOutItem = new OLECheckOutItem();
426 oleCheckOutItem.setCode("900");
427 oleCheckOutItem.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.ITEM_BARCODE_REQUIRED));
428 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.ITEM_BARCODE_REQUIRED));
429 return oleCheckOutItemConverter.generateCheckOutItemXml(oleCheckOutItem);
430 }
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447 OleLoanDocument oleLoanDocument;
448 try {
449 try{
450 oleLoanDocument = getLoanProcessor().getLoanDocument(patronId, null, true, false);
451 olePatronDocument = oleLoanDocument.getOlePatron();
452 }catch (Exception e){
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 if(isSIP2Request){
458 return oleCheckOutItemConverter.generateCheckOutItemXmlForSIP2(oleCheckOutItem);
459 }else{
460 return oleCheckOutItemConverter.generateCheckOutItemXml(oleCheckOutItem);
461 }
462 }
463 long t66 = System.currentTimeMillis();
464 oleLoanDocument.setLoanOperatorId(operatorId);
465 Map<String, String> circulationDeskDetailMaps = new HashMap<String, String>();
466 circulationDeskDetailMaps.put(OLENCIPConstants.OPERATOR_ID, operatorId);
467 circulationDeskDetailMaps.put("defaultLocation", "Y");
468 List<OleCirculationDeskDetail> oleCirculationDeskDetailList = (List<OleCirculationDeskDetail>) businessObjectService.findMatching(OleCirculationDeskDetail.class, circulationDeskDetailMaps);
469 if (oleCirculationDeskDetailList != null && oleCirculationDeskDetailList.size() > 0) {
470 for (OleCirculationDeskDetail oleCirculationDeskDetail : oleCirculationDeskDetailList) {
471 if (oleCirculationDeskDetail.isDefaultLocation()) {
472 String circulationDeskId = oleCirculationDeskDetail.getCirculationDeskId();
473 oleLoanDocument.setCirculationLocationId(circulationDeskId);
474 if(oleCirculationDeskDetail.getOleCirculationDesk()!=null){
475 oleLoanDocument.setOleCirculationDesk(oleCirculationDeskDetail.getOleCirculationDesk());
476 }else{
477 Map<String, String> circulationMap = new HashMap<String, String>();
478 circulationMap.put(OLEConstants.CIRCULATION_DESK_ID, circulationDeskId);
479 List<OleCirculationDesk> oleCirculationDeskList = (List<OleCirculationDesk>) businessObjectService.findMatching(OleCirculationDesk.class, circulationMap);
480 if (oleCirculationDeskList.size() > 0){
481 oleLoanDocument.setOleCirculationDesk(oleCirculationDeskList.get(0));
482 break;
483 }
484 }
485 }
486 }
487 } else {
488 OLECheckOutItem oleCheckOutItem = new OLECheckOutItem();
489 oleCheckOutItem.setCode("026");
490 oleCheckOutItem.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.CIRCULATION_DESK_NOT_MAPPED_OPERATOR));
491 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.CIRCULATION_DESK_NOT_MAPPED_OPERATOR));
492 if(isSIP2Request){
493 return oleCheckOutItemConverter.generateCheckOutItemXmlForSIP2(oleCheckOutItem);
494 }else{
495 return oleCheckOutItemConverter.generateCheckOutItemXml(oleCheckOutItem);
496 }
497 }
498 if (oleLoanDocument.getErrorMessage() == null || (oleLoanDocument.getErrorMessage() != null && oleLoanDocument.getErrorMessage().isEmpty())) {
499 if (olePatronDocument != null) {
500 oleLoanDocument.setLoanOperatorId(operatorId);
501 oleLoanDocument = getLoanProcessor().addLoan(olePatronDocument.getBarcode(), itemBarcode, oleLoanDocument, operatorId);
502 if (oleLoanDocument.getErrorMessage() == null || (oleLoanDocument.getErrorMessage() != null && oleLoanDocument.getErrorMessage().isEmpty())) {
503 OLECheckOutItem oleCheckOutItem = new OLECheckOutItem();
504 oleCheckOutItem.setDueDate(oleLoanDocument.getLoanDueDate() != null ? oleLoanDocument.getLoanDueDate().toString() : "");
505 oleCheckOutItem.setRenewalCount(oleLoanDocument.getNumberOfRenewals());
506 oleCheckOutItem.setUserType(oleLoanDocument.getBorrowerTypeName());
507 oleCheckOutItem.setBarcode(oleLoanDocument.getItemId());
508 oleCheckOutItem.setPatronId(oleLoanDocument.getPatronId());
509 oleCheckOutItem.setPatronBarcode(patronId);
510 if (oleLoanDocument.getOleItem() != null && oleLoanDocument.getOleItem().getItemType() != null) {
511 oleCheckOutItem.setItemType(oleLoanDocument.getOleItem().getItemType().getCodeValue());
512 }
513 oleCheckOutItem.setCode("030");
514 oleCheckOutItem.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.SUCCESSFULLEY_LOANED));
515 oleCheckOutItem.setItemProperties("Author : " + oleLoanDocument.getAuthor() + " , Status : " + oleLoanDocument.getItemStatus());
516 oleCheckOutItem.setItemType(oleLoanDocument.getItemType());
517 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.SUCCESSFULLEY_LOANED));
518 if(isSIP2Request){
519 return oleCheckOutItemConverter.generateCheckOutItemXmlForSIP2(oleCheckOutItem);
520 }else{
521 return oleCheckOutItemConverter.generateCheckOutItemXml(oleCheckOutItem);
522 }
523
524 } else {
525 if (oleLoanDocument.getOleItem() != null && oleLoanDocument.getOleItem().getLocation() == null) {
526 OLECheckOutItem oleCheckOutItem = new OLECheckOutItem();
527 oleCheckOutItem.setCode("028");
528 oleCheckOutItem.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.INVAL_LOC));
529 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.INVAL_LOC));
530 if(isSIP2Request){
531 return oleCheckOutItemConverter.generateCheckOutItemXmlForSIP2(oleCheckOutItem);
532 }else{
533 return oleCheckOutItemConverter.generateCheckOutItemXml(oleCheckOutItem);
534 }
535 } else if (oleLoanDocument.getOleItem() != null && oleLoanDocument.getOleItem().getItemStatus() != null &&
536 oleLoanDocument.getOleItem().getItemStatus().getCodeValue() != null && oleLoanDocument.getOleItem().getItemStatus().getCodeValue().equalsIgnoreCase("LOANED")) {
537
538 OLECheckOutItem oleCheckOutItem = new OLECheckOutItem();
539 oleCheckOutItem.setCode("100");
540 oleCheckOutItem.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.ITEM_IN_LOAN));
541 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.ITEM_IN_LOAN));
542 if(isSIP2Request){
543 return oleCheckOutItemConverter.generateCheckOutItemXmlForSIP2(oleCheckOutItem);
544 }else{
545 return oleCheckOutItemConverter.generateCheckOutItemXml(oleCheckOutItem);
546 }
547 } else if(oleLoanDocument != null && oleLoanDocument.getErrorMessage() !=null && oleLoanDocument.getErrorMessage().equalsIgnoreCase(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.ITEM_BARCODE_DOESNOT_EXISTS))){
548 OLECheckOutItem oleCheckOutItem = new OLECheckOutItem();
549 oleCheckOutItem.setCode("014");
550 oleCheckOutItem.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.ITEM_BARCODE_DOESNOT_EXISTS));
551 LOG.info(oleLoanDocument.getErrorMessage());
552 if(isSIP2Request){
553 return oleCheckOutItemConverter.generateCheckOutItemXmlForSIP2(oleCheckOutItem);
554 }else{
555 return oleCheckOutItemConverter.generateCheckOutItemXml(oleCheckOutItem);
556 }
557 }else {
558 OLECheckOutItem oleCheckOutItem = new OLECheckOutItem();
559 oleCheckOutItem.setCode("500");
560 oleCheckOutItem.setMessage(oleLoanDocument.getErrorMessage());
561 LOG.info(oleLoanDocument.getErrorMessage());
562 if(isSIP2Request){
563 return oleCheckOutItemConverter.generateCheckOutItemXmlForSIP2(oleCheckOutItem);
564 }else{
565 return oleCheckOutItemConverter.generateCheckOutItemXml(oleCheckOutItem);
566 }
567 }
568 }
569 } else {
570 OLECheckOutItem oleCheckOutItem = new OLECheckOutItem();
571 oleCheckOutItem.setCode("500");
572 oleCheckOutItem.setMessage(oleLoanDocument.getErrorMessage());
573 LOG.info(oleLoanDocument.getErrorMessage());
574 if(isSIP2Request){
575 return oleCheckOutItemConverter.generateCheckOutItemXmlForSIP2(oleCheckOutItem);
576 }else{
577 return oleCheckOutItemConverter.generateCheckOutItemXml(oleCheckOutItem);
578 }
579 }
580 } else {
581 OLECheckOutItem oleCheckOutItem = new OLECheckOutItem();
582 oleCheckOutItem.setCode("500");
583 oleCheckOutItem.setMessage(oleLoanDocument.getErrorMessage());
584 LOG.info(oleLoanDocument.getErrorMessage());
585 if(isSIP2Request){
586 return oleCheckOutItemConverter.generateCheckOutItemXmlForSIP2(oleCheckOutItem);
587 }else{
588 return oleCheckOutItemConverter.generateCheckOutItemXml(oleCheckOutItem);
589 }
590 }
591 } catch (Exception e) {
592 OLECheckOutItem oleCheckOutItem = new OLECheckOutItem();
593 if(e.getCause()!= null && (e.getCause().getMessage()).contains("Duplicate entry")){
594 oleCheckOutItem.setCode("100");
595 oleCheckOutItem.setMessage("Item is already Loaned by a patron.");
596 }else if(e.getLocalizedMessage() == null){
597 oleCheckOutItem.setCode("500");
598 oleCheckOutItem.setMessage("Internal error");
599 } else {
600 oleCheckOutItem.setCode("014");
601 oleCheckOutItem.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.ITEM_BARCODE_DOESNOT_EXISTS));
602 }
603 LOG.info(oleCheckOutItem.getMessage());
604 LOG.error(e, e);
605 if(isSIP2Request){
606 return oleCheckOutItemConverter.generateCheckOutItemXmlForSIP2(oleCheckOutItem);
607 }else{
608 return oleCheckOutItemConverter.generateCheckOutItemXml(oleCheckOutItem);
609 }
610 }
611 }
612
613 public String checkInItem(String patronBarcode, String operatorId, String itemBarcode, String deleteIndicator, boolean isSIP2Request) {
614 LOG.info("Inside checkInItem method .Patron barcode : " + patronBarcode + " Operator Id : " +operatorId + " Item Barcode : " + itemBarcode );
615
616 OleLoanDocument oleLoanDocument = null;
617 OLECheckInItem oleCheckInItem = new OLECheckInItem();
618 try {
619
620
621 if (itemBarcode != null) {
622 oleLoanDocument = getLoanProcessor().getOleLoanDocumentUsingItemBarcode(itemBarcode);
623 } else {
624 oleLoanDocument = getLoanProcessor().getOleLoanDocumentUsingItemUUID(itemBarcode);
625 }
626 if (oleLoanDocument == null) {
627 oleLoanDocument = new OleLoanDocument();
628 }
629 Map<String, String> circulationDeskDetailMap = new HashMap<String, String>();
630 circulationDeskDetailMap.put(OLENCIPConstants.OPERATOR_ID, operatorId);
631 circulationDeskDetailMap.put("defaultLocation", "Y");
632 List<OleCirculationDeskDetail> oleCirculationDeskDetailList = (List<OleCirculationDeskDetail>) businessObjectService.findMatching(OleCirculationDeskDetail.class, circulationDeskDetailMap);
633 if (oleCirculationDeskDetailList != null && oleCirculationDeskDetailList.size() > 0) {
634 for (OleCirculationDeskDetail oleCirculationDeskDetail : oleCirculationDeskDetailList) {
635 if (oleCirculationDeskDetail.isDefaultLocation()) {
636 String circulationDeskId = oleCirculationDeskDetail.getCirculationDeskId();
637 oleLoanDocument.setCirculationLocationId(circulationDeskId);
638 if(oleCirculationDeskDetail.getOleCirculationDesk()!=null){
639 oleLoanDocument.setOleCirculationDesk(oleCirculationDeskDetail.getOleCirculationDesk());
640 }else{
641 Map<String, String> circulationMap = new HashMap<String, String>();
642 circulationMap.put(OLEConstants.CIRCULATION_DESK_ID, circulationDeskId);
643 List<OleCirculationDesk> oleCirculationDeskList = (List<OleCirculationDesk>) businessObjectService.findMatching(OleCirculationDesk.class, circulationMap);
644 if (oleCirculationDeskList.size() > 0){
645 oleLoanDocument.setOleCirculationDesk(oleCirculationDeskList.get(0));
646 break;
647 }
648 }
649 }
650 }
651 oleLoanDocument = getLoanProcessor().returnLoan(itemBarcode, oleLoanDocument);
652 oleCheckInItem.setAuthor(oleLoanDocument.getAuthor());
653 oleCheckInItem.setTitle(oleLoanDocument.getTitle());
654 oleCheckInItem.setCallNumber(oleLoanDocument.getItemCallNumber());
655 oleCheckInItem.setBarcode(oleLoanDocument.getPatronBarcode());
656 oleCheckInItem.setUserId(oleLoanDocument.getPatronBarcode());
657 oleCheckInItem.setUserType(oleLoanDocument.getBorrowerTypeName());
658 if (oleLoanDocument.getOleItem() != null && oleLoanDocument.getOleItem().getItemType() != null) {
659 oleCheckInItem.setItemType(oleLoanDocument.getOleItem().getItemType().getCodeValue());
660 }
661 if (oleLoanDocument.getErrorMessage() == null || (oleLoanDocument.getErrorMessage() != null && oleLoanDocument.getErrorMessage().isEmpty())) {
662 oleCheckInItem.setCode("024");
663 oleCheckInItem.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.SUCCESSFULLEY_CHECKED_IN));
664 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.SUCCESSFULLEY_CHECKED_IN));
665 if (deleteIndicator!=null && deleteIndicator.equalsIgnoreCase("y")) {
666
667 org.kuali.ole.docstore.common.document.Item item = getDocstoreClientLocator().getDocstoreClient().retrieveItem(oleLoanDocument.getItemUuid());
668 String bibId = item.getHolding().getBib().getId();
669
670 getDocstoreClientLocator().getDocstoreClient().deleteBib(bibId);
671 }
672 if(isSIP2Request){
673 return oleCheckInItemConverter.generateCheckInItemXmlForSIP2(oleCheckInItem);
674 }else{
675 return oleCheckInItemConverter.generateCheckInItemXml(oleCheckInItem);
676 }
677
678 } else {
679 oleCheckInItem.setCode("500");
680 oleCheckInItem.setMessage(oleLoanDocument.getErrorMessage());
681 LOG.info(oleLoanDocument.getErrorMessage());
682 if(isSIP2Request){
683 return oleCheckInItemConverter.generateCheckInItemXmlForSIP2(oleCheckInItem);
684 }else{
685 return oleCheckInItemConverter.generateCheckInItemXml(oleCheckInItem);
686 }
687 }
688 } else {
689 oleCheckInItem.setCode("025");
690 oleCheckInItem.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.CHECK_IN_FAILED));
691 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.CHECK_IN_FAILED));
692 if(isSIP2Request){
693 return oleCheckInItemConverter.generateCheckInItemXmlForSIP2(oleCheckInItem);
694 }else{
695 return oleCheckInItemConverter.generateCheckInItemXml(oleCheckInItem);
696 }
697 }
698 } catch (Exception e) {
699 if(e.getMessage()!=null && (e.getMessage().equals(OLEConstants.ITM_BARCD_NT_AVAL_DOC)||e.getMessage().equals(OLEConstants.INVAL_ITEM) ||e.getMessage().equals(OLEConstants.ITM_STS_NT_AVAL)||e.getMessage().equals(OLEConstants.NO_LOC_CIR_DESK))){
700 oleCheckInItem.setCode("014");
701 oleCheckInItem.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.CHECK_IN_FAILED) + "." + e.getMessage());
702 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(e.getMessage()));
703 LOG.error(e,e);
704 if(isSIP2Request){
705 return oleCheckInItemConverter.generateCheckInItemXmlForSIP2(oleCheckInItem);
706 }else{
707 return oleCheckInItemConverter.generateCheckInItemXml(oleCheckInItem);
708 }
709 }
710
711 oleCheckInItem.setCode("025");
712 oleCheckInItem.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.CHECK_IN_FAILED));
713 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.CHECK_IN_FAILED));
714 if(isSIP2Request){
715 return oleCheckInItemConverter.generateCheckInItemXmlForSIP2(oleCheckInItem);
716 }else{
717 return oleCheckInItemConverter.generateCheckInItemXml(oleCheckInItem);
718 }
719 }
720 }
721
722 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 {
723 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 );
724 OLEAcceptItem oleAcceptItem = new OLEAcceptItem();
725 String itemIdentifier = null;
726 if (docstoreUtil.isItemAvailableInDocStore(itemBarcode)) {
727 return itemIdentifier;
728 }
729 BibMarcRecord bibMarcRecord = getLoanProcessor().getBibMarcRecord(title, author);
730
731 List<BibMarcRecord> bibMarcRecordList = new ArrayList<>();
732 bibMarcRecordList.add(bibMarcRecord);
733
734 BibMarcRecords bibMarcRecords = new BibMarcRecords();
735 bibMarcRecords.setRecords(bibMarcRecordList);
736 BibMarcRecordProcessor bibMarcRecordProcessor = new BibMarcRecordProcessor();
737
738
739 Bib bib = new BibMarc();
740 bib.setStaffOnly(true);
741 bib.setCategory(org.kuali.ole.docstore.common.document.content.enums.DocCategory.WORK.getCode());
742 bib.setType(org.kuali.ole.docstore.common.document.content.enums.DocType.BIB.getCode());
743 bib.setFormat(org.kuali.ole.docstore.common.document.content.enums.DocFormat.MARC.getCode());
744 bib.setContent(bibMarcRecordProcessor.toXml(bibMarcRecords));
745 bib.setOperation(DocstoreDocument.OperationType.CREATE);
746
747
748 OleHoldings oleHoldings = new OleHoldings();
749 LocationLevel locationLevel = new LocationLevel();
750 locationLevel = getLoanProcessor().createLocationLevel(itemLocation, locationLevel);
751 Location holdingsLocation = new Location();
752 holdingsLocation.setPrimary(OLEConstants.TRUE);
753 holdingsLocation.setStatus(OLEConstants.PERMANENT);
754 holdingsLocation.setLocationLevel(locationLevel);
755 oleHoldings.setLocation(holdingsLocation);
756 oleHoldings.setStaffOnlyFlag(true);
757 Item item = new Item();
758
759 AccessInformation accessInformation = new AccessInformation();
760 accessInformation.setBarcode(itemBarcode);
761 item.setAccessInformation(accessInformation);
762 item.setStaffOnlyFlag(true);
763 ItemStatus itemStatus = new ItemStatus();
764 itemStatus.setCodeValue(OLEConstants.AVAILABLE);
765 item.setItemStatus(itemStatus);
766 ItemType type = new ItemType();
767 type.setCodeValue(itemType);
768 item.setItemType(type);
769 CallNumber itemCallNumber = new CallNumber();
770 itemCallNumber.setNumber(callNumber);
771 item.setCallNumber(itemCallNumber);
772 ShelvingScheme shelvingScheme = new ShelvingScheme();
773 shelvingScheme.setCodeValue(OLEConstants.LCC);
774 itemCallNumber.setShelvingScheme(shelvingScheme);
775
776 item.setLocation(holdingsLocation);
777 ItemOlemlRecordProcessor itemOlemlRecordProcessor = new ItemOlemlRecordProcessor();
778 org.kuali.ole.docstore.common.document.Item documentItem = new ItemOleml();
779 documentItem.setContent(itemOlemlRecordProcessor.toXML(item));
780 documentItem.setStaffOnly(true);
781 documentItem.setOperation(DocstoreDocument.OperationType.CREATE);
782 Holdings holdings = new PHoldings();
783 holdings.setStaffOnly(true);
784 HoldingOlemlRecordProcessor holdingOlemlRecordProcessor = new HoldingOlemlRecordProcessor();
785 holdings.setContent(holdingOlemlRecordProcessor.toXML(oleHoldings));
786 holdings.setOperation(DocstoreDocument.OperationType.CREATE);
787 HoldingsTree holdingsTree = new HoldingsTree();
788 holdingsTree.setHoldings(holdings);
789 holdingsTree.getItems().add(documentItem);
790 BibTree bibTree = new BibTree();
791 bibTree.setBib(bib);
792 bibTree.getHoldingsTrees().add(holdingsTree);
793 BibTrees bibTrees = new BibTrees();
794 bibTrees.getBibTrees().add(bibTree);
795 bibTrees=getDocstoreClientLocator().getDocstoreClient().processBibTrees(bibTrees);
796 Thread.sleep(200);
797 if(bibTrees!=null && bibTrees.getBibTrees()!=null && bibTrees.getBibTrees().size()>0 &&bibTrees.getBibTrees().get(0).getHoldingsTrees()!=null && bibTrees.getBibTrees().get(0).getHoldingsTrees().size()>0
798 && bibTrees.getBibTrees().get(0).getHoldingsTrees().get(0).getItems() != null && bibTrees.getBibTrees().get(0).getHoldingsTrees().get(0).getItems().size()>0 ){
799 itemIdentifier= bibTrees.getBibTrees().get(0).getHoldingsTrees().get(0).getItems().get(0).getId();
800 }else{
801 itemIdentifier="";
802 }
803 LOG.info("Item Created with identifier : " + itemIdentifier);
804 return itemIdentifier;
805 }
806
807 public HashMap<String, String> getAgencyPropertyMap(String agencyId) {
808 HashMap<String, String> agencyPropertyMap = new HashMap<String, String>();
809 agencyPropertyMap = getOleSIAPIHelperService().getAgencyPropertyMap(OLEConstants.DLVR_NMSPC, OLEConstants.DLVR_CMPNT, OLENCIPConstants.NCIPAPI_PARAMETER_NAME, agencyId, agencyPropertyMap);
810 return agencyPropertyMap;
811 }
812
813 public String renewItem(String patronBarcode, String operatorId, String itemBarcode, boolean isSIP2Request) {
814 LOG.info("Inside Renew Item . Patron Barcode : " + patronBarcode + "Operator Id : "+ operatorId + " Item Barcode : " +itemBarcode);
815 OLERenewItem oleRenewItem = new OLERenewItem();
816 OLERenewItemConverter oleRenewItemConverter = new OLERenewItemConverter();
817 OlePatronDocument olePatronDocument = null;
818 Map<String, String> patronMap = new HashMap<String, String>();
819 patronMap.put(OLEConstants.BARCODE, patronBarcode);
820 List<OlePatronDocument> patronDocuments = (List<OlePatronDocument>) businessObjectService.findMatching(OlePatronDocument.class, patronMap);
821 if (patronDocuments.size() > 0) {
822 olePatronDocument = patronDocuments.get(0);
823 } else {
824 oleRenewItem.setCode("002");
825 oleRenewItem.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.NO_PATRON_INFO));
826 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.NO_PATRON_INFO));
827 if(isSIP2Request){
828 return oleRenewItemConverter.generateRenewItemXmlForSIP2(oleRenewItem);
829 }else{
830 return oleRenewItemConverter.generateRenewItemXml(oleRenewItem);
831 }
832 }
833 if (!getLoanProcessor().hasCirculationDesk(operatorId)) {
834 oleRenewItem.setCode("001");
835 oleRenewItem.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.INVALID_OPRTR_ID));
836 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.INVALID_OPRTR_ID));
837 if(isSIP2Request){
838 return oleRenewItemConverter.generateRenewItemXmlForSIP2(oleRenewItem);
839 }else{
840 return oleRenewItemConverter.generateRenewItemXml(oleRenewItem);
841 }
842 }
843 Map<String, String> loanMap = new HashMap<String, String>();
844 loanMap.put(OLEConstants.PATRON_ID, olePatronDocument.getOlePatronId());
845 loanMap.put(OLEConstants.OleDeliverRequest.ITEM_ID, itemBarcode);
846 List<OleLoanDocument> loanDocuments = (List<OleLoanDocument>) businessObjectService.findMatching(OleLoanDocument.class, loanMap);
847 if (loanDocuments.size() > 0) {
848 OleLoanDocument oleLoanDocument = loanDocuments.get(0);
849
850 if (patronDocuments.size() > 0) {
851 oleLoanDocument.setOlePatron(olePatronDocument);
852 oleLoanDocument.setBorrowerTypeCode(olePatronDocument.getBorrowerTypeCode());
853 oleLoanDocument.setBorrowerTypeId(olePatronDocument.getBorrowerType());
854 oleLoanDocument.setOleBorrowerType(olePatronDocument.getOleBorrowerType());
855 oleLoanDocument.setBorrowerTypeName(olePatronDocument.getBorrowerTypeName());
856 }
857 oleLoanDocument.setRenewalItemFlag(true);
858 oleLoanDocument.setErrorMessage(null);
859 if (getLoanProcessor().canOverrideLoan(operatorId)) {
860 if (!getLoanProcessor().checkPendingRequestforItem(oleLoanDocument.getItemUuid())) {
861 Timestamp currentDate = new Timestamp(System.currentTimeMillis());
862 try {
863 oleLoanDocument = getLoanProcessor().addLoan(oleLoanDocument.getPatronBarcode(), oleLoanDocument.getItemId(), oleLoanDocument, operatorId);
864 if (oleLoanDocument.getErrorMessage() == null || (oleLoanDocument.getErrorMessage() != null && oleLoanDocument.getErrorMessage().trim().isEmpty())) {
865 oleRenewItem.setCode("003");
866 oleRenewItem.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.RENEW_SUCCESS));
867 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.RENEW_SUCCESS));
868 oleRenewItem.setPastDueDate(oleLoanDocument.getPastDueDate().toString());
869 oleRenewItem.setNewDueDate(oleLoanDocument.getLoanDueDate() != null ? oleLoanDocument.getLoanDueDate().toString() : "");
870 oleRenewItem.setRenewalCount(oleLoanDocument.getNumberOfRenewals());
871 oleRenewItem.setPatronBarcode(olePatronDocument.getBarcode());
872 oleRenewItem.setItemBarcode(oleLoanDocument.getItemId());
873 oleRenewItem.setTitleIdentifier(oleLoanDocument.getTitle());
874
875
876 oleRenewItem.setItemProperties("Author="+oleLoanDocument.getAuthor());
877 oleRenewItem.setMediaType(oleLoanDocument.getItemType());
878 if(isSIP2Request){
879 return oleRenewItemConverter.generateRenewItemXmlForSIP2(oleRenewItem);
880 }else{
881 return oleRenewItemConverter.generateRenewItemXml(oleRenewItem);
882 }
883 } else {
884 oleRenewItem.setCode("500");
885 oleRenewItem.setMessage(oleLoanDocument.getErrorMessage());
886 LOG.info(oleLoanDocument.getErrorMessage());
887 if(isSIP2Request){
888 return oleRenewItemConverter.generateRenewItemXmlForSIP2(oleRenewItem);
889 }else{
890 return oleRenewItemConverter.generateRenewItemXml(oleRenewItem);
891 }
892
893 }
894 } catch (Exception e) {
895 LOG.error(e,e);
896 return "Exception occurred while renewing an item";
897 }
898
899 } else {
900 oleRenewItem.setCode("009");
901 oleRenewItem.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.RQST_PNDNG));
902 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.RQST_PNDNG));
903 if(isSIP2Request){
904 return oleRenewItemConverter.generateRenewItemXmlForSIP2(oleRenewItem);
905 }else{
906 return oleRenewItemConverter.generateRenewItemXml(oleRenewItem);
907 }
908 }
909 } else {
910 oleRenewItem.setCode("010");
911 oleRenewItem.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.NO_RENEW));
912 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.NO_RENEW));
913 if(isSIP2Request){
914 return oleRenewItemConverter.generateRenewItemXmlForSIP2(oleRenewItem);
915 }else{
916 return oleRenewItemConverter.generateRenewItemXml(oleRenewItem);
917 }
918 }
919 } else {
920 oleRenewItem.setCode("011");
921 oleRenewItem.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.ITM_NT_LOAN));
922 LOG.info(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.ITM_NT_LOAN));
923 if(isSIP2Request){
924 return oleRenewItemConverter.generateRenewItemXmlForSIP2(oleRenewItem);
925 }else{
926 return oleRenewItemConverter.generateRenewItemXml(oleRenewItem);
927 }
928 }
929 }
930
931
932 public String renewItemList(String patronBarcode, String operatorId, String itemBarcodeList, boolean isSIP2Request) {
933 LOG.info("Inside Renew Item . Patron Barcode : " + patronBarcode + "Operator Id : "+ operatorId + " Item Barcode : " +itemBarcodeList);
934 OLERenewItem oleRenewItemPatron = new OLERenewItem();
935 OLERenewItemList oleRenewItemList = new OLERenewItemList();
936 OLERenewItemConverter oleRenewItemConverter = new OLERenewItemConverter();
937 List<OLERenewItem> oleRenewItems = new ArrayList<>();
938 OlePatronDocument olePatronDocument = null;
939 StringBuffer errorMessage = new StringBuffer();
940 Map<String, String> patronMap = new HashMap<String, String>();
941 patronMap.put(OLEConstants.BARCODE, patronBarcode);
942 Long beginLocation = System.currentTimeMillis();
943 List<OlePatronDocument> patronDocuments = (List<OlePatronDocument>) businessObjectService.findMatching(OlePatronDocument.class, patronMap);
944 Long endLocation = System.currentTimeMillis();
945 Long timeTakenLocation = endLocation-beginLocation;
946 LOG.info("The Time Taken for Patron call using vufind"+timeTakenLocation);
947 if (patronDocuments.size() > 0) {
948 olePatronDocument = patronDocuments.get(0);
949 } else {
950 oleRenewItems = errorCode002(oleRenewItemPatron, oleRenewItems);
951 oleRenewItemList.setRenewItemList(oleRenewItems);
952 if(isSIP2Request){
953 return oleRenewItemConverter.generateRenewItemListXmlForSip2(oleRenewItemList);
954 }else{
955
956 return oleRenewItemConverter.generateRenewItemListXml(oleRenewItemList);
957 }
958 }
959 if (!getLoanProcessor().hasCirculationDesk(operatorId)) {
960 oleRenewItems = errorCode001(oleRenewItemPatron,oleRenewItems);
961 oleRenewItemList.setRenewItemList(oleRenewItems);
962 if(isSIP2Request){
963 return oleRenewItemConverter.generateRenewItemListXmlForSip2(oleRenewItemList);
964 }else{
965
966 return oleRenewItemConverter.generateRenewItemListXml(oleRenewItemList);
967 }
968 }
969 String[] itemBarcode = itemBarcodeList.split(",");
970 if(itemBarcode != null && itemBarcode.length>1){
971 List renewalItemList = new ArrayList();
972 for(int j=0;j<=itemBarcode.length-1;j++){
973 renewalItemList.add(itemBarcode[j]);
974 }
975 Long beginItem = System.currentTimeMillis();
976 List<OleLoanDocument> loanDocuments = (List<OleLoanDocument>) getLoanProcessor().getLoanObjectFromDAOForRenewal(renewalItemList,olePatronDocument.getOlePatronId());
977 Long endItem = System.currentTimeMillis();
978 Long timeTakenItem = endItem-beginItem;
979 LOG.info("The Time Taken to fetch item from loan table using vufind"+timeTakenItem);
980 if(loanDocuments != null && loanDocuments.size() > 0 ){
981 for(int j=0;j<=itemBarcode.length-1;j++){
982 OLERenewItem oleRenewItem = new OLERenewItem();
983 boolean barcodeFlag = true;
984 nextItem:{
985 for(int i=0;i<loanDocuments.size();i++){
986 if(itemBarcode[j].equals(loanDocuments.get(i).getItemId())){
987 OleLoanDocument oleLoanDocument = loanDocuments.get(i);
988 barcodeFlag = false;
989 oleLoanDocument = setPatronInformation(patronDocuments,olePatronDocument,oleLoanDocument);
990 if (getLoanProcessor().canOverrideLoan(operatorId)) {
991 if (!getLoanProcessor().checkPendingRequestforItem(oleLoanDocument.getItemUuid())) {
992 try {
993 oleLoanDocument.setVuFindFlag(true);
994 Long beginItemRenewal = System.currentTimeMillis();
995 oleLoanDocument = getLoanProcessor().addLoan(oleLoanDocument.getPatronBarcode(), oleLoanDocument.getItemId(), oleLoanDocument, operatorId);
996 Long endItemRenewal = System.currentTimeMillis();
997 Long timeTakenRenewal = endItemRenewal-beginItemRenewal;
998 LOG.info("The Time Taken for item renewal using vufind"+timeTakenRenewal);
999 if (oleLoanDocument.getErrorMessage() == null || (oleLoanDocument.getErrorMessage() != null && oleLoanDocument.getErrorMessage().trim().isEmpty())) {
1000 oleRenewItem = errorCode003(oleRenewItem,oleLoanDocument,itemBarcode[j]);
1001 oleRenewItem = populateRenewItemForSip2(olePatronDocument,oleLoanDocument,oleRenewItem);
1002 oleRenewItems.add(oleRenewItem);
1003 break nextItem;
1004 } else {
1005 oleRenewItem = errorCode500(oleRenewItem,oleLoanDocument,itemBarcode[j]);
1006 oleRenewItems.add(oleRenewItem);
1007
1008 break nextItem;
1009 }
1010 } catch (Exception e) {
1011 LOG.error(e,e);
1012 return "Exception occured while renewing an item";
1013 }
1014 } else {
1015 oleRenewItem = errorCode009(oleRenewItem,itemBarcode[j]);
1016 oleRenewItems.add(oleRenewItem);
1017 break nextItem;
1018 }
1019 } else {
1020 oleRenewItem = errorCode010(oleRenewItem,itemBarcode[j]);
1021 oleRenewItems.add(oleRenewItem);
1022 break nextItem;
1023 }
1024 }
1025 }
1026 }
1027 if(barcodeFlag){
1028 oleRenewItem = errorCode011(oleRenewItem, itemBarcode[j]);
1029 oleRenewItems.add(oleRenewItem);
1030 }
1031 }
1032 }
1033 } else {
1034
1035 Map<String, String> loanMap = new HashMap<String, String>();
1036 loanMap.put(OLEConstants.PATRON_ID, olePatronDocument.getOlePatronId());
1037 loanMap.put(OLEConstants.OleDeliverRequest.ITEM_ID, itemBarcode[0]);
1038 List<OleLoanDocument> loanDocuments = (List<OleLoanDocument>) businessObjectService.findMatching(OleLoanDocument.class, loanMap);
1039 OLERenewItem oleRenewItem = new OLERenewItem();
1040 if (loanDocuments.size() > 0) {
1041 OleLoanDocument oleLoanDocument = loanDocuments.get(0);
1042 oleLoanDocument = setPatronInformation(patronDocuments,olePatronDocument,oleLoanDocument);
1043 if (getLoanProcessor().canOverrideLoan(operatorId)) {
1044 if (!getLoanProcessor().checkPendingRequestforItem(oleLoanDocument.getItemUuid())) {
1045 try {
1046 oleLoanDocument.setVuFindFlag(true);
1047 oleLoanDocument = getLoanProcessor().addLoan(oleLoanDocument.getPatronBarcode(), oleLoanDocument.getItemId(), oleLoanDocument, operatorId);
1048 if (oleLoanDocument.getErrorMessage() == null || (oleLoanDocument.getErrorMessage() != null && oleLoanDocument.getErrorMessage().trim().isEmpty())) {
1049 oleRenewItem = errorCode003(oleRenewItem,oleLoanDocument,itemBarcode[0]);
1050 oleRenewItem = populateRenewItemForSip2(olePatronDocument,oleLoanDocument,oleRenewItem);
1051 oleRenewItems.add(oleRenewItem);
1052 } else {
1053 oleRenewItem = errorCode500(oleRenewItem, oleLoanDocument, itemBarcode[0]);
1054 oleRenewItems.add(oleRenewItem);
1055 }
1056 } catch (Exception e) {
1057 LOG.error(e,e);
1058 return "Exception occured while renewing an item";
1059 }
1060
1061 } else {
1062 oleRenewItem = errorCode009(oleRenewItem, itemBarcode[0]);
1063 oleRenewItems.add(oleRenewItem);
1064 }
1065 } else {
1066 oleRenewItem = errorCode010(oleRenewItem, itemBarcode[0]);
1067 oleRenewItems.add(oleRenewItem);
1068 }
1069 } else {
1070 oleRenewItem = errorCode011(oleRenewItem, itemBarcode[0]);
1071 oleRenewItems.add(oleRenewItem);
1072 }
1073 }
1074 oleRenewItemList.setRenewItemList(oleRenewItems);
1075 if(isSIP2Request){
1076 return oleRenewItemConverter.generateRenewItemListXmlForSip2(oleRenewItemList);
1077 }else{
1078
1079 return oleRenewItemConverter.generateRenewItemListXml(oleRenewItemList);
1080 }
1081 }
1082
1083 private List<OLERenewItem> errorCode001(OLERenewItem oleRenewItemPatron,List<OLERenewItem> oleRenewItems){
1084 oleRenewItemPatron.setCode("001");
1085 oleRenewItemPatron.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.INVALID_OPRTR_ID));
1086 LOG.info(oleRenewItemPatron.getMessage());
1087 oleRenewItems.add(oleRenewItemPatron);
1088 return oleRenewItems;
1089 }
1090
1091 private List<OLERenewItem> errorCode002(OLERenewItem oleRenewItemPatron,List<OLERenewItem> oleRenewItems){
1092 oleRenewItemPatron.setCode("002");
1093 oleRenewItemPatron.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.NO_PATRON_INFO));
1094 LOG.info(oleRenewItemPatron.getMessage());
1095 oleRenewItems.add(oleRenewItemPatron);
1096 return oleRenewItems;
1097 }
1098
1099 private OLERenewItem errorCode003(OLERenewItem oleRenewItem,OleLoanDocument oleLoanDocument,String itemBarcode){
1100 oleRenewItem.setCode("003");
1101 oleRenewItem.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.RENEW_SUCCESS)+" - Item Barcode("+itemBarcode+")");
1102 LOG.info(oleRenewItem.getMessage());
1103 if(oleLoanDocument.getPastDueDate() != null)
1104 oleRenewItem.setPastDueDate(oleLoanDocument.getPastDueDate().toString());
1105 oleRenewItem.setNewDueDate(oleLoanDocument.getLoanDueDate() != null ? oleLoanDocument.getLoanDueDate().toString() : "");
1106 oleRenewItem.setRenewalCount(oleLoanDocument.getNumberOfRenewals());
1107 return oleRenewItem;
1108 }
1109
1110 private OLERenewItem errorCode500(OLERenewItem oleRenewItem,OleLoanDocument oleLoanDocument,String itemBarcode){
1111 oleRenewItem.setCode("500");
1112 oleRenewItem.setMessage(oleLoanDocument.getErrorMessage()+" - Item Barcode("+itemBarcode+")");
1113 LOG.info(oleLoanDocument.getErrorMessage());
1114 return oleRenewItem;
1115 }
1116
1117 private OLERenewItem errorCode009(OLERenewItem oleRenewItem,String itemBarcode){
1118 oleRenewItem.setCode("009");
1119 oleRenewItem.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.RQST_PNDNG)+" - Item Barcode("+itemBarcode+")");
1120 LOG.info(oleRenewItem.getMessage());
1121 return oleRenewItem;
1122 }
1123
1124 private OLERenewItem errorCode010(OLERenewItem oleRenewItem,String itemBarcode){
1125 oleRenewItem.setCode("010");
1126 oleRenewItem.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.NO_RENEW)+" - Item Barcode("+itemBarcode+")");
1127 LOG.info(oleRenewItem.getMessage());
1128 return oleRenewItem;
1129 }
1130
1131 private OLERenewItem errorCode011(OLERenewItem oleRenewItem,String itemBarcode){
1132 oleRenewItem.setCode("011");
1133 oleRenewItem.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.ITM_NT_LOAN) +" - Item Barcode("+itemBarcode+")");
1134 LOG.info(oleRenewItem.getMessage());
1135 return oleRenewItem;
1136 }
1137
1138
1139 private OleLoanDocument setPatronInformation(List<OlePatronDocument> patronDocuments,OlePatronDocument olePatronDocument,OleLoanDocument oleLoanDocument){
1140 if (patronDocuments.size() > 0) {
1141 oleLoanDocument.setOlePatron(olePatronDocument);
1142 oleLoanDocument.setBorrowerTypeCode(olePatronDocument.getBorrowerTypeCode());
1143 oleLoanDocument.setBorrowerTypeId(olePatronDocument.getBorrowerType());
1144 oleLoanDocument.setOleBorrowerType(olePatronDocument.getOleBorrowerType());
1145 oleLoanDocument.setBorrowerTypeName(olePatronDocument.getBorrowerTypeName());
1146 }
1147 oleLoanDocument.setRenewalItemFlag(true);
1148 oleLoanDocument.setErrorMessage(null);
1149 return oleLoanDocument;
1150 }
1151
1152
1153
1154
1155 public boolean validPatron(String patronId) {
1156 boolean valid = false;
1157 Map<String, String> patronMap = new HashMap<String, String>();
1158 patronMap.put(OLEConstants.BARCODE, patronId);
1159 List<OlePatronDocument> olePatronDocumentList = (List<OlePatronDocument>) businessObjectService.findMatching(OlePatronDocument.class, patronMap);
1160 if (olePatronDocumentList.size() > 0) {
1161 valid = true;
1162 }
1163 return valid;
1164 }
1165
1166
1167 private Map<String, String> getLocationMap(String itemLocation) {
1168 Map<String, String> locationMap = new HashMap<String, String>();
1169 String[] locationArray = itemLocation.split("['/']");
1170 List<String> locationList = Arrays.asList(locationArray);
1171 for (String value : locationList) {
1172 Map<String, String> requestMap = new HashMap<>();
1173 requestMap.put(OLEConstants.LOCATION_CODE, value);
1174 List<OleLocation> oleLocations = (List<OleLocation>) businessObjectService.findMatching(OleLocation.class, requestMap);
1175 if (oleLocations != null && oleLocations.size() > 0) {
1176 String locationLevelId = oleLocations.get(0).getLevelId();
1177 requestMap.clear();
1178 requestMap.put(OLEConstants.LEVEL_ID, locationLevelId);
1179 List<OleLocationLevel> oleLocationLevels = (List<OleLocationLevel>) businessObjectService.findMatching(OleLocationLevel.class, requestMap);
1180 if (oleLocationLevels != null && oleLocationLevels.size() > 0) {
1181 OleLocationLevel oleLocationLevel = new OleLocationLevel();
1182 oleLocationLevel = oleLocationLevels.get(0);
1183 if (oleLocationLevel.getLevelCode().equals(OLEConstants.OLEBatchProcess.LOCATION_LEVEL_CAMPUS)) {
1184 locationMap.put(OLEConstants.ITEM_CAMPUS, value);
1185 } else if (oleLocationLevel.getLevelCode().equals(OLEConstants.OLEBatchProcess.LOCATION_LEVEL_INSTITUTION)) {
1186 locationMap.put(OLEConstants.ITEM_INSTITUTION, value);
1187 } else if (oleLocationLevel.getLevelCode().equals(OLEConstants.OLEBatchProcess.LOCATION_LEVEL_COLLECTION)) {
1188 locationMap.put(OLEConstants.ITEM_COLLECTION, value);
1189 } else if (oleLocationLevel.getLevelCode().equals(OLEConstants.OLEBatchProcess.LOCATION_LEVEL_LIBRARY)) {
1190 locationMap.put(OLEConstants.ITEM_LIBRARY, value);
1191 } else if (oleLocationLevel.getLevelCode().equals(OLEConstants.OLEBatchProcess.LOCATION_LEVEL_SHELVING)) {
1192 locationMap.put(OLEConstants.ITEM_SHELVING, value);
1193 }
1194 }
1195 }
1196 }
1197 return locationMap;
1198 }
1199
1200
1201
1202
1203
1204
1205 public GregorianCalendar getGregorianCalendarDate(String date) {
1206 if (date != null) {
1207 if(date.equals("")){
1208 return new GregorianCalendar(2025,1,1);
1209 }
1210
1211 SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
1212 Date parsedDate = null;
1213 try{
1214 try {
1215 parsedDate = simpleDateFormat.parse(date);
1216 } catch (ParseException e) {
1217 simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
1218 parsedDate = simpleDateFormat.parse(date);
1219 }
1220 }catch (ParseException e){
1221 LOG.info("Exception occured while parsing the date : " + date);
1222 }
1223 Calendar cal = Calendar.getInstance();
1224 cal.setTime(parsedDate);
1225 int year = cal.get(Calendar.YEAR);
1226 int month = cal.get(Calendar.MONTH);
1227 int day = cal.get(Calendar.DAY_OF_MONTH);
1228 return new GregorianCalendar(year, month, day);
1229 }
1230 return null;
1231 }
1232
1233 public OLERenewItem populateRenewItemForSip2(OlePatronDocument olePatronDocument , OleLoanDocument oleLoanDocument,OLERenewItem oleRenewItem){
1234 oleRenewItem.setPatronBarcode(olePatronDocument.getBarcode());
1235 oleRenewItem.setItemBarcode(oleLoanDocument.getItemId());
1236 oleRenewItem.setTitleIdentifier(oleLoanDocument.getTitle());
1237
1238
1239 oleRenewItem.setItemProperties("Author="+oleLoanDocument.getAuthor());
1240 oleRenewItem.setMediaType(oleLoanDocument.getItemType());
1241 return oleRenewItem;
1242 }
1243 }
1244
1245
1246
1247