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.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 038public class KualiFeedbackHandlerAction extends KualiAction { 039 040 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 041 if (findMethodToCall(form, request) == null || findMethodToCall(form, request).equals("docHandler")) { 042 return executeFeedback(mapping, form, request, response); 043 } 044 else { 045 return super.execute(mapping, form, request, response); 046 } 047 } 048 049 public ActionForward executeFeedback(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 050 ActionForward returnForward = null; 051 KualiFeedbackHandlerForm formObject = (KualiFeedbackHandlerForm) form; 052 if (!formObject.isCancel()) { 053 populateRequest(form, request); 054 returnForward = mapping.findForward(RiceConstants.MAPPING_BASIC); 055 } 056 else { 057 returnForward = mapping.findForward(KRADConstants.MAPPING_CANCEL); 058 } 059 060 return returnForward; 061 } 062 063 public ActionForward submitFeedback(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 064 if (form instanceof KualiFeedbackHandlerForm) { 065 KualiFeedbackHandlerForm feedbackForm = (KualiFeedbackHandlerForm) form; 066 KualiFeedbackService reporterService = KRADServiceLocatorWeb.getKualiFeedbackService(); 067 reporterService.sendFeedback(feedbackForm.getDocumentId(), feedbackForm.getComponentName(), feedbackForm.getDescription()); 068 } 069 return mapping.findForward(KRADConstants.MAPPING_CLOSE); 070 } 071 072 private void populateRequest(ActionForm form, HttpServletRequest request) { 073 UserSession userSession = (UserSession) request.getSession().getAttribute(KRADConstants.USER_SESSION_KEY); 074 Person sessionUser = null; 075 if (userSession != null) { 076 sessionUser = userSession.getPerson(); 077 } 078 if (sessionUser != null) { 079 request.setAttribute("principalName", sessionUser.getPrincipalName()); 080 } 081 } 082 083 @Override 084 protected void checkAuthorization(ActionForm form, String methodToCall) throws AuthorizationException { 085 } 086}