001 package org.kuali.ole.patron.bill.controller; 002 003 import org.apache.log4j.Logger; 004 import org.kuali.incubator.SolrRequestReponseHandler; 005 import org.kuali.ole.OLEConstants; 006 import org.kuali.ole.patron.bill.*; 007 import org.kuali.ole.patron.bill.form.ItemBillForm; 008 import org.kuali.rice.krad.maintenance.MaintenanceDocument; 009 import org.kuali.rice.krad.service.BusinessObjectService; 010 import org.kuali.rice.krad.service.KRADServiceLocator; 011 import org.kuali.rice.krad.util.GlobalVariables; 012 import org.kuali.rice.krad.util.KRADConstants; 013 import org.kuali.rice.krad.web.controller.UifControllerBase; 014 import org.kuali.rice.krad.web.form.MaintenanceForm; 015 import org.kuali.rice.krad.web.form.UifFormBase; 016 import org.springframework.stereotype.Controller; 017 import org.springframework.validation.BindingResult; 018 import org.springframework.web.bind.annotation.ModelAttribute; 019 import org.springframework.web.bind.annotation.RequestMapping; 020 import org.springframework.web.servlet.ModelAndView; 021 022 import javax.servlet.http.HttpServletRequest; 023 import javax.servlet.http.HttpServletResponse; 024 import java.math.BigDecimal; 025 import java.util.HashMap; 026 import java.util.Iterator; 027 import java.util.List; 028 import java.util.Map; 029 030 /** 031 * Created with IntelliJ IDEA. 032 * User: ? 033 * Date: 9/7/12 034 * Time: 11:32 AM 035 * To change this template use File | Settings | File Templates. 036 */ 037 038 @Controller 039 @RequestMapping(value = "/itemPatronBill") 040 public class ItemBillController extends UifControllerBase { 041 042 private static final Logger LOG = Logger.getLogger(ItemBillController.class); 043 044 /** 045 * This method creates new ItemBill form 046 * @param request 047 * @return ItemBillForm 048 */ 049 @Override 050 protected ItemBillForm createInitialForm(HttpServletRequest request) { 051 return new ItemBillForm(); 052 } 053 054 /** 055 * This method takes the initial request when click on Item Bill link 056 * @param form 057 * @param result 058 * @param request 059 * @param response 060 * @return ModelAndView 061 */ 062 @Override 063 @RequestMapping(params = "methodToCall=start") 064 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 065 HttpServletRequest request, HttpServletResponse response) { 066 ItemBillForm itemBillForm = (ItemBillForm) form; 067 return super.start(itemBillForm, result, request, response); 068 } 069 070 /** 071 * This method retrieves all bill information for particular item barcode 072 * @param form 073 * @param result 074 * @param request 075 * @param response 076 * @return ModelAndView 077 */ 078 @RequestMapping(params = "methodToCall=submit") 079 public ModelAndView submitItemBarcode(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 080 HttpServletRequest request, HttpServletResponse response) { 081 ItemBillForm itemBillForm = (ItemBillForm) form; 082 String itemBarcode = itemBillForm.getItemBarcode(); 083 SolrRequestReponseHandler solrRequestReponseHandler = new SolrRequestReponseHandler(); 084 if(itemBarcode.equals("") || itemBarcode == null){ 085 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.ENTR_ITM_BAR ); 086 return getUIFModelAndView(itemBillForm); 087 }else if(!(itemBarcode.equals("")) || itemBarcode != null){ 088 List<HashMap<String, Object>> documentList = solrRequestReponseHandler.retriveResults(OLEConstants.ITM_BAR_DISP + itemBarcode); 089 if (documentList != null && documentList.size() == 0) { 090 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.ITM_BAR_NOT_AVAL); 091 return getUIFModelAndView(itemBillForm); 092 } 093 } 094 Map itemBarcodeMap = new HashMap(); 095 itemBarcodeMap.put("itemBarcode",itemBarcode); 096 List<FeeType> feeTypeList = (List<FeeType>)KRADServiceLocator.getBusinessObjectService().findMatching(FeeType.class,itemBarcodeMap); 097 if(feeTypeList.size()==0){ 098 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.GLOBAL_ERRORS, OLEConstants.BILL_NOT_AVAI_BAR ); 099 return getUIFModelAndView(itemBillForm); 100 } 101 ItemBillHelperService itemBillHelperService = new ItemBillHelperService(); 102 itemBillForm.setItemBillList(itemBillHelperService.getItemBills(itemBarcode)); 103 return getUIFModelAndView(itemBillForm, "ItemViewPage"); 104 } 105 106 /** 107 * This method will clear all elements 108 * @param form 109 * @param result 110 * @param request 111 * @param response 112 * @return ModelAndView 113 */ 114 @RequestMapping(params = "methodToCall=clear") 115 public ModelAndView clearItemBarcode(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 116 HttpServletRequest request, HttpServletResponse response) { 117 ItemBillForm itemBillForm = (ItemBillForm) form; 118 itemBillForm.setItemBarcode(""); 119 return getUIFModelAndView(itemBillForm, "ItemViewPage"); 120 121 } 122 123 /** 124 * Just returns as if return with no value was selected. 125 */ 126 @Override 127 @RequestMapping(params = "methodToCall=close") 128 public ModelAndView close(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 129 HttpServletRequest request, HttpServletResponse response) { 130 return super.close(form, result, request, response); 131 } 132 133 134 135 136 137 }