1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.kew.mail.service.impl; |
18 | |
|
19 | |
import org.apache.commons.lang.StringUtils; |
20 | |
import org.kuali.rice.core.config.ConfigContext; |
21 | |
import org.kuali.rice.kew.actionitem.ActionItem; |
22 | |
import org.kuali.rice.kew.actionlist.service.ActionListService; |
23 | |
import org.kuali.rice.kew.actionrequest.ActionRequestValue; |
24 | |
import org.kuali.rice.kew.doctype.bo.DocumentType; |
25 | |
import org.kuali.rice.kew.dto.ActionRequestDTO; |
26 | |
import org.kuali.rice.kew.dto.DTOConverter; |
27 | |
import org.kuali.rice.kew.dto.RouteHeaderDTO; |
28 | |
import org.kuali.rice.kew.mail.*; |
29 | |
import org.kuali.rice.kew.mail.service.ActionListEmailService; |
30 | |
import org.kuali.rice.kew.preferences.Preferences; |
31 | |
import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue; |
32 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
33 | |
import org.kuali.rice.kew.useroptions.UserOptions; |
34 | |
import org.kuali.rice.kew.useroptions.UserOptionsService; |
35 | |
import org.kuali.rice.kew.util.KEWConstants; |
36 | |
import org.kuali.rice.kew.util.Utilities; |
37 | |
import org.kuali.rice.kim.bo.Person; |
38 | |
import org.kuali.rice.kim.service.KIMServiceLocator; |
39 | |
import org.kuali.rice.kns.util.KNSConstants; |
40 | |
import org.kuali.rice.ksb.service.KSBServiceLocator; |
41 | |
import org.quartz.*; |
42 | |
|
43 | |
import java.text.FieldPosition; |
44 | |
import java.text.MessageFormat; |
45 | |
import java.util.*; |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | 0 | public class ActionListEmailServiceImpl implements ActionListEmailService { |
56 | 0 | private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger |
57 | |
.getLogger(ActionListEmailServiceImpl.class); |
58 | |
|
59 | |
private static final String DEFAULT_EMAIL_FROM_ADDRESS = "admin@localhost"; |
60 | |
|
61 | |
private static final String ACTION_LIST_REMINDER = "Action List Reminder"; |
62 | |
|
63 | |
private static final String IMMEDIATE_REMINDER_EMAIL_MESSAGE_KEY = "immediate.reminder.email.message"; |
64 | |
|
65 | |
private static final String IMMEDIATE_REMINDER_EMAIL_SUBJECT_KEY = "immediate.reminder.email.subject"; |
66 | |
|
67 | |
private static final String DAILY_TRIGGER_NAME = "Daily Email Trigger"; |
68 | |
private static final String DAILY_JOB_NAME = "Daily Email"; |
69 | |
private static final String WEEKLY_TRIGGER_NAME = "Weekly Email Trigger"; |
70 | |
private static final String WEEKLY_JOB_NAME = "Weekly Email"; |
71 | |
|
72 | |
private String deploymentEnvironment; |
73 | |
|
74 | |
public String getDocumentTypeEmailAddress(DocumentType documentType) { |
75 | 0 | String fromAddress = (documentType == null ? null : documentType |
76 | |
.getNotificationFromAddress()); |
77 | 0 | if (Utilities.isEmpty(fromAddress)) { |
78 | 0 | fromAddress = getApplicationEmailAddress(); |
79 | |
} |
80 | 0 | return fromAddress; |
81 | |
} |
82 | |
|
83 | |
public String getApplicationEmailAddress() { |
84 | |
|
85 | 0 | String fromAddress = Utilities.getKNSParameterValue(KEWConstants.KEW_NAMESPACE, KNSConstants.DetailTypes.MAILER_DETAIL_TYPE, KEWConstants.EMAIL_REMINDER_FROM_ADDRESS); |
86 | |
|
87 | 0 | if (Utilities.isEmpty(fromAddress)) { |
88 | 0 | fromAddress = DEFAULT_EMAIL_FROM_ADDRESS; |
89 | |
} |
90 | 0 | return fromAddress; |
91 | |
} |
92 | |
|
93 | |
protected String getHelpLink() { |
94 | 0 | return getHelpLink(null); |
95 | |
} |
96 | |
|
97 | |
protected String getHelpLink(DocumentType documentType) { |
98 | 0 | return "For additional help, email " + "<mailto:" |
99 | |
+ getDocumentTypeEmailAddress(documentType) + ">"; |
100 | |
} |
101 | |
|
102 | |
public EmailSubject getEmailSubject() { |
103 | 0 | String subject = ConfigContext.getCurrentContextConfig().getProperty(IMMEDIATE_REMINDER_EMAIL_SUBJECT_KEY); |
104 | 0 | if (subject == null) { |
105 | 0 | subject = ACTION_LIST_REMINDER; |
106 | |
} |
107 | 0 | return new EmailSubject(subject); |
108 | |
} |
109 | |
|
110 | |
public EmailSubject getEmailSubject(String customSubject) { |
111 | 0 | String subject = ConfigContext.getCurrentContextConfig().getProperty(IMMEDIATE_REMINDER_EMAIL_SUBJECT_KEY); |
112 | 0 | if (subject == null) { |
113 | 0 | subject = ACTION_LIST_REMINDER; |
114 | |
} |
115 | 0 | return new EmailSubject(subject + " " + customSubject); |
116 | |
} |
117 | |
|
118 | |
protected EmailFrom getEmailFrom(DocumentType documentType) { |
119 | 0 | return new EmailFrom(getDocumentTypeEmailAddress(documentType)); |
120 | |
} |
121 | |
|
122 | |
protected void sendEmail(Person user, EmailSubject subject, |
123 | |
EmailBody body) { |
124 | 0 | sendEmail(user, subject, body, null); |
125 | 0 | } |
126 | |
|
127 | |
protected void sendEmail(Person user, EmailSubject subject, |
128 | |
EmailBody body, DocumentType documentType) { |
129 | |
try { |
130 | 0 | if (isProduction()) { |
131 | 0 | KEWServiceLocator.getEmailService().sendEmail( |
132 | |
getEmailFrom(documentType), |
133 | |
new EmailTo(user.getEmailAddressUnmasked()), subject, body, |
134 | |
false); |
135 | |
} else { |
136 | 0 | KEWServiceLocator |
137 | |
.getEmailService() |
138 | |
.sendEmail( |
139 | |
getEmailFrom(documentType), |
140 | |
new EmailTo(Utilities.getKNSParameterValue(KEWConstants.KEW_NAMESPACE, KNSConstants.DetailTypes.ACTION_LIST_DETAIL_TYPE, KEWConstants.ACTIONLIST_EMAIL_TEST_ADDRESS)), |
141 | |
subject, body, false); |
142 | |
} |
143 | 0 | } catch (Exception e) { |
144 | 0 | LOG.error("Error sending Action List email.", e); |
145 | 0 | } |
146 | 0 | } |
147 | |
|
148 | |
public void sendImmediateReminder(Person user, ActionItem actionItem) { |
149 | 0 | boolean shouldSendActionListEmailNotification = sendActionListEmailNotification(); |
150 | 0 | if (shouldSendActionListEmailNotification) { |
151 | 0 | LOG.debug("sending immediate reminder"); |
152 | 0 | DocumentRouteHeaderValue document = KEWServiceLocator |
153 | |
.getRouteHeaderService().getRouteHeader( |
154 | |
actionItem.getRouteHeaderId()); |
155 | 0 | StringBuffer emailBody = new StringBuffer( |
156 | |
buildImmediateReminderBody(user, actionItem, document |
157 | |
.getDocumentType())); |
158 | 0 | StringBuffer emailSubject = new StringBuffer(); |
159 | |
try { |
160 | 0 | CustomEmailAttribute customEmailAttribute = actionItem |
161 | |
.getRouteHeader().getCustomEmailAttribute(); |
162 | 0 | if (customEmailAttribute != null) { |
163 | 0 | RouteHeaderDTO routeHeaderVO = DTOConverter |
164 | |
.convertRouteHeader(actionItem.getRouteHeader(), |
165 | |
user.getPrincipalId()); |
166 | 0 | ActionRequestValue actionRequest = KEWServiceLocator |
167 | |
.getActionRequestService().findByActionRequestId( |
168 | |
actionItem.getActionRequestId()); |
169 | 0 | ActionRequestDTO actionRequestVO = DTOConverter |
170 | |
.convertActionRequest(actionRequest); |
171 | 0 | customEmailAttribute.setRouteHeaderVO(routeHeaderVO); |
172 | 0 | customEmailAttribute.setActionRequestVO(actionRequestVO); |
173 | 0 | String customBody = customEmailAttribute |
174 | |
.getCustomEmailBody(); |
175 | 0 | if (!Utilities.isEmpty(customBody)) { |
176 | 0 | emailBody.append(customBody); |
177 | |
} |
178 | 0 | String customEmailSubject = customEmailAttribute |
179 | |
.getCustomEmailSubject(); |
180 | 0 | if (!Utilities.isEmpty(customEmailSubject)) { |
181 | 0 | emailSubject.append(customEmailSubject); |
182 | |
} |
183 | |
} |
184 | 0 | } catch (Exception e) { |
185 | 0 | LOG |
186 | |
.error( |
187 | |
"Error when checking for custom email body and subject.", |
188 | |
e); |
189 | 0 | } |
190 | 0 | LOG.debug("Sending email to " + user); |
191 | 0 | sendEmail(user, getEmailSubject(emailSubject.toString()), |
192 | |
new EmailBody(emailBody.toString()), document |
193 | |
.getDocumentType()); |
194 | |
} |
195 | |
|
196 | 0 | } |
197 | |
|
198 | |
protected boolean isProduction() { |
199 | 0 | return ConfigContext.getCurrentContextConfig().getProperty(KEWConstants.PROD_DEPLOYMENT_CODE).equalsIgnoreCase(getDeploymentEnvironment()); |
200 | |
} |
201 | |
|
202 | |
public void sendDailyReminder() { |
203 | 0 | if (sendActionListEmailNotification()) { |
204 | 0 | Collection<Person> users = getUsersWithEmailSetting(KEWConstants.EMAIL_RMNDR_DAY_VAL); |
205 | 0 | for (Iterator<Person> userIter = users.iterator(); userIter.hasNext();) { |
206 | 0 | Person user = userIter.next(); |
207 | |
try { |
208 | 0 | Collection actionItems = getActionListService().getActionList(user.getPrincipalId(), null); |
209 | 0 | if (actionItems != null && actionItems.size() > 0) { |
210 | 0 | sendPeriodicReminder(user, actionItems, |
211 | |
KEWConstants.EMAIL_RMNDR_DAY_VAL); |
212 | |
} |
213 | 0 | } catch (Exception e) { |
214 | 0 | LOG.error( |
215 | |
"Error sending daily action list reminder to user: " |
216 | |
+ user.getEmailAddressUnmasked(), e); |
217 | 0 | } |
218 | 0 | } |
219 | |
} |
220 | 0 | LOG.debug("Daily action list emails sent successful"); |
221 | 0 | } |
222 | |
|
223 | |
public void sendWeeklyReminder() { |
224 | 0 | if (sendActionListEmailNotification()) { |
225 | 0 | List<Person> users = getUsersWithEmailSetting(KEWConstants.EMAIL_RMNDR_WEEK_VAL); |
226 | 0 | for (Iterator<Person> userIter = users.iterator(); userIter.hasNext();) { |
227 | 0 | Person user = userIter.next(); |
228 | |
try { |
229 | 0 | Collection actionItems = getActionListService() |
230 | |
.getActionList(user.getPrincipalId(), null); |
231 | 0 | if (actionItems != null && actionItems.size() > 0) { |
232 | 0 | sendPeriodicReminder(user, actionItems, |
233 | |
KEWConstants.EMAIL_RMNDR_WEEK_VAL); |
234 | |
} |
235 | 0 | } catch (Exception e) { |
236 | 0 | LOG.error( |
237 | |
"Error sending weekly action list reminder to user: " |
238 | |
+ user.getEmailAddressUnmasked(), e); |
239 | 0 | } |
240 | 0 | } |
241 | |
} |
242 | 0 | LOG.debug("Weekly action list emails sent successful"); |
243 | 0 | } |
244 | |
|
245 | |
protected void sendPeriodicReminder(Person user, Collection<ActionItem> actionItems, String emailSetting) { |
246 | 0 | String emailBody = null; |
247 | 0 | actionItems = filterActionItemsToNotify(user.getPrincipalId(), actionItems); |
248 | |
|
249 | |
|
250 | 0 | if (actionItems.isEmpty()) { |
251 | 0 | return; |
252 | |
} |
253 | 0 | if (KEWConstants.EMAIL_RMNDR_DAY_VAL.equals(emailSetting)) { |
254 | 0 | emailBody = buildDailyReminderBody(user, actionItems); |
255 | 0 | } else if (KEWConstants.EMAIL_RMNDR_WEEK_VAL.equals(emailSetting)) { |
256 | 0 | emailBody = buildWeeklyReminderBody(user, actionItems); |
257 | |
} |
258 | 0 | sendEmail(user, getEmailSubject(), new EmailBody(emailBody)); |
259 | 0 | } |
260 | |
|
261 | |
|
262 | |
|
263 | |
|
264 | |
|
265 | |
|
266 | |
|
267 | |
protected Collection filterActionItemsToNotify(String principalId, Collection actionItems) { |
268 | 0 | List filteredItems = new ArrayList(); |
269 | 0 | Preferences preferences = KEWServiceLocator.getPreferencesService().getPreferences(principalId); |
270 | 0 | for (Iterator iterator = actionItems.iterator(); iterator.hasNext();) { |
271 | 0 | ActionItem actionItem = (ActionItem) iterator.next(); |
272 | 0 | if (!actionItem.getPrincipalId().equals(principalId)) { |
273 | 0 | LOG.warn("Encountered an ActionItem with an incorrect workflow ID. Was " + actionItem.getPrincipalId() + |
274 | |
" but expected " + principalId); |
275 | 0 | continue; |
276 | |
} |
277 | 0 | boolean includeItem = true; |
278 | 0 | if (KEWConstants.DELEGATION_PRIMARY.equals(actionItem.getDelegationType())) { |
279 | 0 | includeItem = KEWConstants.PREFERENCES_YES_VAL.equals(preferences.getNotifyPrimaryDelegation()); |
280 | 0 | } else if (KEWConstants.DELEGATION_SECONDARY.equals(actionItem.getDelegationType())) { |
281 | 0 | includeItem = KEWConstants.PREFERENCES_YES_VAL.equals(preferences.getNotifySecondaryDelegation()); |
282 | |
} |
283 | 0 | if (includeItem) { |
284 | 0 | filteredItems.add(actionItem); |
285 | |
} |
286 | 0 | } |
287 | 0 | return filteredItems; |
288 | |
} |
289 | |
|
290 | |
protected List<Person> getUsersWithEmailSetting(String setting) { |
291 | 0 | List users = new ArrayList(); |
292 | 0 | Collection userOptions = getUserOptionsService().findByOptionValue( |
293 | |
KEWConstants.EMAIL_RMNDR_KEY, setting); |
294 | 0 | for (Iterator iter = userOptions.iterator(); iter.hasNext();) { |
295 | 0 | String workflowId = ((UserOptions) iter.next()).getWorkflowId(); |
296 | |
try { |
297 | |
|
298 | 0 | users.add(KIMServiceLocator.getPersonService().getPerson(workflowId)); |
299 | 0 | } catch (Exception e) { |
300 | 0 | LOG.error("error retrieving workflow user with ID: " |
301 | |
+ workflowId); |
302 | 0 | } |
303 | 0 | } |
304 | 0 | return users; |
305 | |
} |
306 | |
|
307 | |
|
308 | |
|
309 | |
|
310 | |
|
311 | |
|
312 | |
|
313 | |
|
314 | |
|
315 | |
|
316 | |
|
317 | 0 | private static final MessageFormat DEFAULT_IMMEDIATE_REMINDER = new MessageFormat( |
318 | |
"Your Action List has an eDoc(electronic document) that needs your attention: \n\n" + |
319 | |
"Document ID:\t{0,number,#}\n" + |
320 | |
"Initiator:\t\t{1}\n" + |
321 | |
"Type:\t\tAdd/Modify {2}\n" + |
322 | |
"Title:\t\t{3}\n" + |
323 | |
"\n\n" + |
324 | |
"To respond to this eDoc: \n" + |
325 | |
"\tGo to {4}\n\n" + |
326 | |
"\tOr you may access the eDoc from your Action List: \n" + |
327 | |
"\tGo to {5}, and then click on the numeric Document ID: {0,number,#} in the first column of the List. \n" + |
328 | |
"\n\n\n" + |
329 | |
"To change how these email notifications are sent(daily, weekly or none): \n" + |
330 | |
"\tGo to {6}\n" + |
331 | |
"\n\n\n" + |
332 | |
"{7}\n\n\n" |
333 | |
); |
334 | |
|
335 | |
|
336 | |
|
337 | |
|
338 | |
|
339 | |
|
340 | |
|
341 | |
|
342 | |
|
343 | |
|
344 | 0 | private static final MessageFormat DEFAULT_IMMEDIATE_REMINDER_NO_DOC_HANDLER = new MessageFormat( |
345 | |
"Your Action List has an eDoc(electronic document) that needs your attention: \n\n" + |
346 | |
"Document ID:\t{0,number,#}\n" + |
347 | |
"Initiator:\t\t{1}\n" + |
348 | |
"Type:\t\tAdd/Modify {2}\n" + |
349 | |
"Title:\t\t{3}\n" + |
350 | |
"\n\n" + |
351 | |
"To respond to this eDoc you may use your Action List: \n" + |
352 | |
"\tGo to {4}, and then take actions related to Document ID: {0,number,#}. \n" + |
353 | |
"\n\n\n" + |
354 | |
"To change how these email notifications are sent(daily, weekly or none): \n" + |
355 | |
"\tGo to {5}\n" + |
356 | |
"\n\n\n" + |
357 | |
"{6}\n\n\n" |
358 | |
); |
359 | |
|
360 | |
public String buildImmediateReminderBody(Person person, |
361 | |
ActionItem actionItem, DocumentType documentType) { |
362 | 0 | String docHandlerUrl = actionItem.getRouteHeader().getDocumentType() |
363 | |
.getDocHandlerUrl(); |
364 | 0 | if (StringUtils.isNotBlank(docHandlerUrl)) { |
365 | 0 | if (!docHandlerUrl.contains("?")) { |
366 | 0 | docHandlerUrl += "?"; |
367 | |
} else { |
368 | 0 | docHandlerUrl += "&"; |
369 | |
} |
370 | 0 | docHandlerUrl += KEWConstants.ROUTEHEADER_ID_PARAMETER + "=" |
371 | |
+ actionItem.getRouteHeaderId(); |
372 | 0 | docHandlerUrl += "&" + KEWConstants.COMMAND_PARAMETER + "=" |
373 | |
+ KEWConstants.ACTIONLIST_COMMAND; |
374 | |
} |
375 | 0 | StringBuffer sf = new StringBuffer(); |
376 | |
|
377 | |
|
378 | |
|
379 | |
|
380 | |
|
381 | |
|
382 | |
|
383 | |
|
384 | |
|
385 | |
|
386 | |
|
387 | |
|
388 | |
|
389 | |
|
390 | |
|
391 | |
|
392 | |
|
393 | |
|
394 | |
|
395 | |
|
396 | |
|
397 | |
|
398 | |
|
399 | |
|
400 | |
|
401 | |
|
402 | |
|
403 | |
|
404 | |
|
405 | |
|
406 | |
|
407 | |
|
408 | |
|
409 | 0 | MessageFormat messageFormat = null; |
410 | 0 | String stringMessageFormat = ConfigContext.getCurrentContextConfig().getProperty(IMMEDIATE_REMINDER_EMAIL_MESSAGE_KEY); |
411 | 0 | LOG.debug("Immediate reminder email message from configuration (" + IMMEDIATE_REMINDER_EMAIL_MESSAGE_KEY + "): " + stringMessageFormat); |
412 | 0 | if (stringMessageFormat == null) { |
413 | 0 | messageFormat = DEFAULT_IMMEDIATE_REMINDER; |
414 | |
} else { |
415 | 0 | messageFormat = new MessageFormat(stringMessageFormat); |
416 | |
} |
417 | 0 | String initiatorUser = (person == null ? "" : person.getName()); |
418 | |
|
419 | 0 | if (StringUtils.isNotBlank(docHandlerUrl)) { |
420 | 0 | Object[] args = { actionItem.getRouteHeaderId(), |
421 | |
initiatorUser, |
422 | |
actionItem.getRouteHeader().getDocumentType().getName(), |
423 | |
actionItem.getDocTitle(), |
424 | |
docHandlerUrl, |
425 | |
getActionListUrl(), |
426 | |
getPreferencesUrl(), |
427 | |
getHelpLink(documentType) |
428 | |
}; |
429 | |
|
430 | 0 | messageFormat.format(args, sf, new FieldPosition(0)); |
431 | |
|
432 | 0 | LOG.debug("default immediate reminder: " + DEFAULT_IMMEDIATE_REMINDER.format(args)); |
433 | 0 | } else { |
434 | 0 | Object[] args = { actionItem.getRouteHeaderId(), |
435 | |
initiatorUser, |
436 | |
actionItem.getRouteHeader().getDocumentType().getName(), |
437 | |
actionItem.getDocTitle(), |
438 | |
getActionListUrl(), |
439 | |
getPreferencesUrl(), |
440 | |
getHelpLink(documentType) |
441 | |
}; |
442 | |
|
443 | 0 | messageFormat.format(args, sf, new FieldPosition(0)); |
444 | |
|
445 | 0 | LOG.debug("default immediate reminder: " + DEFAULT_IMMEDIATE_REMINDER_NO_DOC_HANDLER.format(args)); |
446 | |
} |
447 | 0 | LOG.debug("immediate reminder: " + sf); |
448 | |
|
449 | |
|
450 | 0 | if (!isProduction()) { |
451 | |
try { |
452 | 0 | sf.append("Action Item sent to " + actionItem.getPerson().getPrincipalName()); |
453 | 0 | if (actionItem.getDelegationType() != null) { |
454 | 0 | sf.append(" for delegation type " |
455 | |
+ actionItem.getDelegationType()); |
456 | |
} |
457 | 0 | } catch (Exception e) { |
458 | 0 | throw new RuntimeException(e); |
459 | 0 | } |
460 | |
} |
461 | |
|
462 | 0 | return sf.toString(); |
463 | |
} |
464 | |
|
465 | |
public String buildDailyReminderBody(Person user, |
466 | |
Collection actionItems) { |
467 | 0 | StringBuffer sf = new StringBuffer(); |
468 | 0 | sf.append(getDailyWeeklyMessageBody(actionItems)); |
469 | 0 | sf |
470 | |
.append("To change how these email notifications are sent (immediately, weekly or none): \n"); |
471 | 0 | sf.append("\tGo to " + getPreferencesUrl() + "\n"); |
472 | |
|
473 | |
|
474 | |
|
475 | |
|
476 | 0 | sf.append("\n\n\n"); |
477 | 0 | sf.append(getHelpLink() + "\n\n\n"); |
478 | 0 | return sf.toString(); |
479 | |
} |
480 | |
|
481 | |
public String buildWeeklyReminderBody(Person user, |
482 | |
Collection actionItems) { |
483 | 0 | StringBuffer sf = new StringBuffer(); |
484 | 0 | sf.append(getDailyWeeklyMessageBody(actionItems)); |
485 | 0 | sf |
486 | |
.append("To change how these email notifications are sent (immediately, daily or none): \n"); |
487 | 0 | sf.append("\tGo to " + getPreferencesUrl() + "\n"); |
488 | |
|
489 | |
|
490 | |
|
491 | |
|
492 | 0 | sf.append("\n\n\n"); |
493 | 0 | sf.append(getHelpLink() + "\n\n\n"); |
494 | 0 | return sf.toString(); |
495 | |
} |
496 | |
|
497 | |
String getDailyWeeklyMessageBody(Collection actionItems) { |
498 | 0 | StringBuffer sf = new StringBuffer(); |
499 | 0 | HashMap docTypes = getActionListItemsStat(actionItems); |
500 | |
|
501 | 0 | sf |
502 | |
.append("Your Action List has " |
503 | |
+ actionItems.size() |
504 | |
+ " eDocs(electronic documents) that need your attention: \n\n"); |
505 | 0 | Iterator iter = docTypes.keySet().iterator(); |
506 | 0 | while (iter.hasNext()) { |
507 | 0 | String docTypeName = (String) iter.next(); |
508 | 0 | sf.append("\t" + ((Integer) docTypes.get(docTypeName)).toString() |
509 | |
+ "\t" + docTypeName + "\n"); |
510 | 0 | } |
511 | 0 | sf.append("\n\n"); |
512 | 0 | sf.append("To respond to each of these eDocs: \n"); |
513 | 0 | sf |
514 | |
.append("\tGo to " |
515 | |
+ getActionListUrl() |
516 | |
+ ", and then click on its numeric Document ID in the first column of the List.\n"); |
517 | 0 | sf.append("\n\n\n"); |
518 | 0 | return sf.toString(); |
519 | |
} |
520 | |
|
521 | |
private HashMap getActionListItemsStat(Collection actionItems) { |
522 | 0 | HashMap docTypes = new LinkedHashMap(); |
523 | 0 | Iterator iter = actionItems.iterator(); |
524 | |
|
525 | 0 | while (iter.hasNext()) { |
526 | 0 | String docTypeName = ((ActionItem) iter.next()).getRouteHeader() |
527 | |
.getDocumentType().getName(); |
528 | 0 | if (docTypes.containsKey(docTypeName)) { |
529 | 0 | docTypes.put(docTypeName, new Integer(((Integer) docTypes |
530 | |
.get(docTypeName)).intValue() + 1)); |
531 | |
} else { |
532 | 0 | docTypes.put(docTypeName, new Integer(1)); |
533 | |
} |
534 | 0 | } |
535 | 0 | return docTypes; |
536 | |
} |
537 | |
|
538 | |
protected boolean sendActionListEmailNotification() { |
539 | 0 | LOG.debug("actionlistsendconstant: " + Utilities.getKNSParameterValue(KEWConstants.KEW_NAMESPACE, KNSConstants.DetailTypes.ACTION_LIST_DETAIL_TYPE, KEWConstants.ACTION_LIST_SEND_EMAIL_NOTIFICATION_IND)); |
540 | |
|
541 | 0 | return KEWConstants.ACTION_LIST_SEND_EMAIL_NOTIFICATION_VALUE |
542 | |
.equals(Utilities.getKNSParameterValue(KEWConstants.KEW_NAMESPACE, KNSConstants.DetailTypes.ACTION_LIST_DETAIL_TYPE, KEWConstants.ACTION_LIST_SEND_EMAIL_NOTIFICATION_IND)); |
543 | |
} |
544 | |
|
545 | |
public void scheduleBatchEmailReminders() throws Exception { |
546 | 0 | String emailBatchGroup = "Email Batch"; |
547 | 0 | String dailyCron = ConfigContext.getCurrentContextConfig().getProperty(KEWConstants.DAILY_EMAIL_CRON_EXPRESSION); |
548 | 0 | if (!StringUtils.isBlank(dailyCron)) { |
549 | 0 | LOG.info("Scheduling Daily Email batch with cron expression: " + dailyCron); |
550 | 0 | CronTrigger dailyTrigger = new CronTrigger(DAILY_TRIGGER_NAME, emailBatchGroup, dailyCron); |
551 | 0 | JobDetail dailyJobDetail = new JobDetail(DAILY_JOB_NAME, emailBatchGroup, DailyEmailJob.class); |
552 | 0 | dailyTrigger.setJobName(dailyJobDetail.getName()); |
553 | 0 | dailyTrigger.setJobGroup(dailyJobDetail.getGroup()); |
554 | 0 | addJobToScheduler(dailyJobDetail); |
555 | 0 | addTriggerToScheduler(dailyTrigger); |
556 | 0 | } else { |
557 | 0 | LOG.warn("No " + KEWConstants.DAILY_EMAIL_CRON_EXPRESSION + " parameter was configured. Daily Email batch was not scheduled!"); |
558 | |
} |
559 | |
|
560 | 0 | String weeklyCron = ConfigContext.getCurrentContextConfig().getProperty(KEWConstants.WEEKLY_EMAIL_CRON_EXPRESSION); |
561 | 0 | if (!StringUtils.isBlank(weeklyCron)) { |
562 | 0 | LOG.info("Scheduling Weekly Email batch with cron expression: " + weeklyCron); |
563 | 0 | CronTrigger weeklyTrigger = new CronTrigger(WEEKLY_TRIGGER_NAME, emailBatchGroup, weeklyCron); |
564 | 0 | JobDetail weeklyJobDetail = new JobDetail(WEEKLY_JOB_NAME, emailBatchGroup, WeeklyEmailJob.class); |
565 | 0 | weeklyTrigger.setJobName(weeklyJobDetail.getName()); |
566 | 0 | weeklyTrigger.setJobGroup(weeklyJobDetail.getGroup()); |
567 | 0 | addJobToScheduler(weeklyJobDetail); |
568 | 0 | addTriggerToScheduler(weeklyTrigger); |
569 | 0 | } else { |
570 | 0 | LOG.warn("No " + KEWConstants.WEEKLY_EMAIL_CRON_EXPRESSION + " parameter was configured. Weekly Email batch was not scheduled!"); |
571 | |
} |
572 | 0 | } |
573 | |
|
574 | |
private void addJobToScheduler(JobDetail jobDetail) throws SchedulerException { |
575 | 0 | getScheduler().addJob(jobDetail, true); |
576 | 0 | } |
577 | |
|
578 | |
private void addTriggerToScheduler(Trigger trigger) throws SchedulerException { |
579 | 0 | boolean triggerExists = (getScheduler().getTrigger(trigger.getName(), trigger.getGroup()) != null); |
580 | 0 | if (!triggerExists) { |
581 | |
try { |
582 | 0 | getScheduler().scheduleJob(trigger); |
583 | 0 | } catch (ObjectAlreadyExistsException ex) { |
584 | 0 | getScheduler().rescheduleJob(trigger.getName(), trigger.getGroup(), trigger); |
585 | 0 | } |
586 | |
} else { |
587 | 0 | getScheduler().rescheduleJob(trigger.getName(), trigger.getGroup(), trigger); |
588 | |
} |
589 | 0 | } |
590 | |
|
591 | |
private Scheduler getScheduler() { |
592 | 0 | return KSBServiceLocator.getScheduler(); |
593 | |
} |
594 | |
|
595 | |
private UserOptionsService getUserOptionsService() { |
596 | 0 | return (UserOptionsService) KEWServiceLocator |
597 | |
.getUserOptionsService(); |
598 | |
} |
599 | |
|
600 | |
protected ActionListService getActionListService() { |
601 | 0 | return (ActionListService) KEWServiceLocator.getActionListService(); |
602 | |
} |
603 | |
|
604 | |
public String getDeploymentEnvironment() { |
605 | 0 | return deploymentEnvironment; |
606 | |
} |
607 | |
|
608 | |
public void setDeploymentEnvironment(String deploymentEnvironment) { |
609 | 0 | this.deploymentEnvironment = deploymentEnvironment; |
610 | 0 | } |
611 | |
|
612 | |
protected String getActionListUrl() { |
613 | 0 | return ConfigContext.getCurrentContextConfig().getProperty(KNSConstants.WORKFLOW_URL_KEY) |
614 | |
+ "/" + "ActionList.do"; |
615 | |
} |
616 | |
|
617 | |
protected String getPreferencesUrl() { |
618 | 0 | return ConfigContext.getCurrentContextConfig().getProperty(KNSConstants.WORKFLOW_URL_KEY) |
619 | |
+ "/" + "Preferences.do"; |
620 | |
} |
621 | |
} |