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