Search in sources :

Example 1 with ActivityStreamPluginApi

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

the class DefaultWatchListEventFeedManager method getFeed.

@Override
@SuppressWarnings("unchecked")
public SyndFeed getFeed(String user, int entryNumber) throws XWikiException {
    XWikiContext context = contextProvider.get();
    Collection<String> wikis = store.getWatchedElements(user, WatchedElementType.WIKI);
    Collection<String> spaces = store.getWatchedElements(user, WatchedElementType.SPACE);
    Collection<String> documents = store.getWatchedElements(user, WatchedElementType.DOCUMENT);
    List<Object> parameters = new ArrayList<Object>();
    ActivityStreamPluginApi asApi = (ActivityStreamPluginApi) context.getWiki().getPluginApi("activitystream", context);
    parameters.addAll(wikis);
    parameters.addAll(spaces);
    parameters.addAll(documents);
    Transformer transformer = new ConstantTransformer("?");
    List<String> wikisPlaceholders = ListUtils.transformedList(new ArrayList<String>(), transformer);
    wikisPlaceholders.addAll(wikis);
    List<String> spacesPlaceholders = ListUtils.transformedList(new ArrayList<String>(), transformer);
    spacesPlaceholders.addAll(spaces);
    List<String> documentsPlaceholders = ListUtils.transformedList(new ArrayList<String>(), transformer);
    documentsPlaceholders.addAll(documents);
    String listItemsJoint = ",";
    String concatWiki = " or concat(act.wiki,'";
    String query = "1=0";
    if (!wikis.isEmpty()) {
        query += " or act.wiki in (" + StringUtils.join(wikisPlaceholders, listItemsJoint) + ')';
    }
    if (!spaces.isEmpty()) {
        query += concatWiki + DefaultWatchListStore.WIKI_SPACE_SEP + "',act.space) in (" + StringUtils.join(spacesPlaceholders, listItemsJoint) + ')';
    }
    if (!documents.isEmpty()) {
        query += concatWiki + DefaultWatchListStore.WIKI_SPACE_SEP + "',act.page) in (" + StringUtils.join(documentsPlaceholders, listItemsJoint) + ')';
    }
    List<ActivityEvent> events = asApi.searchEvents(query, false, true, entryNumber, 0, parameters);
    SyndFeed feed = asApi.getFeed(events);
    setFeedMetaData(feed, context);
    return feed;
}
Also used : Transformer(org.apache.commons.collections.Transformer) ConstantTransformer(org.apache.commons.collections.functors.ConstantTransformer) ActivityEvent(com.xpn.xwiki.plugin.activitystream.plugin.ActivityEvent) ActivityStreamPluginApi(com.xpn.xwiki.plugin.activitystream.plugin.ActivityStreamPluginApi) ArrayList(java.util.ArrayList) XWikiContext(com.xpn.xwiki.XWikiContext) ConstantTransformer(org.apache.commons.collections.functors.ConstantTransformer) SyndFeed(com.sun.syndication.feed.synd.SyndFeed)

Aggregations

SyndFeed (com.sun.syndication.feed.synd.SyndFeed)1 XWikiContext (com.xpn.xwiki.XWikiContext)1 ActivityEvent (com.xpn.xwiki.plugin.activitystream.plugin.ActivityEvent)1 ActivityStreamPluginApi (com.xpn.xwiki.plugin.activitystream.plugin.ActivityStreamPluginApi)1 ArrayList (java.util.ArrayList)1 Transformer (org.apache.commons.collections.Transformer)1 ConstantTransformer (org.apache.commons.collections.functors.ConstantTransformer)1