1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
35
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 }