1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.watchlist.internal

File DefaultWatchListEventFeedManager.java

 

Coverage histogram

../../../../img/srcFileCovDistChart0.png
83% of files have more coverage

Code metrics

6
35
2
1
139
83
5
0.14
17.5
2
2.5

Classes

Class Line # Actions
DefaultWatchListEventFeedManager 53 35 0% 5 43
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.watchlist.internal;
21   
22    import java.util.ArrayList;
23    import java.util.Collection;
24    import java.util.List;
25   
26    import javax.inject.Inject;
27    import javax.inject.Provider;
28    import javax.inject.Singleton;
29   
30    import org.apache.commons.collections.ListUtils;
31    import org.apache.commons.collections.Transformer;
32    import org.apache.commons.collections.functors.ConstantTransformer;
33    import org.apache.commons.lang3.StringUtils;
34    import org.xwiki.component.annotation.Component;
35    import org.xwiki.localization.ContextualLocalizationManager;
36    import org.xwiki.watchlist.internal.api.WatchListEventFeedManager;
37    import org.xwiki.watchlist.internal.api.WatchListStore;
38    import org.xwiki.watchlist.internal.api.WatchedElementType;
39   
40    import com.sun.syndication.feed.synd.SyndFeed;
41    import com.xpn.xwiki.XWikiContext;
42    import com.xpn.xwiki.XWikiException;
43    import com.xpn.xwiki.plugin.activitystream.plugin.ActivityEvent;
44    import com.xpn.xwiki.plugin.activitystream.plugin.ActivityStreamPluginApi;
45   
46    /**
47    * Default implementation for {@link WatchListEventFeedManager}.
48    *
49    * @version $Id: 2806c84318aee4c18846671edfbca530f3937772 $
50    */
51    @Component
52    @Singleton
 
53    public class DefaultWatchListEventFeedManager implements WatchListEventFeedManager
54    {
55    /**
56    * The watchlist store component instance.
57    */
58    @Inject
59    private WatchListStore store;
60   
61    /**
62    * Used to resolve translations.
63    */
64    @Inject
65    private ContextualLocalizationManager localization;
66   
67    /**
68    * Used to obtain the current context.
69    */
70    @Inject
71    private Provider<XWikiContext> contextProvider;
72   
 
73  0 toggle @Override
74    @SuppressWarnings("unchecked")
75    public SyndFeed getFeed(String user, int entryNumber) throws XWikiException
76    {
77  0 XWikiContext context = contextProvider.get();
78   
79  0 Collection<String> wikis = store.getWatchedElements(user, WatchedElementType.WIKI);
80  0 Collection<String> spaces = store.getWatchedElements(user, WatchedElementType.SPACE);
81  0 Collection<String> documents = store.getWatchedElements(user, WatchedElementType.DOCUMENT);
82  0 List<Object> parameters = new ArrayList<Object>();
83  0 ActivityStreamPluginApi asApi =
84    (ActivityStreamPluginApi) context.getWiki().getPluginApi("activitystream", context);
85   
86  0 parameters.addAll(wikis);
87  0 parameters.addAll(spaces);
88  0 parameters.addAll(documents);
89   
90  0 Transformer transformer = new ConstantTransformer("?");
91  0 List<String> wikisPlaceholders = ListUtils.transformedList(new ArrayList<String>(), transformer);
92  0 wikisPlaceholders.addAll(wikis);
93  0 List<String> spacesPlaceholders = ListUtils.transformedList(new ArrayList<String>(), transformer);
94  0 spacesPlaceholders.addAll(spaces);
95  0 List<String> documentsPlaceholders = ListUtils.transformedList(new ArrayList<String>(), transformer);
96  0 documentsPlaceholders.addAll(documents);
97   
98  0 String listItemsJoint = ",";
99  0 String concatWiki = " or concat(act.wiki,'";
100  0 String query = "1=0";
101  0 if (!wikis.isEmpty()) {
102  0 query += " or act.wiki in (" + StringUtils.join(wikisPlaceholders, listItemsJoint) + ')';
103    }
104  0 if (!spaces.isEmpty()) {
105  0 query +=
106    concatWiki + DefaultWatchListStore.WIKI_SPACE_SEP + "',act.space) in ("
107    + StringUtils.join(spacesPlaceholders, listItemsJoint) + ')';
108    }
109  0 if (!documents.isEmpty()) {
110  0 query +=
111    concatWiki + DefaultWatchListStore.WIKI_SPACE_SEP + "',act.page) in ("
112    + StringUtils.join(documentsPlaceholders, listItemsJoint) + ')';
113    }
114  0 List<ActivityEvent> events = asApi.searchEvents(query, false, true, entryNumber, 0, parameters);
115   
116  0 SyndFeed feed = asApi.getFeed(events);
117  0 setFeedMetaData(feed, context);
118   
119  0 return feed;
120    }
121   
122    /**
123    * Set the standard feed metadata values, based on static translated messages and wiki configuration.
124    *
125    * @param feed the feed to configure
126    * @param context the current request context
127    * @throws XWikiException if the wiki can't be properly accessed
128    */
 
129  0 toggle private void setFeedMetaData(SyndFeed feed, XWikiContext context) throws XWikiException
130    {
131  0 String msgPrefix = DefaultWatchList.APP_RES_PREFIX + "rss.";
132   
133  0 feed.setAuthor(localization.getTranslationPlain(msgPrefix + "author"));
134  0 feed.setTitle(localization.getTranslationPlain(msgPrefix + "title"));
135  0 feed.setDescription(localization.getTranslationPlain(msgPrefix + "description"));
136  0 feed.setCopyright(context.getWiki().getXWikiPreference("copyright", context));
137  0 feed.setLink(context.getWiki().getExternalURL("xwiki:Main.WebHome", "view", context));
138    }
139    }