View Javadoc
1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kns.web.struts.action;
17  
18  import javax.servlet.http.HttpServletRequest;
19  import javax.servlet.http.HttpServletResponse;
20  
21  import org.apache.struts.action.ActionForm;
22  import org.apache.struts.action.ActionForward;
23  import org.apache.struts.action.ActionMapping;
24  import org.kuali.rice.core.api.util.RiceConstants;
25  import org.kuali.rice.kim.api.identity.Person;
26  import org.kuali.rice.kns.web.struts.form.KualiFeedbackHandlerForm;
27  import org.kuali.rice.krad.UserSession;
28  import org.kuali.rice.krad.exception.AuthorizationException;
29  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
30  import org.kuali.rice.krad.service.KualiFeedbackService;
31  import org.kuali.rice.krad.util.KRADConstants;
32  
33  /**
34   * This class handles when the feedback form is submitted.
35   * It invokes the KualiFeedbackService to send the feedback email
36   *
37   * @deprecated KNS Struts deprecated, use KRAD and the Spring MVC framework.
38   */
39  @Deprecated
40  public class KualiFeedbackHandlerAction extends KualiAction {
41  
42  	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
43  		if (findMethodToCall(form, request) == null || findMethodToCall(form, request).equals("docHandler")) {
44  			return executeFeedback(mapping, form, request, response);
45  		}
46  		else {
47  			return super.execute(mapping, form, request, response);
48  		}
49  	}
50  
51  	public ActionForward executeFeedback(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
52  		ActionForward returnForward = null;
53  		KualiFeedbackHandlerForm formObject = (KualiFeedbackHandlerForm) form;
54  		if (!formObject.isCancel()) {
55  			populateRequest(form, request);
56  			returnForward = mapping.findForward(RiceConstants.MAPPING_BASIC);
57  		}
58  		else {
59  			returnForward = mapping.findForward(KRADConstants.MAPPING_CANCEL);
60  		}
61  
62  		return returnForward;
63  	}
64  
65  	public ActionForward submitFeedback(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
66  		if (form instanceof KualiFeedbackHandlerForm) {
67  			KualiFeedbackHandlerForm feedbackForm = (KualiFeedbackHandlerForm) form;
68  			KualiFeedbackService reporterService = KRADServiceLocatorWeb.getKualiFeedbackService();
69  			reporterService.sendFeedback(feedbackForm.getDocumentId(), feedbackForm.getComponentName(), feedbackForm.getDescription());
70  		}
71  		return mapping.findForward(KRADConstants.MAPPING_CLOSE);
72  	}
73  
74  	private void populateRequest(ActionForm form, HttpServletRequest request) {
75  		UserSession userSession = (UserSession) request.getSession().getAttribute(KRADConstants.USER_SESSION_KEY);
76  		Person sessionUser = null;
77  		if (userSession != null) {
78  			sessionUser = userSession.getPerson();
79  		}
80  		if (sessionUser != null) {
81  			request.setAttribute("principalName", sessionUser.getPrincipalName());
82  		}
83  	}
84  
85  	@Override
86  	protected void checkAuthorization(ActionForm form, String methodToCall) throws AuthorizationException {
87  	}
88  }