001 package org.kuali.ole.deliver.loan.controller; 002 003 import org.apache.log4j.Logger; 004 import org.kuali.ole.OLEConstants; 005 import org.kuali.ole.deliver.loan.LoanProcessor; 006 import org.kuali.ole.deliver.loan.bo.OleLoanFastAdd; 007 import org.kuali.ole.deliver.loan.form.OleLoanForm; 008 import org.kuali.ole.docstore.model.xmlpojo.ingest.Response; 009 import org.kuali.ole.docstore.model.xmlpojo.work.instance.oleml.Item; 010 import org.kuali.ole.docstore.model.xmlpojo.work.instance.oleml.OleHoldings; 011 import org.kuali.ole.docstore.model.xstream.ingest.ResponseHandler; 012 import org.kuali.ole.editor.service.DocstoreHelperService; 013 import org.kuali.ole.pojo.bib.BibliographicRecord; 014 import org.kuali.rice.krad.web.controller.UifControllerBase; 015 import org.kuali.rice.krad.web.form.UifFormBase; 016 import org.springframework.stereotype.Controller; 017 import org.springframework.validation.BindingResult; 018 import org.springframework.web.bind.annotation.ModelAttribute; 019 import org.springframework.web.bind.annotation.RequestMapping; 020 import org.springframework.web.servlet.ModelAndView; 021 022 import javax.servlet.http.HttpServletRequest; 023 import javax.servlet.http.HttpServletResponse; 024 025 /** 026 * Created with IntelliJ IDEA. 027 * User: palanivel 028 * Date: 3/15/13 029 * Time: 11:08 AM 030 * To change this template use File | Settings | File Templates. 031 */ 032 @Controller 033 @RequestMapping(value = "/fastAddController") 034 public class FastAddItemController extends UifControllerBase { 035 private static final Logger LOG = Logger.getLogger(FastAddItemController.class); 036 037 @Override 038 protected OleLoanForm createInitialForm(HttpServletRequest request) { 039 return new OleLoanForm(); 040 } 041 042 @Override 043 @RequestMapping(params = "methodToCall=start") 044 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 045 HttpServletRequest request, HttpServletResponse response) { 046 OleLoanForm oleLoanForm = (OleLoanForm) form; 047 OleLoanFastAdd oleLoanFastAdd = new OleLoanFastAdd(); 048 oleLoanFastAdd.setCallNumberType(OLEConstants.DEFAULT_CALL_NUMBER_TYPE); 049 oleLoanFastAdd.setCallNumber(OLEConstants.DEFAULT_CALL_NUMBER); 050 oleLoanForm.setOleLoanFastAdd(oleLoanFastAdd); 051 return getUIFModelAndView(oleLoanForm, "FastAddItemViewPage"); 052 } 053 054 /** 055 * Create a Bib and Instance record in docstore. 056 * @param form 057 * @param result 058 * @param request 059 * @param response 060 * @return 061 */ 062 @RequestMapping(params = "methodToCall=createFastAddItem") 063 public ModelAndView createFastAddItem(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 064 HttpServletRequest request, HttpServletResponse response) { 065 LOG.debug("Inside the create fast add item method"); 066 OleLoanForm oleLoanForm = (OleLoanForm) form; 067 String maxSessionTime = oleLoanForm.getMaxTimeForCheckOutConstant(); 068 LOG.info("session timeout"+maxSessionTime); 069 if(maxSessionTime != null && !maxSessionTime.equalsIgnoreCase("")) 070 oleLoanForm.setMaxSessionTime(Integer.parseInt(maxSessionTime)); 071 oleLoanForm.setInformation(""); 072 oleLoanForm.setReturnInformation(""); 073 LoanProcessor loanProcessor = new LoanProcessor(); 074 if(!oleLoanForm.getOleLoanFastAdd().getBarcode().isEmpty() && !oleLoanForm.getOleLoanFastAdd().getCallNumberType().isEmpty() && !oleLoanForm.getOleLoanFastAdd().getCallNumber().isEmpty() && !oleLoanForm.getOleLoanFastAdd().getCheckinNote().isEmpty() && !oleLoanForm.getOleLoanFastAdd().getLocationName().isEmpty() && !oleLoanForm.getOleLoanFastAdd().getItemType().isEmpty()){ 075 BibliographicRecord bibliographicRecord=loanProcessor.getBibliographicRecord(oleLoanForm.getOleLoanFastAdd().getTitle(),oleLoanForm.getOleLoanFastAdd().getAuthor()); 076 Item item= loanProcessor.getItemRecord(oleLoanForm.getOleLoanFastAdd()); 077 OleHoldings oleHoldings = loanProcessor.getHoldingRecord(oleLoanForm.getOleLoanFastAdd()); 078 DocstoreHelperService docstoreHelperService=new DocstoreHelperService(); 079 String responseXML=docstoreHelperService.persistNewToDocstoreForIngest(bibliographicRecord,item,oleHoldings); 080 ResponseHandler responseHandler = new ResponseHandler(); 081 Response docStoreResponse = responseHandler.toObject(responseXML); 082 if(docStoreResponse!=null && !docStoreResponse.getStatus().equalsIgnoreCase("success")){ 083 oleLoanForm.setInformation(docStoreResponse.getStatusMessage()); 084 } 085 }else{ 086 oleLoanForm.setInformation(OLEConstants.REQ_FIELD); 087 } 088 oleLoanForm.setItem(oleLoanForm.getOleLoanFastAdd().getBarcode()); 089 oleLoanForm.setFastAddItemIndicator(true); 090 LoanController.fastAddBarcode=oleLoanForm.getItem(); 091 return getUIFModelAndView(oleLoanForm, "FastAddItemViewPage"); 092 } 093 094 }