1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package mocks;
17
18 import org.apache.log4j.Logger;
19 import org.kuali.rice.core.mail.Mailer;
20 import org.kuali.rice.kew.actionitem.ActionItem;
21 import org.kuali.rice.kew.mail.service.EmailContentService;
22 import org.kuali.rice.kim.api.identity.principal.Principal;
23 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
24 import org.kuali.rice.kim.bo.Person;
25
26 import java.util.ArrayList;
27 import java.util.Collection;
28 import java.util.HashMap;
29 import java.util.Iterator;
30 import java.util.List;
31 import java.util.Map;
32
33
34 public class MockEmailNotificationServiceImpl
35 private static final Logger LOG = Logger.getLogger(MockEmailNotificationServiceImpl.class);
36
37 private static Map<String,List> immediateReminders = new HashMap<String,List>();
38 private static Map<String,Integer> aggregateReminderCount = new HashMap<String,Integer>();
39 public static boolean SEND_DAILY_REMINDER_CALLED = false;
40 public static boolean SEND_WEEKLY_REMINDER_CALLED = false;
41
42 private EmailContentService contentService;
43 private String deploymentEnvironment;
44
45 private Mailer mailer;
46
47
48
49
50 public void resetReminderCounts() {
51 aggregateReminderCount.clear();
52 immediateReminders.clear();
53 }
54
55
56
57
58
59 @Override
60 public void sendImmediateReminder(Person user, ActionItem actionItem) {
61
62 List actionItemsSentUser = (List)immediateReminders.get(user.getPrincipalId());
63 if (actionItemsSentUser == null) {
64 actionItemsSentUser = new ArrayList();
65 immediateReminders.put(user.getPrincipalId(), actionItemsSentUser);
66 }
67 actionItemsSentUser.add(actionItem);
68 }
69
70
71
72
73
74 protected boolean sendActionListEmailNotification() {
75
76 return true;
77 }
78
79 @Override
80 public void sendDailyReminder() {
81 resetStyleService();
82
83 SEND_DAILY_REMINDER_CALLED = true;
84 }
85
86 @Override
87 public void sendWeeklyReminder() {
88 resetStyleService();
89
90 SEND_WEEKLY_REMINDER_CALLED = true;
91 }
92
93 @Override
94 public void scheduleBatchEmailReminders() throws Exception {
95
96 }
97
98
99 protected void sendPeriodicReminder(Person user, Collection<ActionItem> actionItems, String emailSetting) {
100
101 if (!aggregateReminderCount.containsKey(emailSetting)) {
102 aggregateReminderCount.put(emailSetting, actionItems.size());
103 } else {
104 aggregateReminderCount.put(emailSetting, aggregateReminderCount.get(emailSetting) + actionItems.size());
105 }
106 }
107
108 public Integer getTotalPeriodicRemindersSent(String emailReminderConstant) {
109 Integer returnVal = aggregateReminderCount.get(emailReminderConstant);
110 if (returnVal == null) {
111 returnVal = Integer.valueOf(0);
112 }
113 return returnVal;
114 }
115
116 public Integer getTotalPeriodicRemindersSent() {
117 int total = 0;
118 for (Map.Entry<String, Integer> mapEntry : aggregateReminderCount.entrySet()) {
119 Integer value = mapEntry.getValue();
120 total += (value == null) ? 0 : value.intValue();
121 }
122 return Integer.valueOf(total);
123 }
124
125 public boolean wasStyleServiceAccessed() {
126 return getEmailContentGenerator().wasServiceAccessed();
127 }
128
129 private void resetStyleService() {
130 getEmailContentGenerator().resetServiceAccessed();
131 }
132
133 public int immediateReminderEmailsSent(String networkId, String documentId, String actionRequestCd) {
134 Principal principal = KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName(networkId);
135 List actionItemsSentUser = immediateReminders.get(principal.getPrincipalId());
136 if (actionItemsSentUser == null) {
137 return 0;
138 }
139 int emailsSent = 0;
140 for (Iterator iter = actionItemsSentUser.iterator(); iter.hasNext();) {
141 ActionItem actionItem = (ActionItem) iter.next();
142 if (actionItem.getDocumentId().equals(documentId) && actionItem.getActionRequestCd().equals(actionRequestCd)) {
143 emailsSent++;
144 }
145 }
146 return emailsSent;
147 }
148
149 public void setEmailContentGenerator(EmailContentService contentService) {
150 this.contentService = contentService;
151 }
152
153 protected MockStyleableEmailContentService getEmailContentGenerator() {
154 return (MockStyleableEmailContentService) contentService;
155 }
156
157 public void setMailer(Mailer mailer){
158 this.mailer = mailer;
159 }
160
161 public void setDeploymentEnvironment(String deploymentEnvironment) {
162 this.deploymentEnvironment = deploymentEnvironment;
163 }
164 }