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.krad.service.KRADServiceLocator;
14 import org.kuali.rice.krad.util.GlobalVariables;
15 import org.kuali.rice.krad.util.KRADConstants;
16 import org.kuali.rice.krad.web.controller.UifControllerBase;
17 import org.kuali.rice.krad.web.form.UifFormBase;
18 import org.springframework.stereotype.Controller;
19 import org.springframework.validation.BindingResult;
20 import org.springframework.web.bind.annotation.ModelAttribute;
21 import org.springframework.web.bind.annotation.RequestMapping;
22 import org.springframework.web.servlet.ModelAndView;
23
24 import javax.servlet.http.HttpServletRequest;
25 import javax.servlet.http.HttpServletResponse;
26 import java.util.HashMap;
27 import java.util.List;
28 import java.util.Map;
29
30
31
32
33
34
35
36
37
38 @Controller
39 @RequestMapping(value = "/itemPatronBill")
40 public class ItemBillController extends UifControllerBase {
41
42 private static final Logger LOG = Logger.getLogger(ItemBillController.class);
43 private DocstoreClientLocator docstoreClientLocator;
44
45 public DocstoreClientLocator getDocstoreClientLocator() {
46
47 if (docstoreClientLocator == null) {
48 docstoreClientLocator = SpringContext.getBean(DocstoreClientLocator.class);
49
50 }
51 return docstoreClientLocator;
52 }
53
54
55
56
57
58
59
60
61 @Override
62 protected ItemBillForm createInitialForm(HttpServletRequest request) {
63 return new ItemBillForm();
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 ItemBillForm itemBillForm = (ItemBillForm) form;
80 return super.start(itemBillForm, result, request, response);
81 }
82
83
84
85
86
87
88
89
90
91
92 @RequestMapping(params = "methodToCall=submit")
93 public ModelAndView submitItemBarcode(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
94 HttpServletRequest request, HttpServletResponse response) {
95 ItemBillForm itemBillForm = (ItemBillForm) form;
96 String itemBarcode = itemBillForm.getItemBarcode();
97 if (itemBarcode.equals("") || itemBarcode == null) {
98 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.ENTR_ITM_BAR);
99 return getUIFModelAndView(itemBillForm);
100 } else if (!(itemBarcode.equals("")) || itemBarcode != null) {
101
102 org.kuali.ole.docstore.common.document.Item item = new ItemOleml();
103 org.kuali.ole.docstore.common.search.SearchParams search_Params = new org.kuali.ole.docstore.common.search.SearchParams();
104 SearchResponse searchResponse = null;
105 search_Params.getSearchConditions().add(search_Params.buildSearchCondition("", search_Params.buildSearchField(org.kuali.ole.docstore.common.document.content.enums.DocType.ITEM.getCode(), item.ITEM_BARCODE, itemBarcode), ""));
106
107
108 search_Params.getSearchResultFields().add(search_Params.buildSearchResultField(org.kuali.ole.docstore.common.document.content.enums.DocType.ITEM.getCode(), "id"));
109
110 try {
111
112
113 searchResponse = getDocstoreClientLocator().getDocstoreClient().search(search_Params);
114
115
116 } catch (Exception ex) {
117 ex.printStackTrace();
118 }
119
120
121 if (searchResponse.getSearchResults() != null && searchResponse.getSearchResults().size() == 0) {
122 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ITM_BAR_NOT_AVAL);
123 return getUIFModelAndView(itemBillForm);
124 }
125 }
126 Map itemBarcodeMap = new HashMap();
127 itemBarcodeMap.put("itemBarcode", itemBarcode);
128 List<FeeType> feeTypeList = (List<FeeType>) KRADServiceLocator.getBusinessObjectService().findMatching(FeeType.class, itemBarcodeMap);
129 if (feeTypeList.size() == 0) {
130 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.BILL_NOT_AVAI_BAR);
131 return getUIFModelAndView(itemBillForm);
132 }
133 ItemBillHelperService itemBillHelperService = new ItemBillHelperService();
134 List<FeeType> feeTypes = itemBillHelperService.getItemBillDetails(itemBarcode);
135 itemBillForm.setFeeType(itemBillHelperService.getFeeTypeDetails(feeTypes != null && feeTypes.size() > 0 ? feeTypes.get(0) : null));
136 itemBillForm.setFeeTypes(feeTypes);
137 return getUIFModelAndView(itemBillForm, "ItemViewPage");
138 }
139
140
141
142
143
144
145
146
147
148
149 @RequestMapping(params = "methodToCall=clear")
150 public ModelAndView clearItemBarcode(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
151 HttpServletRequest request, HttpServletResponse response) {
152 ItemBillForm itemBillForm = (ItemBillForm) form;
153 itemBillForm.setItemBarcode("");
154 return getUIFModelAndView(itemBillForm, "ItemViewPage");
155
156 }
157
158
159
160
161 @Override
162 @RequestMapping(params = "methodToCall=back")
163 public ModelAndView back(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
164 HttpServletRequest request, HttpServletResponse response) {
165 return super.back(form, result, request, response);
166 }
167
168
169 }