1 package org.kuali.ole.deliver.controller.checkout;
2
3 import org.apache.commons.lang3.StringUtils;
4 import org.apache.log4j.Logger;
5 import org.apache.log4j.spi.LoggerFactory;
6 import org.jfree.util.Log;
7 import org.kuali.ole.deliver.controller.PatronLookupCircController;
8 import org.kuali.ole.deliver.drools.DroolsConstants;
9 import org.kuali.ole.deliver.form.CircForm;
10 import org.kuali.ole.deliver.form.OleLoanForm;
11 import org.kuali.ole.deliver.util.ErrorMessage;
12 import org.kuali.ole.utility.OleStopWatch;
13 import org.kuali.rice.krad.util.GlobalVariables;
14 import org.kuali.rice.krad.web.form.UifFormBase;
15 import org.springframework.stereotype.Controller;
16 import org.springframework.validation.BindingResult;
17 import org.springframework.web.bind.annotation.ModelAttribute;
18 import org.springframework.web.bind.annotation.RequestMapping;
19 import org.springframework.web.servlet.ModelAndView;
20
21 import javax.servlet.http.HttpServletRequest;
22 import javax.servlet.http.HttpServletResponse;
23
24
25
26
27 @Controller
28 @RequestMapping(value = "/patronCheckoutController")
29 public class CheckoutPatronController extends CheckoutItemController {
30
31 private static final Logger LOG = Logger.getLogger(CheckoutPatronController.class);
32 private PatronLookupCircController patronLookupCircController;
33
34 @RequestMapping(params = "methodToCall=searchPatron")
35 public ModelAndView searchPatron(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
36 HttpServletRequest request, HttpServletResponse response) throws Exception {
37 CircForm circForm = (CircForm) form;
38
39 resetUI(circForm, result, request, response );
40
41 OleStopWatch oleStopWatch = new OleStopWatch();
42 oleStopWatch.start();
43 ErrorMessage errorMessage = getPatronLookupCircController().searchPatron(circForm);
44 oleStopWatch.end();
45 Log.info("Time taken to look up patron: " + oleStopWatch.getTotalTime() + " ms");
46
47 if (null != errorMessage && StringUtils.isNotBlank(errorMessage.getErrorMessage())) {
48 circForm.setErrorMessage(errorMessage);
49 if (null != errorMessage.getErrorCode() && errorMessage.getErrorCode().equals(DroolsConstants.GENERAL_MESSAGE_FLAG)) {
50 showDialog("generalMessageDialog", circForm, request, response);
51 } else {
52 showErrorMessageDialog(circForm, request, response);
53 }
54 } else {
55 return handleProxyPatronsIfExists(circForm, result, request, response);
56 }
57 return getUIFModelAndView(circForm, "circViewPage");
58 }
59
60 @RequestMapping(params = "methodToCall=handleProxyPatronsIfExists")
61 public ModelAndView handleProxyPatronsIfExists(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
62 HttpServletRequest request, HttpServletResponse response) throws Exception {
63 CircForm circForm = (CircForm) form;
64 if (!circForm.isProxyCheckDone()) {
65 PatronLookupCircController patronLookupCircController = getPatronLookupCircController();
66 boolean proxyPatrons = patronLookupCircController.hasProxyPatrons(circForm);
67 if (!proxyPatrons) {
68 setProceedWithCheckoutFlag(circForm);
69 circForm.setProxyCheckDone(true);
70 } else {
71 showDialog("proxyListCheckoutDialog", circForm, request, response);
72 }
73 } else {
74 setProceedWithCheckoutFlag(circForm);
75 }
76 return getUIFModelAndView(form);
77 }
78
79 @RequestMapping(params = "methodToCall=processPatronSearchPostProxyHandling")
80 public ModelAndView processPatronSearchPostProxyHandling(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
81 HttpServletRequest request, HttpServletResponse response) throws Exception {
82 CircForm circForm = (CircForm) form;
83 ErrorMessage errorMessage = getPatronLookupCircController().processPatronSearchPostProxyHandling(circForm);
84 if(null != errorMessage && StringUtils.isNotEmpty(errorMessage.getErrorMessage())){
85 showDialog("ptrnValidationErrorMessageDialog", circForm, request, response);
86 } else {
87 setProceedWithCheckoutFlag(circForm);
88 }
89 return getUIFModelAndView(circForm);
90 }
91
92 private void setProceedWithCheckoutFlag(CircForm circForm) {
93 circForm.setProceedWithCheckout(true);
94 circForm.getErrorMessage().setErrorCode(null);
95 circForm.getErrorMessage().setErrorMessage(null);
96 }
97
98 @RequestMapping(params = "methodToCall=close")
99 public ModelAndView patronDone(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
100 HttpServletRequest request, HttpServletResponse response) {
101 fastAddBarcode = "";
102 CircForm circForm = (CircForm) form;
103 clearUI(circForm, result, request, response);
104 String principalId = GlobalVariables.getUserSession().getPrincipalId();
105 String circDesk = getCircDesk(principalId);
106 if (circDesk != null) {
107 circForm.setSelectedCirculationDesk(circDesk);
108 circForm.setPreviouslySelectedCirculationDesk(circForm.getSelectedCirculationDesk());
109 }
110 return getUIFModelAndView(circForm, circForm.getPageId());
111 }
112
113 @RequestMapping(params = "methodToCall=clearPatron")
114 public ModelAndView clearPatron(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
115 HttpServletRequest request, HttpServletResponse response) {
116 fastAddBarcode = "";
117 CircForm circForm = (CircForm) form;
118 clearUI(circForm, result, request, response);
119 return getUIFModelAndView(circForm, circForm.getPageId());
120 }
121
122 private PatronLookupCircController getPatronLookupCircController() {
123 if (null == patronLookupCircController) {
124 patronLookupCircController = new PatronLookupCircController();
125 }
126 return patronLookupCircController;
127 }
128 }