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.PatronBillPayment;
6 import org.kuali.ole.deliver.bo.PatronBillReview;
7 import org.kuali.ole.deliver.form.PatronBillReviewForm;
8 import org.kuali.rice.krad.service.BusinessObjectService;
9 import org.kuali.rice.krad.service.KRADServiceLocator;
10 import org.kuali.rice.krad.util.GlobalVariables;
11 import org.kuali.rice.krad.util.KRADConstants;
12 import org.kuali.rice.krad.web.controller.UifControllerBase;
13 import org.kuali.rice.krad.web.form.UifFormBase;
14 import org.springframework.stereotype.Controller;
15 import org.springframework.validation.BindingResult;
16 import org.springframework.web.bind.annotation.ModelAttribute;
17 import org.springframework.web.bind.annotation.RequestMapping;
18 import org.springframework.web.servlet.ModelAndView;
19
20 import javax.servlet.http.HttpServletRequest;
21 import javax.servlet.http.HttpServletResponse;
22 import java.util.HashMap;
23 import java.util.Iterator;
24 import java.util.List;
25 import java.util.Map;
26
27
28
29
30
31
32
33
34 @Controller
35 @RequestMapping(value = "/patronBillReview")
36 public class PatronBillReviewController extends UifControllerBase {
37
38 private static final Logger LOG = Logger.getLogger(org.kuali.ole.deliver.controller.PatronBillReviewController.class);
39
40
41 private BusinessObjectService businessObjectService;
42
43
44
45
46
47
48 private BusinessObjectService getBusinessObjectService() {
49 if (null == businessObjectService) {
50 businessObjectService = KRADServiceLocator.getBusinessObjectService();
51 }
52 return businessObjectService;
53 }
54
55
56
57
58
59
60
61 @Override
62 protected PatronBillReviewForm createInitialForm(HttpServletRequest request) {
63 return new PatronBillReviewForm();
64 }
65
66
67
68
69
70
71
72
73
74
75 @Override
76 @RequestMapping(params = "methodToCall=start")
77 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
78 HttpServletRequest request, HttpServletResponse response) {
79 PatronBillReviewForm patronBillReviewForm = (PatronBillReviewForm) form;
80 PatronBillReview patronBillReview = new PatronBillReview();
81 List<PatronBillReviewForm> patronBillReviewFormList = patronBillReview.getPatronBill();
82 if (patronBillReviewFormList.size() == 0) {
83 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.NO_BILLS);
84 }
85 patronBillReviewForm.setPatronBillReviewFormList(patronBillReviewFormList);
86
87 List<PatronBillReviewForm> patronBillReviewedFormList = patronBillReview.getPatronReviewedBill();
88 patronBillReviewForm.setPatronBillReviewedFormList(patronBillReviewedFormList);
89 return super.start(patronBillReviewForm, result, request, response);
90 }
91
92
93 @RequestMapping(params = "methodToCall=review")
94 public ModelAndView billReviewed(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
95 HttpServletRequest request, HttpServletResponse response) {
96 PatronBillReviewForm patronBillReviewForm = (PatronBillReviewForm) form;
97 List<PatronBillReviewForm> patronBillReviewFormList = patronBillReviewForm.getPatronBillReviewFormList();
98 Iterator itr = patronBillReviewFormList.iterator();
99 PatronBillReviewForm patronBillReviewForms;
100 int count = 0;
101 while (itr.hasNext()) {
102 patronBillReviewForms = (PatronBillReviewForm) itr.next();
103 boolean billReview = patronBillReviewForms.isSelect();
104 if (billReview) {
105 count += 1;
106 String billNumber = patronBillReviewForms.getBillNumber();
107 Map billNumberMap = new HashMap();
108 billNumberMap.put("billNumber", billNumber);
109 PatronBillPayment patronBillPayment = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(PatronBillPayment.class, billNumberMap);
110 patronBillPayment.setReviewed(true);
111 getBusinessObjectService().save(patronBillPayment);
112 }
113 }
114 if (count == 0) {
115 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.SELECT);
116 }
117
118 return start(patronBillReviewForm, result, request, response);
119 }
120 }
121
122
123
124