Coverage Report - org.kuali.rice.kew.mail.service.impl.CustomizableActionListEmailServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
CustomizableActionListEmailServiceImpl
0%
0/22
0%
0/8
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  
 
 18  
 package org.kuali.rice.kew.mail.service.impl;
 19  
 
 20  
 import java.util.Collection;
 21  
 
 22  
 import org.apache.log4j.Logger;
 23  
 import org.kuali.rice.core.mail.EmailBody;
 24  
 import org.kuali.rice.core.mail.EmailContent;
 25  
 import org.kuali.rice.core.mail.EmailSubject;
 26  
 import org.kuali.rice.kew.actionitem.ActionItem;
 27  
 import org.kuali.rice.kew.mail.service.EmailContentService;
 28  
 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
 29  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 30  
 import org.kuali.rice.kew.util.KEWConstants;
 31  
 import org.kuali.rice.kim.bo.Person;
 32  
 
 33  
 
 34  
 /**
 35  
  * ActionListEmailService implementation whose content is configurable/parameterizable
 36  
  * via a pluggable EmailContentService
 37  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 38  
  */
 39  0
 public class CustomizableActionListEmailServiceImpl extends ActionListEmailServiceImpl {
 40  0
     private static final Logger LOG = Logger.getLogger(CustomizableActionListEmailServiceImpl.class);
 41  
 
 42  
     private EmailContentService contentService;
 43  
 
 44  
     // ---- Spring property
 45  
 
 46  
     public void setEmailContentGenerator(EmailContentService contentService) {
 47  0
         this.contentService = contentService;
 48  0
     }
 49  
 
 50  
     protected EmailContentService getEmailContentGenerator() {
 51  0
         return contentService;
 52  
     }
 53  
 
 54  
     public void sendImmediateReminder(Person user, ActionItem actionItem) {
 55  0
         if (!sendActionListEmailNotification()) {
 56  0
             LOG.debug("not sending immediate reminder");
 57  0
             return;
 58  
         }
 59  
         // since this is a message for a single document, we can customize the from
 60  
         // line based on DocumentType
 61  0
         DocumentRouteHeaderValue document = KEWServiceLocator.getRouteHeaderService().getRouteHeader(actionItem.getDocumentId());
 62  0
         EmailContent content = getEmailContentGenerator().generateImmediateReminder(user, actionItem, document.getDocumentType());
 63  0
         sendEmail(user, new EmailSubject(content.getSubject()),
 64  
                         new EmailBody(content.getBody()), document.getDocumentType());
 65  0
     }
 66  
 
 67  
     @Override
 68  
     protected void sendPeriodicReminder(Person person, Collection<ActionItem> actionItems, String emailSetting) {
 69  0
         actionItems = filterActionItemsToNotify(person.getPrincipalId(), actionItems);
 70  
         // if there are no action items after being filtered, there's no
 71  
         // reason to send the email
 72  0
         if (actionItems.isEmpty()) {
 73  0
             return;
 74  
         }
 75  
         EmailContent content;
 76  0
         if (KEWConstants.EMAIL_RMNDR_DAY_VAL.equals(emailSetting)) {
 77  0
             content = getEmailContentGenerator().generateDailyReminder(person, actionItems);
 78  0
         } else if (KEWConstants.EMAIL_RMNDR_WEEK_VAL.equals(emailSetting)) {
 79  0
             content = getEmailContentGenerator().generateWeeklyReminder(person, actionItems);
 80  
         } else {
 81  
             // else...refactor this...
 82  0
             throw new RuntimeException("invalid email setting. this code needs refactoring");
 83  
         }
 84  0
         sendEmail(person, new EmailSubject(content.getSubject()), new EmailBody(content.getBody()));
 85  0
     }
 86  
 
 87  
 }