001/** 002 * Copyright 2005-2018 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.krad.web.controller; 017 018import org.apache.commons.lang.StringUtils; 019import org.kuali.rice.core.api.config.property.ConfigContext; 020import org.kuali.rice.krad.service.KRADServiceLocatorWeb; 021import org.kuali.rice.krad.service.KualiExceptionIncidentService; 022import org.kuali.rice.krad.uif.UifConstants; 023import org.kuali.rice.krad.uif.UifParameters; 024import org.kuali.rice.krad.util.KRADConstants; 025import org.kuali.rice.krad.web.form.IncidentReportForm; 026import org.kuali.rice.krad.web.form.UifFormBase; 027import org.springframework.stereotype.Controller; 028import org.springframework.validation.BindingResult; 029import org.springframework.web.bind.annotation.ModelAttribute; 030import org.springframework.web.bind.annotation.RequestMapping; 031import org.springframework.web.bind.annotation.RequestMethod; 032import org.springframework.web.servlet.ModelAndView; 033 034import javax.servlet.http.HttpServletRequest; 035import javax.servlet.http.HttpServletResponse; 036import java.util.Properties; 037 038/** 039 * Handler for incident reports 040 * 041 * @author Kuali Rice Team (rice.collab@kuali.org) 042 */ 043@Controller 044@RequestMapping(value = "/incidentReport") 045public class IncidentReportController extends UifControllerBase { 046 047 /** 048 * {@inheritDoc} 049 */ 050 @Override 051 protected IncidentReportForm createInitialForm() { 052 return new IncidentReportForm(); 053 } 054 055 /** 056 * Emails the report and closes the incident report screen 057 */ 058 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=submitReport") 059 public ModelAndView submitReport(UifFormBase uifForm, HttpServletRequest request) throws Exception { 060 // get the exception incident service and use it to mail the report 061 KualiExceptionIncidentService reporterService = KRADServiceLocatorWeb.getKualiExceptionIncidentService(); 062 reporterService.emailReport(((IncidentReportForm) uifForm).createEmailSubject(), 063 ((IncidentReportForm) uifForm).createEmailMessage()); 064 065 // return the close redirect 066 return back(uifForm); 067 } 068 069 /** 070 * Returns back to the application url on a cancel 071 * 072 * @see UifControllerBase#cancel 073 */ 074 @RequestMapping(params = "methodToCall=cancel") 075 public ModelAndView cancel(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 076 HttpServletRequest request, HttpServletResponse response) { 077 Properties props = new Properties(); 078 props.put(UifParameters.METHOD_TO_CALL, UifConstants.MethodToCallNames.REFRESH); 079 080 if (StringUtils.isNotBlank(form.getReturnFormKey())) { 081 props.put(UifParameters.FORM_KEY, form.getReturnFormKey()); 082 } 083 084 String returnUrl = ConfigContext.getCurrentContextConfig().getProperty(KRADConstants.APPLICATION_URL_KEY); 085 086 return performRedirect(form, returnUrl, props); 087 } 088 089}