| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
package org.kuali.rice.kew.feedback.web; |
| 18 | |
|
| 19 | |
import java.util.Date; |
| 20 | |
|
| 21 | |
import javax.servlet.http.HttpServletRequest; |
| 22 | |
import javax.servlet.http.HttpServletResponse; |
| 23 | |
|
| 24 | |
import org.apache.commons.lang.StringUtils; |
| 25 | |
import org.apache.struts.action.ActionForm; |
| 26 | |
import org.apache.struts.action.ActionForward; |
| 27 | |
import org.apache.struts.action.ActionMapping; |
| 28 | |
import org.kuali.rice.core.config.ConfigContext; |
| 29 | |
import org.kuali.rice.kew.doctype.bo.DocumentType; |
| 30 | |
import org.kuali.rice.kew.mail.EmailBody; |
| 31 | |
import org.kuali.rice.kew.mail.EmailContent; |
| 32 | |
import org.kuali.rice.kew.mail.EmailFrom; |
| 33 | |
import org.kuali.rice.kew.mail.EmailSubject; |
| 34 | |
import org.kuali.rice.kew.mail.EmailTo; |
| 35 | |
import org.kuali.rice.kew.mail.service.EmailContentService; |
| 36 | |
import org.kuali.rice.kew.mail.service.EmailService; |
| 37 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
| 38 | |
import org.kuali.rice.kew.web.KewKualiAction; |
| 39 | |
import org.kuali.rice.kew.web.session.UserSession; |
| 40 | |
import org.kuali.rice.kim.bo.Person; |
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | 0 | public class FeedbackAction extends KewKualiAction { |
| 49 | |
|
| 50 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(FeedbackAction.class); |
| 51 | |
|
| 52 | |
public ActionForward start(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 53 | |
|
| 54 | |
|
| 55 | 0 | FeedbackForm feedbackForm = (FeedbackForm) form; |
| 56 | 0 | feedbackForm.setTimeDate(new Date().toString()); |
| 57 | |
|
| 58 | |
|
| 59 | 0 | feedbackForm.setComments(""); |
| 60 | |
|
| 61 | |
|
| 62 | 0 | String documentType = request.getParameter("docType"); |
| 63 | 0 | if (documentType == null) { |
| 64 | 0 | documentType = ""; |
| 65 | |
} |
| 66 | 0 | feedbackForm.setDocumentType(documentType); |
| 67 | |
|
| 68 | 0 | String pageUrl = request.getParameter("pageUrl"); |
| 69 | 0 | if (pageUrl == null) { |
| 70 | 0 | pageUrl = ""; |
| 71 | |
} |
| 72 | 0 | feedbackForm.setPageUrl(pageUrl); |
| 73 | |
|
| 74 | 0 | String routeHeaderId = request.getParameter("routeHeaderId"); |
| 75 | 0 | if (routeHeaderId == null) { |
| 76 | 0 | routeHeaderId = ""; |
| 77 | |
} |
| 78 | 0 | feedbackForm.setRouteHeaderId(routeHeaderId); |
| 79 | |
|
| 80 | 0 | String exception = request.getParameter("exception"); |
| 81 | 0 | if (exception == null) { |
| 82 | 0 | feedbackForm.setException(""); |
| 83 | 0 | feedbackForm.setCategory(""); |
| 84 | |
} else { |
| 85 | 0 | feedbackForm.setCategory("problem"); |
| 86 | 0 | feedbackForm.setException(exception); |
| 87 | |
} |
| 88 | |
|
| 89 | 0 | UserSession uSession = getUserSession(request); |
| 90 | |
|
| 91 | 0 | Person workflowUser = uSession.getPerson(); |
| 92 | 0 | if (workflowUser != null) { |
| 93 | 0 | feedbackForm.setNetworkId(workflowUser.getPrincipalName()); |
| 94 | 0 | feedbackForm.setUserEmail(workflowUser.getEmailAddress()); |
| 95 | 0 | String name = workflowUser.getName().trim(); |
| 96 | 0 | feedbackForm.setUserName(name); |
| 97 | 0 | String firstName = name.substring(0, name.indexOf(" ")); |
| 98 | 0 | String lastName = name.substring(name.lastIndexOf(" ") + 1, name.length()); |
| 99 | 0 | feedbackForm.setFirstName(firstName); |
| 100 | 0 | feedbackForm.setLastName(lastName); |
| 101 | 0 | } else { |
| 102 | 0 | feedbackForm.setNetworkId(""); |
| 103 | 0 | feedbackForm.setUserEmail(""); |
| 104 | 0 | feedbackForm.setUserName(""); |
| 105 | 0 | feedbackForm.setFirstName(""); |
| 106 | 0 | feedbackForm.setLastName(""); |
| 107 | |
} |
| 108 | |
|
| 109 | 0 | return mapping.findForward("start"); |
| 110 | |
} |
| 111 | |
|
| 112 | |
public ActionForward sendFeedback(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
| 113 | 0 | FeedbackForm feedbackForm = (FeedbackForm)form; |
| 114 | 0 | EmailService emailService = KEWServiceLocator.getEmailService(); |
| 115 | 0 | EmailContentService emailContentService = KEWServiceLocator.getEmailContentService(); |
| 116 | 0 | String fromAddress = determineFromAddress(emailContentService, feedbackForm); |
| 117 | 0 | String toAddress = emailContentService.getApplicationEmailAddress(); |
| 118 | 0 | EmailContent content = emailContentService.generateFeedback(feedbackForm); |
| 119 | 0 | emailService.sendEmail(new EmailFrom(fromAddress), new EmailTo(toAddress), new EmailSubject(content.getSubject()), new EmailBody(content.getBody()), content.isHtml()); |
| 120 | 0 | return mapping.findForward("sent"); |
| 121 | |
} |
| 122 | |
|
| 123 | |
private String determineFromAddress(EmailContentService emailContentService, FeedbackForm form) { |
| 124 | 0 | DocumentType docType = null; |
| 125 | 0 | if (!StringUtils.isEmpty(form.getDocumentType())) { |
| 126 | 0 | docType = KEWServiceLocator.getDocumentTypeService().findByName(form.getDocumentType()); |
| 127 | 0 | if (docType == null) { |
| 128 | 0 | LOG.warn("Couldn't locate document type for the given name to determine feedback from address! " + form.getDocumentType()); |
| 129 | |
} |
| 130 | |
} |
| 131 | |
|
| 132 | 0 | return emailContentService.getDocumentTypeEmailAddress(docType); |
| 133 | |
} |
| 134 | |
|
| 135 | |
private String constructSubject(FeedbackForm form) { |
| 136 | 0 | String subject = "Feedback from " + form.getNetworkId(); |
| 137 | 0 | if (form.getRouteHeaderId() != null) { |
| 138 | 0 | subject += (" for document " + form.getRouteHeaderId()); |
| 139 | |
} |
| 140 | 0 | return subject; |
| 141 | |
} |
| 142 | |
|
| 143 | |
private String constructEmailBody(FeedbackForm form) { |
| 144 | 0 | StringBuffer buffer = new StringBuffer(); |
| 145 | 0 | buffer.append("\n"); |
| 146 | 0 | buffer.append("Network ID: " + form.getNetworkId()).append("\n"); |
| 147 | 0 | buffer.append("Name: " + form.getUserName()).append("\n"); |
| 148 | 0 | buffer.append("Email: " + form.getUserEmail()).append("\n"); |
| 149 | 0 | buffer.append("Phone: " + form.getPhone()).append("\n"); |
| 150 | 0 | buffer.append("Time: " + form.getTimeDate()).append("\n"); |
| 151 | 0 | buffer.append("Environment: " + ConfigContext.getCurrentContextConfig().getEnvironment()).append("\n\n"); |
| 152 | |
|
| 153 | 0 | buffer.append("Document type: " + form.getDocumentType()).append("\n"); |
| 154 | 0 | buffer.append("Document id: " + form.getRouteHeaderId()).append("\n\n"); |
| 155 | |
|
| 156 | 0 | buffer.append("Category: " + form.getCategory()).append("\n"); |
| 157 | 0 | buffer.append("Comments: \n" + form.getComments()).append("\n\n"); |
| 158 | |
|
| 159 | 0 | buffer.append("Exception: \n" + form.getException()); |
| 160 | 0 | return buffer.toString(); |
| 161 | |
} |
| 162 | |
|
| 163 | |
private static UserSession getUserSession(HttpServletRequest request) { |
| 164 | 0 | return UserSession.getAuthenticatedUser(); |
| 165 | |
} |
| 166 | |
} |
| 167 | |
|