| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 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 | |
|
| 34 | |
|
| 35 | |
|
| 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 | |
|
| 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 | |
|
| 80 | |
|
| 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 | |
|
| 92 | |
|
| 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 | |
|
| 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 | |
} |