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.FeeType;
6   import org.kuali.ole.deliver.bo.ItemBillHelperService;
7   import org.kuali.ole.deliver.form.ItemBillForm;
8   import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
9   
10  import org.kuali.ole.docstore.common.document.ItemOleml;
11  import org.kuali.ole.docstore.common.search.SearchResponse;
12  import org.kuali.ole.sys.context.SpringContext;
13  import org.kuali.rice.core.api.criteria.QueryByCriteria;
14  import org.kuali.rice.kns.service.KNSServiceLocator;
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   * Created with IntelliJ IDEA.
34   * User: ?
35   * Date: 9/7/12
36   * Time: 11:32 AM
37   * To change this template use File | Settings | File Templates.
38   */
39  
40  @Controller
41  @RequestMapping(value = "/itemPatronBill")
42  public class ItemBillController extends UifControllerBase {
43  
44      private static final Logger LOG = Logger.getLogger(ItemBillController.class);
45      private DocstoreClientLocator docstoreClientLocator;
46  
47      public DocstoreClientLocator getDocstoreClientLocator() {
48  
49          if (docstoreClientLocator == null) {
50              docstoreClientLocator = SpringContext.getBean(DocstoreClientLocator.class);
51  
52          }
53          return docstoreClientLocator;
54      }
55  
56  
57      /**
58       * This method creates new ItemBillform
59       *
60       * @param request
61       * @return ItemBillForm
62       */
63      @Override
64      protected ItemBillForm createInitialForm() {
65          return new ItemBillForm();
66      }
67  
68      /**
69       * This method takes the initial request when click on  Item Bill link
70       *
71       * @param form
72       * @param result
73       * @param request
74       * @param response
75       * @return ModelAndView
76       */
77      @Override
78      @RequestMapping(params = "methodToCall=start")
79      /*public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
80                                HttpServletRequest request, HttpServletResponse response) {*/
81      public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form) {
82          ItemBillForm itemBillForm = (ItemBillForm) form;
83          /*return super.start(itemBillForm);*/
84          return super.start(itemBillForm);
85      }
86  
87      /**
88       * This method retrieves all bill information for particular item barcode
89       *
90       * @param form
91       * @param result
92       * @param request
93       * @param response
94       * @return ModelAndView
95       */
96      @RequestMapping(params = "methodToCall=submit")
97      public ModelAndView submitItemBarcode(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
98                                            HttpServletRequest request, HttpServletResponse response) {
99          ItemBillForm itemBillForm = (ItemBillForm) form;
100         String itemBarcode = itemBillForm.getItemBarcode();
101         if (itemBarcode.equals("") || itemBarcode == null) {
102             GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.ENTR_ITM_BAR);
103             return getModelAndView(itemBillForm);
104         } else if (!(itemBarcode.equals("")) || itemBarcode != null) {
105 
106             org.kuali.ole.docstore.common.document.Item item = new ItemOleml();
107             org.kuali.ole.docstore.common.search.SearchParams search_Params = new org.kuali.ole.docstore.common.search.SearchParams();
108             SearchResponse searchResponse = null;
109             search_Params.getSearchConditions().add(search_Params.buildSearchCondition("phrase", search_Params.buildSearchField(org.kuali.ole.docstore.common.document.content.enums.DocType.ITEM.getCode(), item.ITEM_BARCODE, itemBarcode), ""));
110 
111 
112             search_Params.getSearchResultFields().add(search_Params.buildSearchResultField(org.kuali.ole.docstore.common.document.content.enums.DocType.ITEM.getCode(), "id"));
113 
114             try {
115 
116 
117                 searchResponse = getDocstoreClientLocator().getDocstoreClient().search(search_Params);
118 
119 
120             } catch (Exception ex) {
121                 ex.printStackTrace();
122             }
123 
124 
125             if (searchResponse.getSearchResults() != null && searchResponse.getSearchResults().size() == 0) {
126                 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ITM_BAR_NOT_AVAL);
127                 return getModelAndView(itemBillForm);
128             }
129         }
130         Map itemBarcodeMap = new HashMap();
131         itemBarcodeMap.put("itemBarcode", itemBarcode);
132         //List<FeeType> feeTypeList = (List<FeeType>) KRADServiceLocator.KRADServiceLocatorWeb.getLegacyDataAdapter().findMatching(FeeType.class, itemBarcodeMap);
133         List<FeeType> feeTypeList = (List<FeeType>) KRADServiceLocator.getDataObjectService().findMatching(FeeType.class, QueryByCriteria.Builder.andAttributes(itemBarcodeMap).build()).getResults();
134         if (feeTypeList.size() == 0) {
135             GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.BILL_NOT_AVAI_BAR);
136             return getModelAndView(itemBillForm);
137         }
138         ItemBillHelperService itemBillHelperService = new ItemBillHelperService();
139         List<FeeType> feeTypes = itemBillHelperService.getItemBillDetails(itemBarcode);
140         itemBillForm.setFeeType(itemBillHelperService.getFeeTypeDetails(feeTypes != null && feeTypes.size() > 0 ? feeTypes.get(0) : null));
141         itemBillForm.setFeeTypes(feeTypes);
142         return getModelAndView(itemBillForm, "ItemViewPage");
143     }
144 
145     /**
146      * This method will clear all elements
147      *
148      * @param form
149      * @param result
150      * @param request
151      * @param response
152      * @return ModelAndView
153      */
154     @RequestMapping(params = "methodToCall=clear")
155     public ModelAndView clearItemBarcode(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
156                                          HttpServletRequest request, HttpServletResponse response) {
157         ItemBillForm itemBillForm = (ItemBillForm) form;
158         itemBillForm.setItemBarcode("");
159         return getModelAndView(itemBillForm, "ItemViewPage");
160 
161     }
162 
163     /**
164      * Just returns as if return with no value was selected.
165      */
166     @Override
167     @RequestMapping(params = "methodToCall=back")
168     public ModelAndView back(@ModelAttribute("KualiForm") UifFormBase form) {
169         return super.back(form);
170     }
171 
172 
173 }