1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
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 |
|
@link |
48 |
|
|
49 |
|
@version |
50 |
|
|
51 |
|
@Component |
52 |
|
@Singleton |
|
|
| 0% |
Uncovered Elements: 43 (43) |
Complexity: 5 |
Complexity Density: 0.14 |
|
53 |
|
public class DefaultWatchListEventFeedManager implements WatchListEventFeedManager |
54 |
|
{ |
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
@Inject |
59 |
|
private WatchListStore store; |
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
@Inject |
65 |
|
private ContextualLocalizationManager localization; |
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
@Inject |
71 |
|
private Provider<XWikiContext> contextProvider; |
72 |
|
|
|
|
| 0% |
Uncovered Elements: 35 (35) |
Complexity: 4 |
Complexity Density: 0.14 |
|
73 |
0 |
@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 |
|
|
124 |
|
|
125 |
|
@param |
126 |
|
@param |
127 |
|
@throws |
128 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
129 |
0 |
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 |
|
} |