Search in sources :

Example 1 with ActivityStreamPlugin

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

the class ActivityStreamCleaner method getNumberOfDaysToKeep.

/**
 * @param context the XWiki context
 * @return the number of days activitystream events should be kept (default: infinite duration).
 */
public static int getNumberOfDaysToKeep(XWikiContext context) {
    ActivityStreamPlugin plugin = (ActivityStreamPlugin) context.getWiki().getPlugin(ActivityStreamPlugin.PLUGIN_NAME, context);
    String pref = plugin.getActivityStreamPreference("daystokeepevents", "0", context);
    return Integer.parseInt(pref);
}
Also used : ActivityStreamPlugin(com.xpn.xwiki.plugin.activitystream.plugin.ActivityStreamPlugin)

Example 2 with ActivityStreamPlugin

use of com.xpn.xwiki.plugin.activitystream.plugin.ActivityStreamPlugin 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)

Example 3 with ActivityStreamPlugin

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

the class BridgeEventStream method getRelatedEvents.

@Override
public EventGroup getRelatedEvents(Event e) {
    XWikiContext context = getXWikiContext();
    ActivityStreamPlugin plugin = getPlugin(context);
    EventGroup result = new EventGroup();
    try {
        result.addEvents(convertActivitiesToEvents(plugin.getActivityStream().getRelatedEvents(eventConverter.convertEventToActivity(e), context)).toArray(new Event[0]));
    } catch (ActivityStreamException ex) {
    // Should not happen, and the eventual error was already reported downstream
    }
    return result;
}
Also used : XWikiContext(com.xpn.xwiki.XWikiContext) EventStreamDeletedEvent(org.xwiki.eventstream.events.EventStreamDeletedEvent) ActivityEvent(com.xpn.xwiki.plugin.activitystream.api.ActivityEvent) Event(org.xwiki.eventstream.Event) EventStreamAddedEvent(org.xwiki.eventstream.events.EventStreamAddedEvent) ActivityStreamException(com.xpn.xwiki.plugin.activitystream.api.ActivityStreamException) EventGroup(org.xwiki.eventstream.EventGroup) ActivityStreamPlugin(com.xpn.xwiki.plugin.activitystream.plugin.ActivityStreamPlugin)

Example 4 with ActivityStreamPlugin

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

the class BridgeEventStream method addEvent.

@Override
public void addEvent(Event e) {
    try {
        XWikiContext context = getXWikiContext();
        ActivityStreamPlugin plugin = getPlugin(context);
        plugin.getActivityStream().addActivityEvent(eventConverter.convertEventToActivity(e), context);
        this.observationManager.notify(new EventStreamAddedEvent(), e);
    } catch (ActivityStreamException ex) {
    // Unlikely; nothing we can do
    }
}
Also used : EventStreamAddedEvent(org.xwiki.eventstream.events.EventStreamAddedEvent) XWikiContext(com.xpn.xwiki.XWikiContext) ActivityStreamException(com.xpn.xwiki.plugin.activitystream.api.ActivityStreamException) ActivityStreamPlugin(com.xpn.xwiki.plugin.activitystream.plugin.ActivityStreamPlugin)

Example 5 with ActivityStreamPlugin

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

the class BridgeEventStream method deleteEvent.

@Override
public void deleteEvent(Event e) {
    try {
        XWikiContext context = getXWikiContext();
        ActivityStreamPlugin plugin = getPlugin(context);
        plugin.getActivityStream().deleteActivityEvent(eventConverter.convertEventToActivity(e), context);
        this.observationManager.notify(new EventStreamDeletedEvent(), e);
    } catch (ActivityStreamException ex) {
    // Unlikely; nothing we can do
    }
}
Also used : EventStreamDeletedEvent(org.xwiki.eventstream.events.EventStreamDeletedEvent) XWikiContext(com.xpn.xwiki.XWikiContext) ActivityStreamException(com.xpn.xwiki.plugin.activitystream.api.ActivityStreamException) ActivityStreamPlugin(com.xpn.xwiki.plugin.activitystream.plugin.ActivityStreamPlugin)

Aggregations

ActivityStreamPlugin (com.xpn.xwiki.plugin.activitystream.plugin.ActivityStreamPlugin)8 XWikiContext (com.xpn.xwiki.XWikiContext)6 ActivityStreamException (com.xpn.xwiki.plugin.activitystream.api.ActivityStreamException)4 ActivityEvent (com.xpn.xwiki.plugin.activitystream.api.ActivityEvent)3 ArrayList (java.util.ArrayList)2 EventStreamAddedEvent (org.xwiki.eventstream.events.EventStreamAddedEvent)2 EventStreamDeletedEvent (org.xwiki.eventstream.events.EventStreamDeletedEvent)2 ActivityStream (com.xpn.xwiki.plugin.activitystream.api.ActivityStream)1 Date (java.util.Date)1 Event (org.xwiki.eventstream.Event)1 EventGroup (org.xwiki.eventstream.EventGroup)1 WatchListEvent (org.xwiki.watchlist.internal.api.WatchListEvent)1