View Javadoc
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   * Created with IntelliJ IDEA.
29   * User: ?
30   * Date: 12/6/12
31   * Time: 2:53 PM
32   * To change this template use File | Settings | File Templates.
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       * Gets the businessObjectService attribute.
45       *
46       * @return Returns the businessObjectService
47       */
48      private BusinessObjectService getBusinessObjectService() {
49          if (null == businessObjectService) {
50              businessObjectService = KRADServiceLocator.getBusinessObjectService();
51          }
52          return businessObjectService;
53      }
54  
55      /**
56       * This method creates new PatronBillReview form
57       *
58       * @param request
59       * @return PatronBillReviewForm
60       */
61      @Override
62      protected PatronBillReviewForm createInitialForm(HttpServletRequest request) {
63          return new PatronBillReviewForm();
64      }
65  
66      /**
67       * This method takes the initial request when click(Patron Bill) on Patron Screen.
68       *
69       * @param form
70       * @param result
71       * @param request
72       * @param response
73       * @return ModelAndView
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