001/**
002 * Copyright 2005-2016 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 javax.servlet.http.HttpServletRequest;
019import javax.servlet.http.HttpServletResponse;
020
021import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
022import org.kuali.rice.krad.service.KualiExceptionIncidentService;
023import org.kuali.rice.krad.web.form.IncidentReportForm;
024import org.kuali.rice.krad.web.form.UifFormBase;
025import org.springframework.stereotype.Controller;
026import org.springframework.validation.BindingResult;
027import org.springframework.web.bind.annotation.ModelAttribute;
028import org.springframework.web.bind.annotation.RequestMapping;
029import org.springframework.web.bind.annotation.RequestMethod;
030import org.springframework.web.servlet.ModelAndView;
031
032/**
033 * Handler for incident reports
034 * 
035 * @author Kuali Rice Team (rice.collab@kuali.org)
036 */
037@Controller
038@RequestMapping(value = "/incidentReport")
039public class IncidentReportController extends UifControllerBase {
040
041    /**
042     * @see org.kuali.rice.krad.web.controller.UifControllerBase#createInitialForm(javax.servlet.http.HttpServletRequest)
043     */
044    @Override
045    protected IncidentReportForm createInitialForm(HttpServletRequest request) {
046        return new IncidentReportForm();
047    }
048
049    /**
050     * Emails the report and closes the incident report screen
051     */
052    @RequestMapping(method = RequestMethod.POST, params = "methodToCall=submitReport")
053    public ModelAndView submitReport(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
054            HttpServletRequest request, HttpServletResponse response) throws Exception {
055        // get the exception incident service and use it to mail the report
056        KualiExceptionIncidentService reporterService = KRADServiceLocatorWeb.getKualiExceptionIncidentService();
057        reporterService.emailReport(((IncidentReportForm) uifForm).createEmailSubject(),
058                ((IncidentReportForm) uifForm).createEmailMessage());
059
060        // return the close redirect
061        return close(uifForm, result, request, response);
062    }
063
064}