View Javadoc

1   /**
2    * Copyright 2005-2013 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  
38  public class KualiFeedbackHandlerAction extends KualiAction {
39  
40  	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
41  		if (findMethodToCall(form, request) == null || findMethodToCall(form, request).equals("docHandler")) {
42  			return executeFeedback(mapping, form, request, response);
43  		}
44  		else {
45  			return super.execute(mapping, form, request, response);
46  		}
47  	}
48  
49  	public ActionForward executeFeedback(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
50  		ActionForward returnForward = null;
51  		KualiFeedbackHandlerForm formObject = (KualiFeedbackHandlerForm) form;
52  		if (!formObject.isCancel()) {
53  			populateRequest(form, request);
54  			returnForward = mapping.findForward(RiceConstants.MAPPING_BASIC);
55  		}
56  		else {
57  			returnForward = mapping.findForward(KRADConstants.MAPPING_CANCEL);
58  		}
59  
60  		return returnForward;
61  	}
62  
63  	public ActionForward submitFeedback(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
64  		if (form instanceof KualiFeedbackHandlerForm) {
65  			KualiFeedbackHandlerForm feedbackForm = (KualiFeedbackHandlerForm) form;
66  			KualiFeedbackService reporterService = KRADServiceLocatorWeb.getKualiFeedbackService();
67  			reporterService.sendFeedback(feedbackForm.getDocumentId(), feedbackForm.getComponentName(), feedbackForm.getDescription());
68  		}
69  		return mapping.findForward(KRADConstants.MAPPING_CLOSE);
70  	}
71  
72  	private void populateRequest(ActionForm form, HttpServletRequest request) {
73  		UserSession userSession = (UserSession) request.getSession().getAttribute(KRADConstants.USER_SESSION_KEY);
74  		Person sessionUser = null;
75  		if (userSession != null) {
76  			sessionUser = userSession.getPerson();
77  		}
78  		if (sessionUser != null) {
79  			request.setAttribute("principalName", sessionUser.getPrincipalName());
80  		}
81  	}
82  
83  	@Override
84  	protected void checkAuthorization(ActionForm form, String methodToCall) throws AuthorizationException {
85  	}
86  }