1 package org.kuali.ole.loan.controller;
2
3 import org.apache.log4j.Logger;
4 import org.kuali.ole.OLEConstants;
5 import org.kuali.ole.loan.LoanProcessor;
6 import org.kuali.ole.loan.bo.OleLoanDocument;
7 import org.kuali.ole.loan.form.OleLoanForm;
8 import org.kuali.rice.krad.service.BusinessObjectService;
9 import org.kuali.rice.krad.web.controller.UifControllerBase;
10 import org.kuali.rice.krad.web.form.UifFormBase;
11 import org.springframework.stereotype.Controller;
12 import org.springframework.validation.BindingResult;
13 import org.springframework.web.bind.annotation.ModelAttribute;
14 import org.springframework.web.bind.annotation.RequestMapping;
15 import org.springframework.web.servlet.ModelAndView;
16
17 import javax.servlet.http.HttpServletRequest;
18 import javax.servlet.http.HttpServletResponse;
19 import java.sql.Timestamp;
20 import java.util.ArrayList;
21 import java.util.Collections;
22 import java.util.Comparator;
23 import java.util.List;
24
25
26
27
28
29 @Controller
30 @RequestMapping(value = "/loancontroller")
31 public class LoanController extends UifControllerBase {
32
33 private static final Logger LOG = Logger.getLogger(LoanController.class);
34
35 private BusinessObjectService boService;
36
37
38
39
40
41
42 @Override
43 protected OleLoanForm createInitialForm(HttpServletRequest request) {
44 return new OleLoanForm();
45 }
46
47
48
49
50
51
52
53
54
55 @Override
56 @RequestMapping(params = "methodToCall=start")
57 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
58 HttpServletRequest request, HttpServletResponse response) {
59 OleLoanForm oleLoanForm = (OleLoanForm) form;
60 return super.start(oleLoanForm, result, request, response);
61 }
62
63
64
65
66
67
68
69
70
71 @RequestMapping(params = "methodToCall=searchPatron")
72 public ModelAndView searchPatron(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
73 HttpServletRequest request, HttpServletResponse response) {
74 OleLoanForm oleLoanForm = (OleLoanForm) form;
75 try{
76 OleLoanDocument oleLoanDocument = getLoanProcessor().getLoanDocument(oleLoanForm.getPatronBarcode());
77 oleLoanForm.setBorrowerType(oleLoanDocument.getBorrowerTypeName());
78 oleLoanForm.setPatronName(oleLoanDocument.getPatronName());
79 oleLoanForm.setPatronId(oleLoanDocument.getPatronId());
80 oleLoanForm.setBorrowerTypeId(oleLoanDocument.getBorrowerTypeId());
81 oleLoanForm.setInformation("");
82 oleLoanForm.setDummyLoan(oleLoanDocument);
83 if(oleLoanDocument.getErrorMessage()!=null){
84 oleLoanForm.setSuccess(false);
85 oleLoanForm.setInformation("");
86 oleLoanForm.setMessage(oleLoanDocument.getErrorMessage());
87 oleLoanForm.setPatronName(null);
88 }
89 }catch (Exception e){
90 oleLoanForm.setInformation(e.getMessage());
91 }
92 return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
93 }
94
95
96
97
98
99
100
101
102
103 @RequestMapping(params = "methodToCall=addItem")
104 public ModelAndView addItem(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
105 HttpServletRequest request, HttpServletResponse response) {
106 OleLoanForm oleLoanForm = (OleLoanForm) form;
107 try{
108 List<OleLoanDocument> existingItemList = new ArrayList<OleLoanDocument>();
109
110 OleLoanDocument oleLoanDocument = new OleLoanDocument();
111 oleLoanDocument.setPatronId(oleLoanForm.getPatronId());
112 oleLoanDocument.setBorrowerTypeId(oleLoanForm.getBorrowerTypeId());
113 oleLoanDocument.setBorrowerTypeName(oleLoanForm.getBorrowerType());
114 oleLoanDocument = getLoanProcessor().addLoan(oleLoanForm.getPatronBarcode(),oleLoanForm.getItem(),oleLoanDocument);
115 oleLoanForm.setItemUuid(oleLoanDocument.getItemUuid());
116 oleLoanForm.setInstanceUuid(oleLoanDocument.getInstanceUuid());
117 oleLoanForm.setOleItem(oleLoanDocument.getOleItem());
118 oleLoanForm.setDueDateMap(oleLoanDocument.getLoanDueDate());
119 oleLoanForm.setMessage(oleLoanDocument.getErrorMessage());
120 if(oleLoanForm.getPatronName()==null){
121 oleLoanForm.setPatronName(oleLoanDocument.getPatronName());
122 }
123 if(oleLoanDocument.getErrorMessage() == null){
124 existingItemList.add(oleLoanDocument);
125 oleLoanForm.setItem("");
126 oleLoanForm.setInformation("");
127 } else {
128 oleLoanForm.setDueDateEmpty(oleLoanDocument.isDueDateEmpty());
129 oleLoanForm.setDummyLoan(oleLoanDocument);
130 oleLoanForm.setSuccess(false);
131 oleLoanForm.setInformation("");
132 }
133 if(oleLoanForm.getLoanList()!=null && !oleLoanForm.getLoanList().isEmpty()){
134 existingItemList.addAll(oleLoanForm.getLoanList());
135 }
136 oleLoanForm.setLoanList(existingItemList);
137 }catch (Exception e){
138 oleLoanForm.setInformation(e.getMessage());
139
140 }
141 return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
142 }
143
144
145
146
147
148
149
150
151
152 @RequestMapping(params = "methodToCall=loan")
153 public ModelAndView loanPatron(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
154 HttpServletRequest request, HttpServletResponse response) {
155 OleLoanForm oleLoanForm = (OleLoanForm) form;
156 try{
157 List<OleLoanDocument> existingItemList = new ArrayList<OleLoanDocument>();
158 OleLoanDocument oleLoanDocument = oleLoanForm.getDummyLoan();
159 if(oleLoanDocument!=null){
160 if(oleLoanForm.getDueDateMap()!=null){
161 oleLoanDocument.setLoanDueDate(new java.sql.Timestamp(oleLoanForm.getDueDateMap().getTime()));
162 getLoanProcessor().saveLoan(oleLoanDocument);
163 existingItemList.add(oleLoanDocument);
164 if(oleLoanForm.getLoanList()!=null && !oleLoanForm.getLoanList().isEmpty()){
165 existingItemList.addAll(oleLoanForm.getLoanList());
166 }
167 oleLoanForm.setLoanList(existingItemList);
168 }
169 if(oleLoanForm.getPatronName()==null){
170 oleLoanForm.setPatronName(oleLoanDocument.getPatronName());
171 }
172 oleLoanForm.setSuccess(true);
173 oleLoanForm.setMessage(null);
174 oleLoanForm.setItem("");
175 oleLoanForm.setInformation("");
176 }
177 }catch (Exception e){
178 oleLoanForm.setInformation(e.getMessage());
179 }
180 return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
181 }
182
183
184
185
186
187
188
189
190
191 @RequestMapping(params = "methodToCall=noLoan")
192 public ModelAndView doNotLoanPatron(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
193 HttpServletRequest request, HttpServletResponse response) {
194 OleLoanForm oleLoanForm = (OleLoanForm) form;
195 oleLoanForm.setItem("");
196 oleLoanForm.setInformation("");
197 oleLoanForm.setMessage(null);
198 oleLoanForm.setSuccess(true);
199 return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
200 }
201
202
203
204
205
206
207
208
209
210 @RequestMapping(params = "methodToCall=saveAndClear")
211 public ModelAndView clearPatron(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
212 HttpServletRequest request, HttpServletResponse response) {
213 OleLoanForm oleLoanForm = (OleLoanForm) form;
214 oleLoanForm.setBorrowerType(null);
215 oleLoanForm.setPatronBarcode(null);
216 oleLoanForm.setPatronName(null);
217 oleLoanForm.setLoanList(null);
218 oleLoanForm.setMessage(null);
219 oleLoanForm.setSuccess(true);
220 return getUIFModelAndView(oleLoanForm, "PatronItemViewPage");
221 }
222
223
224
225
226
227 private LoanProcessor getLoanProcessor() {
228 return new LoanProcessor();
229 }
230
231
232
233 }