001package org.kuali.ole.deliver.controller; 002 003import org.apache.log4j.Logger; 004import org.kuali.ole.deliver.bo.OleCirculationDeskDetail; 005import org.kuali.ole.deliver.form.OleCirculationDeskDetailForm; 006import org.kuali.ole.deliver.service.OleCirculationDeskDetailServiceImpl; 007import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; 008import org.kuali.rice.kim.api.permission.PermissionService; 009import org.kuali.rice.kim.api.services.KimApiServiceLocator; 010import org.kuali.rice.krad.exception.DocumentAuthorizationException; 011import org.kuali.rice.krad.util.GlobalVariables; 012import org.kuali.rice.krad.web.controller.UifControllerBase; 013import org.kuali.rice.krad.web.form.UifFormBase; 014import org.springframework.stereotype.Controller; 015import org.springframework.validation.BindingResult; 016import org.springframework.web.bind.annotation.ModelAttribute; 017import org.springframework.web.bind.annotation.RequestMapping; 018import org.springframework.web.servlet.ModelAndView; 019 020import javax.servlet.http.HttpServletRequest; 021import javax.servlet.http.HttpServletResponse; 022import java.util.ArrayList; 023import java.util.List; 024 025 026/** 027 * The OleCirculationDeskDetailController is the controller class for processing all the actions that corresponds to the Circulation Desk functionality in OLE. 028 * The request mapping tag takes care of mapping the individual action to the corresponding functions. 029 */ 030@Controller 031@RequestMapping(value = "/circulationDeskDetailController") 032public class OleCirculationDeskDetailController extends UifControllerBase { 033 034 private static final Logger LOG = Logger.getLogger(OleCirculationDeskDetailController.class); 035 private OleCirculationDeskDetailServiceImpl oleCirculationDeskDetailService; 036 037 private OleCirculationDeskDetailServiceImpl getCirculationDeskDetailService() { 038 if (null == oleCirculationDeskDetailService) { 039 oleCirculationDeskDetailService = GlobalResourceLoader.getService("oleCirculationDeskDetailService"); 040 } 041 return oleCirculationDeskDetailService; 042 } 043 044 /** 045 * This method creates new OleCirculationDeskDetailForm 046 * 047 * @param request 048 * @return OleCirculationDeskDetailForm 049 */ 050 @Override 051 protected OleCirculationDeskDetailForm createInitialForm(HttpServletRequest request) { 052 return new OleCirculationDeskDetailForm(); 053 } 054 055 /** 056 * This method is for setting the form to the screen 057 * 058 * @param form 059 * @param result 060 * @param request 061 * @param response 062 * @return ModelAndView 063 */ 064 @Override 065 @RequestMapping(params = "methodToCall=start") 066 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 067 HttpServletRequest request, HttpServletResponse response) { 068 OleCirculationDeskDetailForm oleCirculationDeskDetailForm = (OleCirculationDeskDetailForm) form; 069 070 PermissionService service = KimApiServiceLocator.getPermissionService(); 071 boolean isAuthorized = service.hasPermission(GlobalVariables.getUserSession().getPrincipalId(), "OLE-PTRN", "Mapping Circulation Desk"); 072 if (!isAuthorized) { 073 throw new DocumentAuthorizationException(GlobalVariables.getUserSession().getPrincipalId(), "not Authorized to map ", "CirculationDesk"); 074 //oleCirculationDeskDetailForm.setErrorAuthrisedUserMessage(OLEConstants.OleCirculationDeskDetail.OLE_CIRCULATION_UNAUTHORISED_USER_MSG); 075 // return new OLEKRADAuthorizationResolver().resolveException(request,response,null,new Exception("is not authorized")); 076 } 077 oleCirculationDeskDetailForm.setMessage(null); 078 oleCirculationDeskDetailForm.setOperatorId(null); 079 080 oleCirculationDeskDetailForm.setOleCirculationDetailsCreateList(getCirculationDeskDetailService().populateCreateList()); 081 return getUIFModelAndView(oleCirculationDeskDetailForm, "OleCirculationDeskDetailViewPage"); 082 } 083 084 /** 085 * This method is for searching the circulation details 086 * 087 * @param form 088 * @param result 089 * @param request 090 * @param response 091 * @return ModelAndView 092 */ 093 @RequestMapping(params = "methodToCall=search") 094 public ModelAndView search(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 095 HttpServletRequest request, HttpServletResponse response) { 096 OleCirculationDeskDetailForm oleCirculationDeskDetailForm = (OleCirculationDeskDetailForm) form; 097 OleCirculationDeskDetailForm deskDetailForm = getCirculationDeskDetailService().performSearch(oleCirculationDeskDetailForm); 098 deskDetailForm .setViewId("OleCirculationDeskDetailView"); 099 return getUIFModelAndView(deskDetailForm, "OleCirculationDeskDetailViewPage"); 100 } 101 102 /** 103 * This method is for saving the circulation desk details for the operator 104 * 105 * @param form 106 * @param result 107 * @param request 108 * @param response 109 * @return ModelAndView 110 */ 111 @RequestMapping(params = "methodToCall=save") 112 public ModelAndView save(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 113 HttpServletRequest request, HttpServletResponse response) throws Exception { 114 115 116 OleCirculationDeskDetailForm oleCirculationDeskDetailForm = (OleCirculationDeskDetailForm) form; 117 OleCirculationDeskDetailForm deskDetailForm = getCirculationDeskDetailService().performSave(oleCirculationDeskDetailForm); 118 return getUIFModelAndView(deskDetailForm, "OleCirculationDeskDetailViewPage"); 119 } 120 121 122 @RequestMapping(params = "methodToCall=clearCircDeskMap") 123 public ModelAndView clearCirculationDeskMap(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 124 HttpServletRequest request, HttpServletResponse response) throws Exception { 125 126 OleCirculationDeskDetailForm oleCirculationDeskDetailForm = (OleCirculationDeskDetailForm) form; 127 List clearList = oleCirculationDeskDetailForm.getOleCirculationDetailsCreateList(); 128 oleCirculationDeskDetailService = getCirculationDeskDetailService(); 129 List circDeskMapRemoved = oleCirculationDeskDetailService.clearAllCirulationMapping(clearList); 130 oleCirculationDeskDetailForm.setOleCirculationDetailsCreateList(circDeskMapRemoved); 131 OleCirculationDeskDetailForm deskDetailForm = getCirculationDeskDetailService().performSave(oleCirculationDeskDetailForm); 132 return getUIFModelAndView(deskDetailForm, "OleCirculationDeskDetailViewPage"); 133 } 134 135 /** 136 * This method is overridden for performing the search when the operator value is populated 137 * 138 * @param form 139 * @param result 140 * @param request 141 * @param response 142 * @return ModelAndView 143 * @throws Exception 144 */ 145 @Override 146 @RequestMapping(params = "methodToCall=refresh") 147 public ModelAndView refresh(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 148 HttpServletRequest request, HttpServletResponse response) throws Exception { 149 form.setView(getViewService().getViewById("OleCirculationDeskDetailView")); 150 super.refresh(form, result, request, response); 151 return search(form, result, request, response); 152 } 153}