Search in sources :

Example 1 with WatchListEventConverter

use of org.xwiki.watchlist.internal.WatchListEventConverter in project xwiki-platform by xwiki.

the class WatchListNotifier method sendEmailNotification.

/**
 * Sends the email notifying the subscriber that the updatedDocuments have been changed.
 *
 * @param subscriber user to notify
 * @param events list of events
 * @param emailTemplate email template to use
 * @param previousFireTime last time the notification was fired
 * @param context the XWiki context
 * @throws XWikiException if mail sending fails
 */
public void sendEmailNotification(String subscriber, List<WatchListEvent> events, String emailTemplate, Date previousFireTime, XWikiContext context) throws XWikiException {
    // Convert the parameters.
    List<org.xwiki.watchlist.internal.api.WatchListEvent> watchListEvents = new ArrayList<>();
    WatchListEventConverter<ActivityEvent> eventConverter = Utils.getComponent(new DefaultParameterizedType(null, WatchListEventConverter.class, ActivityEvent.class));
    for (WatchListEvent event : events) {
        List<ActivityEvent> activityEvents = event.getData();
        // Get the main event.
        org.xwiki.watchlist.internal.api.WatchListEvent watchListEvent = eventConverter.convert(activityEvents.get(0));
        // Possibly composite event.
        for (int i = 1; i < activityEvents.size(); i++) {
            org.xwiki.watchlist.internal.api.WatchListEvent associatedEvent = eventConverter.convert(activityEvents.get(i));
            watchListEvent.addEvent(associatedEvent);
        }
        // Add the converted event to the list.
        watchListEvents.add(watchListEvent);
    }
    // Delegate to the component.
    org.xwiki.watchlist.internal.api.WatchListNotifier notifier = Utils.getComponent(org.xwiki.watchlist.internal.api.WatchListNotifier.class);
    notifier.sendNotification(subscriber, watchListEvents, emailTemplate, previousFireTime);
}
Also used : ActivityEvent(com.xpn.xwiki.plugin.activitystream.api.ActivityEvent) ArrayList(java.util.ArrayList) WatchListEventConverter(org.xwiki.watchlist.internal.WatchListEventConverter) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType)

Aggregations

ActivityEvent (com.xpn.xwiki.plugin.activitystream.api.ActivityEvent)1 ArrayList (java.util.ArrayList)1 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)1 WatchListEventConverter (org.xwiki.watchlist.internal.WatchListEventConverter)1