1 package org.kuali.ole.deliver.controller;
2
3 import org.apache.commons.collections.CollectionUtils;
4 import org.apache.commons.lang.StringUtils;
5 import org.apache.log4j.Logger;
6 import org.kuali.ole.OLEConstants;
7 import org.kuali.ole.deliver.OleLoanDocumentsFromSolrBuilder;
8 import org.kuali.ole.deliver.bo.OleLoanDocument;
9 import org.kuali.ole.deliver.bo.OlePatronDocument;
10 import org.kuali.ole.deliver.form.OlePatronLoanedRecordsForm;
11 import org.kuali.ole.deliver.processor.LoanProcessor;
12 import org.kuali.ole.deliver.service.OLEDeliverService;
13 import org.kuali.rice.kim.impl.identity.entity.EntityBo;
14 import org.kuali.rice.kim.impl.identity.name.EntityNameBo;
15 import org.kuali.rice.krad.service.KRADServiceLocator;
16 import org.kuali.rice.krad.util.GlobalVariables;
17 import org.kuali.rice.krad.util.KRADConstants;
18 import org.kuali.rice.krad.web.controller.UifControllerBase;
19 import org.kuali.rice.krad.web.form.UifFormBase;
20 import org.springframework.stereotype.Controller;
21 import org.springframework.validation.BindingResult;
22 import org.springframework.web.bind.annotation.ModelAttribute;
23 import org.springframework.web.bind.annotation.RequestMapping;
24 import org.springframework.web.servlet.ModelAndView;
25
26 import javax.servlet.http.HttpServletRequest;
27 import javax.servlet.http.HttpServletResponse;
28 import java.util.HashMap;
29 import java.util.List;
30 import java.util.Map;
31
32
33
34
35 @Controller
36 @RequestMapping(value = "/patronLoanedRecord")
37 public class OlePatronLoanedRecordsController extends UifControllerBase {
38
39
40
41
42 private static final Logger LOG = Logger.getLogger(org.kuali.ole.deliver.controller.OlePatronLoanedRecordsController.class);
43 private OleLoanDocumentsFromSolrBuilder oleLoanDocumentsFromSolrBuilder;
44
45 @Override
46 protected OlePatronLoanedRecordsForm createInitialForm(HttpServletRequest request) {
47 return new OlePatronLoanedRecordsForm();
48 }
49
50
51
52
53
54
55
56
57
58
59 @Override
60 @RequestMapping(params = "methodToCall=start")
61 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
62 HttpServletRequest request, HttpServletResponse response) {
63 LOG.debug("Start -- Start Method of OleTemporaryCirculationRecordsForm");
64 OlePatronLoanedRecordsForm olePatronLoanedRecordsForm = (OlePatronLoanedRecordsForm) form;
65 return super.start(olePatronLoanedRecordsForm, result, request, response);
66 }
67
68
69
70
71
72
73
74
75
76
77
78 @RequestMapping(params = "methodToCall=viewLoanedRecords")
79 public ModelAndView viewLoanedRecords(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
80 HttpServletRequest request, HttpServletResponse response) throws Exception {
81
82 OlePatronLoanedRecordsForm olePatronLoanedRecordsForm = (OlePatronLoanedRecordsForm) form;
83 String patronId = request.getParameter("patronId");
84 Map patron = new HashMap();
85 patron.put(OLEConstants.OlePatron.PATRON_ID, patronId);
86 OlePatronDocument olePatronDocument = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OlePatronDocument.class, patron);
87 if (olePatronDocument != null) {
88 EntityBo entity = olePatronDocument.getEntity();
89 EntityNameBo entityName = entity.getNames().get(0);
90 String firstName = entityName.getFirstName();
91 String lastName = entityName.getLastName();
92 String name = firstName + " " + lastName;
93 olePatronLoanedRecordsForm.setPatronName(name);
94 olePatronLoanedRecordsForm.setOlePatronDocument(olePatronDocument);
95 LoanProcessor loanProcessor = new LoanProcessor();
96 try {
97 olePatronDocument.setOleLoanDocuments(getOleLoanDocumentsFromSolrBuilder().getPatronLoanedItemBySolr(olePatronDocument
98 .getOlePatronId(), null));
99 if(CollectionUtils.isNotEmpty(olePatronDocument.getOleLoanDocuments())) {
100 for(OleLoanDocument oleLoanDocument : olePatronDocument.getOleLoanDocuments()) {
101 if(StringUtils.isNotEmpty(oleLoanDocument.getRealPatronName())) {
102 Map patronMap = new HashMap();
103 patronMap.put(OLEConstants.OlePatron.PATRON_ID, oleLoanDocument.getRealPatronName());
104 OlePatronDocument patronDocument = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OlePatronDocument.class, patronMap);
105 if(patronDocument != null){
106 patronDocument = OLEDeliverService.populatePatronName(patronDocument);
107 oleLoanDocument.setRealPatronName(patronDocument.getPatronName());
108 oleLoanDocument.setProxyPatronBarcode(patronDocument.getBarcode());
109 oleLoanDocument.setProxyPatronBarcodeUrl(OLEConstants.ASSIGN_INQUIRY_PATRON_ID + patronDocument.getOlePatronId() + OLEConstants.ASSIGN_PATRON_INQUIRY);
110 }
111 }
112 }
113 }
114 } catch (Exception e) {
115 LOG.error("Exception while setting loan documents", e);
116 }
117 List<OleLoanDocument> oleLoanDocuments = olePatronDocument.getOleLoanDocuments();
118 olePatronLoanedRecordsForm.setLoanDocuments(oleLoanDocuments);
119 } else {
120 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.OlePatron.ERROR_PATRON_NOT_FOUND);
121 }
122 return getUIFModelAndView(olePatronLoanedRecordsForm, "OlePatronLoanedRecordPage");
123 }
124
125 private OleLoanDocumentsFromSolrBuilder getOleLoanDocumentsFromSolrBuilder() {
126 if (null == oleLoanDocumentsFromSolrBuilder) {
127 oleLoanDocumentsFromSolrBuilder = new OleLoanDocumentsFromSolrBuilder();
128 }
129 return oleLoanDocumentsFromSolrBuilder;
130 }
131
132 public void setOleLoanDocumentsFromSolrBuilder(OleLoanDocumentsFromSolrBuilder oleLoanDocumentsFromSolrBuilder) {
133 this.oleLoanDocumentsFromSolrBuilder = oleLoanDocumentsFromSolrBuilder;
134 }
135 }