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