001package org.kuali.asr.service.impl;
002
003
004import org.apache.commons.lang.StringUtils;
005import org.apache.log4j.Logger;
006import org.kuali.ole.DataCarrierService;
007import org.kuali.ole.LoanUtil;
008import org.kuali.ole.OLEConstants;
009import org.kuali.ole.OLEParameterConstants;
010import org.kuali.ole.deliver.batch.OleDeliverBatchServiceImpl;
011import org.kuali.ole.deliver.batch.OleMailer;
012import org.kuali.ole.deliver.batch.OleNoticeBo;
013import org.kuali.ole.deliver.batch.OleSms;
014import org.kuali.ole.deliver.bo.*;
015import org.kuali.ole.deliver.processor.LoanProcessor;
016import org.kuali.ole.describe.bo.OleInstanceItemType;
017import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
018import org.kuali.ole.docstore.common.document.ItemOleml;
019import org.kuali.ole.docstore.common.document.content.enums.DocType;
020import org.kuali.ole.docstore.common.document.content.instance.xstream.ItemOlemlRecordProcessor;
021import org.kuali.ole.docstore.common.search.SearchResponse;
022import org.kuali.ole.docstore.common.search.SearchResult;
023import org.kuali.ole.docstore.common.search.SearchResultField;
024import org.kuali.ole.ingest.pojo.MatchBo;
025import org.kuali.ole.sys.context.SpringContext;
026import org.kuali.ole.util.DocstoreUtil;
027import org.kuali.rice.core.api.config.property.ConfigContext;
028import org.kuali.rice.core.api.mail.EmailBody;
029import org.kuali.rice.core.api.mail.EmailFrom;
030import org.kuali.rice.core.api.mail.EmailSubject;
031import org.kuali.rice.core.api.mail.EmailTo;
032import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
033import org.kuali.rice.coreservice.impl.parameter.ParameterBo;
034import org.kuali.rice.kim.api.permission.PermissionService;
035import org.kuali.rice.kim.api.role.RoleService;
036import org.kuali.rice.kim.api.services.KimApiServiceLocator;
037import org.kuali.rice.kim.impl.identity.type.EntityTypeContactInfoBo;
038import org.kuali.rice.krad.service.BusinessObjectService;
039import org.kuali.rice.krad.service.KRADServiceLocator;
040import org.kuali.rice.krad.util.GlobalVariables;
041import org.kuali.rice.krad.util.ObjectUtils;
042import org.kuali.rice.krms.api.KrmsApiServiceLocator;
043import org.kuali.rice.krms.api.engine.*;
044import org.kuali.rice.krms.impl.repository.AgendaBo;
045
046import java.math.BigDecimal;
047import java.sql.Timestamp;
048import java.text.DateFormat;
049import java.text.SimpleDateFormat;
050import java.util.*;
051
052/**
053 * Created with IntelliJ IDEA.
054 * User: sheiksalahudeenm
055 * Date: 1/15/14
056 * Time: 11:45 AM
057 * To change this template use File | Settings | File Templates.
058 */
059public class OLEASRPlaceRequestHelperServiceImpl {
060    private static final Logger LOG = Logger.getLogger(OLEASRPlaceRequestHelperServiceImpl.class);
061    private static final String NAMESPACE_CODE_SELECTOR = "namespaceCode";
062    private static final String NAME_SELECTOR = "name";
063    private final static String RULE_EVALUATED = "Rule Evaluated";
064    private final static String ROUTED_EXTERNAL = "Routed External";
065    private BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService();
066    private int queuePosition = 0;
067    private LoanProcessor loanProcessor = new LoanProcessor();
068    private DocstoreUtil docstoreUtil = new DocstoreUtil();
069
070    private PermissionService getPermissionService() {
071        PermissionService service = KimApiServiceLocator.getPermissionService();
072        return service;
073    }
074
075    private DocstoreClientLocator docstoreClientLocator;
076
077    public DocstoreClientLocator getDocstoreClientLocator() {
078
079        if (docstoreClientLocator == null) {
080            docstoreClientLocator = SpringContext.getBean(DocstoreClientLocator.class);
081
082        }
083        return docstoreClientLocator;
084    }
085
086    /**
087     * Gets the businessObjectService attribute.
088     *
089     * @return Returns the businessObjectService
090     */
091    private BusinessObjectService getBusinessObjectService() {
092        if (null == businessObjectService) {
093            businessObjectService = KRADServiceLocator.getBusinessObjectService();
094        }
095        return businessObjectService;
096    }
097
098    public void setbusinessObjectService(BusinessObjectService businessObjectService) {
099        this.businessObjectService = businessObjectService;
100    }
101
102    public LoanProcessor getLoanProcessor() {
103        return loanProcessor;
104    }
105
106    public void setLoanProcessor(LoanProcessor loanProcessor) {
107        this.loanProcessor = loanProcessor;
108    }
109
110    /**
111     * This method is used to change the request type based on selection of  pick up  location
112     *
113     * @param oleDeliverRequestBo
114     * @return oleDeliverRequestBo
115     */
116    public OleDeliverRequestBo processRequestType(OleDeliverRequestBo oleDeliverRequestBo) {
117
118        LOG.debug("Inside processRequestType for the Request id :" + oleDeliverRequestBo.getRequestId());
119        oleDeliverRequestBo = processPatron(oleDeliverRequestBo);
120        oleDeliverRequestBo = processItem(oleDeliverRequestBo);
121        if (oleDeliverRequestBo.getRequestTypeId() != null) {
122            if (oleDeliverRequestBo.getRequestTypeId().equals("3") && oleDeliverRequestBo.getPickUpLocationId() != null && !oleDeliverRequestBo.getPickUpLocationId().isEmpty()) {
123                oleDeliverRequestBo.setRequestTypeId("4");
124            } else if (oleDeliverRequestBo.getRequestTypeId().equals("5") && oleDeliverRequestBo.getPickUpLocationId() != null && !oleDeliverRequestBo.getPickUpLocationId().isEmpty()) {
125                oleDeliverRequestBo.setRequestTypeId("6");
126            } else if (oleDeliverRequestBo.getRequestTypeId().equals("1") && oleDeliverRequestBo.getPickUpLocationId() != null && !oleDeliverRequestBo.getPickUpLocationId().isEmpty()) {
127                oleDeliverRequestBo.setRequestTypeId("2");
128            }
129        }
130        return oleDeliverRequestBo;
131    }
132
133
134    /**
135     * This is to create a new patron object if the user enters the operator Id manually
136     *
137     * @param oleDeliverRequestBo
138     * @return deliver
139     */
140    public OleDeliverRequestBo processPatron(OleDeliverRequestBo oleDeliverRequestBo) {
141        LOG.debug("Inside processPatron");
142        OleDeliverRequestBo deliver = oleDeliverRequestBo;
143
144        if (oleDeliverRequestBo.getBorrowerBarcode() != null || oleDeliverRequestBo.getProxyBorrowerBarcode() != null) {
145            Map<String, String> patronMap = new HashMap<String, String>();
146            patronMap.put(OLEConstants.OleDeliverRequest.PATRON_BARCODE, oleDeliverRequestBo.getBorrowerBarcode());
147            List<OlePatronDocument> olePatronDocumentList = (List<OlePatronDocument>) businessObjectService.findMatching(OlePatronDocument.class, patronMap);
148            if (olePatronDocumentList != null && olePatronDocumentList.size() > 0) {
149                deliver.setOlePatron(olePatronDocumentList.get(0));
150                deliver.setBorrowerName(olePatronDocumentList.get(0).getPatronName());
151                deliver.setBorrowerId(olePatronDocumentList.get(0).getOlePatronId());
152            } else if (olePatronDocumentList != null && olePatronDocumentList.size() == 0) {
153                deliver.setBorrowerId(null);
154                deliver.setFirstName(null);
155                deliver.setLastName(null);
156                deliver.setOlePatron(null);
157                deliver.setBorrowerName(null);
158                deliver.setBorrowerBarcode(null);
159            }
160            if (oleDeliverRequestBo.getRequestCreator().equals(OLEConstants.OleDeliverRequest.REQUESTER_PROXY_PATRON)) {
161                Map<String, String> proxyPatronMap = new HashMap<String, String>();
162                proxyPatronMap.put(OLEConstants.OleDeliverRequest.PATRON_BARCODE, oleDeliverRequestBo.getProxyBorrowerBarcode());
163                List<OlePatronDocument> oleProxyPatronDocumentList = (List<OlePatronDocument>) businessObjectService.findMatching(OlePatronDocument.class, proxyPatronMap);
164                if (oleProxyPatronDocumentList != null && oleProxyPatronDocumentList.size() > 0) {
165                    deliver.setOleProxyPatron(oleProxyPatronDocumentList.get(0));
166                    deliver.setProxyBorrowerName(oleProxyPatronDocumentList.get(0).getPatronName());
167                    deliver.setProxyBorrowerId(oleProxyPatronDocumentList.get(0).getOlePatronId());
168                } else if (oleProxyPatronDocumentList != null && oleProxyPatronDocumentList.size() == 0) {
169                    deliver.setProxyBorrowerId(null);
170                    deliver.setProxyBorrowerName(null);
171                    deliver.setOleProxyPatron(null);
172                }
173            }
174
175        }
176
177        return deliver;
178    }
179
180    public boolean processOperator(String principalId) {
181        /*if (getPermissionService().hasPermission(oleDeliverRequestBo.getOperatorCreateId(), OLEConstants.OlePatron.PATRON_NAMESPACE, OLEConstants.CAN_LOAN)) {
182            return true;
183        }*/
184        // Modified as per comments in Jira OLE-4901
185        boolean isOperator = true;
186        Collection<String> roles = getRoleService().getRoleMemberPrincipalIds(OLEConstants.OlePatron.PATRON_NAMESPACE, OLEConstants.OleDeliverRequest.REQUESTER_OPERATOR, null);
187        if (roles != null) {
188            isOperator = roles.contains(principalId);
189        }
190        return isOperator;
191    }
192
193    /**
194     * This is to check whether the pick up location is selected for the hold type of Request
195     *
196     * @param oleDeliverRequestBo
197     * @return validRequest
198     */
199    public boolean validateRequestType(OleDeliverRequestBo oleDeliverRequestBo) {
200        LOG.debug("Inside validateRequestType");
201        boolean validRequest = true;
202        if ((oleDeliverRequestBo.getRequestTypeId().equals("2") || oleDeliverRequestBo.getRequestTypeId().equals("4") || oleDeliverRequestBo.getRequestTypeId().equals("6")) && (oleDeliverRequestBo.getPickUpLocationId() == null) || (oleDeliverRequestBo.getPickUpLocationId() != null && oleDeliverRequestBo.getPickUpLocationId().isEmpty())) {
203            validRequest = false;
204        }
205        return validRequest;
206    }
207
208
209    /**
210     * This is to check whether the patron is having delivery privilege or not
211     *
212     * @param oleDeliverRequestBo
213     * @return hasDeliveryPrivilege
214     */
215    public boolean validateDeliveryPrivilege(OleDeliverRequestBo oleDeliverRequestBo) {
216        LOG.debug("Inside validateDeliveryPrivilege");
217        boolean hasDeliveryPrivilege = true;
218        if (oleDeliverRequestBo.getRequestTypeId().equals("1") || oleDeliverRequestBo.getRequestTypeId().equals("3") || oleDeliverRequestBo.getRequestTypeId().equals("5")) {
219            if (oleDeliverRequestBo.getOlePatron() != null && !oleDeliverRequestBo.getOlePatron().isDeliveryPrivilege()) {
220                hasDeliveryPrivilege = false;
221            }
222        } else if (oleDeliverRequestBo.getRequestTypeId().equals("2") || oleDeliverRequestBo.getRequestTypeId().equals("4") || oleDeliverRequestBo.getRequestTypeId().equals("6")) {
223            if (oleDeliverRequestBo.getOlePatron() != null && !oleDeliverRequestBo.getOlePatron().isDeliveryPrivilege() && oleDeliverRequestBo.getPickUpLocationId() == null) {
224                hasDeliveryPrivilege = false;
225            }
226        }
227        return hasDeliveryPrivilege;
228    }
229
230
231    /**
232     * This is to check whether the patron is having paging privilege or not
233     *
234     * @param oleDeliverRequestBo
235     * @return hasPagePrivilege
236     */
237    public boolean validatePagingPrivilege(OleDeliverRequestBo oleDeliverRequestBo) {
238        LOG.debug("Inside validatePagingPrivilege");
239        boolean hasPagePrivilege = true;
240        if (oleDeliverRequestBo.getRequestTypeId().equals("5") || oleDeliverRequestBo.getRequestTypeId().equals("6")) {
241            if (!oleDeliverRequestBo.getOlePatron().isPagingPrivilege()) {
242                hasPagePrivilege = false;
243            }
244        }
245        return hasPagePrivilege;
246    }
247
248
249    /**
250     * This for setting the null values for the unselected requester
251     *
252     * @param oleDeliverRequestBo
253     * @return oleDeliverRequestBo
254     */
255    public OleDeliverRequestBo processRequester(OleDeliverRequestBo oleDeliverRequestBo) {
256        LOG.debug("Inside processRequester");
257        if (oleDeliverRequestBo.getRequestCreator().equals(OLEConstants.OleDeliverRequest.REQUESTER_PATRON)) {
258            oleDeliverRequestBo.setProxyBorrowerId(null);
259            oleDeliverRequestBo.setOleProxyPatron(null);
260            oleDeliverRequestBo.setOperatorCreateId(null);
261            oleDeliverRequestBo.setOperatorCreator(null);
262        } else if (oleDeliverRequestBo.getRequestCreator().equals(OLEConstants.OleDeliverRequest.REQUESTER_PROXY_PATRON)) {
263            oleDeliverRequestBo.setOperatorCreateId(null);
264            oleDeliverRequestBo.setOperatorCreator(null);
265        } else if (oleDeliverRequestBo.getRequestCreator().equals(OLEConstants.OleDeliverRequest.REQUESTER_OPERATOR)) {
266            oleDeliverRequestBo.setProxyBorrowerId(null);
267            oleDeliverRequestBo.setOleProxyPatron(null);
268        }
269        return oleDeliverRequestBo;
270    }
271
272
273    /**
274     * This is to check whether the login patron is the proxy patron for the real patron
275     *
276     * @param oleDeliverRequestBo
277     * @return validProxy
278     */
279    public boolean isValidProxyPatron(OleDeliverRequestBo oleDeliverRequestBo) {
280        LOG.debug("Inside isValidProxyPatron");
281        boolean validProxy = true;
282        Map<String, String> proxyMap = new HashMap<String, String>();
283        proxyMap.put(OLEConstants.OleDeliverRequest.PATRON_ID, oleDeliverRequestBo.getBorrowerId());
284        proxyMap.put(OLEConstants.OleDeliverRequest.PROXY_PATRON_ID, oleDeliverRequestBo.getProxyBorrowerId());
285        if (oleDeliverRequestBo.getProxyBorrowerId() != null && !oleDeliverRequestBo.getProxyBorrowerId().isEmpty()) {
286            List<OleProxyPatronDocument> proxyPatronDocuments = (List<OleProxyPatronDocument>) businessObjectService.findMatching(OleProxyPatronDocument.class, proxyMap);
287            if (proxyPatronDocuments.size() == 0) {
288                validProxy = false;
289            }
290        }
291        return validProxy;
292    }
293
294
295    /**
296     * This is to check whether the request is already raised by the patron for this item
297     *
298     * @param oleDeliverRequestBo
299     * @return alreadyExist
300     */
301    public boolean isRequestAlreadyRaisedByPatron(OleDeliverRequestBo oleDeliverRequestBo) {
302        LOG.debug("Inside isRequestAlreadyRaised");
303        boolean alreadyExist = false;
304        Map<String, String> requestMap = new HashMap<String, String>();
305        requestMap.put(OLEConstants.OleDeliverRequest.BORROWER_ID, oleDeliverRequestBo.getBorrowerId());
306        requestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
307        List<OleDeliverRequestBo> deliverRequestBos = (List<OleDeliverRequestBo>) businessObjectService.findMatching(OleDeliverRequestBo.class, requestMap);
308        if (deliverRequestBos != null && deliverRequestBos.size() > 0) {
309            alreadyExist = true;
310        }
311        return alreadyExist;
312    }
313
314
315    /**
316     * This is to check whether the requested item is currently in loan to the requesting patron
317     *
318     * @param oleDeliverRequestBo
319     * @return alreadyLoaned
320     */
321    public boolean isAlreadyLoaned(OleDeliverRequestBo oleDeliverRequestBo) {
322        LOG.debug("Inside isAlreadyLoaned");
323        boolean alreadyLoaned = false;
324        Map<String, String> loanMap = new HashMap<String, String>();
325        loanMap.put(OLEConstants.OleDeliverRequest.LOAN_PATRON_ID, oleDeliverRequestBo.getBorrowerId());
326        loanMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
327        List<OleLoanDocument> loanDocuments = (List<OleLoanDocument>) businessObjectService.findMatching(OleLoanDocument.class, loanMap);
328        if (loanDocuments != null && loanDocuments.size() > 0) {
329            alreadyLoaned = true;
330        }
331        return alreadyLoaned;
332    }
333
334
335    /**
336     * This is to check whether the item is available in the desk or not
337     *
338     * @param oleDeliverRequestBo
339     * @return itemAvailable
340     */
341    public boolean isItemAvailable(OleDeliverRequestBo oleDeliverRequestBo) {
342        LOG.debug("Inside isItemAvailable");
343        boolean itemAvailable = true;
344
345        String itemStatuslist = null;
346        String requestTypeCode = oleDeliverRequestBo.getRequestTypeCode();
347        if (requestTypeCode.equals("Recall/Delivery Request")) {
348            itemStatuslist = loanProcessor.getParameter(OLEConstants.RECALL_DELIVERY_ITEM_STATUS);
349        } else if (requestTypeCode.equals("Recall/Hold Request")) {
350            itemStatuslist = loanProcessor.getParameter(OLEConstants.RECALL_HOLD_ITEM_STATUS);
351        } else if (requestTypeCode.equals("Hold/Delivery Request")) {
352            itemStatuslist = loanProcessor.getParameter(OLEConstants.HOLD_DELIVERY_ITEM_STATUS);
353        } else if (requestTypeCode.equals("Hold/Hold Request")) {
354            itemStatuslist = loanProcessor.getParameter(OLEConstants.HOLD_HOLD_ITEM_STATUS);
355        } else if (requestTypeCode.equals("Page/Delivery Request")) {
356            itemStatuslist = loanProcessor.getParameter(OLEConstants.PAGE_DELIVERY_ITEM_STATUS);
357        } else if (requestTypeCode.equals("Page/Hold Request")) {
358            itemStatuslist = loanProcessor.getParameter(OLEConstants.PAGE_HOLD_ITEM_STATUS);
359        } else if (requestTypeCode.equals("Copy Request")) {
360            itemStatuslist = loanProcessor.getParameter(OLEConstants.COPY_REQUEST_ITEM_STATUS);
361        } else {
362            GlobalVariables.getMessageMap().putError(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, OLEConstants.OleDeliverRequest.REQUEST_ID_INVALID);
363        }
364        String[] str = itemStatuslist.split(";");
365        for (String itemStatus : str) {
366            if ((itemStatus != null) && (!itemStatus.isEmpty()) && (itemStatus.equals(oleDeliverRequestBo.getItemStatus()))) {
367                itemAvailable = false;
368            }
369        }
370        return itemAvailable;
371    }
372
373
374    /**
375     * This is to check whether the item is available in the desk or not
376     *
377     * @param oleDeliverRequestBo
378     * @return itemAvailable
379     */
380    public boolean isItemAvailableForLoan(OleDeliverRequestBo oleDeliverRequestBo) {
381        LOG.debug("Inside isItemAvailable");
382        boolean itemAvailable = false;
383        Map<String, String> loanItemMap = new HashMap<String, String>();
384        loanItemMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
385        List<OleLoanDocument> loanItemDocuments = (List<OleLoanDocument>) businessObjectService.findMatching(OleLoanDocument.class, loanItemMap);
386        if (loanItemDocuments.size() == 0) {
387            itemAvailable = true;
388        }
389        return itemAvailable;
390    }
391
392
393    /**
394     * This is to check whether the item is eligible to loan
395     *
396     * @param oleDeliverRequestBo
397     * @return itemEligible
398     */
399    public boolean isItemEligible(OleDeliverRequestBo oleDeliverRequestBo) {
400        LOG.debug("Inside isItemEligible");
401        boolean itemEligible = true;
402        Map<String, String> statusMap = new HashMap<String, String>();
403        statusMap.put(OLEConstants.OleDeliverRequest.LOSTBILLREPLACEMENT, OLEConstants.OleDeliverRequest.LOSTBILLREPLACEMENT);
404        statusMap.put(OLEConstants.OleDeliverRequest.MISSINGFINALOVERDUE, OLEConstants.OleDeliverRequest.MISSINGFINALOVERDUE);
405        statusMap.put(OLEConstants.OleDeliverRequest.WITHDRAWNCLIAMSRETURN, OLEConstants.OleDeliverRequest.WITHDRAWNCLIAMSRETURN);
406
407        if (statusMap.containsKey(oleDeliverRequestBo.getItemStatus())) {
408            itemEligible = false;
409        }
410        return itemEligible;
411    }
412
413    /**
414     * This is to check whether the patron record is alive or expired
415     *
416     * @param oleDeliverRequestBo
417     * @return expired
418     */
419    public String patronRecordExpired(OleDeliverRequestBo oleDeliverRequestBo) {
420        LOG.debug("Inside patronRecordExpired");
421        String expired = null;
422        Map<String, String> patronMap = new HashMap<String, String>();
423        patronMap.put(OLEConstants.OleDeliverRequest.PATRON_ID, oleDeliverRequestBo.getBorrowerId());
424        List<OlePatronDocument> olePatronDocuments = (List<OlePatronDocument>) businessObjectService.findMatching(OlePatronDocument.class, patronMap);
425        if (olePatronDocuments != null && olePatronDocuments.size() > 0) {
426            SimpleDateFormat fmt = new SimpleDateFormat(OLEConstants.OleDeliverRequest.DATE_FORMAT);
427            Date expirationDate = olePatronDocuments.get(0).getExpirationDate();
428            Date activationDate = olePatronDocuments.get(0).getActivationDate();
429            if ((fmt.format(activationDate)).compareTo(fmt.format(new Date(System.currentTimeMillis()))) <= 0) {
430                if (expirationDate != null) {
431                    if ((fmt.format(expirationDate)).compareTo(fmt.format(new Date(System.currentTimeMillis()))) < 0) {
432                        expired = OLEConstants.OleDeliverRequest.PATRON_RECORD_EXPIRE;
433                    }
434                }
435            } else {
436                expired = OLEConstants.OleDeliverRequest.PATRON_RECORD_FUTURE;
437            }
438        }
439        return expired;
440    }
441
442
443    /**
444     * This is for retrieving the request raised by  the patron
445     *
446     * @param olePatronId
447     * @return deliverRequestBos
448     */
449    public List<OleDeliverRequestBo> getRequestedItems(String olePatronId) {
450        LOG.debug("Inside getRequestedItems");
451        Map<String, String> requestMap = new HashMap<String, String>();
452        requestMap.put(OLEConstants.OleDeliverRequest.BORROWER_ID, olePatronId);
453        List<OleDeliverRequestBo> deliverRequestBos = (List<OleDeliverRequestBo>) businessObjectService.findMatching(OleDeliverRequestBo.class, requestMap);
454        for (int i = 0; i < deliverRequestBos.size(); i++) {
455            processItem(deliverRequestBos.get(i));
456        }
457        return deliverRequestBos;
458
459    }
460
461
462    /**
463     * This is to check the  duplicate in the queue Position while re -ordering
464     *
465     * @param itemList
466     * @return exist
467     */
468    public String validateQueuePosition(List<OleDeliverRequestBo> itemList) {
469        LOG.debug("Inside validateQueuePosition");
470        String message = OLEConstants.OleDeliverRequest.REORDER_SUCCESS;
471        List<Integer> queuePositionList = new ArrayList<Integer>();
472        if (itemList.get(0).getBorrowerQueuePosition() < 1) {
473            return OLEConstants.OleDeliverRequest.POSITIVE_QUEUE_POSITION;
474        }
475        queuePositionList.add(itemList.get(0).getBorrowerQueuePosition());
476
477        for (int i = 1; i < itemList.size(); i++) {
478            for (int j = 0; j < queuePositionList.size(); j++) {
479                if (itemList.get(i).getBorrowerQueuePosition() != null) {
480                    if ((itemList.get(i).getBorrowerQueuePosition() >= 1) && (itemList.get(i).getBorrowerQueuePosition() == queuePositionList.get(j))) {
481                        return OLEConstants.OleDeliverRequest.QUEUE_DUPLICATE;
482                    } else if ((itemList.get(i).getBorrowerQueuePosition() <= 0)) {
483                        return OLEConstants.OleDeliverRequest.POSITIVE_QUEUE_POSITION;
484                    }
485                }
486            }
487            queuePositionList.add(itemList.get(i).getBorrowerQueuePosition());
488        }
489        return message;
490    }
491
492    //
493
494    /**
495     * This is to check whether any request raised for the item
496     *
497     * @param oleDeliverRequestBo
498     * @return exist
499     */
500    public boolean isRequestRaised(OleDeliverRequestBo oleDeliverRequestBo) {
501        LOG.debug("Inside isRequestRaised");
502        boolean exist = false;
503        Map<String, String> requestMap = new HashMap<String, String>();
504        requestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
505        List<OleDeliverRequestBo> deliverRequestBos = (List<OleDeliverRequestBo>) businessObjectService.findMatching(OleDeliverRequestBo.class, requestMap);
506        if (deliverRequestBos.size() > 0) {
507            exist = true;
508        }
509        return exist;
510    }
511
512
513    /**
514     * This method is used to cancel the request document
515     *
516     * @param oleDeliverRequestBo
517     */
518    public void cancelDocument(OleDeliverRequestBo oleDeliverRequestBo) {
519        LOG.debug("Inside cancelDocument");
520        Map<String, String> itemMap = new HashMap<String, String>();
521        itemMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
522        Map<String, String> requestMap = new HashMap<String, String>();
523        requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_ID, oleDeliverRequestBo.getRequestId());
524        businessObjectService.deleteMatching(OleDeliverRequestBo.class, requestMap);
525        List<OleDeliverRequestBo> oleDeliverRequestDocumentsList = (List<OleDeliverRequestBo>) businessObjectService.findMatchingOrderBy(OleDeliverRequestBo.class, itemMap, OLEConstants.OleDeliverRequest.QUEUE_POSITION, true);
526        businessObjectService.delete(oleDeliverRequestDocumentsList);
527        int queuePosition = 1;
528        for (int i = 0; i < oleDeliverRequestDocumentsList.size(); i++) {
529            oleDeliverRequestDocumentsList.get(i).setBorrowerQueuePosition(queuePosition);
530            queuePosition = queuePosition + 1;
531        }
532        businessObjectService.save(oleDeliverRequestDocumentsList);
533    }
534
535    public void cancelPendingRequestForClaimsReturnedItem(String itemUuid) throws Exception {
536        Map<String, String> requestMap = new HashMap<String, String>();
537        requestMap.put("itemUuid", itemUuid);
538        OleDeliverBatchServiceImpl oleDeliverBatchService = new OleDeliverBatchServiceImpl();
539        List<OleDeliverRequestBo> oleDeliverRequestBoList = (List<OleDeliverRequestBo>) businessObjectService.findMatching(OleDeliverRequestBo.class, requestMap);
540        for (OleDeliverRequestBo oleDeliverRequestBo : oleDeliverRequestBoList) {
541            cancelDocument(oleDeliverRequestBo);
542            OleItemSearch itemSearch = docstoreUtil.getOleItemSearchList(itemUuid);
543            EntityTypeContactInfoBo entityTypeContactInfoBo = oleDeliverRequestBo.getOlePatron().getEntity().getEntityTypeContactInfos().get(0);
544            List<OleNoticeBo> oleNoticeBos = new ArrayList<OleNoticeBo>();
545            OleNoticeBo oleNoticeBo = new OleNoticeBo();
546            oleNoticeBo.setNoticeName(OLEConstants.CANCELLATION_NOTICE);
547            oleNoticeBo.setAuthor(itemSearch.getAuthor() != null ? itemSearch.getAuthor() : "");
548            oleNoticeBo.setItemCallNumber(itemSearch.getCallNumber() != null ? itemSearch.getCallNumber() : "");
549            oleNoticeBo.setItemShelvingLocation(itemSearch.getShelvingLocation() != null ? itemSearch.getShelvingLocation() : "");
550            oleNoticeBo.setItemId(itemSearch.getItemUUID() != null ? itemSearch.getItemUUID() : "");
551            oleNoticeBo.setTitle(itemSearch.getTitle() != null ? itemSearch.getTitle() : "");
552            oleNoticeBo.setOleItem(getItem(oleDeliverRequestBo.getItemUuid()));
553            oleNoticeBo.setPatronEmailAddress(getPatronHomeEmailId(entityTypeContactInfoBo) != null ? getPatronHomeEmailId(entityTypeContactInfoBo) : "");
554            if (oleNoticeBo.getPatronEmailAddress() != null && !oleNoticeBo.getPatronEmailAddress().isEmpty()) {
555                oleNoticeBos.add(oleNoticeBo);
556                List list = oleDeliverBatchService.getNoticeForPatron(oleNoticeBos);
557                String content = list.toString();
558                content = content.replace('[', ' ');
559                content = content.replace(']', ' ');
560                if (!content.trim().equals("")) {
561                    OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer");
562                    String replyToEmail = getLoanProcessor().getReplyToEmail(oleNoticeBo.getItemShelvingLocation());
563                    if (replyToEmail != null) {
564                        oleMailer.sendEmail(new EmailFrom(replyToEmail), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.CANCELLATION_NOTICE), new EmailBody(content), true);
565                    } else {
566                        String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL);
567                        if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) {
568                            fromAddress = OLEConstants.KUALI_MAIL;
569                        }
570                        oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.CANCELLATION_NOTICE), new EmailBody(content), true);
571                    }
572                }
573            }
574        }
575    }
576
577    /**
578     * This method is to set the item values from docstore
579     *
580     * @param oleDeliverRequestBo
581     * @return oleDeliverRequestBo
582     */
583    public OleDeliverRequestBo processItem(OleDeliverRequestBo oleDeliverRequestBo) {
584        LOG.debug("Inside processItem");
585        OleItemSearch oleItemSearch = null;
586        if (oleDeliverRequestBo.getItemType() == null) {
587            // Map<String, String> itemMap = new HashMap<String, String>();
588            //itemMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
589            OleItemSearch itemSearchList = docstoreUtil.getOleItemSearchList(oleDeliverRequestBo.getItemUuid());
590            try {
591                //org.kuali.ole.docstore.common.document.Item item=getDocstoreClientLocator().getDocstoreClient().retrieveItem( oleDeliverRequestBo.getItemUuid());
592
593
594                if (itemSearchList != null) {
595                    oleItemSearch = itemSearchList;
596                    oleDeliverRequestBo.setTitle(itemSearchList.getTitle());
597                    oleDeliverRequestBo.setAuthor(itemSearchList.getAuthor());
598                    oleDeliverRequestBo.setCallNumber(itemSearchList.getCallNumber());
599                    oleDeliverRequestBo.setItemType(itemSearchList.getItemType());
600                    oleDeliverRequestBo.setItemLocation(itemSearchList.getShelvingLocation());
601                }
602            } catch (Exception ex) {
603                ex.printStackTrace();
604            }
605            try {
606                if (oleItemSearch == null) {
607                    oleItemSearch = new OleItemSearch();
608                }
609                // Map docStoreDetails = loanProcessor.getItemDetails(oleDeliverRequestBo.getItemId());
610                String itemXml = loanProcessor.getItemXML(oleDeliverRequestBo.getItemUuid());
611                org.kuali.ole.docstore.common.document.content.instance.Item oleItem = loanProcessor.getItemPojo(itemXml);
612                oleItemSearch.setCopyNumber(oleItem.getCopyNumber());
613                if (oleItem.getItemStatus() != null) {
614                    oleItemSearch.setItemStatus(oleItem.getItemStatus().getCodeValue());
615                }
616                oleItemSearch.setShelvingLocation(getShelvingLocation(oleItem.getLocation()));
617                oleDeliverRequestBo.setCopyNumber(oleItem.getCopyNumber());
618                if (oleItem.getItemStatus() != null) {
619                    oleDeliverRequestBo.setItemStatus(oleItem.getItemStatus().getCodeValue());
620                }
621                oleDeliverRequestBo.setShelvingLocation(getShelvingLocation(oleItem.getLocation()));
622                if (oleDeliverRequestBo.getRequestTypeId().equals("8")) {
623                    oleDeliverRequestBo.setInTransitCheckInNote(oleItem.getCheckinNote());
624                }
625            } catch (Exception e) {
626                LOG.error(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.INVAL_LOC), e);  //To change body of catch statement use File | Settings | File Templates.
627            }
628        }
629        oleDeliverRequestBo.setOleItemSearch(oleItemSearch);
630        oleDeliverRequestBo = processItemType(oleDeliverRequestBo);
631        return oleDeliverRequestBo;
632    }
633
634    /**
635     * This method is to set the item type name  based on the item type code
636     *
637     * @param oleDeliverRequestBo
638     * @return
639     */
640    public OleDeliverRequestBo processItemType(OleDeliverRequestBo oleDeliverRequestBo) {
641        LOG.debug("Inside process Item Type");
642        Map<String, String> itemMap = new HashMap<String, String>();
643        itemMap = new HashMap<String, String>();
644        itemMap.put(OLEConstants.OleDeliverRequest.ITEM_TYPE_CODE, oleDeliverRequestBo.getItemType());
645        List<OleInstanceItemType> oleInstanceItemTypeList = (List<OleInstanceItemType>) businessObjectService.findMatching(OleInstanceItemType.class, itemMap);
646        if (oleInstanceItemTypeList != null && oleInstanceItemTypeList.size() > 0) {
647            OleInstanceItemType oleInstanceItemType = oleInstanceItemTypeList.get(0);
648            oleDeliverRequestBo.setItemTypeName(oleInstanceItemType.getInstanceItemTypeName());
649        }
650
651        return oleDeliverRequestBo;
652    }
653
654    /**
655     * This method is to retrieve the shelving location from item
656     *
657     * @param oleLocation
658     * @return locationLevelName
659     */
660    private String getShelvingLocation(org.kuali.ole.docstore.common.document.content.instance.Location oleLocation) {
661
662        LOG.debug("Inside getShelvingLocation");
663        String locationLevelName = "";
664        if (oleLocation != null) {
665            org.kuali.ole.docstore.common.document.content.instance.LocationLevel locationLevel =
666                    oleLocation.getLocationLevel();
667            if (locationLevel != null) {
668                while (locationLevel.getLocationLevel() != null && !locationLevel.getLevel().equalsIgnoreCase(OLEConstants.OleDeliverRequest.SHELVING)) {
669                    locationLevel = locationLevel.getLocationLevel();
670                }
671                locationLevelName = locationLevel.getName();
672            }
673        }
674        return locationLevelName;
675    }
676
677
678    /**
679     * This method is to check whether the selected  request can be raised for the item
680     *
681     * @param oleDeliverRequestBo
682     * @return canRaiseRequest
683     */
684    public boolean canRaiseRequest(OleDeliverRequestBo oleDeliverRequestBo) {
685        LOG.debug("Inside canRaiseRequest");
686        boolean canRaiseRequest = true;
687
688        if (isItemAvailable(oleDeliverRequestBo)) {
689            canRaiseRequest = false;
690
691
692        }
693        return canRaiseRequest;
694    }
695
696
697    /**
698     * racle
699     * This method is to update the request id in the loan document
700     *
701     * @param oleDeliverRequestBo
702     */
703    public OleDeliverRequestBo updateLoanDocument(OleDeliverRequestBo oleDeliverRequestBo) {
704        LOG.debug("Inside updateLoanDocument");
705        Map<String, String> loanMap = new HashMap<String, String>();
706        loanMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
707        List<OleLoanDocument> oleLoanDocumentList = (List<OleLoanDocument>) businessObjectService.findMatching(OleLoanDocument.class, loanMap);
708        if (oleLoanDocumentList != null && oleLoanDocumentList.size() > 0 && oleLoanDocumentList.get(0) != null && oleLoanDocumentList.get(0).getOleRequestId() == null) {
709            if (oleLoanDocumentList.get(0).getLoanId() != null) {
710                // oleLoanDocumentList.get(0).setOleRequestId(oleDeliverRequestBo.getRequestId());
711                oleDeliverRequestBo.setLoanTransactionRecordNumber(oleLoanDocumentList.get(0).getLoanId());
712            }
713            //  businessObjectService.save(oleLoanDocumentList.get(0));
714
715        }
716        return oleDeliverRequestBo;
717    }
718
719    /**
720     * @param requestId
721     * @param itemUUID
722     * @param operatorId
723     * @param loanTransactionNumber
724     */
725    public void deleteRequest(String requestId, String itemUUID, String operatorId, String loanTransactionNumber) {
726        LOG.debug("Inside deleteRequest");
727        Map<String, String> requestMap = new HashMap<String, String>();
728        requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_ID, requestId);
729        createRequestHistoryRecord(requestId, operatorId, loanTransactionNumber);
730        Map<String, String> itemMap = new HashMap<String, String>();
731        itemMap.put(OLEConstants.ITEM_UUID, itemUUID);
732        List<OleDeliverRequestBo> oleDeliverRequestDocumentsList = (List<OleDeliverRequestBo>) businessObjectService.findMatchingOrderBy(OleDeliverRequestBo.class, itemMap, OLEConstants.OleDeliverRequest.QUEUE_POSITION, true);
733        businessObjectService.delete(oleDeliverRequestDocumentsList);
734        int queuePosition = 1;
735        for (int i = 0; i < oleDeliverRequestDocumentsList.size(); i++) {
736            oleDeliverRequestDocumentsList.get(i).setBorrowerQueuePosition(queuePosition);
737            queuePosition = queuePosition + 1;
738        }
739        businessObjectService.save(oleDeliverRequestDocumentsList);
740
741    }
742
743    /**
744     * This for retrieving the item Details from docstore
745     *
746     * @param itemUUID
747     * @return oleItemSearch
748     */
749    public OleItemSearch getItemDetails(String itemUUID) {
750        LOG.debug("Inside getItemDetails");
751        OleItemSearch oleItemSearch = getItemDetailsForPatron(itemUUID);
752        try {
753            // Map  docStoreDetails= loanProcessor.getItemDetails(itemBarCode);
754            String itemXml = loanProcessor.getItemXML(itemUUID);
755            org.kuali.ole.docstore.common.document.content.instance.Item oleItem = loanProcessor.getItemPojo(itemXml);
756            if (oleItem != null && oleItem.getItemType() != null) {
757                oleItemSearch.setItemType(processItemType(oleItem.getItemType().getCodeValue()));
758            }
759            oleItemSearch.setCopyNumber(oleItem.getCopyNumber());
760            if (oleItem.getItemStatus() != null) {
761                oleItemSearch.setItemStatus(oleItem.getItemStatus().getCodeValue());
762            }
763            oleItemSearch.setShelvingLocation(getShelvingLocation(oleItem.getLocation()));
764            oleItemSearch.setVolumeNumber(oleItem.getVolumeNumber());
765        } catch (Exception e) {
766            LOG.error("Not able to retrieve information from the docstore for the Item Barcode : " + itemUUID, e);  //To change body of catch statement use File | Settings | File Templates.
767        }
768        return oleItemSearch;
769    }
770
771    /**
772     * This method is for retrieving the item details for displaying in the patron screen
773     *
774     * @param itemUUID
775     * @return OleItemSearch
776     */
777    public OleItemSearch getItemDetailsForPatron(String itemUUID) {
778        LOG.debug("Inside getItemDetailsForPatron");
779        OleItemSearch oleItemSearch;
780        try {
781
782            Map<String, String> itemMap = new HashMap<String, String>();
783            // itemMap.put(OLEConstants.OleDeliverRequest.ITEM_UUID, itemUUID);
784            OleItemSearch itemSearchList = docstoreUtil.getOleItemSearchList(itemUUID);
785            if (itemSearchList != null) {
786                return oleItemSearch = itemSearchList;
787            }
788        } catch (NullPointerException e) {
789            LOG.error("No item details available for the Item Barcode : " + itemUUID, e);
790        }
791
792        return new OleItemSearch();
793
794    }
795
796    /**
797     * This method is to re-order the queuePosition based on the priority while creating the request
798     *
799     * @param oleDeliverRequestBo
800     * @return OleDeliverRequestBo
801     */
802    public OleDeliverRequestBo reOrderQueuePosition(OleDeliverRequestBo oleDeliverRequestBo) {
803        LOG.debug("Inside reOrderQueuePosition");
804        List<OleDeliverRequestBo> existingRequest = new ArrayList<OleDeliverRequestBo>();
805        String queue = getLoanProcessor().getParameter(OLEConstants.OleDeliverRequest.REQUEST_QUEUE);
806        List<String> orderQueue = new ArrayList<String>();
807        String[] queueArray = queue.split(";");
808        for (int i = 0; i < queueArray.length; i++) {
809            orderQueue.add(queueArray[i]);
810        }
811        List<OleDeliverRequestBo> finalList = new ArrayList<OleDeliverRequestBo>();
812        Map<String, String> recallRequestMap = new HashMap<String, String>();
813        recallRequestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
814        recallRequestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "1");
815        Map<String, String> recallHoldRequestMap = new HashMap<String, String>();
816        recallHoldRequestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
817        recallHoldRequestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "2");
818        Map<String, String> holdRequestMap = new HashMap<String, String>();
819        holdRequestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
820        holdRequestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "3");
821        Map<String, String> holdHoldRequestMap = new HashMap<String, String>();
822        holdHoldRequestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
823        holdHoldRequestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "4");
824        Map<String, String> pageRequestMap = new HashMap<String, String>();
825        pageRequestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
826        pageRequestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "5");
827        Map<String, String> pageHoldRequestMap = new HashMap<String, String>();
828        pageHoldRequestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
829        pageHoldRequestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "6");
830        Map<String, String> copyRequestMap = new HashMap<String, String>();
831        copyRequestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
832        copyRequestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "7");
833        Map<String, String> inTransitRequestMap = new HashMap<String, String>();
834        inTransitRequestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
835        inTransitRequestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "8");
836        List<OleDeliverRequestBo> recallList = (List<OleDeliverRequestBo>) businessObjectService.findMatchingOrderBy(OleDeliverRequestBo.class, recallRequestMap, OLEConstants.OleDeliverRequest.QUEUE_POSITION, true);
837        List<OleDeliverRequestBo> recallHoldList = (List<OleDeliverRequestBo>) businessObjectService.findMatchingOrderBy(OleDeliverRequestBo.class, recallHoldRequestMap, OLEConstants.OleDeliverRequest.QUEUE_POSITION, true);
838        List<OleDeliverRequestBo> holdList = (List<OleDeliverRequestBo>) businessObjectService.findMatchingOrderBy(OleDeliverRequestBo.class, holdRequestMap, OLEConstants.OleDeliverRequest.QUEUE_POSITION, true);
839        List<OleDeliverRequestBo> holdHoldList = (List<OleDeliverRequestBo>) businessObjectService.findMatchingOrderBy(OleDeliverRequestBo.class, holdHoldRequestMap, OLEConstants.OleDeliverRequest.QUEUE_POSITION, true);
840        List<OleDeliverRequestBo> pageList = (List<OleDeliverRequestBo>) businessObjectService.findMatchingOrderBy(OleDeliverRequestBo.class, pageRequestMap, OLEConstants.OleDeliverRequest.QUEUE_POSITION, true);
841        List<OleDeliverRequestBo> pageHoldList = (List<OleDeliverRequestBo>) businessObjectService.findMatchingOrderBy(OleDeliverRequestBo.class, pageHoldRequestMap, OLEConstants.OleDeliverRequest.QUEUE_POSITION, true);
842        List<OleDeliverRequestBo> copyList = (List<OleDeliverRequestBo>) businessObjectService.findMatchingOrderBy(OleDeliverRequestBo.class, copyRequestMap, OLEConstants.OleDeliverRequest.QUEUE_POSITION, true);
843        List<OleDeliverRequestBo> inTransitList = (List<OleDeliverRequestBo>) businessObjectService.findMatchingOrderBy(OleDeliverRequestBo.class, inTransitRequestMap, OLEConstants.OleDeliverRequest.QUEUE_POSITION, true);
844        if (oleDeliverRequestBo.getOleDeliverRequestType().getRequestTypeCode().contains(OLEConstants.OleDeliverRequest.RECALL_DELIVERY)) {
845            recallList.add(oleDeliverRequestBo);
846        } else if (oleDeliverRequestBo.getOleDeliverRequestType().getRequestTypeCode().contains(OLEConstants.OleDeliverRequest.HOLD_DELIVERY)) {
847            holdList.add(oleDeliverRequestBo);
848        } else if (oleDeliverRequestBo.getOleDeliverRequestType().getRequestTypeCode().contains(OLEConstants.OleDeliverRequest.PAGE_DELIVERY)) {
849            pageList.add(oleDeliverRequestBo);
850        } else if (oleDeliverRequestBo.getOleDeliverRequestType().getRequestTypeCode().contains(OLEConstants.OleDeliverRequest.COPY)) {
851            copyList.add(oleDeliverRequestBo);
852        } else if (oleDeliverRequestBo.getOleDeliverRequestType().getRequestTypeCode().contains(OLEConstants.OleDeliverRequest.INTRANSIT)) {
853            inTransitList.add(oleDeliverRequestBo);
854        } else if (oleDeliverRequestBo.getOleDeliverRequestType().getRequestTypeCode().contains(OLEConstants.OleDeliverRequest.RECALL_HOLD)) {
855            recallHoldList.add(oleDeliverRequestBo);
856        } else if (oleDeliverRequestBo.getOleDeliverRequestType().getRequestTypeCode().contains(OLEConstants.OleDeliverRequest.HOLD_HOLD)) {
857            holdHoldList.add(oleDeliverRequestBo);
858        } else if (oleDeliverRequestBo.getOleDeliverRequestType().getRequestTypeCode().contains(OLEConstants.OleDeliverRequest.PAGE_HOLD)) {
859            pageHoldList.add(oleDeliverRequestBo);
860        }
861        OleDeliverRequestBo oleDeliverRequestBo1;
862        for (int i = 0; i < orderQueue.size(); i++) {
863            if (orderQueue.get(i).equals(OLEConstants.OleDeliverRequest.RECALL) && recallList.size() > 0) {
864                for (int x = 0; x < recallList.size(); x++) {
865                    oleDeliverRequestBo1 = (OleDeliverRequestBo) ObjectUtils.deepCopy(recallList.get(x));
866                    oleDeliverRequestBo1.setBorrowerQueuePosition(this.queuePosition + 1);
867                    this.queuePosition = this.queuePosition + 1;
868                    finalList.add(oleDeliverRequestBo1);
869
870                }
871            }
872            if (orderQueue.get(i).equals(OLEConstants.OleDeliverRequest.HOLD) && holdList.size() > 0) {
873                for (int x = 0; x < holdList.size(); x++) {
874                    oleDeliverRequestBo1 = (OleDeliverRequestBo) ObjectUtils.deepCopy(holdList.get(x));
875                    oleDeliverRequestBo1.setBorrowerQueuePosition(this.queuePosition + 1);
876                    this.queuePosition = this.queuePosition + 1;
877                    finalList.add(oleDeliverRequestBo1);
878
879                }
880            }
881            if (orderQueue.get(i).equals(OLEConstants.OleDeliverRequest.PAGE) && pageList.size() > 0) {
882                for (int x = 0; x < pageList.size(); x++) {
883                    oleDeliverRequestBo1 = (OleDeliverRequestBo) ObjectUtils.deepCopy(pageList.get(x));
884                    oleDeliverRequestBo1.setBorrowerQueuePosition(this.queuePosition + 1);
885                    this.queuePosition = this.queuePosition + 1;
886                    finalList.add(oleDeliverRequestBo1);
887                }
888            }
889            if (orderQueue.get(i).equals(OLEConstants.OleDeliverRequest.RECALL) && recallHoldList.size() > 0) {
890                for (int x = 0; x < recallHoldList.size(); x++) {
891                    oleDeliverRequestBo1 = (OleDeliverRequestBo) ObjectUtils.deepCopy(recallHoldList.get(x));
892                    oleDeliverRequestBo1.setBorrowerQueuePosition(this.queuePosition + 1);
893                    this.queuePosition = this.queuePosition + 1;
894                    finalList.add(oleDeliverRequestBo1);
895
896                }
897            }
898            if (orderQueue.get(i).equals(OLEConstants.OleDeliverRequest.HOLD) && holdHoldList.size() > 0) {
899                for (int x = 0; x < holdHoldList.size(); x++) {
900                    oleDeliverRequestBo1 = (OleDeliverRequestBo) ObjectUtils.deepCopy(holdHoldList.get(x));
901                    oleDeliverRequestBo1.setBorrowerQueuePosition(this.queuePosition + 1);
902                    this.queuePosition = this.queuePosition + 1;
903                    finalList.add(oleDeliverRequestBo1);
904
905                }
906            }
907            if (orderQueue.get(i).equals(OLEConstants.OleDeliverRequest.PAGE) && pageHoldList.size() > 0) {
908                for (int x = 0; x < pageHoldList.size(); x++) {
909                    oleDeliverRequestBo1 = (OleDeliverRequestBo) ObjectUtils.deepCopy(pageHoldList.get(x));
910                    oleDeliverRequestBo1.setBorrowerQueuePosition(this.queuePosition + 1);
911                    this.queuePosition = this.queuePosition + 1;
912                    finalList.add(oleDeliverRequestBo1);
913                }
914            }
915            if (orderQueue.get(i).equals(OLEConstants.OleDeliverRequest.COPY) && copyList.size() > 0) {
916                for (int x = 0; x < copyList.size(); x++) {
917                    oleDeliverRequestBo1 = (OleDeliverRequestBo) ObjectUtils.deepCopy(copyList.get(x));
918                    oleDeliverRequestBo1.setBorrowerQueuePosition(this.queuePosition + 1);
919                    this.queuePosition = this.queuePosition + 1;
920                    finalList.add(oleDeliverRequestBo1);
921
922                }
923            }
924            if (orderQueue.get(i).equals(OLEConstants.OleDeliverRequest.INTRANSIT) && inTransitList.size() > 0) {
925                for (int x = 0; x < inTransitList.size(); x++) {
926                    oleDeliverRequestBo1 = (OleDeliverRequestBo) ObjectUtils.deepCopy(inTransitList.get(x));
927                    oleDeliverRequestBo1.setBorrowerQueuePosition(this.queuePosition + 1);
928                    this.queuePosition = this.queuePosition + 1;
929                    finalList.add(oleDeliverRequestBo1);
930
931                }
932            }
933        }
934        for (int i = 0; i < finalList.size(); i++) {
935            if (finalList.get(i).getRequestId() == null) {
936                oleDeliverRequestBo.setBorrowerQueuePosition(finalList.get(i).getBorrowerQueuePosition());
937                finalList.remove(finalList.get(i));
938            }
939        }
940        businessObjectService.save(finalList);
941        this.queuePosition = 0;
942        return oleDeliverRequestBo;
943    }
944
945    /**
946     * Thsi method is to check whether the item is available in doc store or not
947     *
948     * @param oleDeliverRequestBo
949     * @return boolean
950     */
951    public boolean isItemAvailbleInDocstore(OleDeliverRequestBo oleDeliverRequestBo) {
952        LOG.debug("Inside isItemAvailbleInDocstore");
953        boolean available = false;
954        Map<String, String> itemMap = new HashMap<String, String>();
955        try {
956            String itemUUID = "";
957            org.kuali.ole.docstore.common.document.Item item = new ItemOleml();
958            org.kuali.ole.docstore.common.search.SearchParams search_Params = new org.kuali.ole.docstore.common.search.SearchParams();
959            SearchResponse searchResponse = null;
960            search_Params.getSearchConditions().add(search_Params.buildSearchCondition("", search_Params.buildSearchField(org.kuali.ole.docstore.common.document.content.enums.DocType.ITEM.getCode(), item.ITEM_BARCODE, oleDeliverRequestBo.getItemId()), ""));
961
962
963            search_Params.getSearchResultFields().add(search_Params.buildSearchResultField(org.kuali.ole.docstore.common.document.content.enums.DocType.ITEM.getCode(), "id"));
964            ;
965
966                   /* Map<String,String> map=new HashMap<>();
967                    map.put(item.BARCODE, itemBarcode);
968                    item=getDocstoreClientLocator().getDocstoreClient().findItem(map);*/
969
970            searchResponse = getDocstoreClientLocator().getDocstoreClient().search(search_Params);
971            for (SearchResult searchResult : searchResponse.getSearchResults()) {
972                for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
973                    String fieldName = searchResultField.getFieldName();
974                    String fieldValue = searchResultField.getFieldValue() != null ? searchResultField.getFieldValue() : "";
975
976                    if (fieldName.equalsIgnoreCase("id") && !fieldValue.isEmpty() && searchResultField.getDocType().equalsIgnoreCase("item")) {
977                        itemUUID = fieldValue;
978                    }
979
980                }
981            }
982
983
984            oleDeliverRequestBo.setItemUuid(itemUUID);
985        } catch (Exception e) {
986            LOG.error(e, e);
987            //To change body of catch statement use File | Settings | File Templates.
988        }
989        // itemMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
990        OleItemSearch itemSearchList = docstoreUtil.getOleItemSearchList(oleDeliverRequestBo.getItemUuid());
991        if (itemSearchList != null) {
992            oleDeliverRequestBo.setTitle(itemSearchList.getTitle());
993            oleDeliverRequestBo.setAuthor(itemSearchList.getAuthor());
994            oleDeliverRequestBo.setCallNumber(itemSearchList.getCallNumber());
995            oleDeliverRequestBo.setItemType(itemSearchList.getItemType());
996        }
997        try {
998            // Map docStoreDetails = loanProcessor.getItemDetailsByUUID(oleDeliverRequestBo.getItemId());
999            String itemXml = loanProcessor.getItemXML(oleDeliverRequestBo.getItemUuid());
1000            org.kuali.ole.docstore.common.document.content.instance.Item oleItem = loanProcessor.getItemPojo(itemXml);
1001
1002            oleDeliverRequestBo.setCopyNumber(oleItem.getCopyNumber());
1003            if (oleItem.getItemStatus() != null) {
1004                oleDeliverRequestBo.setItemStatus(oleItem.getItemStatus().getCodeValue());
1005            }
1006            oleDeliverRequestBo.setShelvingLocation(getShelvingLocation(oleItem.getLocation()));
1007            available = true;
1008        } catch (Exception e) {
1009            LOG.error(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.INVAL_LOC), e);  //To change body of catch statement use File | Settings | File Templates.
1010        }
1011        return available;
1012    }
1013
1014    public OleDeliverRequestBo populateItemDetailsToRequest(OleDeliverRequestBo oleDeliverRequestBo, OleItemSearch oleItemSearch) {
1015        LOG.debug("Inside populateItemDetailsToRequest");
1016        if (oleDeliverRequestBo != null && oleItemSearch != null) {
1017            oleDeliverRequestBo.setAuthor(oleItemSearch.getAuthor());
1018            oleDeliverRequestBo.setTitle(oleItemSearch.getTitle());
1019            oleDeliverRequestBo.setCallNumber(oleItemSearch.getCallNumber());
1020            oleDeliverRequestBo.setCopyNumber(oleItemSearch.getCopyNumber());
1021            oleDeliverRequestBo.setItemType(oleItemSearch.getItemType());
1022            oleDeliverRequestBo.setItemStatus(oleItemSearch.getItemStatus());
1023            oleItemSearch.setShelvingLocation(oleDeliverRequestBo.getShelvingLocation());
1024        }
1025        return oleDeliverRequestBo;
1026    }
1027
1028
1029    public OleDeliverRequestBo generateRecallNotice(OleDeliverRequestBo oleDeliverRequestBo) throws Exception {
1030        Map<String, String> loanMap = new HashMap<String, String>();
1031        loanMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
1032        List<OleLoanDocument> loanDocuments = (List<OleLoanDocument>) businessObjectService.findMatching(OleLoanDocument.class, loanMap);
1033        OleLoanDocument oleLoanDocument = loanDocuments.get(0);
1034        Map<String, String> patronMap = new HashMap<String, String>();
1035        patronMap.put(OLEConstants.OleDeliverRequest.PATRON_ID, oleLoanDocument.getPatronId());
1036        List<OlePatronDocument> patronDocumentList = (List<OlePatronDocument>) businessObjectService.findMatching(OlePatronDocument.class, patronMap);
1037        OleNoticeBo oleNoticeBo = new OleNoticeBo();
1038        org.kuali.ole.docstore.common.document.content.instance.Item item;
1039        if (patronDocumentList.size() > 0) {
1040            OlePatronDocument olePatronDocument = patronDocumentList.get(0);
1041            EntityTypeContactInfoBo entityTypeContactInfoBo = olePatronDocument.getEntity().getEntityTypeContactInfos().get(0);
1042            oleNoticeBo.setPatronName(olePatronDocument.getEntity().getNames().get(0).getFirstName() + " " + oleDeliverRequestBo.getOlePatron().getEntity().getNames().get(0).getLastName());
1043            oleNoticeBo.setPatronAddress(getPatronPreferredAddress(entityTypeContactInfoBo) != null ? getPatronPreferredAddress(entityTypeContactInfoBo) : "");
1044            oleNoticeBo.setPatronEmailAddress(getPatronHomeEmailId(entityTypeContactInfoBo) != null ? getPatronHomeEmailId(entityTypeContactInfoBo) : "");
1045            oleNoticeBo.setPatronPhoneNumber(getPatronHomePhoneNumber(entityTypeContactInfoBo) != null ? getPatronHomePhoneNumber(entityTypeContactInfoBo) : "");
1046        }
1047        oleNoticeBo.setAuthor(oleDeliverRequestBo.getAuthor() != null ? oleDeliverRequestBo.getAuthor() : "");
1048        oleNoticeBo.setCirculationDeskAddress("");
1049        oleNoticeBo.setCirculationDeskName("");
1050        oleNoticeBo.setCirculationDeskEmailAddress("");
1051        oleNoticeBo.setCirculationDeskPhoneNumber("");
1052        oleNoticeBo.setItemCallNumber(oleDeliverRequestBo.getCallNumber() != null ? oleDeliverRequestBo.getCallNumber() : "");
1053        oleNoticeBo.setItemShelvingLocation(oleDeliverRequestBo.getShelvingLocation() != null ? oleDeliverRequestBo.getShelvingLocation() : "");
1054        oleNoticeBo.setItemId(oleDeliverRequestBo.getItemId() != null ? oleDeliverRequestBo.getItemId() : "");
1055        oleNoticeBo.setTitle(oleDeliverRequestBo.getTitle() != null ? oleDeliverRequestBo.getTitle() : "");
1056        oleNoticeBo.setOleItem(getItem(oleDeliverRequestBo.getItemUuid()));
1057        oleNoticeBo.setOlePatron(oleDeliverRequestBo.getOlePatron());
1058        oleNoticeBo.setVolumeNumber(oleNoticeBo.getOleItem().getVolumeNumber() != null ? oleNoticeBo.getOleItem().getVolumeNumber() : "");
1059        oleNoticeBo.setOriginalDueDate(oleLoanDocument.getLoanDueDate());
1060        oleNoticeBo.setNewDueDate(oleDeliverRequestBo.getNewDueDate());
1061        oleNoticeBo.setOriginalDueDate(oleDeliverRequestBo.getOriginalDueDate());
1062        /*if (oleDeliverRequestBo.getRecallDueDate() != null) {
1063            oleNoticeBo.setNewDueDate(oleDeliverRequestBo.getRecallDueDate());
1064        } else {
1065            oleNoticeBo.setNewDueDate(oleLoanDocument.getLoanDueDate());
1066        }*/
1067        oleNoticeBo.setNoticeName(OLEConstants.NOTICE_RECALL);
1068        String noticeContent = getLoanProcessor().getParameter(OLEConstants.OleDeliverRequest.RECALL_BODY);
1069        oleNoticeBo.setNoticeSpecificContent(noticeContent);
1070        //  oleNoticeBo = setPatronDetailsForNotice(oleNoticeBo,oleDeliverRequestBo.getOlePatron());
1071        OleDeliverBatchServiceImpl oleDeliverBatchService = new OleDeliverBatchServiceImpl();
1072        List<OleNoticeBo> oleNoticeBos = new ArrayList<OleNoticeBo>();
1073        String noticeType = getLoanProcessor().getParameter(OLEConstants.OleDeliverRequest.RECALL_NOTICE_TYPE);
1074        oleNoticeBos.add(oleNoticeBo);
1075        if (noticeType.equalsIgnoreCase(OLEConstants.EMAIL)) {
1076            if (oleNoticeBo.getPatronEmailAddress() != null && !oleNoticeBo.getPatronEmailAddress().isEmpty()) {
1077                List list = oleDeliverBatchService.getNoticeForPatron(oleNoticeBos);
1078                String content = list.toString();
1079                content = content.replace('[', ' ');
1080                content = content.replace(']', ' ');
1081                if (!content.trim().equals("")) {
1082                    OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer");
1083                    String replyToEmail = getLoanProcessor().getReplyToEmail(oleNoticeBo.getItemShelvingLocation());
1084                    if (replyToEmail != null) {
1085                        oleMailer.sendEmail(new EmailFrom(replyToEmail), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(content), true);
1086                    } else {
1087                        String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL);
1088                        if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) {
1089                            fromAddress = OLEConstants.KUALI_MAIL;
1090                        }
1091                        oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(content), true);
1092                    }
1093                } else {
1094                    for (OleNoticeBo oleNoticeBo1 : oleNoticeBos) {
1095                        LOG.info("Notice Type :" + oleNoticeBo1.getNoticeName() + "  " + "Item Barcode : " + oleNoticeBo1.getItemId() + " " + "Patron Name :" + oleNoticeBo1.getPatronName());
1096                    }
1097                }
1098                LOG.info("Mail send successfully to " + oleNoticeBo.getPatronEmailAddress());
1099/*
1100                Mailer  mailer = CoreApiServiceLocator.getMailer();
1101                mailer.sendEmail(new EmailFrom(OLEConstants.KUALI_MAIL), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(list.toString()), true);
1102          */
1103            }
1104        } else if (noticeType.equalsIgnoreCase(OLEConstants.SMS)) {
1105            //oleNoticeBos.add(oleNoticeBo);
1106            Map map = oleDeliverBatchService.getSMSForPatron(oleNoticeBos);
1107            HashMap sms = (HashMap) map.get(OLEConstants.OleDeliverRequest.RECALL);
1108            Iterator it = sms.entrySet().iterator();
1109            while (it.hasNext()) {
1110                Map.Entry pairs = (Map.Entry) it.next();
1111                String patronPhoneNumber = oleNoticeBo.getPatronPhoneNumber();
1112                OleSms oleSms = new OleSms();
1113                oleSms.sendSms("", patronPhoneNumber, (String) pairs.getValue());
1114            }
1115
1116        }
1117        if (noticeType.equalsIgnoreCase(OLEConstants.MAIL) || noticeType.equalsIgnoreCase(OLEConstants.EMAIL)) {
1118            //oleNoticeBos.add(oleNoticeBo);
1119            oleDeliverBatchService.getPdfNoticeForPatron(oleNoticeBos);
1120            LOG.info("Recall Notice Pdf generated for item Id" + oleNoticeBo.getItemId());
1121        }
1122        oleDeliverRequestBo = (OleDeliverRequestBo) ObjectUtils.deepCopy(oleDeliverRequestBo);
1123        oleDeliverRequestBo.setRecallNoticeSentDate(new java.sql.Date(System.currentTimeMillis()));
1124        return oleDeliverRequestBo;
1125    }
1126
1127
1128    public void generateOnHoldNotice() throws Exception {
1129
1130        List<OleDeliverRequestBo> finalDeliverRequestBoList = new ArrayList<OleDeliverRequestBo>();
1131        Map<String, String> onHoldNoticeMap = new HashMap<String, String>();
1132        onHoldNoticeMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "2");
1133        List<OleDeliverRequestBo> oleDeliverRequestBoList = (List<OleDeliverRequestBo>) businessObjectService.findMatching(OleDeliverRequestBo.class, onHoldNoticeMap);
1134        Map<String, String> onHoldHoldNoticeMap = new HashMap<String, String>();
1135        onHoldHoldNoticeMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "4");
1136        List<OleDeliverRequestBo> oleDeliverRequestBoList1 = (List<OleDeliverRequestBo>) businessObjectService.findMatching(OleDeliverRequestBo.class, onHoldHoldNoticeMap);
1137        oleDeliverRequestBoList.addAll(oleDeliverRequestBoList1);
1138        OleDeliverRequestBo oleDeliverRequestBo;
1139        List<OleNoticeBo> noticesList = new ArrayList<OleNoticeBo>();
1140        EntityTypeContactInfoBo entityTypeContactInfoBo;
1141        OleNoticeBo oleNoticeBo;
1142        org.kuali.ole.docstore.common.document.content.instance.Item item;
1143        for (int i = 0; i < oleDeliverRequestBoList.size(); i++) {
1144            if (docstoreUtil.isItemAvailableInDocStore(oleDeliverRequestBoList.get(i))) {
1145                item = oleDeliverRequestBoList.get(i).getOleItem();
1146                if (item != null && item.getItemStatus() != null && item.getItemStatus().getCodeValue() != null && item.getItemStatus().getCodeValue().equals(OLEConstants.ITEM_STATUS_ON_HOLD) && oleDeliverRequestBoList.get(i).getOnHoldNoticeSentDate() == null) {
1147                    entityTypeContactInfoBo = oleDeliverRequestBoList.get(i).getOlePatron().getEntity().getEntityTypeContactInfos().get(0);
1148                    oleNoticeBo = new OleNoticeBo();
1149                    oleNoticeBo.setAuthor(oleDeliverRequestBoList.get(i).getAuthor());
1150                    oleNoticeBo.setCirculationDeskAddress("");
1151                    oleNoticeBo.setCirculationDeskName("");
1152                    oleNoticeBo.setCirculationDeskEmailAddress("");
1153                    oleNoticeBo.setCirculationDeskPhoneNumber("");
1154                    oleNoticeBo.setPatronName(oleDeliverRequestBoList.get(i).getOlePatron().getEntity().getNames().get(0).getFirstName() + " " + oleDeliverRequestBoList.get(i).getOlePatron().getEntity().getNames().get(0).getLastName());
1155                    oleNoticeBo.setPatronAddress(getPatronPreferredAddress(entityTypeContactInfoBo) != null ? getPatronPreferredAddress(entityTypeContactInfoBo) : "");
1156                    oleNoticeBo.setPatronEmailAddress(getPatronHomeEmailId(entityTypeContactInfoBo) != null ? getPatronHomeEmailId(entityTypeContactInfoBo) : "");
1157                    oleNoticeBo.setPatronPhoneNumber(getPatronHomePhoneNumber(entityTypeContactInfoBo) != null ? getPatronHomePhoneNumber(entityTypeContactInfoBo) : "");
1158                    oleNoticeBo.setItemCallNumber(oleDeliverRequestBoList.get(i).getCallNumber() != null ? oleDeliverRequestBoList.get(i).getCallNumber() : "");
1159                    oleNoticeBo.setItemShelvingLocation(oleDeliverRequestBoList.get(i).getShelvingLocation() != null ? oleDeliverRequestBoList.get(i).getShelvingLocation() : "");
1160                    oleNoticeBo.setItemId(oleDeliverRequestBoList.get(i).getItemId() != null ? oleDeliverRequestBoList.get(i).getItemId() : "");
1161                    oleNoticeBo.setTitle(oleDeliverRequestBoList.get(i).getTitle() != null ? oleDeliverRequestBoList.get(i).getTitle() : "");
1162                    oleNoticeBo.setOleItem(item);
1163                    oleNoticeBo.setOlePatron(oleDeliverRequestBoList.get(i).getOlePatron());
1164                    oleNoticeBo.setVolumeNumber(item.getVolumeNumber() != null ? item.getVolumeNumber() : "");
1165                    oleNoticeBo.setNewDueDate(new Date());
1166                    oleNoticeBo.setOriginalDueDate(new Date());
1167                    oleNoticeBo.setNoticeName(OLEConstants.NOTICE_ONHOLD);
1168                    oleNoticeBo.setCirculationDeskName(oleDeliverRequestBoList.get(i).getOlePickUpLocation().getCirculationDeskPublicName());
1169                    String circulationDeskId = oleDeliverRequestBoList.get(i).getPickUpLocationId();
1170                    int noDays = 0;
1171                    Map<String, String> mapCirculationDesk = new HashMap<String, String>();
1172                    mapCirculationDesk.put("circulationDeskId", circulationDeskId);
1173                    List<OleCirculationDesk> oleCirculationDesks = (List<OleCirculationDesk>) KRADServiceLocator.getBusinessObjectService().findMatching(OleCirculationDesk.class, mapCirculationDesk);
1174                    if (oleCirculationDesks.size() > 0) {
1175                        OleCirculationDesk oleCirculationDesk = oleCirculationDesks.get(0);
1176                        noDays = Integer.parseInt(oleCirculationDesk.getOnHoldDays());
1177                    }
1178                    Calendar calendar = Calendar.getInstance();
1179                    calendar.add(Calendar.DATE, noDays);
1180                    Date date = calendar.getTime();
1181                    oleNoticeBo.setExpiredOnHoldDate(date);
1182                    String maxNumOfDays = oleDeliverRequestBoList.get(i).getOlePickUpLocation().getOnHoldDays() != null ? oleDeliverRequestBoList.get(i).getOlePickUpLocation().getOnHoldDays() : loanProcessor.getParameter(OLEConstants.MAX_NO_OF_DAYS_ON_HOLD);
1183                    Integer maxNumberOfDaysOnHold = new Integer(maxNumOfDays);
1184                    oleNoticeBo.setOnHoldDueDate(dateAdd(oleDeliverRequestBoList.get(i).getCreateDate(), maxNumberOfDaysOnHold));
1185                    String noticeContent = getLoanProcessor().getParameter(OLEConstants.OleDeliverRequest.ONHOLD_BODY);
1186                    oleNoticeBo.setNoticeSpecificContent(noticeContent);
1187                    noticesList.add(oleNoticeBo);
1188                    OleDeliverBatchServiceImpl oleDeliverBatchService = new OleDeliverBatchServiceImpl();
1189                    String agendaName = OLEConstants.BATCH_PROGRAM_AGENDA;
1190                    HashMap<String, Object> termValues = new HashMap<String, Object>();
1191                    OleCirculationDesk oleCirculationDesk = oleDeliverRequestBoList.get(i).getOlePickUpLocation();
1192                    OlePatronDocument olePatronDocument = oleDeliverRequestBoList.get(i).getOlePatron();
1193                    String deskLocation = oleCirculationDesk != null ? oleCirculationDesk.getCirculationDeskCode() : "";
1194                    String deskLocationName = oleCirculationDesk != null ? oleCirculationDesk.getCirculationDeskPublicName() : "";
1195                    termValues.put(OLEConstants.BORROWER_TYPE, olePatronDocument.getOleBorrowerType().getBorrowerTypeCode());
1196                    termValues.put(OLEConstants.DESK_LOCATION, deskLocation);
1197                    termValues.put(OLEConstants.NOTICE, OLEConstants.NOTICE_ONHOLD);
1198                    LOG.info("termValues.toString()" + termValues.toString());
1199                    EngineResults engineResults = loanProcessor.getEngineResults(agendaName, termValues);
1200                    String noticeType = (String) engineResults.getAttribute(OLEConstants.NOTICE_TYPE);
1201                    LOG.info("**************" + noticeType);
1202                    noticeType = noticeType != null ? noticeType : getLoanProcessor().getParameter(OLEConstants.OleDeliverRequest.ONHOLD_NOTICE_TYPE);
1203                    if (noticeType != null && (noticeType.equalsIgnoreCase(OLEConstants.EMAIL) || noticeType.equalsIgnoreCase(OLEConstants.MAIL))) {
1204                        LOG.info("noticesList.size()" + noticesList.size());
1205                        oleDeliverBatchService.getPdfNoticeForPatron(noticesList);
1206                        LOG.info("OnHold Notice Pdf generated for item Id" + oleNoticeBo.getItemId());
1207                    }
1208                    if (noticeType != null && noticeType.equalsIgnoreCase(OLEConstants.EMAIL)) {
1209                        if (oleNoticeBo.getPatronEmailAddress() != null && !oleNoticeBo.getPatronEmailAddress().isEmpty()) {
1210                            List list = oleDeliverBatchService.getNoticeForPatron(noticesList);
1211                            String content = list.toString();
1212                            content = content.replace('[', ' ');
1213                            content = content.replace(']', ' ');
1214                            if (!content.trim().equals("")) {
1215                                OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer");
1216                                if (oleDeliverRequestBoList.get(i).getOlePickUpLocation() != null && StringUtils.isNotBlank(oleDeliverRequestBoList.get(i).getOlePickUpLocation().getReplyToEmail())) {
1217                                    oleMailer.sendEmail(new EmailFrom(oleDeliverRequestBoList.get(i).getOlePickUpLocation().getReplyToEmail()), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(content), true);
1218                                } else {
1219                                    String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL);
1220                                    if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) {
1221                                        fromAddress = OLEConstants.KUALI_MAIL;
1222                                    }
1223                                    oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(content), true);
1224                                }
1225                            } else {
1226                                for (OleNoticeBo oleNoticeBo1 : noticesList) {
1227                                    LOG.info("Notice Type :" + oleNoticeBo1.getNoticeName() + "  " + "Item Barcode : " + oleNoticeBo1.getItemId() + " " + "Patron Name :" + oleNoticeBo1.getPatronName());
1228                                }
1229                            }
1230                            LOG.info("Mail send successfully to " + oleNoticeBo.getPatronEmailAddress());
1231                       /* Mailer mailer = CoreApiServiceLocator.getMailer();
1232                        mailer.sendEmail(new EmailFrom(OLEConstants.KUALI_MAIL), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(list.toString()), true);
1233                   */
1234                        }
1235                    } else if (noticeType != null && noticeType.equalsIgnoreCase(OLEConstants.SMS)) {
1236                        Map map = oleDeliverBatchService.getSMSForPatron(noticesList);
1237                        HashMap sms = (HashMap) map.get(OLEConstants.NOTICE_ONHOLD);
1238                        Iterator it = sms.entrySet().iterator();
1239                        while (it.hasNext()) {
1240                            Map.Entry pairs = (Map.Entry) it.next();
1241                            String patronPhoneNumber = oleNoticeBo.getPatronPhoneNumber();
1242                            OleSms oleSms = new OleSms();
1243                            oleSms.sendSms("", patronPhoneNumber, (String) pairs.getValue());
1244                        }
1245                    }
1246                    // To do send Notice
1247                    oleDeliverRequestBoList.get(i).setOleItem(null);
1248                    oleDeliverRequestBo = (OleDeliverRequestBo) ObjectUtils.deepCopy(oleDeliverRequestBoList.get(i));
1249                    oleDeliverRequestBo.setOnHoldNoticeSentDate(new java.sql.Date(System.currentTimeMillis()));
1250                    finalDeliverRequestBoList.add(oleDeliverRequestBo);
1251                }
1252            }
1253            businessObjectService.save(finalDeliverRequestBoList);
1254        }
1255    }
1256
1257    public void generateRequestExpirationNotice() throws Exception {
1258        List<OleDeliverRequestBo> oleDeliverRequestBoList = new ArrayList<OleDeliverRequestBo>();
1259        OleDeliverBatchServiceImpl oleDeliverBatchService = new OleDeliverBatchServiceImpl();
1260        oleDeliverRequestBoList = (List<OleDeliverRequestBo>) businessObjectService.findAll(OleDeliverRequestBo.class);
1261        SimpleDateFormat fmt = new SimpleDateFormat(OLEConstants.OleDeliverRequest.DATE_FORMAT);
1262        EntityTypeContactInfoBo entityTypeContactInfoBo;
1263        List<OleNoticeBo> noticesList = new ArrayList<OleNoticeBo>();
1264        org.kuali.ole.docstore.common.document.content.instance.Item item;
1265        String noticeType = null;
1266        OleNoticeBo oleNoticeBo = new OleNoticeBo();
1267        if (oleDeliverRequestBoList.size() > 0) {
1268            for (int i = 0; i < oleDeliverRequestBoList.size(); i++) {
1269                if (docstoreUtil.isItemAvailableInDocStore(oleDeliverRequestBoList.get(i))) {
1270                    //  processItem(oleDeliverRequestBoList.get(i));
1271                    item = oleDeliverRequestBoList.get(i).getOleItem();
1272                    LOG.info("Expiration Date :" + oleDeliverRequestBoList.get(i).getRequestExpiryDate());
1273                    if (oleDeliverRequestBoList.get(i).getOlePatron().isCourtesyNotice() && (fmt.format(oleDeliverRequestBoList.get(i).getRequestExpiryDate())).compareTo(fmt.format(new Date(System.currentTimeMillis()))) <= 0) {
1274                        LOG.info("Inside Expiration Date :" + oleDeliverRequestBoList.get(i).getRequestExpiryDate());
1275                        entityTypeContactInfoBo = oleDeliverRequestBoList.get(i).getOlePatron().getEntity().getEntityTypeContactInfos().get(0);
1276                        oleNoticeBo = new OleNoticeBo();
1277                        oleNoticeBo.setAuthor(oleDeliverRequestBoList.get(i).getAuthor());
1278                        oleNoticeBo.setCirculationDeskAddress("");
1279                        oleNoticeBo.setCirculationDeskName("");
1280                        oleNoticeBo.setCirculationDeskEmailAddress("");
1281                        oleNoticeBo.setCirculationDeskPhoneNumber("");
1282                        oleNoticeBo.setPatronName(oleDeliverRequestBoList.get(i).getOlePatron().getEntity().getNames().get(0).getFirstName() + " " + oleDeliverRequestBoList.get(i).getOlePatron().getEntity().getNames().get(0).getLastName());
1283                        oleNoticeBo.setPatronAddress(getPatronPreferredAddress(entityTypeContactInfoBo) != null ? getPatronPreferredAddress(entityTypeContactInfoBo) : "");
1284                        oleNoticeBo.setPatronEmailAddress(getPatronHomeEmailId(entityTypeContactInfoBo) != null ? getPatronHomeEmailId(entityTypeContactInfoBo) : "");
1285                        oleNoticeBo.setPatronPhoneNumber(getPatronHomePhoneNumber(entityTypeContactInfoBo) != null ? getPatronHomePhoneNumber(entityTypeContactInfoBo) : "");
1286                        oleNoticeBo.setItemCallNumber(oleDeliverRequestBoList.get(i).getCallNumber() != null ? oleDeliverRequestBoList.get(i).getCallNumber() : "");
1287                        oleNoticeBo.setItemShelvingLocation(oleDeliverRequestBoList.get(i).getShelvingLocation() != null ? oleDeliverRequestBoList.get(i).getShelvingLocation() : "");
1288                        oleNoticeBo.setItemId(oleDeliverRequestBoList.get(i).getItemId() != null ? oleDeliverRequestBoList.get(i).getItemId() : "");
1289                        oleNoticeBo.setTitle(oleDeliverRequestBoList.get(i).getTitle() != null ? oleDeliverRequestBoList.get(i).getTitle() : "");
1290                        oleNoticeBo.setOleItem(item);
1291                        oleNoticeBo.setOlePatron(oleDeliverRequestBoList.get(i).getOlePatron());
1292                        oleNoticeBo.setVolumeNumber(item.getVolumeNumber() != null ? item.getVolumeNumber() : "");
1293                        oleNoticeBo.setNewDueDate(new Date());
1294                        oleNoticeBo.setOriginalDueDate(new Date());
1295                        oleNoticeBo.setNoticeName(OLEConstants.OleDeliverRequest.EXPIRED_REQUEST);
1296                        String noticeContent = getLoanProcessor().getParameter(OLEConstants.OleDeliverRequest.EXP_HOLD_NOTICE_CONTENT);
1297                        oleNoticeBo.setNoticeSpecificContent(noticeContent);
1298                        noticesList.add(oleNoticeBo);
1299                        String agendaName = OLEConstants.BATCH_PROGRAM_AGENDA;
1300                        HashMap<String, Object> termValues = new HashMap<String, Object>();
1301                        OleCirculationDesk oleCirculationDesk = oleDeliverRequestBoList.get(i).getOlePickUpLocation();
1302                        OlePatronDocument olePatronDocument = oleDeliverRequestBoList.get(i).getOlePatron();
1303                        String deskLocation = oleCirculationDesk != null ? oleCirculationDesk.getCirculationDeskCode() : "";
1304                        String deskLocationName = oleCirculationDesk != null ? oleCirculationDesk.getCirculationDeskPublicName() : "";
1305                        termValues.put(OLEConstants.BORROWER_TYPE, olePatronDocument.getOleBorrowerType().getBorrowerTypeCode());
1306                        termValues.put(OLEConstants.DESK_LOCATION, deskLocation);
1307                        termValues.put(OLEConstants.NOTICE, OLEConstants.OleDeliverRequest.EXPIRED_REQUEST);
1308                        LOG.info("termValues.toString()" + termValues.toString());
1309                        EngineResults engineResults = loanProcessor.getEngineResults(agendaName, termValues);
1310                        noticeType = (String) engineResults.getAttribute(OLEConstants.NOTICE_TYPE);
1311                        LOG.info("**************" + noticeType);
1312                        noticeType = noticeType != null ? noticeType : getLoanProcessor().getParameter(OLEConstants.OleDeliverRequest.RQST_EXPR_NOTICE_TYPE);
1313                        if (noticeType != null && noticeType.equalsIgnoreCase(OLEConstants.SMS)) {
1314                            // noticesList.add(oleNoticeBo);
1315                            Map map = oleDeliverBatchService.getSMSForPatron(noticesList);
1316                            HashMap sms = (HashMap) map.get(OLEConstants.OleDeliverRequest.EXPIRED_REQUEST);
1317                            Iterator it = sms.entrySet().iterator();
1318                            while (it.hasNext()) {
1319                                Map.Entry pairs = (Map.Entry) it.next();
1320
1321                                String patronPhoneNumber = oleNoticeBo.getPatronPhoneNumber();
1322                                OleSms oleSms = new OleSms();
1323                                oleSms.sendSms("", patronPhoneNumber, (String) pairs.getValue());
1324                            }
1325                        }
1326                    }
1327                }
1328                if (noticeType != null && (noticeType.equalsIgnoreCase(OLEConstants.EMAIL) || noticeType.equalsIgnoreCase(OLEConstants.MAIL))) {
1329                    oleDeliverBatchService.getPdfNoticeForPatron(noticesList);
1330                    LOG.info("Request Expiration Notice Pdf generated for item Id");
1331                }
1332                if (noticeType != null && noticeType.equalsIgnoreCase(OLEConstants.EMAIL)) {
1333                    //  noticesList.add(oleNoticeBo);
1334                    List list = (List) oleDeliverBatchService.getNoticeForPatron(noticesList);
1335                    String noticeContent = list.toString();
1336                    noticeContent = noticeContent.replace('[', ' ');
1337                    noticeContent = noticeContent.replace(']', ' ');
1338                    if (!noticeContent.trim().equals("")) {
1339                        OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer");
1340                        String replyToEmail = getLoanProcessor().getReplyToEmail(oleNoticeBo.getItemShelvingLocation());
1341                        if (replyToEmail != null) {
1342                            oleMailer.sendEmail(new EmailFrom(replyToEmail), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(noticeContent), true);
1343                        } else {
1344                            String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL);
1345                            if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) {
1346                                fromAddress = OLEConstants.KUALI_MAIL;
1347                            }
1348                            oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(noticeContent), true);
1349                        }
1350                    } else {
1351                        for (OleNoticeBo oleNoticeBo1 : noticesList) {
1352                            LOG.info("Notice Type :" + oleNoticeBo1.getNoticeName() + "  " + "Item Barcode : " + oleNoticeBo1.getItemId() + " " + "Patron Name :" + oleNoticeBo1.getPatronName());
1353                        }
1354                    }
1355                    LOG.info("Mail send successfully to " + oleNoticeBo.getPatronEmailAddress());
1356
1357                }
1358            }
1359        }
1360    }
1361
1362    private java.sql.Date dateAdd(java.sql.Date in, int daysToAdd) {
1363        if (in == null) {
1364            return null;
1365        }
1366        GregorianCalendar cal = new GregorianCalendar();
1367        cal.setTime(in);
1368        cal.add(Calendar.DAY_OF_MONTH, daysToAdd);
1369        return new java.sql.Date(cal.getTime().getTime());
1370    }
1371
1372    public void deletingExpiredRequests() {
1373        LOG.info("Inside deletingExpiredRequests");
1374        List<OleDeliverRequestBo> oleDeliverRequestBoList = new ArrayList<OleDeliverRequestBo>();
1375        List<OleDeliverRequestBo> newOleDeliverRequestBoList = new ArrayList<OleDeliverRequestBo>();
1376        try {
1377            oleDeliverRequestBoList = (List<OleDeliverRequestBo>) businessObjectService.findAll(OleDeliverRequestBo.class);
1378            businessObjectService.delete(oleDeliverRequestBoList);
1379            SimpleDateFormat fmt = new SimpleDateFormat(OLEConstants.OleDeliverRequest.DATE_FORMAT);
1380            for (int i = 0; i < oleDeliverRequestBoList.size(); i++) {
1381                if ((fmt.format(oleDeliverRequestBoList.get(i).getRequestExpiryDate())).compareTo(fmt.format(new Date(System.currentTimeMillis()))) > 0) {
1382                    newOleDeliverRequestBoList.add(oleDeliverRequestBoList.get(i));
1383                }
1384            }
1385            businessObjectService.save(newOleDeliverRequestBoList);
1386        } catch (Exception e) {
1387            businessObjectService.save(oleDeliverRequestBoList);
1388            LOG.error(e, e);
1389        }
1390    }
1391
1392    private org.kuali.ole.docstore.common.document.content.instance.Item getItem(String itemUUID) {
1393        LOG.debug("Inside getItem");
1394        try {
1395            // Map  docStoreDetails= loanProcessor.getItemDetails(itemBarCode);
1396            String itemXml = loanProcessor.getItemXML(itemUUID);
1397            org.kuali.ole.docstore.common.document.content.instance.Item oleItem = loanProcessor.getItemPojo(itemXml);
1398            return oleItem;
1399        } catch (Exception e) {
1400            LOG.error("Item not available in doc store", e);
1401        }
1402        return null;
1403    }
1404
1405
1406    private OleNoticeBo setPatronDetailsForNotice(OleNoticeBo oleNoticeBo, OlePatronDocument olePatronDocument) {
1407        LOG.debug("Inside setPatronDetailsForNotice");
1408        if (oleNoticeBo.getAuthor() != null && olePatronDocument.getOlePatronId() != null) {
1409            oleNoticeBo.setPatronName(olePatronDocument.getName().getFirstName());
1410            if (olePatronDocument.getAddresses().size() > 0) {
1411                oleNoticeBo.setPatronAddress(olePatronDocument.getAddresses().get(0).getLine1() + "/n" + olePatronDocument.getAddresses().get(0).getLine2() + "/n" + olePatronDocument.getAddresses().get(0).getCity());
1412            }
1413            oleNoticeBo.setPatronEmailAddress(olePatronDocument.getEmailAddress());
1414            oleNoticeBo.setPatronPhoneNumber(olePatronDocument.getPhoneNumber());
1415        }
1416        return oleNoticeBo;
1417    }
1418
1419
1420    private void createRequestHistoryRecord(String requestId, String OperatorId, String loanTransactionNumber) {
1421        LOG.debug("Inside createRequestHistoryRecord");
1422        Map<String, String> requestMap = new HashMap<String, String>();
1423        requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_ID, requestId);
1424        List<OleDeliverRequestBo> oleDeliverRequestBoList = (List<OleDeliverRequestBo>) businessObjectService.findMatching(OleDeliverRequestBo.class, requestMap);
1425        if (oleDeliverRequestBoList.size() > 0) {
1426            OleDeliverRequestBo oleDeliverRequestBo = oleDeliverRequestBoList.get(0);
1427            OleDeliverRequestHistoryRecord oleDeliverRequestHistoryRecord = new OleDeliverRequestHistoryRecord();
1428            oleDeliverRequestHistoryRecord.setRequestId(oleDeliverRequestBo.getRequestId());
1429            oleDeliverRequestHistoryRecord.setItemId(oleDeliverRequestBo.getItemId());
1430            oleDeliverRequestHistoryRecord.setArchiveDate(new java.sql.Date(System.currentTimeMillis()));
1431            oleDeliverRequestHistoryRecord.setPickUpLocationCode(oleDeliverRequestBo.getPickUpLocationCode());
1432            oleDeliverRequestHistoryRecord.setOperatorId(OperatorId);
1433            oleDeliverRequestHistoryRecord.setDeliverRequestTypeCode(oleDeliverRequestBo.getRequestTypeCode());
1434            oleDeliverRequestHistoryRecord.setPoLineItemNumber("");
1435            oleDeliverRequestHistoryRecord.setLoanTransactionId(loanTransactionNumber);
1436            //oleDeliverRequestHistoryRecord.setMachineId("");      //commented for jira OLE-5675
1437            businessObjectService.save(oleDeliverRequestHistoryRecord);
1438        }
1439        businessObjectService.delete(oleDeliverRequestBoList);
1440    }
1441
1442    public OleDeliverRequestBo getOleDeliverRequestBo(String itemUUID) {
1443
1444        LOG.debug("Inside getOleDeliverRequestBo method");
1445        Map<String, String> requestMap = new HashMap<String, String>();
1446        requestMap.put(OLEConstants.ITEM_UUID, itemUUID);
1447        List<OleDeliverRequestBo> oleDeliverRequestBoList = (List<OleDeliverRequestBo>) businessObjectService.findMatching(OleDeliverRequestBo.class, requestMap);
1448        if (oleDeliverRequestBoList.size() > 0)
1449            return oleDeliverRequestBoList.get(0);
1450        return null;
1451    }
1452
1453    public String getPatronPreferredAddress(EntityTypeContactInfoBo entityTypeContactInfoBo) throws Exception {
1454        LOG.debug("Inside the getPatronPreferredAddress method");
1455        String address = "";
1456        if (entityTypeContactInfoBo.getAddresses() != null) {
1457            for (int i = 0; i < entityTypeContactInfoBo.getAddresses().size(); i++) {
1458                if (entityTypeContactInfoBo.getAddresses().get(i).isDefaultValue()) {
1459                    if (entityTypeContactInfoBo.getAddresses().get(i).getLine1() != null)
1460                        if (!entityTypeContactInfoBo.getAddresses().get(i).getLine1().isEmpty())
1461                            address += entityTypeContactInfoBo.getAddresses().get(i).getLine1() + ",";
1462
1463                    if (entityTypeContactInfoBo.getAddresses().get(i).getLine2() != null)
1464                        if (!entityTypeContactInfoBo.getAddresses().get(i).getLine2().isEmpty())
1465                            address += entityTypeContactInfoBo.getAddresses().get(i).getLine2() + ",";
1466
1467                    if (entityTypeContactInfoBo.getAddresses().get(i).getLine3() != null)
1468                        if (!entityTypeContactInfoBo.getAddresses().get(i).getLine3().isEmpty())
1469                            address += entityTypeContactInfoBo.getAddresses().get(i).getLine3() + ",";
1470
1471                    if (entityTypeContactInfoBo.getAddresses().get(i).getCity() != null)
1472                        if (!entityTypeContactInfoBo.getAddresses().get(i).getCity().isEmpty())
1473                            address += entityTypeContactInfoBo.getAddresses().get(i).getCity() + ",";
1474
1475                    if (entityTypeContactInfoBo.getAddresses().get(i).getStateProvinceCode() != null)
1476                        if (!entityTypeContactInfoBo.getAddresses().get(i).getStateProvinceCode().isEmpty())
1477                            address += entityTypeContactInfoBo.getAddresses().get(i).getStateProvinceCode() + ",";
1478
1479                    if (entityTypeContactInfoBo.getAddresses().get(i).getCountryCode() != null)
1480                        if (!entityTypeContactInfoBo.getAddresses().get(i).getCountryCode().isEmpty())
1481                            address += entityTypeContactInfoBo.getAddresses().get(i).getCountryCode() + ",";
1482
1483                    if (entityTypeContactInfoBo.getAddresses().get(i).getPostalCode() != null)
1484                        if (!entityTypeContactInfoBo.getAddresses().get(i).getPostalCode().isEmpty())
1485                            address += entityTypeContactInfoBo.getAddresses().get(i).getPostalCode();
1486                }
1487            }
1488        }
1489
1490        return address;
1491    }
1492
1493    public String getPatronHomePhoneNumber(EntityTypeContactInfoBo entityTypeContactInfoBo) throws Exception {
1494        LOG.debug("Inside the getPatronHomePhoneNumber method");
1495        String phoneNumber = "";
1496        if (entityTypeContactInfoBo.getPhoneNumbers() != null) {
1497            for (int j = 0; j < entityTypeContactInfoBo.getPhoneNumbers().size(); j++) {
1498                if (entityTypeContactInfoBo.getPhoneNumbers().get(j).getPhoneTypeCode().equalsIgnoreCase("HM")) {
1499                    phoneNumber = (entityTypeContactInfoBo.getPhoneNumbers().get(j).getPhoneNumber());
1500                }
1501            }
1502        }
1503        return phoneNumber;
1504    }
1505
1506    public String getPatronHomeEmailId(EntityTypeContactInfoBo entityTypeContactInfoBo) throws Exception {
1507        LOG.debug("Inside the getPatronHomeEmailId method");
1508        String emailId = "";
1509        if (entityTypeContactInfoBo.getEmailAddresses() != null) {
1510            for (int j = 0; j < entityTypeContactInfoBo.getEmailAddresses().size(); j++) {
1511                if (entityTypeContactInfoBo.getEmailAddresses().get(j).getEmailTypeCode().equalsIgnoreCase("HM")) {
1512                    emailId = (entityTypeContactInfoBo.getEmailAddresses().get(j).getEmailAddress());
1513                }
1514            }
1515        }
1516        return emailId;
1517    }
1518
1519    private static int determineDifferenceInDays(Date currentDate, Date dueDate) {
1520        Calendar calendar1 = Calendar.getInstance();
1521        calendar1.setTime(dueDate);
1522        Calendar calendar2 = Calendar.getInstance();
1523        calendar2.setTime(currentDate);
1524        long diffInMillis = calendar2.getTimeInMillis() - calendar1.getTimeInMillis();
1525        return (int) (diffInMillis / (24 * 1000 * 60 * 60));
1526    }
1527
1528
1529    public void generateNotices() throws Exception {
1530        DataCarrierService dataCarrierService = GlobalResourceLoader.getService(OLEConstants.DATA_CARRIER_SERVICE);
1531        List<OlePatronDocument> patronDocumentList = (List<OlePatronDocument>) KRADServiceLocator.getBusinessObjectService().findAll(OlePatronDocument.class);
1532        for (OlePatronDocument olePatronDocument : patronDocumentList) {
1533            Map<String, String> requestMap = new HashMap<String, String>();
1534            requestMap.put(OLEConstants.OleDeliverRequest.LOAN_PATRON_ID, olePatronDocument.getOlePatronId());
1535            List<OleLoanDocument> oleLoanDocumentList = (List<OleLoanDocument>) KRADServiceLocator.getBusinessObjectService().findMatching(OleLoanDocument.class, requestMap);
1536            for (OleLoanDocument oleLoanDocument : oleLoanDocumentList) {
1537                try {
1538                    List<OleNoticeBo> oleNoticeBos = new ArrayList<OleNoticeBo>();
1539                    org.kuali.ole.docstore.common.document.Item item = new ItemOleml();
1540                    org.kuali.ole.docstore.common.search.SearchParams search_Params = new org.kuali.ole.docstore.common.search.SearchParams();
1541                    SearchResponse searchResponse = null;
1542                    search_Params.getSearchConditions().add(search_Params.buildSearchCondition("", search_Params.buildSearchField(org.kuali.ole.docstore.common.document.content.enums.DocType.ITEM.getCode(), item.ITEM_BARCODE, oleLoanDocument.getItemId()), ""));
1543                    //search_Params.getSearchResultFields().add(search_Params.buildSearchResultField(org.kuali.ole.docstore.common.document.content.enums.DocType.ITEM.getCode(), "id"));
1544                    search_Params.getSearchResultFields().add(search_Params.buildSearchResultField(org.kuali.ole.docstore.common.document.content.enums.DocType.HOLDINGS.getCode(), "id"));
1545                    // search_Params.getSearchResultFields().add(search_Params.buildSearchResultField(org.kuali.ole.docstore.common.document.content.enums.DocType.BIB.getCode(), "id"));
1546                   /* Map<String,String> map=new HashMap<>();
1547                    map.put(item.BARCODE, itemBarcode);
1548                    item=getDocstoreClientLocator().getDocstoreClient().findItem(map);*/
1549                    searchResponse = getDocstoreClientLocator().getDocstoreClient().search(search_Params);
1550                    for (SearchResult searchResult : searchResponse.getSearchResults()) {
1551                        for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
1552                            String fieldName = searchResultField.getFieldName();
1553                            String fieldValue = searchResultField.getFieldValue() != null ? searchResultField.getFieldValue() : "";
1554
1555                            if (fieldName.equalsIgnoreCase("id") && !fieldValue.isEmpty() && searchResultField.getDocType().equalsIgnoreCase("holdings")) {
1556                                oleLoanDocument.setInstanceUuid(fieldValue);
1557                            }
1558
1559                        }
1560                    }
1561                    String itemXml = loanProcessor.getItemXML(oleLoanDocument.getItemUuid());
1562                    org.kuali.ole.docstore.common.document.content.instance.Item oleItem = loanProcessor.getItemPojo(itemXml);
1563                    oleLoanDocument.setOleItem(oleItem);
1564                    oleLoanDocument.setOlePatron(olePatronDocument);
1565                    OleNoticeBo oleNoticeBo = new OleNoticeBo();
1566                    Date dueDate = oleLoanDocument.getLoanDueDate();
1567                    Date currentDate = new Date();
1568                    Integer dueDateDiffInterval = dueDate!=null ? determineDifferenceInDays(dueDate, currentDate) : 0;
1569                    DateFormat formatter = new SimpleDateFormat(OLEConstants.DAT_FORMAT_EFFECTIVE_NOTICE);
1570                    LOG.info("oleItem.getItemStatusEffectiveDate()" + oleItem.getItemStatusEffectiveDate());
1571                    Date itemStatusEffectiveDate = (Date) formatter.parse(oleItem.getItemStatusEffectiveDate());
1572                    Integer numberOfDaysOnHold = determineDifferenceInDays(itemStatusEffectiveDate, currentDate);
1573                    Integer dueDateSumInterval = dueDate!=null ? determineDifferenceInDays(currentDate, dueDate) : 0;
1574                    Integer overdueNoticeInterval = Integer.parseInt(getIntervalForOverdueNotice());
1575                    Integer intervalWithNoticeCount = 0;
1576                    Integer loanNoOfOverdueNoticeSent = oleLoanDocument.getNumberOfOverdueNoticesSent() != null ? Integer.parseInt(oleLoanDocument.getNumberOfOverdueNoticesSent()) : 0;
1577                    if (oleLoanDocument.getNumberOfOverdueNoticesSent() != null) {
1578                        intervalWithNoticeCount = Integer.parseInt(oleLoanDocument.getNumberOfOverdueNoticesSent()) + 1;
1579                    } else {
1580                        intervalWithNoticeCount = intervalWithNoticeCount + 1;
1581                    }
1582                 //   intervalWithNoticeCount = intervalWithNoticeCount * overdueNoticeInterval;
1583                    dueDateSumInterval = dueDateSumInterval / intervalWithNoticeCount;
1584                    if (dueDateSumInterval < 0) {
1585                        dueDateSumInterval = 0;
1586                    }
1587                    if (dueDateDiffInterval < 0) {
1588                        dueDateDiffInterval = 0;
1589                    }
1590                    Integer maxNumberOfDaysOnHold = 0;
1591                    OleCirculationDesk oleCirculationDesk = null;
1592                    if (oleLoanDocument.getCirculationLocationId() != null) {
1593                        oleCirculationDesk = loanProcessor.getOleCirculationDesk(oleLoanDocument.getCirculationLocationId());
1594                        String maxNumOfDays = oleCirculationDesk.getOnHoldDays() != null ? oleCirculationDesk.getOnHoldDays() : loanProcessor.getParameter(OLEConstants.MAX_NO_OF_DAYS_ON_HOLD);
1595                        maxNumberOfDaysOnHold = new Integer(maxNumOfDays);
1596                    }
1597                    if (oleItem.getTemporaryItemType() != null && oleItem.getTemporaryItemType().getCodeValue() != "") {
1598                        OleInstanceItemType oleInstanceItemType = loanProcessor.getItemTypeIdByItemType(oleItem.getTemporaryItemType().getCodeValue());
1599                        oleLoanDocument.setItemTypeName(oleInstanceItemType.getInstanceItemTypeCode());
1600                    }
1601                    else if (oleItem.getItemType() != null && oleItem.getItemType().getCodeValue() != "") {
1602                        OleInstanceItemType oleInstanceItemType = loanProcessor.getItemTypeIdByItemType(oleItem.getItemType().getCodeValue());
1603                        oleLoanDocument.setItemTypeName(oleInstanceItemType.getInstanceItemTypeCode());
1604                    }
1605                    oleLoanDocument.setInstanceUuid(oleLoanDocument.getInstanceUuid());
1606                    loanProcessor.getLocation(oleItem, oleLoanDocument);
1607                    String agendaName = OLEConstants.NOTICE_AGENDA_NM;
1608                    dataCarrierService.addData(OLEConstants.CIRC_POLICY_FOUND, null);
1609                    HashMap<String, Object> termValues = new HashMap<String, Object>();
1610                    termValues.put(OLEConstants.BORROWER_TYPE, olePatronDocument.getOleBorrowerType().getBorrowerTypeCode());
1611                    termValues.put(OLEConstants.ITEM_TYPE, oleLoanDocument.getItemTypeName());
1612                    termValues.put(OLEConstants.OVERLAY_ITEM_LOCATION, oleLoanDocument.getItemLocation());
1613                    termValues.put(OLEConstants.DUE_DATE_DIFF_INTERVAL, dueDateDiffInterval);
1614                    if (oleItem.getItemStatus() != null)
1615                        termValues.put(OLEConstants.ITEM_STATUS, oleItem.getItemStatus().getCodeValue());
1616                    termValues.put(OLEConstants.NO_OF_DAYS_ON_HOLD, numberOfDaysOnHold);
1617                    termValues.put(OLEConstants.MAX_NO_OF_DAYS_ONHOLD, maxNumberOfDaysOnHold);
1618                    termValues.put(OLEConstants.OleDeliverRequest.CLAIM_RETURNED, oleItem.isClaimsReturnedFlag() ? "true" : "false");
1619                    termValues.put(OLEConstants.OleDeliverRequest.REPLACEMENT_FEE_PATRON_BILL, oleLoanDocument.getRepaymentFeePatronBillId() != null ? "true" : "false");
1620                    termValues.put(OLEConstants.OleDeliverRequest.NUBER_OF_OVER_DUE_SENT, loanNoOfOverdueNoticeSent);
1621                    termValues.put(OLEConstants.OleDeliverRequest.DUE_DATE_SUM_INTERVAL, dueDateSumInterval);
1622                    termValues.put(OLEConstants.OleDeliverRequest.CONFIGURABLE_INTERVAL, Integer.parseInt(getIntervalForCourtesyNotice()));
1623                    termValues.put(OLEConstants.OleDeliverRequest.INTERVAL_WITH_NOTICE_COUNT, intervalWithNoticeCount);
1624                    termValues.put(OLEConstants.ITEM_SHELVING, oleLoanDocument.getItemLocation());
1625                    termValues.put(OLEConstants.ITEM_COLLECTION, oleLoanDocument.getItemCollection());
1626                    termValues.put(OLEConstants.ITEM_LIBRARY, oleLoanDocument.getItemLibrary());
1627                    termValues.put(OLEConstants.ITEM_CAMPUS, oleLoanDocument.getItemCampus());
1628                    termValues.put(OLEConstants.ITEM_INSTITUTION, oleLoanDocument.getItemInstitution());
1629                    LOG.info("termValues.toString()" + termValues.toString());
1630                    EngineResults engineResults = loanProcessor.getEngineResults(agendaName, termValues);
1631                    String notice = (String) engineResults.getAttribute(OLEConstants.NOTICE);
1632                    String itemStatus = (String) engineResults.getAttribute(OLEConstants.ITEM_STATUS);
1633                    BigDecimal replacementBill = (BigDecimal) engineResults.getAttribute(OLEConstants.REPLACEMENT_BILL);
1634                    List<String> errorMessage = (List<String>) engineResults.getAttribute(OLEConstants.ERROR_ACTION);
1635                    if (errorMessage != null) {
1636                        LOG.info("errorMessage" + errorMessage.toString());
1637                    }
1638                    LOG.info("notice" + notice);
1639                    agendaName = OLEConstants.BATCH_PROGRAM_AGENDA;
1640                    termValues = new HashMap<String, Object>();
1641                    String deskLocation = oleCirculationDesk != null ? oleCirculationDesk.getCirculationDeskCode() : "";
1642                    String deskLocationName = oleCirculationDesk != null ? oleCirculationDesk.getCirculationDeskPublicName() : "";
1643                    termValues.put(OLEConstants.BORROWER_TYPE, olePatronDocument.getOleBorrowerType().getBorrowerTypeCode());
1644                    termValues.put(OLEConstants.DESK_LOCATION, deskLocation);
1645                    termValues.put(OLEConstants.NOTICE, notice);
1646                    engineResults = loanProcessor.getEngineResults(agendaName, termValues);
1647                    String noticeType = (String) engineResults.getAttribute(OLEConstants.NOTICE_TYPE);
1648                    errorMessage = (List<String>) engineResults.getAttribute(OLEConstants.ERROR_ACTION);
1649                    if (errorMessage != null) {
1650                        LOG.info("errorMessage" + errorMessage);
1651                    }
1652                    LOG.info("noticeType" + noticeType);
1653                    if (itemStatus != null) {
1654                        int noOfOverdueNoticeSent = Integer.parseInt(oleLoanDocument.getNumberOfOverdueNoticesSent() != null ? oleLoanDocument.getNumberOfOverdueNoticesSent() : "0");
1655                        noOfOverdueNoticeSent = noOfOverdueNoticeSent + 1;
1656                        oleLoanDocument.setNumberOfOverdueNoticesSent(Integer.toString(noOfOverdueNoticeSent));
1657                        oleLoanDocument.setOverDueNoticeDate(new java.sql.Date(System.currentTimeMillis()));
1658                        String billNumber = loanProcessor.generatePatronBillPayment(oleLoanDocument, OLEConstants.REPLACEMENT_FEE, replacementBill);
1659                        oleLoanDocument.setRepaymentFeePatronBillId(billNumber);
1660                        getBusinessObjectService().save(oleLoanDocument);
1661                        loanProcessor.updateItemStatus(oleItem, itemStatus);
1662                    }
1663                    OleDeliverBatchServiceImpl oleDeliverBatchService = new OleDeliverBatchServiceImpl();
1664                    if (notice != null) {
1665                        oleNoticeBo.setNoticeName(notice);
1666                    /*if(notice.equalsIgnoreCase(OLEConstants.NOTICE_HOLD_COURTESY)){
1667                        oleNoticeBo = getExpiredHoldNotice(oleLoanDocument);
1668                    } else */
1669                        if (notice.equalsIgnoreCase(OLEConstants.NOTICE_OVERDUE)) {
1670                            oleNoticeBo = getOverdueNotice(oleLoanDocument);
1671                            noticeType = noticeType == null ? loanProcessor.getParameter(OLEParameterConstants.OVERDUE_NOTICE_TYPE) : noticeType;
1672                        } else if (notice.equalsIgnoreCase(OLEConstants.NOTICE_COURTESY) && olePatronDocument.isCourtesyNotice() && !oleLoanDocument.isCourtesyNoticeFlag()) {
1673                            oleNoticeBo = getCourtesyNotice(oleLoanDocument);
1674                            noticeType = noticeType == null ? loanProcessor.getParameter(OLEParameterConstants.COURTESY_NOTICE_TYPE) : noticeType;
1675                        }
1676                        oleNoticeBo.setCirculationDeskName(deskLocationName);
1677                        if (!olePatronDocument.isCourtesyNotice()) {
1678                            oleNoticeBo = null;
1679                        }
1680                        if (oleNoticeBo != null) {
1681                            oleNoticeBos.add(oleNoticeBo);
1682                        }
1683                        if (oleNoticeBos != null && oleNoticeBos.size() > 0 && noticeType != null && (noticeType.equalsIgnoreCase(OLEConstants.EMAIL) || noticeType.equalsIgnoreCase(OLEConstants.MAIL))) {
1684                            oleDeliverBatchService.getPdfNoticeForPatron(oleNoticeBos);
1685                        }
1686                    }
1687                    olePatronDocument = oleLoanDocument.getOlePatron();
1688                    if (oleNoticeBos != null && oleNoticeBos.size() > 0 && oleNoticeBos != null && oleNoticeBos.size() > 0 && noticeType != null && noticeType.equalsIgnoreCase(OLEConstants.EMAIL)) {
1689                        if (olePatronDocument.getEmailAddress() != null && !olePatronDocument.getEmailAddress().isEmpty()) {
1690                            List list = oleDeliverBatchService.getNoticeForPatron(oleNoticeBos);
1691                            String noticeContent = list.toString();
1692                            noticeContent = noticeContent.replace('[', ' ');
1693                            noticeContent = noticeContent.replace(']', ' ');
1694                            if (!noticeContent.trim().equals("")) {
1695                                OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer");
1696                                String replyToEmail = getLoanProcessor().getReplyToEmail(oleNoticeBo.getItemShelvingLocation());
1697                                if (replyToEmail != null) {
1698                                    oleMailer.sendEmail(new EmailFrom(replyToEmail), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(noticeContent), true);
1699                                } else {
1700                                    String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL);
1701                                    if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) {
1702                                        fromAddress = OLEConstants.KUALI_MAIL;
1703                                    }
1704                                    oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(noticeContent), true);
1705                                }
1706                            } else {
1707                                for (OleNoticeBo oleNoticeBo1 : oleNoticeBos) {
1708                                    LOG.info("Notice Type :" + oleNoticeBo1.getNoticeName() + "  " + "Item Barcode : " + oleNoticeBo1.getItemId() + " " + "Patron Name :" + oleNoticeBo1.getPatronName());
1709                                }
1710                            }
1711                            LOG.info("Mail send successfully to " + oleNoticeBo.getPatronEmailAddress());
1712                      /*  Mailer mailer =CoreApiServiceLocator.getMailer();
1713                        mailer.sendEmail(new EmailFrom(OLEConstants.KUALI_MAIL), new EmailTo(olePatronDocument.getEmailAddress()), new EmailSubject("Notice Mail"), new EmailBody(list.toString()), true);
1714                      */
1715                            LOG.info("olePatronDocument.getEmailAddress()" + olePatronDocument.getEmailAddress());
1716                        }
1717                    } else if (noticeType != null && noticeType.equalsIgnoreCase(OLEConstants.SMS)) {
1718                        //TODO : sms in progress.
1719                    }
1720                } catch (Exception e) {
1721                    LOG.error("Exception in generateNotices()" + e.getMessage(), e);
1722                }
1723            }
1724        }
1725    }
1726
1727    public void generateHoldCourtesyNotice() throws Exception {
1728        List<OleDeliverRequestBo> oleDeliverRequestBos = (List<OleDeliverRequestBo>) KRADServiceLocator.getBusinessObjectService().findAll(OleDeliverRequestBo.class);
1729        for (OleDeliverRequestBo oleDeliverRequestBo : oleDeliverRequestBos) {
1730            List<OleNoticeBo> oleNoticeBos = new ArrayList<OleNoticeBo>();
1731            DataCarrierService dataCarrierService = GlobalResourceLoader.getService(OLEConstants.DATA_CARRIER_SERVICE);
1732            if (docstoreUtil.isItemAvailableInDocStore(oleDeliverRequestBo)) {
1733                org.kuali.ole.docstore.common.document.content.instance.Item oleItem = oleDeliverRequestBo.getOleItem();
1734                OleNoticeBo oleNoticeBo = new OleNoticeBo();
1735                Date currentDate = new Date();
1736                DateFormat formatter = new SimpleDateFormat(OLEConstants.DAT_FORMAT_EFFECTIVE_NOTICE);
1737                Date itemStatusEffectiveDate = (Date) formatter.parse(oleItem.getItemStatusEffectiveDate());
1738                Integer numberOfDaysOnHold = determineDifferenceInDays(currentDate, itemStatusEffectiveDate);
1739                Integer maxNumberOfDaysOnHold = 0;
1740                OleCirculationDesk oleCirculationDesk = null;
1741                if (oleDeliverRequestBo.getPickUpLocationId() != null) {
1742                    oleCirculationDesk = loanProcessor.getOleCirculationDesk(oleDeliverRequestBo.getPickUpLocationId());
1743                    String maxNumOfDays = oleCirculationDesk.getOnHoldDays() != null ? oleCirculationDesk.getOnHoldDays() : loanProcessor.getParameter(OLEConstants.MAX_NO_OF_DAYS_ON_HOLD);
1744                    maxNumberOfDaysOnHold = new Integer(maxNumOfDays);
1745                }
1746                String itemTypeName = null;
1747                if (oleItem.getTemporaryItemType() != null && oleItem.getTemporaryItemType().getCodeValue() != "") {
1748                    OleInstanceItemType oleInstanceItemType = loanProcessor.getItemTypeIdByItemType(oleItem.getTemporaryItemType().getCodeValue());
1749                    itemTypeName = oleInstanceItemType.getInstanceItemTypeCode();
1750                }else if (oleItem.getItemType() != null && oleItem.getItemType().getCodeValue() != "") {
1751                    OleInstanceItemType oleInstanceItemType = loanProcessor.getItemTypeIdByItemType(oleItem.getItemType().getCodeValue());
1752                    itemTypeName = oleInstanceItemType.getInstanceItemTypeCode();
1753                }
1754                OlePatronDocument olePatronDocument = oleDeliverRequestBo.getOlePatron();
1755                String agendaName = "Notice Validation";
1756                dataCarrierService.addData(OLEConstants.CIRC_POLICY_FOUND, null);
1757                HashMap<String, Object> termValues = new HashMap<String, Object>();
1758                termValues.put(OLEConstants.BORROWER_TYPE, olePatronDocument.getOleBorrowerType().getBorrowerTypeCode());
1759                termValues.put(OLEConstants.ITEM_TYPE, itemTypeName);
1760                termValues.put(OLEConstants.OVERLAY_ITEM_LOCATION, oleDeliverRequestBo.getShelvingLocation());
1761                termValues.put(OLEConstants.NO_OF_DAYS_ON_HOLD, numberOfDaysOnHold);
1762                termValues.put(OLEConstants.MAX_NO_OF_DAYS_ONHOLD, maxNumberOfDaysOnHold);
1763                termValues.put(OLEConstants.ITEM_SHELVING, oleDeliverRequestBo.getShelvingLocation());
1764                termValues.put(OLEConstants.ITEM_COLLECTION, oleDeliverRequestBo.getItemCollection());
1765                termValues.put(OLEConstants.ITEM_LIBRARY, oleDeliverRequestBo.getItemLibrary());
1766                termValues.put(OLEConstants.ITEM_CAMPUS, oleDeliverRequestBo.getItemCampus());
1767                termValues.put(OLEConstants.ITEM_INSTITUTION, oleDeliverRequestBo.getItemInstitution());
1768                if (oleItem.getItemStatus() != null)
1769                    termValues.put(OLEConstants.ITEM_STATUS, oleItem.getItemStatus().getCodeValue());
1770                LOG.info("termValues.toString()" + termValues.toString());
1771                EngineResults engineResults = loanProcessor.getEngineResults(agendaName, termValues);
1772                String notice = (String) engineResults.getAttribute(OLEConstants.NOTICE);
1773                LOG.info("notice" + notice);
1774                agendaName = OLEConstants.BATCH_PROGRAM_AGENDA;
1775                termValues = new HashMap<String, Object>();
1776                String deskLocation = oleCirculationDesk != null ? oleCirculationDesk.getCirculationDeskCode() : "";
1777                String deskLocationName = oleCirculationDesk != null ? oleCirculationDesk.getCirculationDeskPublicName() : "";
1778                termValues.put(OLEConstants.BORROWER_TYPE, olePatronDocument.getOleBorrowerType().getBorrowerTypeCode());
1779                termValues.put(OLEConstants.DESK_LOCATION, deskLocation);
1780                termValues.put(OLEConstants.NOTICE, notice);
1781                LOG.info("termValues.toString()" + termValues.toString());
1782                engineResults = loanProcessor.getEngineResults(agendaName, termValues);
1783                String noticeType = (String) engineResults.getAttribute(OLEConstants.NOTICE_TYPE);
1784                LOG.info("**************" + noticeType);
1785                OleDeliverBatchServiceImpl oleDeliverBatchService = new OleDeliverBatchServiceImpl();
1786                if (notice != null) {
1787                    oleNoticeBo.setNoticeName(notice);
1788                    if (notice.equalsIgnoreCase(OLEConstants.NOTICE_HOLD_COURTESY)) {
1789                        oleNoticeBo = getExpiredHoldNotice(oleDeliverRequestBo);
1790                        oleNoticeBo.setCirculationDeskName(deskLocationName);
1791                        oleNoticeBos.add(oleNoticeBo);
1792                        noticeType = noticeType == null ? loanProcessor.getParameter("HOLDCOURTESY_NOTICE_TYPE") : noticeType;
1793                    }
1794                    if (oleNoticeBos.size() > 0 && noticeType != null && (noticeType.equalsIgnoreCase(OLEConstants.EMAIL) || noticeType.equalsIgnoreCase(OLEConstants.MAIL))) {
1795                        oleDeliverBatchService.getPdfNoticeForPatron(oleNoticeBos);
1796                    }
1797
1798                }
1799                olePatronDocument = oleDeliverRequestBo.getOlePatron();
1800                if (noticeType != null && noticeType.equalsIgnoreCase(OLEConstants.EMAIL)) {
1801                    if (olePatronDocument.getEmailAddress() != null && !olePatronDocument.getEmailAddress().isEmpty()) {
1802                        List list = oleDeliverBatchService.getNoticeForPatron(oleNoticeBos);
1803                        String noticeContent = list.toString();
1804                        noticeContent = noticeContent.replace('[', ' ');
1805                        noticeContent = noticeContent.replace(']', ' ');
1806                        if (!noticeContent.trim().equals("")) {
1807                            OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer");
1808                            if (oleDeliverRequestBo.getOlePickUpLocation() != null && StringUtils.isNotBlank(oleDeliverRequestBo.getOlePickUpLocation().getReplyToEmail())) {
1809                                oleMailer.sendEmail(new EmailFrom(oleDeliverRequestBo.getOlePickUpLocation().getReplyToEmail()), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(noticeContent), true);
1810                            } else {
1811                                String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL);
1812                                if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) {
1813                                    fromAddress = OLEConstants.KUALI_MAIL;
1814                                }
1815                                oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(noticeContent), true);
1816                            }
1817                        } else {
1818                            for (OleNoticeBo oleNoticeBo1 : oleNoticeBos) {
1819                                LOG.info("Notice Type :" + oleNoticeBo1.getNoticeName() + "  " + "Item Barcode : " + oleNoticeBo1.getItemId() + " " + "Patron Name :" + oleNoticeBo1.getPatronName());
1820                            }
1821                        }
1822/*
1823                        Mailer mailer =CoreApiServiceLocator.getMailer();
1824                        mailer.sendEmail(new EmailFrom(OLEConstants.KUALI_MAIL), new EmailTo(olePatronDocument.getEmailAddress()), new EmailSubject("Notice Mail"), new EmailBody(list.toString()), true);
1825                     */
1826                        LOG.info("olePatronDocument.getEmailAddress()" + olePatronDocument.getEmailAddress());
1827                    }
1828                } else if (noticeType != null && noticeType.equalsIgnoreCase(OLEConstants.SMS)) {
1829                    //TODO : sms in progress.
1830                }
1831            }
1832        }
1833    }
1834
1835    public void deleteTemporaryHistoryRecord() throws Exception {
1836        List<OlePatronDocument> patronDocumentList = (List<OlePatronDocument>) KRADServiceLocator.getBusinessObjectService().findAll(OlePatronDocument.class);
1837        for (OlePatronDocument olePatronDocument : patronDocumentList) {
1838            Map<String, String> requestMap = new HashMap<String, String>();
1839            requestMap.put(OLEConstants.OlePatron.PATRON_ID, olePatronDocument.getOlePatronId());
1840            List<OleTemporaryCirculationHistory> oleTemporaryCirculationHistoryList = (List<OleTemporaryCirculationHistory>) KRADServiceLocator.getBusinessObjectService().findMatching(OleTemporaryCirculationHistory.class, requestMap);
1841            List<OleTemporaryCirculationHistory> deleteRecords = new ArrayList<OleTemporaryCirculationHistory>();
1842            for (OleTemporaryCirculationHistory oleTemporaryCirculationHistory : oleTemporaryCirculationHistoryList) {
1843                String agendaName = OLEConstants.BATCH_PROGRAM_AGENDA;
1844                HashMap<String, Object> termValues = new HashMap<String, Object>();
1845                termValues.put(OLEConstants.OleDeliverRequest.IS_TEMPORARY_HISTORY_RECORD, "true");
1846                DataCarrierService dataCarrierService = GlobalResourceLoader.getService(OLEConstants.DATA_CARRIER_SERVICE);
1847                dataCarrierService.addData(OLEConstants.DATE_CHECK_IN, oleTemporaryCirculationHistory.getCheckInDate());
1848                EngineResults engineResults = loanProcessor.getEngineResults(agendaName, termValues);
1849                Boolean deleteRecord = (Boolean) engineResults.getAttribute(OLEConstants.OVERLAY_OPTION_DELETE);
1850                if (deleteRecord != null && deleteRecord) {
1851                    deleteRecords.add(oleTemporaryCirculationHistory);
1852                }
1853            }
1854            getBusinessObjectService().delete(deleteRecords);
1855        }
1856    }
1857
1858    private OleNoticeBo getExpiredHoldNotice(OleDeliverRequestBo oleDeliverRequestBo) throws Exception {
1859        LOG.debug("Expired Hold Notice");
1860        org.kuali.ole.docstore.common.document.content.instance.Item oleItem = oleDeliverRequestBo.getOleItem();
1861        EntityTypeContactInfoBo entityTypeContactInfoBo = oleDeliverRequestBo.getOlePatron().getEntity().getEntityTypeContactInfos().get(0);
1862        OleNoticeBo oleNoticeBo = new OleNoticeBo();
1863        org.kuali.ole.docstore.common.document.Item item = getDocstoreClientLocator().getDocstoreClient().retrieveItem(oleDeliverRequestBo.getItemUuid());
1864        String shelvingLocation = oleDeliverRequestBo.getShelvingLocation();
1865        OleCirculationDesk oleCirculationDesk = getOleCirculationDesk(oleDeliverRequestBo.getPickUpLocationId());
1866        if (oleCirculationDesk != null)
1867            oleNoticeBo.setCirculationDeskName(oleCirculationDesk.getCirculationDeskPublicName());
1868        else
1869            oleNoticeBo.setCirculationDeskName("");
1870        oleNoticeBo.setCirculationDeskAddress("");
1871        oleNoticeBo.setCirculationDeskEmailAddress("");
1872        oleNoticeBo.setCirculationDeskPhoneNumber("");
1873        oleNoticeBo.setCirculationDeskPhoneNumber("");
1874        oleNoticeBo.setPatronName(oleDeliverRequestBo.getOlePatron().getEntity().getNames().get(0).getFirstName() + " " + oleDeliverRequestBo.getOlePatron().getEntity().getNames().get(0).getLastName());
1875        oleNoticeBo.setPatronAddress(getPatronPreferredAddress(entityTypeContactInfoBo) != null ? getPatronPreferredAddress(entityTypeContactInfoBo) : "");
1876        oleNoticeBo.setPatronEmailAddress(getPatronHomeEmailId(entityTypeContactInfoBo) != null ? getPatronHomeEmailId(entityTypeContactInfoBo) : "");
1877        oleNoticeBo.setPatronPhoneNumber(getPatronHomePhoneNumber(entityTypeContactInfoBo) != null ? getPatronHomePhoneNumber(entityTypeContactInfoBo) : "");
1878        oleNoticeBo.setNoticeName(OLEConstants.NOTICE_HOLD_COURTESY);
1879        oleNoticeBo.setNoticeSpecificContent(LoanUtil.getLoanUtil().getProperty(OLEConstants.OleDeliverRequest.EXP_HOLD_NOTICE_CONTENT));
1880        oleNoticeBo.setTitle(item.getHolding().getBib().getTitle());
1881        oleNoticeBo.setAuthor(item.getHolding().getBib().getAuthor());
1882        /*oleNoticeBo.setTitle((String) bibInformation.get(OLEConstants.TITLE) != null ? (String) bibInformation.get(OLEConstants.TITLE) : "");
1883        oleNoticeBo.setAuthor((String) bibInformation.get(OLEConstants.AUTHOR) != null ? (String) bibInformation.get(OLEConstants.AUTHOR) : "");*/
1884        oleNoticeBo.setVolumeNumber(item.getVolumeNumber());
1885        oleNoticeBo.setItemShelvingLocation(shelvingLocation != null ? shelvingLocation : "");
1886        //oleNoticeBo.setItemCallNumber((String) docStoreDetails.get(OLEConstants.CALL_NUM) != null ? (String) docStoreDetails.get(OLEConstants.CALL_NUM) : "");
1887        oleNoticeBo.setItemCallNumber((String) oleItem.getCallNumber().getNumber() != null && !oleItem.getCallNumber().getNumber().equals("") ? oleItem.getCallNumber().getNumber() : "");
1888        oleNoticeBo.setItemId(oleDeliverRequestBo.getItemId() != null ? oleDeliverRequestBo.getItemId() : "");
1889        oleNoticeBo.setOleItem(oleItem);
1890        oleNoticeBo.setOlePatron(oleDeliverRequestBo.getOlePatron());
1891        oleNoticeBo = setPatronDetailsForNotice(oleNoticeBo, oleDeliverRequestBo.getOlePatron());
1892        oleDeliverRequestBo.getOlePatron().setEmailAddress(oleNoticeBo.getPatronEmailAddress());
1893        return oleNoticeBo;
1894    }
1895
1896    private OleNoticeBo getCourtesyNotice(OleLoanDocument oleLoanDocument) throws Exception {
1897        LOG.debug("Courtesy Notice");
1898        oleLoanDocument.setCourtesyNoticeFlag(true);
1899        Map<String, String> map = new HashMap<String, String>();
1900        map.put("loanId", oleLoanDocument.getLoanId());
1901        KRADServiceLocator.getBusinessObjectService().save(oleLoanDocument);
1902        EntityTypeContactInfoBo entityTypeContactInfoBo = oleLoanDocument.getOlePatron().getEntity().getEntityTypeContactInfos().get(0);
1903        OleNoticeBo oleNoticeBo = new OleNoticeBo();
1904        //String itemId  = oleLoanDocument.getItemId();
1905        org.kuali.ole.docstore.common.document.content.instance.Item oleItem = oleLoanDocument.getOleItem();
1906        org.kuali.ole.docstore.common.document.Item item = getDocstoreClientLocator().getDocstoreClient().retrieveItem(oleLoanDocument.getItemUuid());
1907        ItemOlemlRecordProcessor itemOlemlRecordProcessor = new ItemOlemlRecordProcessor();
1908        org.kuali.ole.docstore.common.document.content.instance.Item itemContent = itemOlemlRecordProcessor.fromXML(item.getContent());
1909        String shelvingLocation = oleLoanDocument.getItemLocation();
1910        OleCirculationDesk oleCirculationDesk = getOleCirculationDesk(oleLoanDocument.getCirculationLocationId());
1911        if (oleCirculationDesk != null)
1912            oleNoticeBo.setCirculationDeskName(oleCirculationDesk.getCirculationDeskPublicName());
1913        else
1914            oleNoticeBo.setCirculationDeskName("");
1915        oleNoticeBo.setCirculationDeskAddress("");
1916        oleNoticeBo.setCirculationDeskEmailAddress("");
1917        oleNoticeBo.setCirculationDeskPhoneNumber("");
1918        oleNoticeBo.setPatronName(oleLoanDocument.getOlePatron().getEntity().getNames().get(0).getFirstName() + " " + oleLoanDocument.getOlePatron().getEntity().getNames().get(0).getLastName());
1919        oleNoticeBo.setPatronAddress(getPatronPreferredAddress(entityTypeContactInfoBo) != null ? getPatronPreferredAddress(entityTypeContactInfoBo) : "");
1920        oleNoticeBo.setPatronEmailAddress(getPatronHomeEmailId(entityTypeContactInfoBo) != null ? getPatronHomeEmailId(entityTypeContactInfoBo) : "");
1921        oleNoticeBo.setPatronPhoneNumber(getPatronHomePhoneNumber(entityTypeContactInfoBo) != null ? getPatronHomePhoneNumber(entityTypeContactInfoBo) : "");
1922        oleNoticeBo.setNoticeName(OLEConstants.NOTICE_COURTESY);
1923        oleNoticeBo.setNoticeSpecificContent(LoanUtil.getLoanUtil().getProperty(OLEConstants.OleDeliverRequest.COURTESY_NOTICE_CONTENT));
1924       /* oleNoticeBo.setTitle((String) bibInformation.get(OLEConstants.TITLE) != null ? (String) bibInformation.get(OLEConstants.TITLE) : "");
1925        oleNoticeBo.setAuthor((String) bibInformation.get(OLEConstants.AUTHOR) != null ? (String) bibInformation.get(OLEConstants.AUTHOR) : "");*/
1926        oleNoticeBo.setTitle(item.getHolding().getBib().getTitle());
1927        oleNoticeBo.setAuthor(item.getHolding().getBib().getAuthor());
1928        oleNoticeBo.setVolumeNumber(item.getVolumeNumber());
1929        oleNoticeBo.setItemShelvingLocation(shelvingLocation != null ? shelvingLocation : "");
1930        // oleNoticeBo.setItemCallNumber((String) docStoreDetails.get(OLEConstants.CALL_NUM) != null ? (String) docStoreDetails.get(OLEConstants.CALL_NUM) : "");
1931        oleNoticeBo.setItemCallNumber(loanProcessor.getItemCallNumber(itemContent, item.getHolding().getId()));
1932        oleNoticeBo.setItemId(oleLoanDocument.getItemId());
1933        oleLoanDocument.getOlePatron().setEmailAddress(oleNoticeBo.getPatronEmailAddress());
1934        LOG.info("oleNoticeBo.getPatronEmailAddress()" + oleNoticeBo.getPatronEmailAddress());
1935        return oleNoticeBo;
1936    }
1937
1938    private OleNoticeBo getOverdueNotice(OleLoanDocument oleLoanDocument) throws Exception {
1939        LOG.debug("Overdue Notice");
1940        EntityTypeContactInfoBo entityTypeContactInfoBo = oleLoanDocument.getOlePatron().getEntity().getEntityTypeContactInfos().get(0);
1941        OleNoticeBo oleNoticeBo = new OleNoticeBo();
1942        //   String itemId  = oleLoanDocument.getItemId();
1943        org.kuali.ole.docstore.common.document.content.instance.Item oleItem = oleLoanDocument.getOleItem();
1944        //  String itemUuid = oleItem.getItemIdentifier();
1945        //String shelvingLocation = oleLoanDocument.getItemLocation();
1946        org.kuali.ole.docstore.common.document.Item item = getDocstoreClientLocator().getDocstoreClient().retrieveItem(oleLoanDocument.getItemUuid());
1947        OleCirculationDesk oleCirculationDesk = getOleCirculationDesk(oleLoanDocument.getCirculationLocationId());
1948        if (oleCirculationDesk != null)
1949            oleNoticeBo.setCirculationDeskName(oleCirculationDesk.getCirculationDeskPublicName());
1950        else
1951            oleNoticeBo.setCirculationDeskName("");
1952        oleNoticeBo.setCirculationDeskAddress("");
1953        oleNoticeBo.setCirculationDeskEmailAddress("");
1954        oleNoticeBo.setCirculationDeskPhoneNumber("");
1955        oleNoticeBo.setPatronName(oleLoanDocument.getOlePatron().getEntity().getNames().get(0).getFirstName() + " " + oleLoanDocument.getOlePatron().getEntity().getNames().get(0).getLastName());
1956        oleNoticeBo.setPatronAddress(getPatronPreferredAddress(entityTypeContactInfoBo) != null ? getPatronPreferredAddress(entityTypeContactInfoBo) : "");
1957        oleNoticeBo.setPatronEmailAddress(getPatronHomeEmailId(entityTypeContactInfoBo) != null ? getPatronHomeEmailId(entityTypeContactInfoBo) : "");
1958        oleNoticeBo.setPatronPhoneNumber(getPatronHomePhoneNumber(entityTypeContactInfoBo) != null ? getPatronHomePhoneNumber(entityTypeContactInfoBo) : "");
1959        oleNoticeBo.setNoticeName(OLEConstants.NOTICE_OVERDUE);
1960        oleNoticeBo.setNoticeSpecificContent(LoanUtil.getLoanUtil().getProperty(OLEConstants.OleDeliverRequest.OVERDUE_NOTICE_CONTENT));
1961        oleNoticeBo.setTitle(item.getHolding().getBib().getTitle());
1962        oleNoticeBo.setAuthor(item.getHolding().getBib().getAuthor());
1963        /*oleNoticeBo.setTitle((String) bibInformation.get(OLEConstants.TITLE) != null ? (String) bibInformation.get(OLEConstants.TITLE) : "");
1964        oleNoticeBo.setAuthor((String) bibInformation.get(OLEConstants.AUTHOR) != null ? (String) bibInformation.get(OLEConstants.AUTHOR) : "");*/
1965
1966        //oleNoticeBo.setVolumeNumber((String) docStoreDetails.get(OLEConstants.VOL_NUM) != null ? (String) docStoreDetails.get(OLEConstants.VOL_NUM) : "");
1967        String volume = (String) oleItem.getEnumeration() != null && !oleItem.getEnumeration().equals("") ? oleItem.getEnumeration() : "";
1968        String issue = new String(" ");
1969        String copyNumber = (String) oleItem.getCopyNumber() != null && !oleItem.getCopyNumber().equals("") ? oleItem.getCopyNumber() : "";
1970        oleNoticeBo.setVolumeIssueCopyNumber(volume + "/" + issue + "/" + copyNumber);
1971        oleNoticeBo.setItemShelvingLocation(item.getLocationName());
1972        /*if (oleItem.getCallNumber().getNumber() != null && !oleItem.getCallNumber().getNumber().equals("")) {
1973            oleNoticeBo.setItemCallNumber((String) oleItem.getCallNumber().getNumber() != null && !oleItem.getCallNumber().getNumber().equals("") ? oleItem.getCallNumber().getNumber() : "");
1974        } else {
1975            oleNoticeBo.setItemCallNumber(getLoanProcessor().getItemCallNumber(oleItem, oleLoanDocument.getInstanceUuid()));
1976        }*/
1977        oleNoticeBo.setItemCallNumber(getLoanProcessor().getItemCallNumber(oleItem, oleLoanDocument.getInstanceUuid()));
1978        //oleNoticeBo.setItemCallNumber((String) docStoreDetails.get(OLEConstants.CALL_NUM) != null ? (String) docStoreDetails.get(OLEConstants.CALL_NUM) : "");
1979        oleNoticeBo.setItemId(oleLoanDocument.getItemId());
1980        //oleNoticeBo.setDueDate(oleLoanDocument.getLoanDueDate()!=null ? oleLoanDocument.getLoanDueDate().toString().substring(0, 10) : null);
1981        oleNoticeBo.setDueDate(oleLoanDocument.getLoanDueDate()!=null ? oleLoanDocument.getLoanDueDate() :null);
1982        oleLoanDocument.getOlePatron().setEmailAddress(oleNoticeBo.getPatronEmailAddress());
1983        LOG.info("oleNoticeBo.getPatronEmailAddress()" + oleNoticeBo.getPatronEmailAddress());
1984        int noOfOverdueNoticeSent = Integer.parseInt(oleLoanDocument.getNumberOfOverdueNoticesSent() != null ? oleLoanDocument.getNumberOfOverdueNoticesSent() : "0");
1985        noOfOverdueNoticeSent = noOfOverdueNoticeSent + 1;
1986        LOG.debug("Updated Loan Record : " + oleLoanDocument);
1987        oleLoanDocument.setNumberOfOverdueNoticesSent(Integer.toString(noOfOverdueNoticeSent));
1988        oleLoanDocument.setOverDueNoticeDate(new java.sql.Date(System.currentTimeMillis()));
1989        getBusinessObjectService().save(oleLoanDocument);
1990        return oleNoticeBo;
1991    }
1992
1993    public void updateItem(org.kuali.ole.docstore.common.document.content.instance.Item oleItem, String itemUuid) throws Exception {
1994        org.kuali.ole.docstore.common.document.content.instance.ItemStatus itemStatus = new org.kuali.ole.docstore.common.document.content.instance.ItemStatus();
1995        itemStatus.setCodeValue(OLEConstants.OleDeliverRequest.MISSING);
1996        itemStatus.setFullValue(OLEConstants.OleDeliverRequest.MISSING);
1997        oleItem.setItemStatus(itemStatus);
1998        oleItem.setStaffOnlyFlag(true);
1999        String itemContent = new ItemOlemlRecordProcessor().toXML(oleItem);
2000        org.kuali.ole.docstore.common.document.Item item = new ItemOleml();
2001        item.setId(itemUuid);
2002        item.setContent(itemContent);
2003        item.setCategory(OLEConstants.WORK_CATEGORY);
2004        item.setType(DocType.ITEM.getCode());
2005        item.setFormat(OLEConstants.OLEML_FORMAT);
2006        getDocstoreClientLocator().getDocstoreClient().updateItem(item);
2007    }
2008
2009    public String getShelvingLocation(org.kuali.ole.docstore.common.document.content.instance.LocationLevel oleLocationLevel) {
2010        String location = null;
2011        if (oleLocationLevel != null) {
2012            if (OLEConstants.LOCATION_LEVEL_SHELVING.equalsIgnoreCase(oleLocationLevel.getLevel()))
2013                location = oleLocationLevel.getName();
2014            else
2015                location = getShelvingLocation(oleLocationLevel.getLocationLevel());
2016        }
2017        if ("".equals(location) || location == null)
2018            return null;
2019        return location;
2020    }
2021
2022
2023    public String getIntervalForCourtesyNotice() {
2024        BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService();
2025        Map<String, String> criteriaMap = new HashMap<String, String>();
2026        criteriaMap.put(OLEConstants.NAMESPACE_CODE, OLEConstants.DLVR_NMSPC);
2027        criteriaMap.put(OLEConstants.COMPONENT_CODE, OLEConstants.DLVR_CMPNT);
2028        criteriaMap.put(OLEConstants.NAME, OLEParameterConstants.COURTESY_NOTICE_INTER);
2029        List<ParameterBo> parametersList = (List<ParameterBo>) businessObjectService.findMatching(ParameterBo.class, criteriaMap);
2030        return parametersList.get(0).getValue();
2031    }
2032
2033    public String getIntervalForOverdueNotice() {
2034        BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService();
2035        Map<String, String> criteriaMap = new HashMap<String, String>();
2036        criteriaMap.put(OLEConstants.NAMESPACE_CODE, OLEConstants.DLVR_NMSPC);
2037        criteriaMap.put(OLEConstants.COMPONENT_CODE, OLEConstants.DLVR_CMPNT);
2038        criteriaMap.put(OLEConstants.NAME, OLEConstants.OVERDUE_NOTICE_INTER);
2039        List<ParameterBo> parametersList = (List<ParameterBo>) businessObjectService.findMatching(ParameterBo.class, criteriaMap);
2040        return parametersList.get(0).getValue();
2041    }
2042
2043
2044    private PatronBillPayment getPatronBillPayment(String patronId) {
2045        LOG.debug("Inside the getPatronBillPayment method");
2046        Map billMap = new HashMap();
2047        billMap.put(OLEConstants.OleDeliverRequest.LOAN_PATRON_ID, patronId);
2048        List<PatronBillPayment> patronBillPaymentList = (List<PatronBillPayment>) getBusinessObjectService().findMatching(PatronBillPayment.class, billMap);
2049        return patronBillPaymentList != null && patronBillPaymentList.size() > 0 ? patronBillPaymentList.get(0) : null;
2050    }
2051
2052    private OlePaymentStatus getPaymentStatus() {
2053        LOG.debug("Inside the getPaymentStatus method");
2054        Map statusMap = new HashMap();
2055        statusMap.put(OLEConstants.OleDeliverRequest.PAYMENT_STATUS_NAME, OLEConstants.PAYMENT_STATUS_OUTSTANDING);
2056        List<OlePaymentStatus> olePaymentStatusList = (List<OlePaymentStatus>) getBusinessObjectService().findMatching(OlePaymentStatus.class, statusMap);
2057        return olePaymentStatusList != null && olePaymentStatusList.size() > 0 ? olePaymentStatusList.get(0) : null;
2058    }
2059
2060    private String getFeeTypeId(String feeTypeName) {
2061        LOG.debug("Inside the getOverdueFeeTypeId method");
2062        Map feeMap = new HashMap();
2063        feeMap.put(OLEConstants.FEE_TYPE_NAME, feeTypeName);
2064        List<OleFeeType> oleFeeTypes = (List<OleFeeType>) getBusinessObjectService().findMatching(OleFeeType.class, feeMap);
2065        return oleFeeTypes != null && oleFeeTypes.size() > 0 ? oleFeeTypes.get(0).getFeeTypeId() : null;
2066    }
2067
2068    public String processItemType(String itemType) {
2069
2070        LOG.debug("Inside process Item Type");
2071        Map<String, String> itemMap = new HashMap<String, String>();
2072        itemMap.put(OLEConstants.OleDeliverRequest.ITEM_TYPE_CODE, itemType);
2073        List<OleInstanceItemType> oleInstanceItemTypeList = (List<OleInstanceItemType>) businessObjectService.findMatching(OleInstanceItemType.class, itemMap);
2074        if (oleInstanceItemTypeList != null && oleInstanceItemTypeList.size() > 0) {
2075            OleInstanceItemType oleInstanceItemType = oleInstanceItemTypeList.get(0);
2076            return oleInstanceItemType.getInstanceItemTypeName();
2077        }
2078        return null;
2079    }
2080
2081    public String placeRequest(String patronId, String operatorId, String itemBarcode, String requestType, String pickUpLocation, String itemIdentifier) {
2082        OleDeliverRequestBo oleDeliverRequestBo = new OleDeliverRequestBo();
2083        oleDeliverRequestBo.setCreateDate(new java.sql.Date(System.currentTimeMillis()));
2084        OlePatronDocument olePatronDocument = null;
2085        Map<String, String> patronMap = new HashMap<String, String>();
2086        patronMap.put("olePatronId", patronId);
2087        OleNoticeBo oleNoticeBo = new OleNoticeBo();
2088        List<OlePatronDocument> olePatronDocumentList = (List<OlePatronDocument>) businessObjectService.findMatching(OlePatronDocument.class, patronMap);
2089        if (olePatronDocumentList.size() > 0) {
2090            olePatronDocument = olePatronDocumentList.get(0);
2091            oleDeliverRequestBo.setBorrowerId(patronId);
2092            oleDeliverRequestBo.setBorrowerBarcode(olePatronDocument.getBarcode());
2093            oleDeliverRequestBo.setOlePatron(olePatronDocument);
2094            EntityTypeContactInfoBo entityTypeContactInfoBo = olePatronDocument.getEntity().getEntityTypeContactInfos().get(0);
2095            try {
2096                oleNoticeBo.setPatronName(olePatronDocument.getEntity().getNames().get(0).getFirstName() + " " + oleDeliverRequestBo.getOlePatron().getEntity().getNames().get(0).getLastName());
2097                oleNoticeBo.setPatronAddress(getPatronPreferredAddress(entityTypeContactInfoBo) != null ? getPatronPreferredAddress(entityTypeContactInfoBo) : "");
2098                oleNoticeBo.setPatronEmailAddress(getPatronHomeEmailId(entityTypeContactInfoBo) != null ? getPatronHomeEmailId(entityTypeContactInfoBo) : "");
2099                oleNoticeBo.setPatronPhoneNumber(getPatronHomePhoneNumber(entityTypeContactInfoBo) != null ? getPatronHomePhoneNumber(entityTypeContactInfoBo) : "");
2100            } catch (Exception e) {
2101                LOG.error(e, e);
2102                LOG.info("Exception Occured while setting the patron information for the patron . Patron Barcode : " + oleDeliverRequestBo.getBorrowerBarcode());
2103            }
2104        } else {
2105            return "No patron information";
2106        }
2107        if (requestType != null) {
2108            Map<String, String> requestTypeMap = new HashMap<String, String>();
2109            requestTypeMap.put("requestTypeCode", requestType);
2110            List<OleDeliverRequestType> oleDeliverRequestTypeList = (List<OleDeliverRequestType>) businessObjectService.findMatching(OleDeliverRequestType.class, requestTypeMap);
2111            if (oleDeliverRequestTypeList != null && (oleDeliverRequestTypeList.size() > 0)) {
2112                oleDeliverRequestBo.setRequestTypeId(oleDeliverRequestTypeList.get(0).getRequestTypeId());
2113                oleDeliverRequestBo.setOleDeliverRequestType(oleDeliverRequestTypeList.get(0));
2114            } else
2115                return "Invalid Request Type Code";
2116
2117        }
2118        if (pickUpLocation != null) {
2119            Map<String, String> circulationDeskMap = new HashMap<String, String>();
2120            circulationDeskMap.put("circulationDeskCode", pickUpLocation);
2121            List<OleCirculationDesk> oleCirculationDeskList = (List<OleCirculationDesk>) businessObjectService.findMatching(OleCirculationDesk.class, circulationDeskMap);
2122            if (oleCirculationDeskList != null && oleCirculationDeskList.size() > 0) {
2123                oleDeliverRequestBo.setPickUpLocationId(oleCirculationDeskList.get(0).getCirculationDeskId());
2124                oleDeliverRequestBo.setPickUpLocationCode(oleCirculationDeskList.get(0).getCirculationDeskCode());
2125                oleDeliverRequestBo.setOlePickUpLocation(oleCirculationDeskList.get(0));
2126            } else {
2127                return "Invalid Pick Up Location";
2128            }
2129
2130        }
2131        try {
2132            if (itemBarcode == null || (itemBarcode != null && itemBarcode.isEmpty())) {
2133                return "invalid barcode";
2134            }
2135            oleDeliverRequestBo.setItemId(itemBarcode);
2136            oleDeliverRequestBo.setItemUuid(itemIdentifier);
2137            Thread.sleep(2000);
2138            docstoreUtil.isItemAvailableInDocStore(oleDeliverRequestBo);
2139            if (oleDeliverRequestBo.getItemUuid() == null || (oleDeliverRequestBo.getItemUuid() != null && oleDeliverRequestBo.getItemUuid().trim().isEmpty())) {
2140                return "invalid barcode";
2141            } else {
2142                oleDeliverRequestBo.setRequestCreator("Operator");
2143                oleDeliverRequestBo.setOperatorCreateId(operatorId);
2144                oleDeliverRequestBo.setBorrowerId(patronId);
2145                oleDeliverRequestBo.setItemId(itemBarcode);
2146                oleDeliverRequestBo.setRequestStatus("1");
2147                if (!processOperator(operatorId)) {
2148                    return OLEConstants.INVALID_OPERATOR;
2149                }
2150                processRequestType(oleDeliverRequestBo);
2151                String message = this.patronRecordExpired(oleDeliverRequestBo);
2152                if (message != null)
2153                    return message;
2154                boolean requestRaised = this.isRequestAlreadyRaisedByPatron(oleDeliverRequestBo);
2155                if (requestRaised)
2156                    return "Request Already Raised For This Item By The Patron ";
2157                boolean itemEligible = this.isItemEligible(oleDeliverRequestBo);
2158                if (!itemEligible)
2159                    return "Item is not eligible for circulation";
2160                boolean alreadyLoaned = this.isAlreadyLoaned(oleDeliverRequestBo);
2161                if (alreadyLoaned)
2162                    return "Item is currently in loan with the requested borrower";
2163
2164                boolean valid = false;
2165                EngineResults engineResult = this.executeEngineResults(oleDeliverRequestBo);
2166                if (engineResult != null) {
2167                    List<ResultEvent> allResults = engineResult.getAllResults();
2168                    if (allResults.size() > 0) {
2169                        for (Iterator<ResultEvent> resultEventIterator = allResults.iterator(); resultEventIterator.hasNext(); ) {
2170                            ResultEvent resultEvent = resultEventIterator.next();
2171                            if (resultEvent.getType().equals(RULE_EVALUATED))
2172                                valid |= resultEvent.getResult();
2173                        }
2174                        if ((oleDeliverRequestBo.getMessage() != null && !oleDeliverRequestBo.getMessage().isEmpty()))
2175                            return oleDeliverRequestBo.getMessage();
2176                    }
2177                }
2178                OleDeliverRequestBo oleDeliverRequestBo1 = oleDeliverRequestBo;
2179                if (oleDeliverRequestBo.getRequestTypeId().equals("1") || oleDeliverRequestBo.getRequestTypeId().equals("2") || oleDeliverRequestBo.getRequestTypeId().equals("3") || oleDeliverRequestBo.getRequestTypeId().equals("4")) {
2180                    if (oleDeliverRequestBo.getRequestTypeId().equals("1") || oleDeliverRequestBo.getRequestTypeId().equals("2"))
2181                        oleDeliverRequestBo1 = this.updateLoanDocument(oleDeliverRequestBo);
2182                    if (isItemAvailable(oleDeliverRequestBo1)) {
2183                        return "Recall / Hold type of request can be raised only for the item which is currently in circulation";
2184                    }
2185                }
2186                oleDeliverRequestBo.setOleItem(null);
2187                this.reOrderQueuePosition(oleDeliverRequestBo1);
2188                getBusinessObjectService().save(oleDeliverRequestBo1);
2189                Map<String, String> requestMap = new HashMap<String, String>();
2190                requestMap.put("borrowerId", patronId);
2191                requestMap.put("itemId", itemBarcode);
2192                List<OleDeliverRequestBo> oleDeliverRequestBoList = (List<OleDeliverRequestBo>) businessObjectService.findMatching(OleDeliverRequestBo.class, requestMap);
2193                String requestId = "";
2194                if (oleDeliverRequestBoList.size() > 0) {
2195                    requestId = ":Request Id :" + oleDeliverRequestBoList.get(0).getRequestId();
2196                }
2197                LOG.info("Request Raised Succesfully" + requestId);
2198                oleNoticeBo.setNoticeName(OLEConstants.PICKUP_NOTICE);
2199                Date pickupDate = addDate(new java.sql.Date(System.currentTimeMillis()), new Integer(oleDeliverRequestBo.getOlePickUpLocation().getOnHoldDays()));
2200                oleNoticeBo.setNoticeSpecificContent(OLEConstants.PICKUP_NOTICE_START_CONTENT + oleDeliverRequestBo.getOlePickUpLocation().getCirculationDeskPublicName() + OLEConstants.PICKUP_NOTICE_MIDDLE_CONTENT + pickupDate + OLEConstants.PICKUP_NOTICE_FINAL_CONTENT);
2201                oleNoticeBo.setAuthor(oleDeliverRequestBo.getAuthor() != null ? oleDeliverRequestBo.getAuthor() : "");
2202                oleNoticeBo.setItemCallNumber(oleDeliverRequestBo.getCallNumber() != null ? oleDeliverRequestBo.getCallNumber() : "");
2203                oleNoticeBo.setItemId(oleDeliverRequestBo.getItemId() != null ? oleDeliverRequestBo.getItemId() : "");
2204                oleNoticeBo.setTitle(oleDeliverRequestBo.getTitle() != null ? oleDeliverRequestBo.getTitle() : "");
2205                OleDeliverBatchServiceImpl oleDeliverBatchService = new OleDeliverBatchServiceImpl();
2206                String content = oleDeliverBatchService.getEmailPickUpNotice(oleNoticeBo);
2207                try {
2208                    if (!content.trim().equals("")) {
2209                        OleMailer oleMailer = GlobalResourceLoader.getService("oleMailer");
2210                        if (oleDeliverRequestBo.getOlePickUpLocation() != null && StringUtils.isNotBlank(oleDeliverRequestBo.getOlePickUpLocation().getReplyToEmail())) {
2211                            oleMailer.sendEmail(new EmailFrom(oleDeliverRequestBo.getOlePickUpLocation().getReplyToEmail()), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(content), true);
2212                        } else {
2213                            String fromAddress = getLoanProcessor().getParameter(OLEParameterConstants.NOTICE_FROM_MAIL);
2214                            if (fromAddress != null && (fromAddress.equals("") || fromAddress.trim().isEmpty())) {
2215                                fromAddress = OLEConstants.KUALI_MAIL;
2216                            }
2217                            oleMailer.sendEmail(new EmailFrom(fromAddress), new EmailTo(oleNoticeBo.getPatronEmailAddress()), new EmailSubject(OLEConstants.NOTICE_MAIL), new EmailBody(content), true);
2218                        }
2219                        LOG.info("Mail send Successfully to " + oleNoticeBo.getPatronEmailAddress());
2220                        oleDeliverBatchService.getPdfPickUpNotice(oleNoticeBo);
2221                    } else {
2222                        LOG.info("Notice Type :" + oleNoticeBo.getNoticeName() + "  " + "Item Barcode : " + oleNoticeBo.getItemId() + " " + "Patron Name :" + oleNoticeBo.getPatronName());
2223                    }
2224                } catch (Exception e) {
2225                    LOG.error(e, e);
2226                    return "Request Raised Succesfully" + requestId + ".Problem occured while sending notice.";
2227                }
2228                return "Request Raised Succesfully" + requestId;
2229            }
2230        } catch (Exception e) {
2231            LOG.error(e, e);
2232            if (e.getMessage().equalsIgnoreCase("Item barcode does not exist.")) {
2233                return "Item barcode does not exist.";
2234            }
2235            return "Request failed";
2236        }
2237    }
2238
2239    private java.sql.Date addDate(java.sql.Date in, int daysToAdd) {
2240        if (in == null) {
2241            return null;
2242        }
2243        GregorianCalendar cal = new GregorianCalendar();
2244        cal.setTime(in);
2245        cal.add(Calendar.DAY_OF_MONTH, daysToAdd);
2246        return new java.sql.Date(cal.getTime().getTime());
2247    }
2248
2249    public EngineResults executeEngineResults(OleDeliverRequestBo oleDeliverRequestBo) {
2250        List<OleDeliverRequestBo> recallList = new ArrayList<OleDeliverRequestBo>();
2251        List<OleDeliverRequestBo> holdList = new ArrayList<OleDeliverRequestBo>();
2252        List<OleDeliverRequestBo> pageList = new ArrayList<OleDeliverRequestBo>();
2253        List<OleDeliverRequestBo> requestsByBorrower = new ArrayList<OleDeliverRequestBo>();
2254        Engine engine = KrmsApiServiceLocator.getEngine();
2255        EngineResults engineResult = null;
2256        HashMap<String, Object> agendaValue = new HashMap<String, Object>();
2257        agendaValue.put(OLEConstants.NAME_NM, OLEConstants.REQUEST_AGENDA_NM);
2258        List<AgendaBo> agendaBos = (List<AgendaBo>) KRADServiceLocator.getBusinessObjectService().findMatching(AgendaBo.class, agendaValue);
2259        if (agendaBos != null && agendaBos.size() > 0) {
2260            AgendaBo agendaBo = agendaBos.get(0);
2261            HashMap<String, String> map = new HashMap<String, String>();
2262            map.put(OLEConstants.AGENDA_NAME, agendaBo.getName());
2263            List<MatchBo> matchBos = (List<MatchBo>) KRADServiceLocator.getBusinessObjectService().findMatching(MatchBo.class, map);
2264
2265            SelectionCriteria selectionCriteria =
2266                    SelectionCriteria.createCriteria(null, getSelectionContext(agendaBo.getContext().getName()),
2267                            getAgendaContext(OLEConstants.REQUEST_AGENDA_NM));
2268
2269            ExecutionOptions executionOptions = new ExecutionOptions();
2270            executionOptions.setFlag(ExecutionFlag.LOG_EXECUTION, true);
2271
2272            Facts.Builder factBuilder = Facts.Builder.create();
2273
2274            String borrowerType = "";
2275            if (oleDeliverRequestBo.getOlePatron() != null && oleDeliverRequestBo.getOlePatron().getOleBorrowerType() != null) {
2276                borrowerType = oleDeliverRequestBo.getOlePatron().getOleBorrowerType().getBorrowerTypeCode();
2277            }
2278            String itemType = oleDeliverRequestBo.getItemType();
2279
2280            String requestTypeId = oleDeliverRequestBo.getRequestTypeId();
2281
2282            String requestType = oleDeliverRequestBo.getRequestTypeCode();
2283
2284            String location = oleDeliverRequestBo.getShelvingLocation();
2285            LoanProcessor loanProcessor = getLoanProcessor();
2286            OleLoanDocument oleLoanDocument = loanProcessor.getOleLoanDocumentUsingItemUUID(oleDeliverRequestBo.getItemUuid());
2287            DataCarrierService dataCarrierService = GlobalResourceLoader.getService(OLEConstants.DATA_CARRIER_SERVICE);
2288            dataCarrierService.addData(OLEConstants.LOANED_DATE, oleLoanDocument != null ? oleLoanDocument.getCreateDate() : null);
2289            dataCarrierService.addData(OLEConstants.CIRC_POLICY_FOUND, null);
2290            String borrowerId = oleDeliverRequestBo.getBorrowerId();
2291            Map<String, String> requestMap = new HashMap<String, String>();
2292            requestMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
2293            if (requestTypeId != null && (requestTypeId.equals("1") || requestTypeId.equals("2"))) {
2294                requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "1");
2295                recallList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap);
2296                requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "2");
2297                recallList.addAll((List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap));
2298            } else if (requestTypeId != null && (requestTypeId.equals("3") || requestTypeId.equals("4"))) {
2299                //  holdList = (List<OleDeliverRequestBo>)getBusinessObjectService().findMatching(OleDeliverRequestBo.class,requestMap);
2300                requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "3");
2301                holdList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap);
2302                requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "4");
2303                holdList.addAll((List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap));
2304            } else if (requestTypeId != null && (requestTypeId.equals("5") || requestTypeId.equals("6"))) {
2305                // pageList = (List<OleDeliverRequestBo>)getBusinessObjectService().findMatching(OleDeliverRequestBo.class,requestMap);
2306                requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "5");
2307                pageList = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap);
2308                requestMap.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, "6");
2309                pageList.addAll((List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestMap));
2310            }
2311            Map<String, String> requestByBorrower = new HashMap<String, String>();
2312            requestByBorrower.put(OLEConstants.OleDeliverRequest.BORROWER_ID, borrowerId);
2313            requestsByBorrower = (List<OleDeliverRequestBo>) getBusinessObjectService().findMatching(OleDeliverRequestBo.class, requestByBorrower);
2314            HashMap<String, Object> termValues = new HashMap<String, Object>();
2315            termValues.put(OLEConstants.BORROWER_TYPE, borrowerType);
2316            termValues.put(OLEConstants.ITEM_TYPE, itemType);
2317            termValues.put(OLEConstants.LOCATION, location);
2318            termValues.put(OLEConstants.ITEM_SHELVING, oleDeliverRequestBo.getShelvingLocation());
2319            termValues.put(OLEConstants.ITEM_COLLECTION, oleDeliverRequestBo.getItemCollection());
2320            termValues.put(OLEConstants.ITEM_LIBRARY, oleDeliverRequestBo.getItemLibrary());
2321            termValues.put(OLEConstants.ITEM_CAMPUS, oleDeliverRequestBo.getItemCampus());
2322            termValues.put(OLEConstants.ITEM_INSTITUTION, oleDeliverRequestBo.getItemInstitution());
2323            termValues.put(OLEConstants.MAX_NO_OF_RECALL_REQUEST, new Integer(recallList.size()) + 1);
2324            termValues.put(OLEConstants.MAX_NO_OF_HOLD_REQUEST, new Integer(holdList.size()) + 1);
2325            termValues.put(OLEConstants.MAX_NO_OF_PAGE_REQUEST, new Integer(pageList.size()) + 1);
2326            // termValues.put("maxNumberOfRequestByBorrower",requestsByBorrower.size());
2327            termValues.put(OLEConstants.OleDeliverRequest.REQUEST_TYPE_ID, requestTypeId);
2328            termValues.put(OLEConstants.REQUEST_TYPE, requestType);
2329
2330
2331            for (Iterator<MatchBo> matchBoIterator = matchBos.iterator(); matchBoIterator.hasNext(); ) {
2332                MatchBo matchBo = matchBoIterator.next();
2333                factBuilder.addFact(matchBo.getTermName(), termValues.get((matchBo.getTermName())));
2334            }
2335            LOG.info("termValues.toString()" + termValues.toString());
2336            engineResult = engine.execute(selectionCriteria, factBuilder.build(), executionOptions);
2337            List<String> errorMessage = (List<String>) engineResult.getAttribute(OLEConstants.ERROR_ACTION);
2338            java.sql.Date d = (java.sql.Date) engineResult.getAttribute(OLEConstants.REQ_EXPIRATION_DATE);
2339            Timestamp recallDueDate = (Timestamp) engineResult.getAttribute(OLEConstants.RECALL_DUE_DATE);
2340            String notice = (String) engineResult.getAttribute(OLEConstants.NOTICE);
2341            oleDeliverRequestBo.setNoticeType(notice);
2342            if (recallDueDate != null && oleLoanDocument.getLoanDueDate()!=null) {
2343                oleLoanDocument.setLoanDueDate(recallDueDate);
2344                oleDeliverRequestBo.setRecallDueDate(recallDueDate);
2345                getBusinessObjectService().save(oleLoanDocument);
2346            }
2347            oleDeliverRequestBo.setRequestExpiryDate(d);
2348            StringBuffer failures = new StringBuffer();
2349            if (errorMessage != null && errorMessage.size() > 0) {
2350                int i = 1;
2351                for (String errMsg : errorMessage) {
2352                    failures.append(i++ + ". " + errMsg + OLEConstants.BREAK);
2353                }
2354            }
2355            if (!failures.toString().isEmpty()) {
2356                oleDeliverRequestBo.setMessage(failures.toString());
2357            }
2358            dataCarrierService.addData(OLEConstants.ERROR_ACTION, null);
2359        }
2360        return engineResult;
2361    }
2362
2363    /**
2364     * This method returns SelectionContext using contextName.
2365     *
2366     * @param contextName
2367     * @return Map
2368     */
2369    protected Map<String, String> getSelectionContext(String contextName) {
2370        Map<String, String> selector = new HashMap<String, String>();
2371        selector.put(NAMESPACE_CODE_SELECTOR, OLEConstants.OLE_NAMESPACE);
2372        selector.put(NAME_SELECTOR, contextName);
2373        return selector;
2374    }
2375
2376    /**
2377     * This method returns AgendaContext using agendaName..
2378     *
2379     * @param agendaName
2380     * @return Map
2381     */
2382    protected Map<String, String> getAgendaContext(String agendaName) {
2383        Map<String, String> selector = new HashMap<String, String>();
2384        selector.put(NAME_SELECTOR, agendaName);
2385        return selector;
2386    }
2387
2388    private OleCirculationDesk getOleCirculationDesk(String circulationDeskId) {
2389        Map<String, String> circulationDeskMap = new HashMap<String, String>();
2390        circulationDeskMap.put("circulationDeskId", circulationDeskId);
2391        List<OleCirculationDesk> oleCirculationDeskList = (List<OleCirculationDesk>) businessObjectService.findMatching(OleCirculationDesk.class, circulationDeskMap);
2392        if (oleCirculationDeskList != null && oleCirculationDeskList.size() > 0) {
2393            return oleCirculationDeskList.get(0);
2394        } else
2395            return null;
2396    }
2397
2398    private RoleService getRoleService() {
2399        RoleService service = KimApiServiceLocator.getRoleService();
2400        return service;
2401    }
2402
2403
2404}
2405
2406
2407
2408
2409
2410