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