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