use of org.xwiki.watchlist.internal.WatchListEventMatcher in project xwiki-platform by xwiki.
the class WatchListJob method executeJob.
/**
* Method called from the scheduler.
*
* @param jobContext Context of the request
* @throws JobExecutionException if the job execution fails.
*/
@Override
public void executeJob(JobExecutionContext jobContext) throws JobExecutionException {
try {
// Don't go further if the application is disabled
if (!isWatchListEnabled()) {
return;
}
init(jobContext);
if (this.watchListJobObject == null) {
return;
}
Collection<String> subscribers = getSubscribers();
// Stop here if nobody is interested.
if (!hasSubscribers()) {
return;
}
// Determine what happened since the last execution for everybody.
Date previousFireTime = getPreviousFireTime();
WatchListEventMatcher eventMatcher = Utils.getComponent(WatchListEventMatcher.class);
List<WatchListEvent> events = eventMatcher.getEventsSince(previousFireTime);
setPreviousFireTime();
// Stop here if nothing happened in the meantime.
if (events.size() == 0) {
return;
}
// Notify all the interested subscribers of the events that occurred.
// When processing the events, a subscriber will only be notified of events that interest him.
Map<String, Object> notificationData = new HashMap<>();
notificationData.put(DefaultWatchListNotifier.PREVIOUS_FIRE_TIME_VARIABLE, previousFireTime);
String mailTemplate = this.watchListJobObject.getStringValue(WatchListJobClassDocumentInitializer.TEMPLATE_FIELD);
notificationData.put(WatchListEventMimeMessageFactory.TEMPLATE_PARAMETER, mailTemplate);
// Send the notification for processing.
this.watchlist.getNotifier().sendNotification(subscribers, events, notificationData);
} catch (Exception e) {
// We're in a job, we don't throw exceptions
LOGGER.error("Exception while running job", e);
}
}
Aggregations