1 package org.kuali.ole.deliver.controller;
2
3 import org.apache.log4j.Logger;
4 import org.kuali.ole.OLEConstants;
5 import org.kuali.ole.deliver.bo.OleDeliverRequestBo;
6 import org.kuali.ole.deliver.bo.OlePatronDocument;
7 import org.kuali.ole.deliver.form.OlePatronRequestedRecordsForm;
8 import org.kuali.ole.deliver.service.OleDeliverRequestDocumentHelperServiceImpl;
9 import org.kuali.rice.kim.impl.identity.entity.EntityBo;
10 import org.kuali.rice.kim.impl.identity.name.EntityNameBo;
11 import org.kuali.rice.krad.service.KRADServiceLocator;
12 import org.kuali.rice.krad.util.GlobalVariables;
13 import org.kuali.rice.krad.util.KRADConstants;
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 import java.util.HashMap;
25 import java.util.List;
26 import java.util.Map;
27
28
29
30
31 @Controller
32 @RequestMapping(value = "/patronRequestedRecord")
33 public class OlePatronRequestedRecordsController extends UifControllerBase {
34
35
36
37
38 private static final Logger LOG = Logger.getLogger(OlePatronRequestedRecordsController.class);
39
40 @Override
41 protected OlePatronRequestedRecordsForm createInitialForm(HttpServletRequest request) {
42 return new OlePatronRequestedRecordsForm();
43 }
44
45
46
47
48
49
50
51
52
53
54 @Override
55 @RequestMapping(params = "methodToCall=start")
56 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
57 HttpServletRequest request, HttpServletResponse response) {
58 LOG.debug("Start -- Start Method of OleTemporaryCirculationRecordsForm");
59 OlePatronRequestedRecordsForm olePatronRequestedRecordsForm = (OlePatronRequestedRecordsForm) form;
60 return super.start(olePatronRequestedRecordsForm, result, request, response);
61 }
62
63
64
65
66
67
68
69
70
71
72
73 @RequestMapping(params = "methodToCall=viewRequestedRecords")
74 public ModelAndView viewRequestedRecords(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
75 HttpServletRequest request, HttpServletResponse response) throws Exception {
76
77 OlePatronRequestedRecordsForm olePatronRequestedRecordsForm = (OlePatronRequestedRecordsForm) form;
78 String patronId = request.getParameter("patronId");
79 Map patron = new HashMap();
80 patron.put(OLEConstants.OlePatron.PATRON_ID, patronId);
81 OlePatronDocument olePatronDocument = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OlePatronDocument.class, patron);
82 if (olePatronDocument != null) {
83 EntityBo entity = olePatronDocument.getEntity();
84 EntityNameBo entityName = entity.getNames().get(0);
85 String firstName = entityName.getFirstName();
86 String lastName = entityName.getLastName();
87 String name = firstName + " " + lastName;
88 olePatronRequestedRecordsForm.setPatronName(name);
89 olePatronRequestedRecordsForm.setOlePatronDocument(olePatronDocument);
90 OleDeliverRequestDocumentHelperServiceImpl oleDeliverRequestDocumentHelperService = new OleDeliverRequestDocumentHelperServiceImpl();
91 List<OleDeliverRequestBo> oleDeliverRequestBos = oleDeliverRequestDocumentHelperService.getRequestedItems(patronId);
92 olePatronRequestedRecordsForm.setRequestBos(oleDeliverRequestBos);
93 } else {
94 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_PATRON_NOT_FOUND);
95 }
96 return getUIFModelAndView(olePatronRequestedRecordsForm, "OlePatronRequestedRecordPage");
97 }
98 }