Coverage Report - org.kuali.rice.kew.feedback.web.FeedbackAction
 
Classes in this File Line Coverage Branch Coverage Complexity
FeedbackAction
0%
0/55
0%
0/14
2.75
 
 1  
 /*
 2  
  * Copyright 2005-2007 The Kuali Foundation
 3  
  *
 4  
  *
 5  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  *
 9  
  * http://www.opensource.org/licenses/ecl2.php
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 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.mail.EmailBody;
 29  
 import org.kuali.rice.core.mail.EmailContent;
 30  
 import org.kuali.rice.core.mail.EmailFrom;
 31  
 import org.kuali.rice.core.mail.EmailSubject;
 32  
 import org.kuali.rice.core.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.bo.Person;
 38  
 import org.kuali.rice.krad.UserSession;
 39  
 import org.kuali.rice.krad.util.GlobalVariables;
 40  
 
 41  
 
 42  
 /**
 43  
  * Struts action which handles the Feedback screen.
 44  
  *
 45  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 46  
  */
 47  0
 public class FeedbackAction extends KewKualiAction {
 48  
 
 49  0
         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  
         // load fixed properties in Form elements
 55  0
         FeedbackForm feedbackForm = (FeedbackForm) form;
 56  0
         feedbackForm.setTimeDate(new Date().toString());
 57  
 
 58  
         // load User properties in Form elements
 59  0
         feedbackForm.setComments("");
 60  
 
 61  
         // load application properties from Request in Form elements
 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 documentId = request.getParameter("documentId");
 75  0
         if (documentId == null) {
 76  0
             documentId = "";
 77  
         }
 78  0
         feedbackForm.setDocumentId(documentId);
 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();
 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
         EmailContentService emailContentService = KEWServiceLocator.getEmailContentService();
 115  0
         String fromAddress = determineFromAddress(emailContentService, feedbackForm);
 116  0
             String toAddress = emailContentService.getApplicationEmailAddress();
 117  0
         EmailContent content = emailContentService.generateFeedback(feedbackForm);
 118  0
         KEWServiceLocator.getMailer().sendEmail(new EmailFrom(fromAddress), new EmailTo(toAddress), new EmailSubject(content.getSubject()), new EmailBody(content.getBody()), content.isHtml());
 119  0
             return mapping.findForward("sent");
 120  
     }
 121  
 
 122  
     private String determineFromAddress(EmailContentService emailContentService, FeedbackForm form) {
 123  0
             DocumentType docType = null;
 124  0
             if (!StringUtils.isEmpty(form.getDocumentType())) {
 125  0
                     docType = KEWServiceLocator.getDocumentTypeService().findByName(form.getDocumentType());
 126  0
                     if (docType == null) {
 127  0
                             LOG.warn("Couldn't locate document type for the given name to determine feedback from address! " + form.getDocumentType());
 128  
                     }
 129  
             }
 130  
             // if we pass null to this method it will return us the application email address
 131  0
             return emailContentService.getDocumentTypeEmailAddress(docType);
 132  
     }
 133  
 
 134  
     private static UserSession getUserSession() {
 135  0
         return GlobalVariables.getUserSession();
 136  
     }
 137  
 }
 138