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.OleLoanDocumentsFromSolrBuilder;
6 import org.kuali.ole.deliver.bo.OlePatronDocument;
7 import org.kuali.ole.deliver.bo.OleTemporaryCirculationHistory;
8 import org.kuali.ole.deliver.form.OleTemporaryCirculationRecordsForm;
9 import org.kuali.ole.deliver.processor.LoanProcessor;
10 import org.kuali.rice.kim.impl.identity.entity.EntityBo;
11 import org.kuali.rice.kim.impl.identity.name.EntityNameBo;
12 import org.kuali.rice.krad.service.KRADServiceLocator;
13 import org.kuali.rice.krad.util.GlobalVariables;
14 import org.kuali.rice.krad.util.KRADConstants;
15 import org.kuali.rice.krad.web.controller.UifControllerBase;
16 import org.kuali.rice.krad.web.form.UifFormBase;
17 import org.springframework.stereotype.Controller;
18 import org.springframework.validation.BindingResult;
19 import org.springframework.web.bind.annotation.ModelAttribute;
20 import org.springframework.web.bind.annotation.RequestMapping;
21 import org.springframework.web.servlet.ModelAndView;
22
23 import javax.servlet.http.HttpServletRequest;
24 import javax.servlet.http.HttpServletResponse;
25 import java.util.HashMap;
26 import java.util.List;
27 import java.util.Map;
28
29
30
31
32 @Controller
33 @RequestMapping(value = "/temporaryCirculationRecord")
34 public class OleTemporaryCirculationRecordsController extends UifControllerBase {
35
36
37
38
39 private static final Logger LOG = Logger.getLogger(OleTemporaryCirculationRecordsController.class);
40 private OleLoanDocumentsFromSolrBuilder oleLoanDocumentsFromSolrBuilder;
41
42 @Override
43 protected OleTemporaryCirculationRecordsForm createInitialForm(HttpServletRequest request) {
44 return new OleTemporaryCirculationRecordsForm();
45 }
46
47
48
49
50
51
52
53
54
55
56 @Override
57 @RequestMapping(params = "methodToCall=start")
58 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
59 HttpServletRequest request, HttpServletResponse response) {
60 LOG.debug("Start -- Start Method of OleTemporaryCirculationRecordsForm");
61 OleTemporaryCirculationRecordsForm oleTemporaryCirculationRecordsForm = (OleTemporaryCirculationRecordsForm) form;
62 return super.start(oleTemporaryCirculationRecordsForm, result, request, response);
63 }
64
65
66
67
68
69
70
71
72
73
74
75 @RequestMapping(params = "methodToCall=viewTempCircRecords")
76 public ModelAndView viewTempCircRecords(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
77 HttpServletRequest request, HttpServletResponse response) throws Exception {
78
79 OleTemporaryCirculationRecordsForm oleTemporaryCirculationRecordsForm = (OleTemporaryCirculationRecordsForm) form;
80 String patronId = request.getParameter("patronId");
81 Map patron = new HashMap();
82 patron.put(OLEConstants.OlePatron.PATRON_ID, patronId);
83 OlePatronDocument olePatronDocument = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OlePatronDocument.class, patron);
84 if (olePatronDocument != null) {
85 EntityBo entity = olePatronDocument.getEntity();
86 EntityNameBo entityName = entity.getNames().get(0);
87 String firstName = entityName.getFirstName();
88 String lastName = entityName.getLastName();
89 String name = firstName + " " + lastName;
90 oleTemporaryCirculationRecordsForm.setPatronName(name);
91 oleTemporaryCirculationRecordsForm.setOlePatronDocument(olePatronDocument);
92 LoanProcessor loanProcessor = new LoanProcessor();
93 try {
94 olePatronDocument.setOleTemporaryCirculationHistoryRecords(getOleLoanDocumentsFromSolrBuilder()
95 .getPatronTemporaryCirculationHistoryRecords(olePatronDocument.getOlePatronId()));
96 } catch (Exception e) {
97 LOG.error("Exception while setting temporary circulation history records", e);
98 }
99 List<OleTemporaryCirculationHistory> oleTemporaryCirculationHistoryRecords = olePatronDocument.getOleTemporaryCirculationHistoryRecords();
100 oleTemporaryCirculationRecordsForm.setOleTemporaryCirculationHistoryRecords(oleTemporaryCirculationHistoryRecords);
101 } else {
102 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_PATRON_NOT_FOUND);
103 }
104 return getUIFModelAndView(oleTemporaryCirculationRecordsForm, "OleTemporaryCirculationHistoryRecordPage");
105 }
106
107 private OleLoanDocumentsFromSolrBuilder getOleLoanDocumentsFromSolrBuilder() {
108 if (null == oleLoanDocumentsFromSolrBuilder) {
109 oleLoanDocumentsFromSolrBuilder = new OleLoanDocumentsFromSolrBuilder();
110 }
111 return oleLoanDocumentsFromSolrBuilder;
112 }
113
114 public void setOleLoanDocumentsFromSolrBuilder(OleLoanDocumentsFromSolrBuilder oleLoanDocumentsFromSolrBuilder) {
115 this.oleLoanDocumentsFromSolrBuilder = oleLoanDocumentsFromSolrBuilder;
116 }
117 }