1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.feedback.web;
17
18 import java.util.Date;
19
20 import javax.servlet.http.HttpServletRequest;
21 import javax.servlet.http.HttpServletResponse;
22
23 import org.apache.commons.lang.StringUtils;
24 import org.apache.struts.action.ActionForm;
25 import org.apache.struts.action.ActionForward;
26 import org.apache.struts.action.ActionMapping;
27 import org.kuali.rice.core.api.CoreApiServiceLocator;
28 import org.kuali.rice.core.api.mail.EmailBody;
29 import org.kuali.rice.core.api.mail.EmailContent;
30 import org.kuali.rice.core.api.mail.EmailFrom;
31 import org.kuali.rice.core.api.mail.EmailSubject;
32 import org.kuali.rice.core.api.mail.EmailTo;
33 import org.kuali.rice.kew.doctype.bo.DocumentType;
34 import org.kuali.rice.kew.mail.service.EmailContentService;
35 import org.kuali.rice.kew.service.KEWServiceLocator;
36 import org.kuali.rice.kew.web.KewKualiAction;
37 import org.kuali.rice.kim.api.identity.Person;
38 import org.kuali.rice.krad.UserSession;
39 import org.kuali.rice.krad.util.GlobalVariables;
40
41
42
43
44
45
46
47 public class FeedbackAction extends KewKualiAction {
48
49 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(FeedbackAction.class);
50
51 @Override
52 public ActionForward start(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
53
54
55 FeedbackForm feedbackForm = (FeedbackForm) form;
56 feedbackForm.setTimeDate(new Date().toString());
57
58
59 feedbackForm.setComments("");
60
61
62 String documentType = request.getParameter("docType");
63 if (documentType == null) {
64 documentType = "";
65 }
66 feedbackForm.setDocumentType(documentType);
67
68 String pageUrl = request.getParameter("pageUrl");
69 if (pageUrl == null) {
70 pageUrl = "";
71 }
72 feedbackForm.setPageUrl(pageUrl);
73
74 String documentId = request.getParameter("documentId");
75 if (documentId == null) {
76 documentId = "";
77 }
78 feedbackForm.setDocumentId(documentId);
79
80 String exception = request.getParameter("exception");
81 if (exception == null) {
82 feedbackForm.setException("");
83 feedbackForm.setCategory("");
84 } else {
85 feedbackForm.setCategory("problem");
86 feedbackForm.setException(exception);
87 }
88
89 UserSession uSession = getUserSession();
90
91 Person workflowUser = uSession.getPerson();
92 if (workflowUser != null) {
93 feedbackForm.setNetworkId(workflowUser.getPrincipalName());
94 feedbackForm.setUserEmail(workflowUser.getEmailAddress());
95 String name = workflowUser.getName().trim();
96 feedbackForm.setUserName(name);
97 String firstName = name.substring(0, name.indexOf(" "));
98 String lastName = name.substring(name.lastIndexOf(" ") + 1, name.length());
99 feedbackForm.setFirstName(firstName);
100 feedbackForm.setLastName(lastName);
101 } else {
102 feedbackForm.setNetworkId("");
103 feedbackForm.setUserEmail("");
104 feedbackForm.setUserName("");
105 feedbackForm.setFirstName("");
106 feedbackForm.setLastName("");
107 }
108
109 return mapping.findForward("start");
110 }
111
112 public ActionForward sendFeedback(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
113 FeedbackForm feedbackForm = (FeedbackForm)form;
114 EmailContentService emailContentService = KEWServiceLocator.getEmailContentService();
115 String fromAddress = determineFromAddress(emailContentService, feedbackForm);
116 String toAddress = emailContentService.getApplicationEmailAddress();
117 EmailContent content = emailContentService.generateFeedback(feedbackForm);
118 CoreApiServiceLocator.getMailer().sendEmail(new EmailFrom(fromAddress), new EmailTo(toAddress), new EmailSubject(content.getSubject()), new EmailBody(content.getBody()), content.isHtml());
119 return mapping.findForward("sent");
120 }
121
122 private String determineFromAddress(EmailContentService emailContentService, FeedbackForm form) {
123 DocumentType docType = null;
124 if (!StringUtils.isEmpty(form.getDocumentType())) {
125 docType = KEWServiceLocator.getDocumentTypeService().findByName(form.getDocumentType());
126 if (docType == null) {
127 LOG.warn("Couldn't locate document type for the given name to determine feedback from address! " + form.getDocumentType());
128 }
129 }
130
131 return emailContentService.getDocumentTypeEmailAddress(docType);
132 }
133
134 private static UserSession getUserSession() {
135 return GlobalVariables.getUserSession();
136 }
137 }
138