Search in sources :

Example 6 with ActivityStreamPlugin

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

the class ActivityStreamCleanerJob method executeJob.

@Override
protected void executeJob(JobExecutionContext jobContext) throws JobExecutionException {
    ActivityStreamPlugin plugin = (ActivityStreamPlugin) getXWikiContext().getWiki().getPlugin(ActivityStreamPlugin.PLUGIN_NAME, getXWikiContext());
    List<Object> parameters = new ArrayList<Object>();
    int days = ActivityStreamCleaner.getNumberOfDaysToKeep(getXWikiContext());
    if (days > 0) {
        parameters.add(DateUtils.addDays(new Date(), days * -1));
        try {
            List<ActivityEvent> events = plugin.getActivityStream().searchEvents("date < ?", false, true, 0, 0, parameters, getXWikiContext());
            for (ActivityEvent event : events) {
                plugin.getActivityStream().deleteActivityEvent(event, getXWikiContext());
            }
        } catch (ActivityStreamException e) {
        // TODO
        }
    }
}
Also used : ActivityEvent(com.xpn.xwiki.plugin.activitystream.api.ActivityEvent) ArrayList(java.util.ArrayList) ActivityStreamException(com.xpn.xwiki.plugin.activitystream.api.ActivityStreamException) Date(java.util.Date) ActivityStreamPlugin(com.xpn.xwiki.plugin.activitystream.plugin.ActivityStreamPlugin)

Example 7 with ActivityStreamPlugin

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

the class ActivityStreamConfiguration method useLocalStore.

/**
 * This method determine if events must be store in the local wiki. If the activitystream is set not to store events
 * in the main wiki, the method will return true. If events are stored in the main wiki, the method retrieves the
 * 'platform.plugin.activitystream.uselocalstore' configuration option. If the option is not found the method
 * returns true (default behavior).
 *
 * @return true if the activity stream is configured to store events in the main wiki, false otherwise
 */
public boolean useLocalStore() {
    if (!useMainStore()) {
        // If the main store is disabled, force local store.
        return true;
    }
    XWikiContext context = contextProvider.get();
    ActivityStreamPlugin plugin = (ActivityStreamPlugin) context.getWiki().getPlugin(ActivityStreamPlugin.PLUGIN_NAME, context);
    return Integer.parseInt(plugin.getActivityStreamPreference("uselocalstore", "1", context)) == 1;
}
Also used : XWikiContext(com.xpn.xwiki.XWikiContext) ActivityStreamPlugin(com.xpn.xwiki.plugin.activitystream.plugin.ActivityStreamPlugin)

Example 8 with ActivityStreamPlugin

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

the class ActivityStreamConfiguration method useMainStore.

/**
 * This method determine if events must be store in the main wiki. If the current wiki is the main wiki, this method
 * returns false, otherwise if retrieves the 'platform.plugin.activitystream.usemainstore' configuration option. If
 * the option is not found the method returns true (default behavior).
 *
 * @return true if the activity stream is configured to store events in the main wiki, false otherwise
 */
public boolean useMainStore() {
    XWikiContext context = contextProvider.get();
    if (context.isMainWiki()) {
        // We're in the main database, we don't have to store the data twice.
        return false;
    }
    ActivityStreamPlugin plugin = (ActivityStreamPlugin) context.getWiki().getPlugin(ActivityStreamPlugin.PLUGIN_NAME, context);
    return Integer.parseInt(plugin.getActivityStreamPreference("usemainstore", "1", context)) == 1;
}
Also used : XWikiContext(com.xpn.xwiki.XWikiContext) 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