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
34
35
36
37
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
59
60
61
62
63 @Override
64 protected ItemBillForm createInitialForm() {
65 return new ItemBillForm();
66 }
67
68
69
70
71
72
73
74
75
76
77 @Override
78 @RequestMapping(params = "methodToCall=start")
79
80
81 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form) {
82 ItemBillForm itemBillForm = (ItemBillForm) form;
83
84 return super.start(itemBillForm);
85 }
86
87
88
89
90
91
92
93
94
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
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
147
148
149
150
151
152
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
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 }