Coverage Report - org.kuali.rice.kew.mail.service.impl.CustomizableActionListEmailServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
CustomizableActionListEmailServiceImpl
0%
0/35
0%
0/20
5.25
 
 1  
 /**
 2  
  * Copyright 2005-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.kew.mail.service.impl;
 17  
 
 18  
 import java.util.Collection;
 19  
 
 20  
 import org.apache.log4j.Logger;
 21  
 import org.kuali.rice.core.mail.EmailBody;
 22  
 import org.kuali.rice.core.mail.EmailContent;
 23  
 import org.kuali.rice.core.mail.EmailSubject;
 24  
 import org.kuali.rice.kew.api.action.ActionItem;
 25  
 import org.kuali.rice.kew.mail.service.EmailContentService;
 26  
 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
 27  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 28  
 import org.kuali.rice.kew.api.KewApiConstants;
 29  
 import org.kuali.rice.kim.api.identity.Person;
 30  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
 31  
 
 32  
 /**
 33  
  * ActionListEmailService implementation whose content is configurable/parameterizable
 34  
  * via a pluggable EmailContentService
 35  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 36  
  */
 37  0
 public class CustomizableActionListEmailServiceImpl extends ActionListEmailServiceImpl {
 38  0
     private static final Logger LOG = Logger.getLogger(CustomizableActionListEmailServiceImpl.class);
 39  
 
 40  
     private EmailContentService contentService;
 41  
 
 42  
     // ---- Spring property
 43  
 
 44  
     public void setEmailContentGenerator(EmailContentService contentService) {
 45  0
         this.contentService = contentService;
 46  0
     }
 47  
 
 48  
     protected EmailContentService getEmailContentGenerator() {
 49  0
         return contentService;
 50  
     }
 51  
 
 52  
     public void sendImmediateReminder(ActionItem actionItem, Boolean skipOnApprovals) {
 53  0
         if (actionItem == null) {
 54  0
             LOG.warn("Request to send immediate reminder to recipient of a null action item... aborting.");
 55  0
             return;
 56  
         }
 57  
         
 58  0
         if (actionItem.getPrincipalId() == null) {
 59  0
             LOG.warn("Request to send immediate reminder to null recipient of an action item... aborting.");
 60  0
             return;
 61  
         }
 62  
         
 63  0
         if (skipOnApprovals != null && skipOnApprovals.booleanValue()
 64  
                 && actionItem.getActionRequestCd().equals(KewApiConstants.ACTION_REQUEST_APPROVE_REQ)) {
 65  0
             LOG.debug("As requested, skipping immediate reminder notification on action item approval for " + actionItem.getPrincipalId());
 66  0
             return;
 67  
         }
 68  
         
 69  0
         if(suppressImmediateReminder(actionItem, actionItem.getPrincipalId())) {
 70  0
             LOG.debug("Email suppressed due to the user's preferences");
 71  0
             return;
 72  
         }
 73  
         
 74  0
         if (!sendActionListEmailNotification()) {
 75  0
             LOG.debug("not sending immediate reminder");
 76  0
             return;
 77  
         }
 78  
         
 79  
         // since this is a message for a single document, we can customize the from
 80  
         // line based on DocumentType
 81  0
         DocumentRouteHeaderValue document = KEWServiceLocator.getRouteHeaderService().getRouteHeader(actionItem.getDocumentId());
 82  0
         Person person = KimApiServiceLocator.getPersonService().getPerson(actionItem.getPrincipalId());
 83  0
         EmailContent content = getEmailContentGenerator().generateImmediateReminder(person, actionItem, document.getDocumentType());
 84  0
         sendEmail(person, new EmailSubject(content.getSubject()),
 85  
                         new EmailBody(content.getBody()), document.getDocumentType());
 86  0
     }
 87  
 
 88  
     @Override
 89  
     protected void sendPeriodicReminder(Person person, Collection<ActionItem> actionItems, String emailSetting) {
 90  0
         actionItems = filterActionItemsToNotify(person.getPrincipalId(), actionItems);
 91  
         // if there are no action items after being filtered, there's no
 92  
         // reason to send the email
 93  0
         if (actionItems.isEmpty()) {
 94  0
             return;
 95  
         }
 96  
         EmailContent content;
 97  0
         if (KewApiConstants.EMAIL_RMNDR_DAY_VAL.equals(emailSetting)) {
 98  0
             content = getEmailContentGenerator().generateDailyReminder(person, actionItems);
 99  0
         } else if (KewApiConstants.EMAIL_RMNDR_WEEK_VAL.equals(emailSetting)) {
 100  0
             content = getEmailContentGenerator().generateWeeklyReminder(person, actionItems);
 101  
         } else {
 102  
             // else...refactor this...
 103  0
             throw new RuntimeException("invalid email setting. this code needs refactoring");
 104  
         }
 105  0
         sendEmail(person, new EmailSubject(content.getSubject()), new EmailBody(content.getBody()));
 106  0
     }
 107  
 
 108  
 }