1 package org.kuali.ole.deliver.controller;
2
3 import org.apache.log4j.Logger;
4 import org.kuali.ole.deliver.api.OleDeliverRequestDefinition;
5 import org.kuali.ole.deliver.bo.OleDeliverRequestBo;
6 import org.kuali.ole.deliver.form.OleMyAccountRequestForm;
7 import org.kuali.ole.deliver.service.OleMyAccountProcess;
8 import org.kuali.ole.service.OlePatronHelperService;
9 import org.kuali.ole.service.OlePatronHelperServiceImpl;
10 import org.kuali.rice.krad.service.BusinessObjectService;
11 import org.kuali.rice.krad.web.controller.UifControllerBase;
12 import org.kuali.rice.krad.web.form.UifFormBase;
13 import org.springframework.stereotype.Controller;
14 import org.springframework.validation.BindingResult;
15 import org.springframework.web.bind.annotation.ModelAttribute;
16 import org.springframework.web.bind.annotation.RequestMapping;
17 import org.springframework.web.servlet.ModelAndView;
18
19 import javax.servlet.http.HttpServletRequest;
20 import javax.servlet.http.HttpServletResponse;
21 import java.util.ArrayList;
22 import java.util.List;
23
24
25
26
27
28 @Controller
29 @RequestMapping(value = "/myaccountrequestcontroller")
30 public class OleMyAccountRequestController extends UifControllerBase {
31
32 private static final Logger LOG = Logger.getLogger(OleMyAccountRequestController.class);
33
34 private BusinessObjectService boService;
35 private OleMyAccountProcess oleMyAccountProcess;
36 private OlePatronHelperService olePatronHelperService = new OlePatronHelperServiceImpl();
37
38
39
40
41
42
43
44 @Override
45 protected OleMyAccountRequestForm createInitialForm(HttpServletRequest request) {
46 return new OleMyAccountRequestForm();
47 }
48
49
50
51
52
53
54
55
56
57
58 @Override
59 @RequestMapping(params = "methodToCall=start")
60 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
61 HttpServletRequest request, HttpServletResponse response) {
62 OleMyAccountRequestForm oleMyAccountRequestForm = (OleMyAccountRequestForm) form;
63 return super.start(oleMyAccountRequestForm, result, request, response);
64 }
65
66 @RequestMapping(params = "methodToCall=requestRecord")
67 public ModelAndView requestRecord(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
68 HttpServletRequest request, HttpServletResponse response) throws Exception {
69 LOG.debug("Inside requestRecord method");
70 String olePatronId = request.getParameter("olePatronId");
71 OleMyAccountRequestForm oleMyAccountRequestForm = (OleMyAccountRequestForm) form;
72 try {
73 List<OleDeliverRequestDefinition> oleDeliverRequestDefinitions = getOleMyAccountProcess().getPatronRequestItems(olePatronId);
74 List<OleDeliverRequestBo> oleDeliverRequestBos = new ArrayList<OleDeliverRequestBo>();
75 for (OleDeliverRequestDefinition oleDeliverRequestDefinition : oleDeliverRequestDefinitions) {
76 OleDeliverRequestBo oleDeliverRequestBo = OleDeliverRequestBo.from(oleDeliverRequestDefinition);
77 oleDeliverRequestBos.add(oleDeliverRequestBo);
78 }
79 oleMyAccountRequestForm.setOleDeliverRequestBos(oleDeliverRequestBos);
80 } catch (Exception e) {
81 LOG.error("request record from Myaccount------->" + e.getMessage(), e);
82 }
83 return getUIFModelAndView(oleMyAccountRequestForm, "OlePatronRequestRecordPage");
84 }
85
86 @RequestMapping(params = "methodToCall=cancelRequest")
87 public ModelAndView cancelRequest(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
88 HttpServletRequest request, HttpServletResponse response) throws Exception {
89 LOG.debug("Inside cancelRequest method");
90 OleMyAccountRequestForm oleMyAccountRequestForm = (OleMyAccountRequestForm) form;
91 String olePatronId = request.getParameter("olePatronId");
92 List<OleDeliverRequestBo> oleDeliverRequestBo = oleMyAccountRequestForm.getOleDeliverRequestBos();
93 List<OleDeliverRequestDefinition> oleDeliverRequestDefinitions = new ArrayList<OleDeliverRequestDefinition>();
94 List<OleDeliverRequestDefinition> oleDeliverRequestDefinitionNew = new ArrayList<OleDeliverRequestDefinition>();
95 try {
96 for (OleDeliverRequestBo oleDeliverRequest : oleDeliverRequestBo) {
97 if (oleDeliverRequest.isRequestFlag()) {
98 OleDeliverRequestDefinition oleDeliverRequestDefinition = OleDeliverRequestBo.to(oleDeliverRequest);
99 oleDeliverRequestDefinitions.add(oleDeliverRequestDefinition);
100 } else {
101 OleDeliverRequestDefinition oleDeliverRequestDefinition = OleDeliverRequestBo.to(oleDeliverRequest);
102 oleDeliverRequestDefinitionNew.add(oleDeliverRequestDefinition);
103 }
104 }
105 getOleMyAccountProcess().cancelRequest(oleDeliverRequestDefinitions);
106 List<OleDeliverRequestBo> oleDeliverRequestBos = new ArrayList<OleDeliverRequestBo>();
107 OleDeliverRequestBo oleDeliverRequestBoNew = new OleDeliverRequestBo();
108 for (OleDeliverRequestDefinition oleDeliverRequestDefinition : oleDeliverRequestDefinitionNew) {
109 oleDeliverRequestBoNew = OleDeliverRequestBo.from(oleDeliverRequestDefinition);
110 oleDeliverRequestBos.add(oleDeliverRequestBoNew);
111 }
112 oleMyAccountRequestForm.setOleDeliverRequestBos(oleDeliverRequestBos);
113 } catch (Exception e) {
114 LOG.error("cancel request from Myaccount------->" + e.getMessage(), e);
115 }
116 return getUIFModelAndView(oleMyAccountRequestForm, "OlePatronRequestRecordPage");
117 }
118
119 public OleMyAccountProcess getOleMyAccountProcess() {
120
121 if (oleMyAccountProcess == null)
122 oleMyAccountProcess = new OleMyAccountProcess();
123 return oleMyAccountProcess;
124 }
125
126 }