1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.stats.impl; |
21 |
|
|
22 |
|
import java.util.ArrayList; |
23 |
|
import java.util.Collection; |
24 |
|
import java.util.Date; |
25 |
|
import java.util.List; |
26 |
|
import java.util.Map; |
27 |
|
|
28 |
|
import org.apache.commons.collections4.queue.CircularFifoQueue; |
29 |
|
import org.slf4j.Logger; |
30 |
|
import org.slf4j.LoggerFactory; |
31 |
|
import org.xwiki.bridge.event.ActionExecutedEvent; |
32 |
|
import org.xwiki.model.reference.DocumentReferenceResolver; |
33 |
|
import org.xwiki.observation.EventListener; |
34 |
|
import org.xwiki.observation.ObservationManager; |
35 |
|
import org.xwiki.observation.event.Event; |
36 |
|
import org.xwiki.observation.remote.RemoteObservationManagerContext; |
37 |
|
|
38 |
|
import com.xpn.xwiki.XWikiContext; |
39 |
|
import com.xpn.xwiki.XWikiException; |
40 |
|
import com.xpn.xwiki.criteria.impl.Duration; |
41 |
|
import com.xpn.xwiki.criteria.impl.Period; |
42 |
|
import com.xpn.xwiki.criteria.impl.Range; |
43 |
|
import com.xpn.xwiki.criteria.impl.Scope; |
44 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
45 |
|
import com.xpn.xwiki.stats.api.XWikiStatsService; |
46 |
|
import com.xpn.xwiki.stats.impl.xwiki.XWikiStatsReader; |
47 |
|
import com.xpn.xwiki.stats.impl.xwiki.XWikiStatsStoreService; |
48 |
|
import com.xpn.xwiki.web.DownloadAction; |
49 |
|
import com.xpn.xwiki.web.SaveAction; |
50 |
|
import com.xpn.xwiki.web.Utils; |
51 |
|
import com.xpn.xwiki.web.ViewAction; |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
@version |
57 |
|
|
|
|
| 62.7% |
Uncovered Elements: 28 (75) |
Complexity: 25 |
Complexity Density: 0.57 |
|
58 |
|
public class XWikiStatsServiceImpl implements XWikiStatsService, EventListener |
59 |
|
{ |
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
private static final Logger LOGGER = LoggerFactory.getLogger(XWikiStatsServiceImpl.class); |
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
private static final String NAME = "statistics"; |
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
private static final List<Event> EVENTS = new ArrayList<Event>() |
74 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
75 |
38 |
{... |
76 |
38 |
add(new ActionExecutedEvent(ViewAction.VIEW_ACTION)); |
77 |
38 |
add(new ActionExecutedEvent(SaveAction.ACTION_NAME)); |
78 |
38 |
add(new ActionExecutedEvent(DownloadAction.ACTION_NAME)); |
79 |
|
} |
80 |
|
}; |
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
private DocumentReferenceResolver<String> currentDocumentReferenceResolver = Utils.getComponent( |
86 |
|
DocumentReferenceResolver.TYPE_STRING, "current"); |
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
private XWikiStatsStoreService statsRegister; |
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
private XWikiStatsReader statsReader = new XWikiStatsReader(); |
97 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
98 |
300 |
@Override... |
99 |
|
public String getName() |
100 |
|
{ |
101 |
300 |
return NAME; |
102 |
|
} |
103 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
104 |
60 |
@Override... |
105 |
|
public List<Event> getEvents() |
106 |
|
{ |
107 |
60 |
return EVENTS; |
108 |
|
} |
109 |
|
|
|
|
| 90% |
Uncovered Elements: 1 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
110 |
60 |
@Override... |
111 |
|
public void init(XWikiContext context) |
112 |
|
{ |
113 |
60 |
if (LOGGER.isInfoEnabled()) { |
114 |
28 |
LOGGER.info("Start statistics service initialization"); |
115 |
|
} |
116 |
|
|
117 |
60 |
if (StatsUtil.isStatsEnabled(context)) { |
118 |
|
|
119 |
60 |
this.statsRegister = new XWikiStatsStoreService(context); |
120 |
60 |
this.statsRegister.start(); |
121 |
|
|
122 |
|
|
123 |
60 |
Utils.getComponent(ObservationManager.class).addListener(this); |
124 |
|
} |
125 |
|
} |
126 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
127 |
0 |
@Override... |
128 |
|
public Collection<Object> getRecentActions(String action, int size, XWikiContext context) |
129 |
|
{ |
130 |
0 |
return this.statsReader.getRecentActions(action, size, context); |
131 |
|
} |
132 |
|
|
|
|
| 80% |
Uncovered Elements: 7 (35) |
Complexity: 9 |
Complexity Density: 0.39 |
|
133 |
924 |
@Override... |
134 |
|
public void onEvent(Event event, Object source, Object data) |
135 |
|
{ |
136 |
924 |
if (Utils.getComponent(RemoteObservationManagerContext.class).isRemoteState()) { |
137 |
|
|
138 |
|
|
139 |
0 |
return; |
140 |
|
} |
141 |
|
|
142 |
923 |
ActionExecutedEvent actionEvent = (ActionExecutedEvent) event; |
143 |
924 |
XWikiDocument document = (XWikiDocument) source; |
144 |
925 |
XWikiContext context = (XWikiContext) data; |
145 |
|
|
146 |
|
|
147 |
|
|
148 |
924 |
if (context.getWiki().isReadOnly()) { |
149 |
0 |
return; |
150 |
|
} |
151 |
|
|
152 |
|
|
153 |
923 |
StatsUtil.findCookie(context); |
154 |
|
|
155 |
924 |
String action = actionEvent.getActionName(); |
156 |
|
|
157 |
|
|
158 |
924 |
synchronized (this) { |
159 |
925 |
if (!action.equals(DownloadAction.ACTION_NAME)) { |
160 |
744 |
Collection actions = StatsUtil.getRecentActionFromSessions(context, action); |
161 |
744 |
if (actions == null) { |
162 |
108 |
actions = new CircularFifoQueue(StatsUtil.getRecentVisitSize(context)); |
163 |
108 |
StatsUtil.setRecentActionsFromSession(context, action, actions); |
164 |
|
} |
165 |
|
|
166 |
744 |
String element = document.getPrefixedFullName(); |
167 |
744 |
if (actions.contains(element)) { |
168 |
365 |
actions.remove(element); |
169 |
|
} |
170 |
744 |
actions.add(element); |
171 |
|
} |
172 |
|
} |
173 |
|
|
174 |
925 |
try { |
175 |
925 |
if (StatsUtil.isWikiStatsEnabled(context) |
176 |
|
&& !StatsUtil.getStorageFilteredUsers(context).contains( |
177 |
|
this.currentDocumentReferenceResolver.resolve(context.getUser()))) { |
178 |
0 |
this.statsRegister.addStats(document, action, context); |
179 |
|
} |
180 |
|
} catch (Exception e) { |
181 |
0 |
LOGGER.error("Faild to get filter users list", e); |
182 |
|
} |
183 |
|
} |
184 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
185 |
0 |
@Override... |
186 |
|
public Map<?, ?> getActionStatistics(String action, Scope scope, Period period, Duration step, |
187 |
|
XWikiContext context) |
188 |
|
{ |
189 |
0 |
return this.statsReader.getActionStatistics(action, scope, period, step, context); |
190 |
|
} |
191 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
192 |
0 |
@Override... |
193 |
|
public List<DocumentStats> getDocumentStatistics(String action, Scope scope, Period period, Range range, |
194 |
|
XWikiContext context) |
195 |
|
{ |
196 |
0 |
return this.statsReader.getDocumentStatistics(action, scope, period, range, context); |
197 |
|
} |
198 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
199 |
0 |
@Override... |
200 |
|
public List<DocumentStats> getBackLinkStatistics(String domain, Scope scope, Period period, Range range, |
201 |
|
XWikiContext context) |
202 |
|
{ |
203 |
0 |
return this.statsReader.getBackLinkStatistics(domain, scope, period, range, context); |
204 |
|
} |
205 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
206 |
0 |
@Override... |
207 |
|
public List<RefererStats> getRefererStatistics(String domain, Scope scope, Period period, Range range, |
208 |
|
XWikiContext context) |
209 |
|
{ |
210 |
0 |
return this.statsReader.getRefererStatistics(domain, scope, period, range, context); |
211 |
|
} |
212 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
213 |
0 |
@Override... |
214 |
|
public List<VisitStats> getVisitStatistics(String action, Period period, Range range, XWikiContext context) |
215 |
|
{ |
216 |
0 |
return this.statsReader.getVisitStatistics(action, period, range, context); |
217 |
|
} |
218 |
|
|
219 |
|
|
220 |
|
|
221 |
|
|
222 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
223 |
0 |
@Override... |
224 |
|
public DocumentStats getDocTotalStats(String docname, String action, XWikiContext context) |
225 |
|
{ |
226 |
0 |
return new DocumentStats(); |
227 |
|
} |
228 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
229 |
0 |
@Override... |
230 |
|
public DocumentStats getDocMonthStats(String docname, String action, Date month, XWikiContext context) |
231 |
|
{ |
232 |
0 |
return this.statsReader.getDocMonthStats(docname, action, month, context); |
233 |
|
} |
234 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
235 |
0 |
@Override... |
236 |
|
public DocumentStats getDocDayStats(String docname, String action, Date day, XWikiContext context) |
237 |
|
{ |
238 |
0 |
return new DocumentStats(); |
239 |
|
} |
240 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
241 |
0 |
@Override... |
242 |
|
public List<?> getRefMonthStats(String docName, Date month, XWikiContext context) throws XWikiException |
243 |
|
{ |
244 |
0 |
return this.statsReader.getRefMonthStats(docName, month, context); |
245 |
|
} |
246 |
|
} |