001package org.kuali.asr.service.impl;
002
003import org.apache.log4j.Logger;
004import org.kuali.asr.ASRConstants;
005import org.kuali.asr.bo.*;
006import org.kuali.asr.service.ASRHelperServiceImpl;
007import org.kuali.asr.service.ASRService;
008import org.kuali.ole.OLEConstants;
009import org.kuali.ole.deliver.bo.ASRTypeRequest;
010import org.kuali.ole.deliver.bo.OleDeliverRequestBo;
011import org.kuali.ole.deliver.processor.LoanProcessor;
012import org.kuali.ole.deliver.service.OleDeliverRequestDocumentHelperServiceImpl;
013import org.kuali.ole.ncip.bo.OLEPlaceRequest;
014import org.kuali.ole.ncip.converter.OLEPlaceRequestConverter;
015import org.kuali.ole.ncip.service.impl.OLECirculationServiceImpl;
016import org.kuali.rice.core.api.config.property.ConfigContext;
017import org.kuali.rice.krad.service.BusinessObjectService;
018import org.kuali.rice.krad.service.KRADServiceLocator;
019
020import java.util.ArrayList;
021import java.util.HashMap;
022import java.util.List;
023import java.util.Map;
024
025/**
026 * Created with IntelliJ IDEA.
027 * User: maheswarang
028 * Date: 12/24/13
029 * Time: 7:46 PM
030 * To change this template use File | Settings | File Templates.
031 */
032
033/**
034 * This class contains implementation of the services which were used by the exposed web services for ASR
035 */
036public class ASRServiceImpl implements ASRService {
037    private static final Logger LOG = Logger.getLogger(ASRServiceImpl.class);
038    private ASRHelperServiceImpl asrHelperService = getAsrHelperService();
039    private BusinessObjectService businessObjectService=getBusinessObjectService();
040    private OLECirculationServiceImpl oleCirculationService=getOleCirculationService();
041    private OLEASRPlaceRequestHelperServiceImpl oleasrPlaceRequestHelperService=new OLEASRPlaceRequestHelperServiceImpl();
042    private OleDeliverRequestDocumentHelperServiceImpl oleDeliverRequestDocumentHelperService;
043    private LoanProcessor loanProcessor = new LoanProcessor();
044
045    public OleDeliverRequestDocumentHelperServiceImpl getOleDeliverRequestDocumentHelperService() {
046         if(oleDeliverRequestDocumentHelperService==null){
047             oleDeliverRequestDocumentHelperService = new OleDeliverRequestDocumentHelperServiceImpl();
048         }
049        return oleDeliverRequestDocumentHelperService ;
050    }
051
052    public void setOleDeliverRequestDocumentHelperService(OleDeliverRequestDocumentHelperServiceImpl oleDeliverRequestDocumentHelperService) {
053        this.oleDeliverRequestDocumentHelperService = oleDeliverRequestDocumentHelperService;
054    }
055
056
057
058
059    public ASRHelperServiceImpl getAsrHelperService(){
060        if(asrHelperService==null){
061            asrHelperService = new ASRHelperServiceImpl();
062        }
063        return asrHelperService;
064    }
065
066    public BusinessObjectService getBusinessObjectService(){
067        if(businessObjectService == null){
068            businessObjectService = KRADServiceLocator.getBusinessObjectService();
069        }
070        return businessObjectService;
071    }
072
073    public OLECirculationServiceImpl getOleCirculationService(){
074        if(oleCirculationService == null){
075            oleCirculationService = new OLECirculationServiceImpl();
076        }
077        return oleCirculationService;
078    }
079
080
081
082    /**
083     * This method returns the ASRItems if there ia any item or return the ASRResponseBo if any error occurs
084     * @param operatorId
085     * @return object
086     */
087    @Override
088    public Object lookupNewASRItems(String operatorId) {
089        LOG.info("Inside the lookupNewASRItems  method . OperatorId : "+operatorId);
090        //check whether the operator id send is a valid one or not
091        if(!asrHelperService.isAuthorized(operatorId)){
092            return asrHelperService.generateResponse(ASRConstants.OPERATOR_NOT_FOUND_CODE, ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.OPERATOR_NOT_FOUND), ASRConstants.SUCCESS_STATUS);
093        }
094        //retrieve all the item whose location is changed to ASRLocation or item created with ASR Location
095        ASRItems asrItems =  asrHelperService.getNewASRItems();
096        if(asrItems.getAsrItems().size()>0){
097            return asrItems;
098        }else{
099            return asrHelperService.generateResponse(ASRConstants.ITEM_NOT_FOUND_CODE, ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.ITEM_NOT_FOUND), ASRConstants.SUCCESS_STATUS);
100        }
101    }
102
103    /**
104     * This method is used to remove an asr item and returns the ASRResponseBo with successful or failure message
105     * @param barcode
106     * @return  ASRResponseBo
107     */
108    @Override
109    public ASRResponseBo removeASRItem(String barcode) {
110        LOG.info("Inside the  removeASRItem  method . Item Barcode : "+barcode);
111        //check whether the item is in the temporary table
112        Map<String,String> itemMap = new HashMap<String,String>();
113        itemMap.put("itemBarcode",barcode);
114        List<org.kuali.ole.deliver.bo.ASRItem> asrItems = (List<org.kuali.ole.deliver.bo.ASRItem>)businessObjectService.findMatching(org.kuali.ole.deliver.bo.ASRItem.class,itemMap);
115       if(asrItems.size() == 0){
116           return asrHelperService.generateResponse(ASRConstants.ITEM_NOT_FOUND_CODE, ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.ITEM_NOT_FOUND), ASRConstants.SUCCESS_STATUS);
117       }
118       businessObjectService.delete(asrItems);
119        //remove the item from the temporary table
120        return asrHelperService.generateResponse(ASRConstants.ITEM_DELETED_CODE,ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.ITEM_DELETED) , ASRConstants.SUCCESS_STATUS);
121    }
122
123    /**
124     * This method updates the itemStatus to available and returns the ASRResponseBo only if there is any error otherwise it will return null
125     * @param updateASRItemRequestBo
126     * @return object
127     */
128    @Override
129    public Object updateASRItemStatusToAvailable(UpdateASRItemRequestBo updateASRItemRequestBo) {
130        LOG.info("Inside the updateASRItemStatusToAvailable  method . Item Barcode : " + updateASRItemRequestBo.getItemBarcode());
131        //identify whether the item barcode send is valid one or not
132        if(!asrHelperService.isAuthorized(updateASRItemRequestBo.getOperatorId())){
133            return asrHelperService.generateResponse(ASRConstants.OPERATOR_NOT_FOUND_CODE,ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.OPERATOR_NOT_FOUND) , ASRConstants.SUCCESS_STATUS);
134        }
135        if(!(updateASRItemRequestBo.getItemStatus().equals(asrHelperService.getParameter(ASRConstants.ASR_ITEM_AVAILABLE)))){
136            return asrHelperService.generateResponse(ASRConstants.STATUS_NOT_MATCH_CODE, ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.STATUS_NOT_MATCH), ASRConstants.SUCCESS_STATUS);
137        }
138        List<String> resultList = new ArrayList<String>();
139        resultList.add(ASRConstants.LOCATION_LEVEL_DISPLAY);
140        String itemLocation = asrHelperService.getLocation(updateASRItemRequestBo.getItemBarcode());
141        if(itemLocation == null){
142            return asrHelperService.generateResponse(ASRConstants.ITEM_NOT_FOUND_CODE, ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.ITEM_NOT_FOUND), ASRConstants.SUCCESS_STATUS);
143        }
144        if(itemLocation!=null &&!asrHelperService.isAnASRItem(itemLocation)){
145            return asrHelperService.generateResponse(ASRConstants.NOT_ASR_ITEM_CODE, ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.NOT_ASR_ITEM), ASRConstants.SUCCESS_STATUS);
146        }
147        //update the item status according to the ststus defined in the input
148        if(!asrHelperService.updateItemStatus(updateASRItemRequestBo.getItemBarcode(),updateASRItemRequestBo.getItemStatus())) {
149            return asrHelperService.generateResponse(ASRConstants.ITEM_STATUS_NOT_UPDATED_CODE, ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.ITEM_STATUS_NOT_UPDATED), ASRConstants.SUCCESS_STATUS);
150        }else{
151            removeASRItem(updateASRItemRequestBo.getItemBarcode());
152        }
153        return null;
154    }
155
156    /**
157     * This method place a request to the asr item with the request type as ASR and returns the ASRResponseBo with  success or failure message
158     * @param placeRequestASRItemBo
159     * @return ASRResponseBo
160     */
161    @Override
162    public ASRResponseBo placeRequestOnASRItem(PlaceASRItemRequestBo placeRequestASRItemBo) {
163        LOG.info("Inside the  placeRequestOnASRItem  method . Item Barcode : "+placeRequestASRItemBo.getItemBarcode() );
164        //identify whether the item barcode send is valid one or not
165        if(!asrHelperService.isAuthorized(placeRequestASRItemBo.getOperatorId())){
166            return asrHelperService.generateResponse(ASRConstants.OPERATOR_NOT_FOUND_CODE, ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.OPERATOR_NOT_FOUND), ASRConstants.SUCCESS_STATUS);
167        }
168        //verify whether the item is an asr item
169        String itemLocation = asrHelperService.getLocation(placeRequestASRItemBo.getItemBarcode());
170        if(itemLocation == null){
171            return asrHelperService.generateResponse(ASRConstants.ITEM_NOT_FOUND_CODE, ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.ITEM_NOT_FOUND), ASRConstants.SUCCESS_STATUS);
172        }
173        if(itemLocation!=null &&!asrHelperService.isAnASRItem(itemLocation)){
174            return asrHelperService.generateResponse(ASRConstants.NOT_ASR_ITEM_CODE, ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.NOT_ASR_ITEM), ASRConstants.SUCCESS_STATUS);
175        }
176        if(!asrHelperService.validatePickupLocation(placeRequestASRItemBo.getPickUpLocation())){
177            return asrHelperService.generateResponse(ASRConstants.INVALID_PKUP_LOCN_CD, ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.INVALID_PKUP_LOCN), ASRConstants.SUCCESS_STATUS);
178        }
179        //place the request to the asr item
180        String requestType = loanProcessor.getParameter(ASRConstants.ASR_TYP_RQST);
181         //String message = oleasrPlaceRequestHelperService.placeRequest(placeRequestASRItemBo.getPatronId(),placeRequestASRItemBo.getOperatorId(),placeRequestASRItemBo.getItemBarcode(),"ASR Request",placeRequestASRItemBo.getPickUpLocation());
182         String message = getOleDeliverRequestDocumentHelperService().placeRequest(placeRequestASRItemBo.getPatronId(),placeRequestASRItemBo.getOperatorId(),placeRequestASRItemBo.getItemBarcode(),requestType,placeRequestASRItemBo.getPickUpLocation(),null,null,null,null,null,null,false,null,null,null);
183        //update the asr response with the corresponding code according to the circulation policy message
184        OLEPlaceRequestConverter olePlaceRequestConverter = new OLEPlaceRequestConverter();
185        OLEPlaceRequest olePlaceRequest = (OLEPlaceRequest)olePlaceRequestConverter.generatePlaceRequestObject(message);
186        message = olePlaceRequest.getMessage();
187        if(message.contains(OLEConstants.RQST_SUCCESS)){
188            return asrHelperService.generateResponse(ASRConstants.HOLD_PLACED_CODE, message, ASRConstants.SUCCESS_STATUS);
189        }
190          return asrHelperService.generateResponse("106",message,ASRConstants.SUCCESS_STATUS);
191    }
192
193    /**
194     * This method is used to cancel the ASRRequest and return the ASRSResponseBO with the success or failure message
195     * @param holdId
196     * @param operatorId
197     * @return ASRResponseBo
198     */
199    @Override
200    public ASRResponseBo cancelASRRequest(String holdId, String operatorId) {
201        LOG.info("Inside the ASRResponseBo  method . Hold Id : "+holdId + ". OperatorId : " +operatorId);
202        //check the operator id send is an operator
203        if(!asrHelperService.isAuthorized(operatorId)){
204            return asrHelperService.generateResponse(ASRConstants.OPERATOR_NOT_FOUND_CODE, ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.OPERATOR_NOT_FOUND), ASRConstants.SUCCESS_STATUS);
205        }
206        //check whether the hold id is present
207        //it should be cancelled if the request status is 1
208        Map<String,String> requestMap = new HashMap<String,String>();
209        requestMap.put("requestId",holdId);
210        requestMap.put("requestStatus","1");
211        OleDeliverRequestBo oleDeliverRequestBo=null;
212        List<OleDeliverRequestBo> oleDeliverRequestBos = asrHelperService.getDeliverRequest(requestMap);
213       if(oleDeliverRequestBos ==  null ||(oleDeliverRequestBos!=null && oleDeliverRequestBos.size()==0)){
214           return asrHelperService.generateResponse(ASRConstants.REQUEST_NOT_FOUND_FOR_HOLD_ID_CODE,ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.REQUEST_NOT_FOUND_FOR_HOLD_ID) +" "+holdId, ASRConstants.SUCCESS_STATUS);
215       }else if((oleDeliverRequestBos!=null && oleDeliverRequestBos.size()>0) && businessObjectService.findMatching(ASRTypeRequest.class,requestMap).size()>0){
216           //businessObjectService.delete(oleDeliverRequestBos.get(0));
217           getOleDeliverRequestDocumentHelperService().cancelDocument(oleDeliverRequestBos.get(0));
218           return asrHelperService.generateResponse(ASRConstants.REQUEST_CANCELED_CODE,ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.REQUEST_CANCELED) , ASRConstants.SUCCESS_STATUS);
219       } else{
220           return asrHelperService.generateResponse("109","Hold is processed",404);
221       }
222    }
223
224    /**
225     * This method is used to retrieve the asrRequests .and returns the ASRSRequests
226     * @param operatorId
227     * @param asrLocation
228     * @return  ASRRequests
229     */
230    @Override
231    public Object lookupASRTypeRequest(String operatorId, String asrLocation) {
232        LOG.info("Inside the  lookupASRTypeRequest  method . OperatorId : "+operatorId +". ASRLocation :" +asrLocation);
233        //check the operator id send is an operator
234        if(!asrHelperService.isAuthorized(operatorId)){
235            return asrHelperService.generateResponse(ASRConstants.OPERATOR_NOT_FOUND_CODE,ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.OPERATOR_NOT_FOUND) , ASRConstants.SUCCESS_STATUS);
236        }
237        //return the request with the request type as ASR with request status = 1
238        ASRRequests asrRequests= asrHelperService.getASRTypeRequest("1");
239        if(asrRequests!=null)
240            asrRequests=asrHelperService.getASRRequestBasedOnLocation(asrRequests,asrLocation);
241        if(asrRequests!=null && asrRequests.getAsrRequests()!=null && asrRequests.getAsrRequests().size()>0){
242            return asrRequests;
243        }else{
244            return asrHelperService.generateResponse(ASRConstants.REQUEST_NOT_FOUND_CODE, ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.REQUEST_NOT_FOUND), ASRConstants.SUCCESS_STATUS);
245        }
246       //return
247    }
248
249    /**
250     * This method is used to update the request status and returns ASRResponseBo only if error occurs
251     * @param updateASRRequestStatusBo
252     * @return Object
253     */
254    @Override
255    public Object updateASRRequestStatus(UpdateASRRequestStatusBo updateASRRequestStatusBo) {
256        LOG.info("Inside the  updateASRItemStatusToMissing method . Request Id  : "+updateASRRequestStatusBo.getHoldId() + ". OperatorId : "+updateASRRequestStatusBo.getOperatorId()  );
257         ASRTypeRequest asrTypeRequest;
258        //check the operator id send is an operator
259        if(!asrHelperService.isAuthorized(updateASRRequestStatusBo.getOperatorId())){
260            return asrHelperService.generateResponse(ASRConstants.OPERATOR_NOT_FOUND_CODE, ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.OPERATOR_NOT_FOUND), ASRConstants.SUCCESS_STATUS);
261        }
262        if((updateASRRequestStatusBo.getStatus().equals(ASRConstants.ASR_REQUEST_IN_PROCESS)) || updateASRRequestStatusBo.getStatus().equals(ASRConstants.ASR_REQUEST_FAILURE)){
263
264        } else{
265            return asrHelperService.generateResponse(ASRConstants.STATUS_NOT_MATCH_CODE, ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.STATUS_NOT_MATCH), ASRConstants.SUCCESS_STATUS);
266        }
267        //check whether the hold id is present
268        List<ASRTypeRequest> asrTypeRequests = getAsrHelperService().getASRRequest("requestId",updateASRRequestStatusBo.getHoldId());
269        if(asrTypeRequests==null || (asrTypeRequests!=null && asrTypeRequests.size()==0)){
270            return asrHelperService.generateResponse(ASRConstants.REQUEST_NOT_FOUND_FOR_HOLD_ID_CODE,ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.REQUEST_NOT_FOUND_FOR_HOLD_ID) +" "+updateASRRequestStatusBo.getHoldId(), ASRConstants.SUCCESS_STATUS);
271        }else {
272            asrTypeRequest = asrTypeRequests.get(0);
273        }
274        //update the status as defined in the input
275        if(!asrHelperService.updateRequestStatus(asrTypeRequest,updateASRRequestStatusBo.getHoldId(),updateASRRequestStatusBo.getStatus())){
276            return asrHelperService.generateResponse(ASRConstants.ITEM_STATUS_NOT_UPDATED_CODE, ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.ITEM_STATUS_NOT_UPDATED), ASRConstants.SUCCESS_STATUS);
277        }
278
279        return null;  //To change body of implemented methods use File | Settings | File Templates.
280    }
281
282    /**
283     * This method is used to update the request status and returns ASRResponseBo only if error occurs
284     * @param updateASRItemStatusBo
285     * @return Object
286     */
287    @Override
288    public Object updateASRItemStatusToBeingRetrieved(UpdateASRItemStatusBo updateASRItemStatusBo) {
289        LOG.info("Inside the  updateASRItemStatusToMissing method . Item Barcode : "+updateASRItemStatusBo.getItemBarcode() + ". OperatorId : "+updateASRItemStatusBo.getOperatorId()  );
290        //check the operator id send is an operator
291        if(!asrHelperService.isAuthorized(updateASRItemStatusBo.getOperatorId())){
292            return asrHelperService.generateResponse(ASRConstants.OPERATOR_NOT_FOUND_CODE, ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.OPERATOR_NOT_FOUND), ASRConstants.SUCCESS_STATUS);
293        }
294        if(!(updateASRItemStatusBo.getItemStatus().equals(asrHelperService.getParameter(ASRConstants.ASR_ITEM_RETRIVED)))){
295            return asrHelperService.generateResponse(ASRConstants.STATUS_NOT_MATCH_CODE, ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.STATUS_NOT_MATCH), ASRConstants.SUCCESS_STATUS);
296        }
297        //identify whether the item barcode send is valid one or not
298        String itemLocation = asrHelperService.getLocation(updateASRItemStatusBo.getItemBarcode());
299        if(itemLocation == null){
300            return asrHelperService.generateResponse(ASRConstants.ITEM_NOT_FOUND_CODE,ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.ITEM_NOT_FOUND) , ASRConstants.SUCCESS_STATUS);
301        }
302        //verify whether the item is an asr item
303        if(itemLocation!=null &&!asrHelperService.isAnASRItem(itemLocation)){
304            return asrHelperService.generateResponse(ASRConstants.NOT_ASR_ITEM_CODE, ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.NOT_ASR_ITEM), ASRConstants.SUCCESS_STATUS);
305        }
306        //update the item status according to the status defined in the input
307        if(!asrHelperService.updateItemStatus(updateASRItemStatusBo.getItemBarcode(),updateASRItemStatusBo.getItemStatus())) {
308            return asrHelperService.generateResponse(ASRConstants.ITEM_STATUS_NOT_UPDATED_CODE,ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.ITEM_STATUS_NOT_UPDATED) , ASRConstants.SUCCESS_STATUS);
309        }
310        return null;  //To change body of implemented methods use File | Settings | File Templates.
311    }
312
313    /**
314     * This method is used to update the request status and returns ASRResponseBo only if error occurs
315     * @param updateASRItemStatusBo
316     * @return Object
317     */
318    @Override
319    public Object updateASRItemStatusToMissing(UpdateASRItemStatusBo updateASRItemStatusBo) {
320        LOG.info("Inside the  updateASRItemStatusToMissing method . Item Barcode : "+updateASRItemStatusBo.getItemBarcode() + ". OperatorId : "+updateASRItemStatusBo.getOperatorId()  );
321        //check the operator id send is an operator
322        if(!asrHelperService.isAuthorized(updateASRItemStatusBo.getOperatorId())){
323            return asrHelperService.generateResponse(ASRConstants.OPERATOR_NOT_FOUND_CODE, ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.OPERATOR_NOT_FOUND), ASRConstants.SUCCESS_STATUS);
324        }
325        if(!(updateASRItemStatusBo.getItemStatus().equals(asrHelperService.getParameter(ASRConstants.ASR_ITEM_MISSING)))){
326            return asrHelperService.generateResponse(ASRConstants.STATUS_NOT_MATCH_CODE, ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.STATUS_NOT_MATCH), ASRConstants.SUCCESS_STATUS);
327        }
328        String itemLocation = asrHelperService.getLocation(updateASRItemStatusBo.getItemBarcode());
329        if(itemLocation == null){
330            return asrHelperService.generateResponse(ASRConstants.ITEM_NOT_FOUND_CODE, ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.ITEM_NOT_FOUND), ASRConstants.SUCCESS_STATUS);
331        }
332        //verify whether the item is an asr item
333        if(itemLocation!=null &&!asrHelperService.isAnASRItem(itemLocation)){
334            return asrHelperService.generateResponse(ASRConstants.NOT_ASR_ITEM_CODE, ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.NOT_ASR_ITEM), ASRConstants.SUCCESS_STATUS);
335        }
336        //update the item status according to the status defined in the input
337        if(!asrHelperService.updateItemStatus(updateASRItemStatusBo.getItemBarcode(),updateASRItemStatusBo.getItemStatus())) {
338            return asrHelperService.generateResponse(ASRConstants.ITEM_STATUS_NOT_UPDATED_CODE, ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.ITEM_STATUS_NOT_UPDATED), ASRConstants.SUCCESS_STATUS);
339        }
340        //identify the holds for the
341         asrHelperService.deleteASRRequest(updateASRItemStatusBo.getItemBarcode());
342        return null;  //To change body of implemented methods use File | Settings | File Templates.
343    }
344
345    /**
346     * This method is used to create a new ASRItem and returns the ASRResponseBo with the success or failure message
347     * @param asrItem
348     * @return ASRResponseBo
349     */
350    @Override
351    public ASRResponseBo addNewASRItem(ASRItem asrItem) {
352        LOG.info("Inside the addNewASRItem  method . Item Barcode : "+asrItem.getItemBarcode());
353        //create ASR Item
354        //check item barcode is valid one
355        String itemLocation = asrHelperService.getLocation(asrItem.getItemBarcode());
356        if(itemLocation == null){
357            return asrHelperService.generateResponse(ASRConstants.ITEM_NOT_FOUND_CODE, ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.ITEM_NOT_FOUND), ASRConstants.SUCCESS_STATUS);
358        }
359        //verify whether the item is an asr item
360        if(itemLocation!=null &&!asrHelperService.isAnASRItem(itemLocation)){
361            return asrHelperService.generateResponse(ASRConstants.NOT_ASR_ITEM_CODE, ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.NOT_ASR_ITEM), ASRConstants.SUCCESS_STATUS);
362        }
363        if(asrHelperService.saveASRItem(asrItem)){
364            return asrHelperService.generateResponse(ASRConstants.SUCESS_REQUEST_CD,ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.SUCESS_ITEM_MESG),ASRConstants.SUCCESS_STATUS);
365        }
366
367
368        return null;  //To change body of implemented methods use File | Settings | File Templates.
369    }
370
371    /**
372     *  This method is used to create a new ASRItem and returns the ASRResponseBo with the success or failure message
373     * @param asrRequestBo
374     * @return ASRResponseBo
375     */
376    @Override
377    public ASRResponseBo sendASRRequest(ASRRequestBo asrRequestBo) {
378        LOG.info("Inside the  sendASRRequest method . Item Barcode : "+asrRequestBo.getItemBarcode());
379        //check item barcode is valid one
380        String itemLocation = asrHelperService.getLocation(asrRequestBo.getItemBarcode());
381        if(itemLocation == null){
382            return asrHelperService.generateResponse(ASRConstants.ITEM_NOT_FOUND_CODE, ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.ITEM_NOT_FOUND), ASRConstants.SUCCESS_STATUS);
383        }
384        //verify whether the item is an asr item
385        if(itemLocation!=null &&!asrHelperService.isAnASRItem(itemLocation)){
386            return asrHelperService.generateResponse(ASRConstants.NOT_ASR_ITEM_CODE, ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.NOT_ASR_ITEM), ASRConstants.SUCCESS_STATUS);
387        }
388        //check patron barcode valid one
389            if(!asrHelperService.validatePatron(asrRequestBo.getPatronBarcode())){
390                return asrHelperService.generateResponse(ASRConstants.PATRON_NOT_FOUND_CODE, ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.PATRON_NOT_FOUND), ASRConstants.SUCCESS_STATUS);
391            }
392
393        //check pick up location a valid one
394         if(!asrHelperService.validatePickupLocation(asrRequestBo.getPickupLocation())){
395             return asrHelperService.generateResponse(ASRConstants.INVALID_PKUP_LOCN_CD, ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.INVALID_PKUP_LOCN), ASRConstants.SUCCESS_STATUS);
396         }
397        //place a request with request type asr
398        if(asrHelperService.saveASRRequest(asrRequestBo)){
399            return asrHelperService.generateResponse(ASRConstants.SUCESS_REQUEST_CD,ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.SUCESS_REQUEST_MESG),ASRConstants.SUCCESS_STATUS);
400        }else{
401            return asrHelperService.generateResponse("",ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.FAILURE_REQUEST_MESG),ASRConstants.FAILURE_STATUS);
402        }
403    }
404
405    /**
406     * This method is used to retrieve the request for the provided item barcode and returns the  LookupASRRequestResponseBO with the request details
407     * @param operatorId
408     * @param itemBarcode
409     * @return LookupASRRequestResponseBO
410     */
411    @Override
412    public Object lookupAsrRequest(String operatorId,String itemBarcode) {
413        LOG.info("Inside the lookupAsrRequest method . Operator Id : "+operatorId +". Item Barcode : "+itemBarcode);
414        LookupASRRequestResponseBO lookupASRRequestResponseBO = new LookupASRRequestResponseBO();
415
416        //check the operator id send is an operator
417        if(!asrHelperService.isAuthorized(operatorId)){
418            return asrHelperService.generateResponse(ASRConstants.OPERATOR_NOT_FOUND_CODE,ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.OPERATOR_NOT_FOUND) , ASRConstants.SUCCESS_STATUS);
419        }
420        //check item barcode as valid one
421        String itemLocation = asrHelperService.getLocation(itemBarcode);
422        if(itemLocation == null){
423            return asrHelperService.generateResponse(ASRConstants.ITEM_NOT_FOUND_CODE, ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.ITEM_NOT_FOUND), ASRConstants.SUCCESS_STATUS);
424        }
425        //verify whether the item is an asr item
426        if(itemLocation!=null &&!asrHelperService.isAnASRItem(itemLocation)){
427            return asrHelperService.generateResponse(ASRConstants.NOT_ASR_ITEM_CODE, ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.NOT_ASR_ITEM), ASRConstants.SUCCESS_STATUS);
428        }
429        ASRRequestDetailsBo asrRequestDetailsBo = asrHelperService.getRequests(itemBarcode);
430        if(asrRequestDetailsBo==null){
431            /*lookupASRRequestResponseBO.setCode("000");
432            lookupASRRequestResponseBO.setMessage("Successful query, holds not found");
433            lookupASRRequestResponseBO.setStatusCode(200);*/
434            lookupASRRequestResponseBO.setCode(ASRConstants.REQUEST_NOT_FOUND_CODE);
435            lookupASRRequestResponseBO.setMessage(ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.REQUEST_NOT_FOUND));
436            lookupASRRequestResponseBO.setStatusCode(ASRConstants.SUCCESS_STATUS);
437        } else if(asrRequestDetailsBo!=null && asrRequestDetailsBo.getAsrRequestDetailBos()!=null && asrRequestDetailsBo.getAsrRequestDetailBos().size()>0){
438            lookupASRRequestResponseBO.setCode("000");
439            lookupASRRequestResponseBO.setMessage("Successful query, holds found");
440            lookupASRRequestResponseBO.setStatusCode(ASRConstants.SUCCESS_STATUS);
441            lookupASRRequestResponseBO.setAsrRequestDetailsBo(asrRequestDetailsBo);
442            return lookupASRRequestResponseBO;
443        }
444        return lookupASRRequestResponseBO;  //To change body of implemented methods use File | Settings | File Templates.
445    }
446
447    /**
448     *  This method is used to change the item status and returns the ASRResponseBo with the success or failure message
449     * @param receiveTransitRequestBo
450     * @return  ASRResponseBo
451     */
452    @Override
453    public ASRResponseBo receiveASRItemTransit(ReceiveTransitRequestBo receiveTransitRequestBo) {
454        LOG.info("Inside the  receiveASRItemTransit  method . Barcode : "+receiveTransitRequestBo.getBarcode() + " Operator Id : "+receiveTransitRequestBo.getOperatorId());
455        //check the operator id send is an operator
456        if(!asrHelperService.isAuthorized(receiveTransitRequestBo.getOperatorId())){
457            return asrHelperService.generateResponse(ASRConstants.OPERATOR_NOT_FOUND_CODE, ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.OPERATOR_NOT_FOUND), ASRConstants.SUCCESS_STATUS);
458        }
459        //check item barcode as valid one
460        String itemLocation = asrHelperService.getLocation(receiveTransitRequestBo.getBarcode());
461        if(itemLocation == null){
462            return asrHelperService.generateResponse(ASRConstants.ITEM_NOT_FOUND_CODE, ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.ITEM_NOT_FOUND), ASRConstants.SUCCESS_STATUS);
463        }
464        //verify whether the item is an asr item
465        if(itemLocation!=null &&!asrHelperService.isAnASRItem(itemLocation)){
466            return asrHelperService.generateResponse(ASRConstants.NOT_ASR_ITEM_CODE, ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.NOT_ASR_ITEM), ASRConstants.SUCCESS_STATUS);
467        }
468        if(!asrHelperService.isAuthorized(receiveTransitRequestBo.getOperatorId())){
469            return asrHelperService.generateResponse(ASRConstants.OPERATOR_NOT_FOUND_CODE, ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.OPERATOR_NOT_FOUND), ASRConstants.SUCCESS_STATUS);
470        }
471        //check whether the operator circulation desk and the item home location is a valid one
472        boolean validLocation = asrHelperService.validateLocation(receiveTransitRequestBo.getOperatorId(),itemLocation);
473        if(validLocation){
474            if(asrHelperService.updateItemStatusForInTransit(receiveTransitRequestBo.getBarcode(),ASRConstants.AVAILABLE))
475                return asrHelperService.generateResponse(ASRConstants.ITEM_STATUS_UPDATED_CODE, ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.ITEM_STATUS_UPDATED), ASRConstants.SUCCESS_STATUS);
476            else
477                return asrHelperService.generateResponse(ASRConstants.ITEM_NOT_IN_TRANSIT_CODE, ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.ITEM_NOT_IN_TRANSIT), ASRConstants.SUCCESS_STATUS);
478        }else{
479            return asrHelperService.generateResponse(ASRConstants.LOCATION_MISMATCH_CODE,ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.LOCATION_MISMATCH),ASRConstants.SUCCESS_STATUS);
480        }
481    }
482
483    /**
484     * This method is used the change the item status of the item during the check-in process and returns the ASRResponseBo with success of failure message
485     * @param asrCheckInBo
486     * @return  ASRResponseBo
487     */
488    @Override
489    public ASRResponseBo checkInASRItem(ASRCheckInBo asrCheckInBo) {
490        LOG.info("Inside the  checkInASRItem  method : Item Barcode : "+asrCheckInBo.getItemBarcode());
491        //check whether item barcode is a valid one and asr item
492        String itemLocation = asrHelperService.getLocation(asrCheckInBo.getItemBarcode());
493        if(itemLocation == null){
494            return asrHelperService.generateResponse(ASRConstants.ITEM_NOT_FOUND_CODE, ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.ITEM_NOT_FOUND), ASRConstants.SUCCESS_STATUS);
495        }
496        //verify whether the item is an asr item
497        if(itemLocation!=null &&!asrHelperService.isAnASRItem(itemLocation)){
498            return asrHelperService.generateResponse(ASRConstants.NOT_ASR_ITEM_CODE, ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.NOT_ASR_ITEM), ASRConstants.SUCCESS_STATUS);
499        }
500        //identify any hold
501        OleDeliverRequestBo oleDeliverRequestBo = asrHelperService.getPrioritizedRequest(asrCheckInBo.getItemBarcode());
502        //if the hold pick up location and item location are same then change the status to hold
503        if(oleDeliverRequestBo!=null){
504            boolean validLocation=asrHelperService.isCirculationDesksLocation(itemLocation,oleDeliverRequestBo.getPickUpLocationId());
505            if(validLocation){
506                asrHelperService.updateItemStatus(asrCheckInBo.getItemBarcode(), ASRConstants.ON_HOLD);
507                return asrHelperService.generateResponse("200",ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.ITEM_STATUS_UPDATED_HOLD)+asrCheckInBo.getItemBarcode(),ASRConstants.SUCCESS_STATUS);
508            }else if(!validLocation){
509                asrHelperService.updateItemStatus(asrCheckInBo.getItemBarcode(), ASRConstants.INTRANSIT_FOR_HOLD);
510                return asrHelperService.generateResponse(ASRConstants.ITEM_STATUS_UPDATED_CODE, ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.ITEM_STATUS_UPDATED)+" "+asrCheckInBo.getItemBarcode(), ASRConstants.SUCCESS_STATUS);
511
512            }
513        }else{
514            return asrHelperService.generateResponse(ASRConstants.REQUEST_NOT_FOUND_CODE, ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.REQUEST_NOT_FOUND), ASRConstants.SUCCESS_STATUS);
515        }
516
517        //if not change the status to in transit
518        return asrHelperService.generateResponse(ASRConstants.REQUEST_NOT_FOUND_CODE, ConfigContext.getCurrentContextConfig().getProperty(ASRConstants.REQUEST_NOT_FOUND), ASRConstants.SUCCESS_STATUS);  //To change body of implemented methods use File | Settings | File Templates.
519    }
520
521
522}