Search in sources :

Example 1 with ActivityStream

use of com.xpn.xwiki.plugin.activitystream.api.ActivityStream in project xwiki-platform by xwiki.

the class DefaultWatchListEventMatcher method getEventsSince.

@Override
public List<WatchListEvent> getEventsSince(Date start) {
    List<WatchListEvent> events = new ArrayList<>();
    XWikiContext context = getXWikiContext();
    ActivityStream actStream = ((ActivityStreamPlugin) context.getWiki().getPlugin(ActivityStreamPlugin.PLUGIN_NAME, context)).getActivityStream();
    List<Object> parameters = new ArrayList<Object>();
    parameters.add(start);
    try {
        // FIXME: Watch out for memory usage here, since the list of events could be huge in some cases.
        List<ActivityEvent> rawEvents = actStream.searchEvents("act.date > ? and act.type in ('" + StringUtils.join(MATCHING_EVENT_TYPES, "','") + "')", false, true, 0, 0, parameters, context);
        // WatchListEvent#equals(WatchListEvent).
        for (ActivityEvent rawEvent : rawEvents) {
            WatchListEvent event = this.eventConverter.convert(rawEvent);
            int existingIndex = events.indexOf(event);
            if (existingIndex == -1) {
                // An event on a new document, add the new event.
                events.add(event);
            } else {
                // An event on an existing document, add to the events of that document.
                WatchListEvent existingCompositeEvent = events.get(existingIndex);
                existingCompositeEvent.addEvent(event);
            }
        }
    } catch (Exception e) {
        logger.error("Failed to retrieve updated documents from activity stream since [{}]", start, e);
    }
    return events;
}
Also used : WatchListEvent(org.xwiki.watchlist.internal.api.WatchListEvent) ActivityEvent(com.xpn.xwiki.plugin.activitystream.api.ActivityEvent) ActivityStream(com.xpn.xwiki.plugin.activitystream.api.ActivityStream) ArrayList(java.util.ArrayList) XWikiContext(com.xpn.xwiki.XWikiContext) ActivityStreamPlugin(com.xpn.xwiki.plugin.activitystream.plugin.ActivityStreamPlugin)

Aggregations

XWikiContext (com.xpn.xwiki.XWikiContext)1 ActivityEvent (com.xpn.xwiki.plugin.activitystream.api.ActivityEvent)1 ActivityStream (com.xpn.xwiki.plugin.activitystream.api.ActivityStream)1 ActivityStreamPlugin (com.xpn.xwiki.plugin.activitystream.plugin.ActivityStreamPlugin)1 ArrayList (java.util.ArrayList)1 WatchListEvent (org.xwiki.watchlist.internal.api.WatchListEvent)1