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