1 package org.kuali.ole.deliver.loan.controller;
2
3 import org.apache.log4j.Logger;
4 import org.kuali.ole.OLEConstants;
5 import org.kuali.ole.deliver.loan.LoanProcessor;
6 import org.kuali.ole.deliver.loan.bo.OleLoanFastAdd;
7 import org.kuali.ole.deliver.loan.form.OleLoanForm;
8 import org.kuali.ole.docstore.model.xmlpojo.ingest.Response;
9 import org.kuali.ole.docstore.model.xmlpojo.work.instance.oleml.Item;
10 import org.kuali.ole.docstore.model.xmlpojo.work.instance.oleml.OleHoldings;
11 import org.kuali.ole.docstore.model.xstream.ingest.ResponseHandler;
12 import org.kuali.ole.editor.service.DocstoreHelperService;
13 import org.kuali.ole.pojo.bib.BibliographicRecord;
14 import org.kuali.rice.krad.web.controller.UifControllerBase;
15 import org.kuali.rice.krad.web.form.UifFormBase;
16 import org.springframework.stereotype.Controller;
17 import org.springframework.validation.BindingResult;
18 import org.springframework.web.bind.annotation.ModelAttribute;
19 import org.springframework.web.bind.annotation.RequestMapping;
20 import org.springframework.web.servlet.ModelAndView;
21
22 import javax.servlet.http.HttpServletRequest;
23 import javax.servlet.http.HttpServletResponse;
24
25
26
27
28
29
30
31
32 @Controller
33 @RequestMapping(value = "/fastAddController")
34 public class FastAddItemController extends UifControllerBase {
35 private static final Logger LOG = Logger.getLogger(FastAddItemController.class);
36
37 @Override
38 protected OleLoanForm createInitialForm(HttpServletRequest request) {
39 return new OleLoanForm();
40 }
41
42 @Override
43 @RequestMapping(params = "methodToCall=start")
44 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
45 HttpServletRequest request, HttpServletResponse response) {
46 OleLoanForm oleLoanForm = (OleLoanForm) form;
47 OleLoanFastAdd oleLoanFastAdd = new OleLoanFastAdd();
48 oleLoanFastAdd.setCallNumberType(OLEConstants.DEFAULT_CALL_NUMBER_TYPE);
49 oleLoanFastAdd.setCallNumber(OLEConstants.DEFAULT_CALL_NUMBER);
50 oleLoanForm.setOleLoanFastAdd(oleLoanFastAdd);
51 return getUIFModelAndView(oleLoanForm, "FastAddItemViewPage");
52 }
53
54
55
56
57
58
59
60
61
62 @RequestMapping(params = "methodToCall=createFastAddItem")
63 public ModelAndView createFastAddItem(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
64 HttpServletRequest request, HttpServletResponse response) {
65 LOG.debug("Inside the create fast add item method");
66 OleLoanForm oleLoanForm = (OleLoanForm) form;
67 String maxSessionTime = oleLoanForm.getMaxTimeForCheckOutConstant();
68 LOG.info("session timeout"+maxSessionTime);
69 if(maxSessionTime != null && !maxSessionTime.equalsIgnoreCase(""))
70 oleLoanForm.setMaxSessionTime(Integer.parseInt(maxSessionTime));
71 oleLoanForm.setInformation("");
72 oleLoanForm.setReturnInformation("");
73 LoanProcessor loanProcessor = new LoanProcessor();
74 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()){
75 BibliographicRecord bibliographicRecord=loanProcessor.getBibliographicRecord(oleLoanForm.getOleLoanFastAdd().getTitle(),oleLoanForm.getOleLoanFastAdd().getAuthor());
76 Item item= loanProcessor.getItemRecord(oleLoanForm.getOleLoanFastAdd());
77 OleHoldings oleHoldings = loanProcessor.getHoldingRecord(oleLoanForm.getOleLoanFastAdd());
78 DocstoreHelperService docstoreHelperService=new DocstoreHelperService();
79 String responseXML=docstoreHelperService.persistNewToDocstoreForIngest(bibliographicRecord,item,oleHoldings);
80 ResponseHandler responseHandler = new ResponseHandler();
81 Response docStoreResponse = responseHandler.toObject(responseXML);
82 if(docStoreResponse!=null && !docStoreResponse.getStatus().equalsIgnoreCase("success")){
83 oleLoanForm.setInformation(docStoreResponse.getStatusMessage());
84 }
85 }else{
86 oleLoanForm.setInformation(OLEConstants.REQ_FIELD);
87 }
88 oleLoanForm.setItem(oleLoanForm.getOleLoanFastAdd().getBarcode());
89 oleLoanForm.setFastAddItemIndicator(true);
90 LoanController.fastAddBarcode=oleLoanForm.getItem();
91 return getUIFModelAndView(oleLoanForm, "FastAddItemViewPage");
92 }
93
94 }