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