001/** 002 * Copyright 2005-2015 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.kns.web.struts.action; 017 018import javax.servlet.http.HttpServletRequest; 019import javax.servlet.http.HttpServletResponse; 020 021import org.apache.struts.action.ActionForm; 022import org.apache.struts.action.ActionForward; 023import org.apache.struts.action.ActionMapping; 024import org.kuali.rice.core.api.util.RiceConstants; 025import org.kuali.rice.kim.api.identity.Person; 026import org.kuali.rice.kns.web.struts.form.KualiFeedbackHandlerForm; 027import org.kuali.rice.krad.UserSession; 028import org.kuali.rice.krad.exception.AuthorizationException; 029import org.kuali.rice.krad.service.KRADServiceLocatorWeb; 030import org.kuali.rice.krad.service.KualiFeedbackService; 031import org.kuali.rice.krad.util.KRADConstants; 032 033/** 034 * This class handles when the feedback form is submitted. 035 * It invokes the KualiFeedbackService to send the feedback email 036 * 037 * @deprecated KNS Struts deprecated, use KRAD and the Spring MVC framework. 038 */ 039@Deprecated 040public class KualiFeedbackHandlerAction extends KualiAction { 041 042 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 043 if (findMethodToCall(form, request) == null || findMethodToCall(form, request).equals("docHandler")) { 044 return executeFeedback(mapping, form, request, response); 045 } 046 else { 047 return super.execute(mapping, form, request, response); 048 } 049 } 050 051 public ActionForward executeFeedback(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 052 ActionForward returnForward = null; 053 KualiFeedbackHandlerForm formObject = (KualiFeedbackHandlerForm) form; 054 if (!formObject.isCancel()) { 055 populateRequest(form, request); 056 returnForward = mapping.findForward(RiceConstants.MAPPING_BASIC); 057 } 058 else { 059 returnForward = mapping.findForward(KRADConstants.MAPPING_CANCEL); 060 } 061 062 return returnForward; 063 } 064 065 public ActionForward submitFeedback(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 066 if (form instanceof KualiFeedbackHandlerForm) { 067 KualiFeedbackHandlerForm feedbackForm = (KualiFeedbackHandlerForm) form; 068 KualiFeedbackService reporterService = KRADServiceLocatorWeb.getKualiFeedbackService(); 069 reporterService.sendFeedback(feedbackForm.getDocumentId(), feedbackForm.getComponentName(), feedbackForm.getDescription()); 070 } 071 return mapping.findForward(KRADConstants.MAPPING_CLOSE); 072 } 073 074 private void populateRequest(ActionForm form, HttpServletRequest request) { 075 UserSession userSession = (UserSession) request.getSession().getAttribute(KRADConstants.USER_SESSION_KEY); 076 Person sessionUser = null; 077 if (userSession != null) { 078 sessionUser = userSession.getPerson(); 079 } 080 if (sessionUser != null) { 081 request.setAttribute("principalName", sessionUser.getPrincipalName()); 082 } 083 } 084 085 @Override 086 protected void checkAuthorization(ActionForm form, String methodToCall) throws AuthorizationException { 087 } 088}