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.net.MalformedURLException; |
23 |
|
import java.net.URL; |
24 |
|
import java.util.ArrayList; |
25 |
|
import java.util.Calendar; |
26 |
|
import java.util.Collection; |
27 |
|
import java.util.Collections; |
28 |
|
import java.util.Date; |
29 |
|
import java.util.List; |
30 |
|
|
31 |
|
import javax.servlet.http.Cookie; |
32 |
|
import javax.servlet.http.HttpSession; |
33 |
|
|
34 |
|
import org.apache.commons.lang3.RandomStringUtils; |
35 |
|
import org.apache.commons.lang3.StringUtils; |
36 |
|
import org.slf4j.Logger; |
37 |
|
import org.slf4j.LoggerFactory; |
38 |
|
import org.xwiki.model.reference.DocumentReference; |
39 |
|
import org.xwiki.query.Query; |
40 |
|
import org.xwiki.query.QueryManager; |
41 |
|
|
42 |
|
import com.xpn.xwiki.XWikiContext; |
43 |
|
import com.xpn.xwiki.XWikiException; |
44 |
|
import com.xpn.xwiki.plugin.rightsmanager.RightsManager; |
45 |
|
import com.xpn.xwiki.user.api.XWikiRightService; |
46 |
|
import com.xpn.xwiki.util.Util; |
47 |
|
import com.xpn.xwiki.web.XWikiRequest; |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
@version |
53 |
|
|
|
|
| 36.7% |
Uncovered Elements: 169 (267) |
Complexity: 67 |
Complexity Density: 0.39 |
|
54 |
|
public final class StatsUtil |
55 |
|
{ |
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
private static final Logger LOGGER = LoggerFactory.getLogger(StatsUtil.class); |
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
private static final String LIST_SEPARATOR = ","; |
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
private static final String ESCAPED_LIST_SEPARATOR = "\\,"; |
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
private static final String CFGPROP_COOKIEDOMAINS = "xwiki.authentication.cookiedomains"; |
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
private static final char CFGPROP_COOKIEDOMAINS_SEP = ','; |
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
private static final String CFGPROP_STATS = "xwiki.stats"; |
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
private static final String CFGPROP_STATS_DEFAULT = "xwiki.stats.default"; |
90 |
|
|
91 |
|
|
92 |
|
@link |
93 |
|
|
94 |
|
@Deprecated |
95 |
|
private static final String DEPRECATED_CFGPROP_STATS_EXCLUDEDUSERSANDGROUPS = "xwiki.stats.excludedUsersAndGroups"; |
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
private static final String CFGPROP_STATS_EXCLUDEDUSERSANDGROUPS_REQUEST = |
102 |
|
"xwiki.stats.request.excludedUsersAndGroups"; |
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
private static final String CFGPROP_STATS_EXCLUDEDUSERSANDGROUPS_STORAGE = |
109 |
|
"xwiki.stats.storage.excludedUsersAndGroups"; |
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
private static final String SESSPROP_RECENT_PREFFIX = "recent_"; |
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
private static final String SESSPROP_VISITOBJECT = "visitObject"; |
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
private static final String PREFPROP_RECENT_VISITS_SIZE = "recent_visits_size"; |
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
|
129 |
|
private static final String PREFPROP_STATISTICS = "statistics"; |
130 |
|
|
131 |
|
|
132 |
|
@link |
133 |
|
|
134 |
|
@Deprecated |
135 |
|
private static final String DEPRECATED_PREFPROP_EXCLUDEDUSERSANDGROUPS = "statistics_excludedUsersAndGroups"; |
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
|
141 |
|
private static final String PREFPROP_EXCLUDEDUSERSANDGROUPS_REQUEST = "statistics_request_excludedUsersAndGroups"; |
142 |
|
|
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
|
147 |
|
private static final String PREFPROP_EXCLUDEDUSERSANDGROUPS_STORAGE = "statistics_storage_excludedUsersAndGroups"; |
148 |
|
|
149 |
|
|
150 |
|
|
151 |
|
|
152 |
|
private static final String REQPROP_REFERER = "referer"; |
153 |
|
|
154 |
|
|
155 |
|
|
156 |
|
|
157 |
|
private static final String REQPROP_USERAGENT = "User-Agent"; |
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
|
162 |
|
private static final String CONTPROP_STATS_COOKIE = "stats_cookie"; |
163 |
|
|
164 |
|
|
165 |
|
|
166 |
|
|
167 |
|
private static final String CONTPROP_STATS_NEWCOOKIE = "stats_newcookie"; |
168 |
|
|
169 |
|
|
170 |
|
|
171 |
|
|
172 |
|
private static final String COOKPROP_VISITID = "visitid"; |
173 |
|
|
174 |
|
|
175 |
|
|
176 |
|
|
177 |
|
private static String[] cookieDomains; |
178 |
|
|
179 |
|
|
180 |
|
|
181 |
|
|
182 |
|
private static Date cookieExpirationDate; |
183 |
|
|
184 |
|
|
185 |
|
|
186 |
|
|
187 |
|
@version |
188 |
|
@since |
189 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
190 |
|
public enum PeriodType |
191 |
|
{ |
192 |
|
|
193 |
|
|
194 |
|
|
195 |
|
MONTH, |
196 |
|
|
197 |
|
|
198 |
|
|
199 |
|
DAY |
200 |
|
} |
201 |
|
|
202 |
|
|
203 |
|
@link |
204 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
205 |
0 |
private StatsUtil()... |
206 |
|
{ |
207 |
|
} |
208 |
|
|
209 |
|
|
210 |
|
|
211 |
|
|
212 |
|
@link |
213 |
|
@link |
214 |
|
|
215 |
|
|
216 |
|
|
217 |
|
@param |
218 |
|
@param@link@link |
219 |
|
@return |
220 |
|
@see |
221 |
|
@since |
222 |
|
|
|
|
| 91.7% |
Uncovered Elements: 1 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
223 |
2 |
public static int getPeriodAsInt(Date date, PeriodType type)... |
224 |
|
{ |
225 |
2 |
int period; |
226 |
|
|
227 |
2 |
Calendar cal = Calendar.getInstance(); |
228 |
2 |
if (date != null) { |
229 |
2 |
cal.setTime(date); |
230 |
|
} |
231 |
|
|
232 |
2 |
if (type == PeriodType.MONTH) { |
233 |
|
|
234 |
1 |
period = cal.get(Calendar.YEAR) * 100 + (cal.get(Calendar.MONTH) + 1); |
235 |
|
} else { |
236 |
|
|
237 |
1 |
period = |
238 |
|
cal.get(Calendar.YEAR) * 10000 + (cal.get(Calendar.MONTH) + 1) * 100 + cal.get(Calendar.DAY_OF_MONTH); |
239 |
|
} |
240 |
|
|
241 |
2 |
return period; |
242 |
|
} |
243 |
|
|
244 |
|
|
245 |
|
@param |
246 |
|
@return |
247 |
|
@since |
248 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
249 |
922 |
public static String[] getCookieDomains(XWikiContext context)... |
250 |
|
{ |
251 |
921 |
if (cookieDomains == null) { |
252 |
29 |
cookieDomains = |
253 |
|
StringUtils.split(context.getWiki().Param(CFGPROP_COOKIEDOMAINS), CFGPROP_COOKIEDOMAINS_SEP); |
254 |
|
} |
255 |
|
|
256 |
925 |
return cookieDomains; |
257 |
|
} |
258 |
|
|
259 |
|
|
260 |
|
@return |
261 |
|
@since |
262 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
263 |
923 |
public static Date getCookieExpirationDate()... |
264 |
|
{ |
265 |
|
|
266 |
923 |
Calendar cal = Calendar.getInstance(); |
267 |
922 |
cal.set(2030, 0, 0); |
268 |
924 |
cookieExpirationDate = cal.getTime(); |
269 |
|
|
270 |
924 |
return cookieExpirationDate; |
271 |
|
} |
272 |
|
|
273 |
|
|
274 |
|
@param |
275 |
|
@param |
276 |
|
@return |
277 |
|
@since |
278 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
279 |
744 |
public static Collection<?> getRecentActionFromSessions(XWikiContext context, String action)... |
280 |
|
{ |
281 |
744 |
return (Collection<?>) context.getRequest().getSession().getAttribute(SESSPROP_RECENT_PREFFIX + action); |
282 |
|
} |
283 |
|
|
284 |
|
|
285 |
|
|
286 |
|
|
287 |
|
@param |
288 |
|
@param |
289 |
|
@param |
290 |
|
@since |
291 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
292 |
108 |
public static void setRecentActionsFromSession(XWikiContext context, String action, Collection<?> actions)... |
293 |
|
{ |
294 |
108 |
context.getRequest().getSession().setAttribute(SESSPROP_RECENT_PREFFIX + action, actions); |
295 |
|
} |
296 |
|
|
297 |
|
|
298 |
|
@param |
299 |
|
@return |
300 |
|
@since |
301 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
302 |
108 |
public static int getRecentVisitSize(XWikiContext context)... |
303 |
|
{ |
304 |
108 |
return context.getWiki().getXWikiPreferenceAsInt(PREFPROP_RECENT_VISITS_SIZE, 20, context); |
305 |
|
} |
306 |
|
|
307 |
|
|
308 |
|
@param |
309 |
|
@return |
310 |
|
@since |
311 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
312 |
0 |
public static VisitStats getVisitFromSession(HttpSession session)... |
313 |
|
{ |
314 |
0 |
return (VisitStats) session.getAttribute(SESSPROP_VISITOBJECT); |
315 |
|
} |
316 |
|
|
317 |
|
|
318 |
|
|
319 |
|
|
320 |
|
@param |
321 |
|
@param |
322 |
|
@since |
323 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
324 |
0 |
public static void setVisitInSession(HttpSession session, VisitStats visitStat)... |
325 |
|
{ |
326 |
0 |
session.setAttribute(SESSPROP_VISITOBJECT, visitStat); |
327 |
|
} |
328 |
|
|
329 |
|
|
330 |
|
@param |
331 |
|
@return |
332 |
|
@since |
333 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
334 |
60 |
public static boolean isStatsEnabled(XWikiContext context)... |
335 |
|
{ |
336 |
60 |
return "1".equals(context.getWiki().Param(CFGPROP_STATS, "1")); |
337 |
|
} |
338 |
|
|
339 |
|
|
340 |
|
@param |
341 |
|
@return |
342 |
|
@since |
343 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
344 |
925 |
public static boolean isWikiStatsEnabled(XWikiContext context)... |
345 |
|
{ |
346 |
925 |
String statsdefault = context.getWiki().Param(CFGPROP_STATS_DEFAULT); |
347 |
925 |
String statsactive = context.getWiki().getXWikiPreference(PREFPROP_STATISTICS, "", context); |
348 |
|
|
349 |
925 |
return "1".equals(statsactive) || (("".equals(statsactive)) && ("1".equals(statsdefault))); |
350 |
|
} |
351 |
|
|
352 |
|
|
353 |
|
|
354 |
|
|
355 |
|
|
356 |
|
|
357 |
|
|
358 |
|
|
359 |
|
|
360 |
|
|
361 |
|
|
362 |
|
|
363 |
|
|
364 |
|
|
365 |
|
|
366 |
|
|
367 |
|
@param |
368 |
|
@return |
369 |
|
@since |
370 |
|
|
|
|
| 0% |
Uncovered Elements: 34 (34) |
Complexity: 8 |
Complexity Density: 0.33 |
|
371 |
0 |
public static VisitStats findVisit(XWikiContext context)... |
372 |
|
{ |
373 |
0 |
XWikiRequest request = context.getRequest(); |
374 |
0 |
HttpSession session = request.getSession(true); |
375 |
|
|
376 |
0 |
VisitStats visitObject = StatsUtil.getVisitFromSession(session); |
377 |
|
|
378 |
0 |
Cookie cookie = (Cookie) context.get(CONTPROP_STATS_COOKIE); |
379 |
0 |
boolean newcookie = ((Boolean) context.get(CONTPROP_STATS_NEWCOOKIE)).booleanValue(); |
380 |
|
|
381 |
0 |
if (visitObject == null) { |
382 |
0 |
visitObject = findVisitByCookieOrIPUA(context); |
383 |
|
} |
384 |
|
|
385 |
0 |
if (visitObject == null || !isVisitObjectValid(visitObject, context)) { |
386 |
0 |
visitObject = createNewVisit(context); |
387 |
|
} else { |
388 |
0 |
if (!newcookie) { |
389 |
|
|
390 |
0 |
String uniqueID = visitObject.getUniqueID(); |
391 |
0 |
String oldcookie = visitObject.getCookie(); |
392 |
|
|
393 |
0 |
if (!uniqueID.equals(oldcookie)) { |
394 |
|
|
395 |
|
|
396 |
0 |
VisitStats newVisitObject = (VisitStats) visitObject.clone(); |
397 |
0 |
newVisitObject.rememberOldObject(visitObject); |
398 |
0 |
newVisitObject.setUniqueID(cookie.getValue()); |
399 |
0 |
visitObject = newVisitObject; |
400 |
|
} |
401 |
|
} |
402 |
|
|
403 |
0 |
if ((!context.getUser().equals(XWikiRightService.GUEST_USER_FULLNAME)) |
404 |
|
&& (visitObject.getUser().equals(XWikiRightService.GUEST_USER_FULLNAME))) { |
405 |
|
|
406 |
|
|
407 |
0 |
VisitStats newVisitObject = visitObject; |
408 |
0 |
newVisitObject.rememberOldObject(visitObject); |
409 |
0 |
newVisitObject.setName(context.getUser()); |
410 |
0 |
visitObject = newVisitObject; |
411 |
|
} |
412 |
|
} |
413 |
|
|
414 |
|
|
415 |
0 |
StatsUtil.setVisitInSession(session, visitObject); |
416 |
|
|
417 |
0 |
return visitObject; |
418 |
|
} |
419 |
|
|
420 |
|
|
421 |
|
|
422 |
|
|
423 |
|
@param |
424 |
|
@return |
425 |
|
@since |
426 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 4 |
Complexity Density: 0.29 |
|
427 |
0 |
private static VisitStats findVisitByCookieOrIPUA(XWikiContext context)... |
428 |
|
{ |
429 |
0 |
VisitStats visitStats = null; |
430 |
|
|
431 |
0 |
XWikiRequest request = context.getRequest(); |
432 |
|
|
433 |
0 |
Cookie cookie = (Cookie) context.get(CONTPROP_STATS_COOKIE); |
434 |
0 |
boolean newcookie = ((Boolean) context.get(CONTPROP_STATS_NEWCOOKIE)).booleanValue(); |
435 |
|
|
436 |
0 |
if (!newcookie) { |
437 |
0 |
try { |
438 |
0 |
visitStats = findVisitByCookie(cookie.getValue(), context); |
439 |
|
} catch (XWikiException e) { |
440 |
0 |
LOGGER.error("Failed to find visit by cookie", e); |
441 |
|
} |
442 |
|
} else { |
443 |
0 |
try { |
444 |
0 |
String ip = request.getRemoteAddr(); |
445 |
0 |
String ua = request.getHeader(REQPROP_USERAGENT); |
446 |
0 |
visitStats = findVisitByIPUA(computeUniqueID(ip, ua), context); |
447 |
|
} catch (XWikiException e) { |
448 |
0 |
LOGGER.error("Failed to find visit by unique id", e); |
449 |
|
} |
450 |
|
} |
451 |
|
|
452 |
0 |
return visitStats; |
453 |
|
} |
454 |
|
|
455 |
|
|
456 |
|
|
457 |
|
|
458 |
|
@param |
459 |
|
@param |
460 |
|
@return |
461 |
|
@since |
462 |
|
|
|
|
| 0% |
Uncovered Elements: 25 (25) |
Complexity: 6 |
Complexity Density: 0.4 |
|
463 |
0 |
private static boolean isVisitObjectValid(VisitStats visitObject, XWikiContext context)... |
464 |
|
{ |
465 |
0 |
boolean valid = true; |
466 |
|
|
467 |
0 |
XWikiRequest request = context.getRequest(); |
468 |
0 |
HttpSession session = request.getSession(true); |
469 |
0 |
Cookie cookie = (Cookie) context.get(CONTPROP_STATS_COOKIE); |
470 |
0 |
Date nowDate = new Date(); |
471 |
|
|
472 |
0 |
if (visitObject != null) { |
473 |
|
|
474 |
|
|
475 |
0 |
if (!visitObject.getCookie().equals(cookie.getValue())) { |
476 |
|
|
477 |
|
|
478 |
|
|
479 |
0 |
if (LOGGER.isDebugEnabled()) { |
480 |
0 |
LOGGER.debug("Found visit with cookie " + visitObject.getCookie() + " in session " |
481 |
|
+ session.getId() + " for request with cookie " + cookie.getValue()); |
482 |
|
} |
483 |
|
|
484 |
0 |
valid = false; |
485 |
0 |
} else if ((nowDate.getTime() - visitObject.getEndDate().getTime()) > 30 * 60 * 1000) { |
486 |
|
|
487 |
|
|
488 |
0 |
valid = false; |
489 |
0 |
} else if (!context.getUser().equals(visitObject.getName())) { |
490 |
|
|
491 |
|
|
492 |
0 |
valid = false; |
493 |
|
} |
494 |
|
} |
495 |
|
|
496 |
0 |
return valid; |
497 |
|
} |
498 |
|
|
499 |
|
|
500 |
|
|
501 |
|
|
502 |
|
@param |
503 |
|
@return |
504 |
|
@since |
505 |
|
|
|
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 3 |
Complexity Density: 0.19 |
|
506 |
0 |
private static VisitStats createNewVisit(XWikiContext context)... |
507 |
|
{ |
508 |
0 |
VisitStats visitStats = null; |
509 |
|
|
510 |
0 |
XWikiRequest request = context.getRequest(); |
511 |
|
|
512 |
0 |
Date nowDate = new Date(); |
513 |
0 |
Cookie cookie = (Cookie) context.get(CONTPROP_STATS_COOKIE); |
514 |
0 |
boolean newcookie = ((Boolean) context.get(CONTPROP_STATS_NEWCOOKIE)).booleanValue(); |
515 |
|
|
516 |
|
|
517 |
0 |
String ip = request.getRemoteAddr(); |
518 |
0 |
String ua = request.getHeader(REQPROP_USERAGENT); |
519 |
0 |
if (ua == null) { |
520 |
0 |
ua = ""; |
521 |
|
} |
522 |
|
|
523 |
0 |
String uniqueID; |
524 |
0 |
if (newcookie) { |
525 |
|
|
526 |
|
|
527 |
0 |
uniqueID = computeUniqueID(ip, ua); |
528 |
|
} else { |
529 |
|
|
530 |
|
|
531 |
0 |
uniqueID = cookie.getValue(); |
532 |
|
} |
533 |
|
|
534 |
0 |
visitStats = new VisitStats(context.getUser(), uniqueID, cookie.getValue(), ip, ua, nowDate, PeriodType.MONTH); |
535 |
0 |
visitStats.setEndDate(nowDate); |
536 |
|
|
537 |
0 |
return visitStats; |
538 |
|
} |
539 |
|
|
540 |
|
|
541 |
|
|
542 |
|
|
543 |
|
|
544 |
|
|
545 |
|
|
546 |
|
@param |
547 |
|
@param |
548 |
|
@return |
549 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
550 |
0 |
private static String computeUniqueID(String ip, String ua)... |
551 |
|
{ |
552 |
0 |
return StringUtils.substring(ip + ua, 0, 255); |
553 |
|
} |
554 |
|
|
555 |
|
|
556 |
|
|
557 |
|
|
558 |
|
@param |
559 |
|
@param |
560 |
|
@param |
561 |
|
@return |
562 |
|
@throws |
563 |
|
@since |
564 |
|
|
|
|
| 0% |
Uncovered Elements: 24 (24) |
Complexity: 7 |
Complexity Density: 0.39 |
|
565 |
0 |
protected static VisitStats findVisitByField(String fieldName, String fieldValue, XWikiContext context)... |
566 |
|
throws XWikiException |
567 |
|
{ |
568 |
0 |
VisitStats visitStats = null; |
569 |
|
|
570 |
0 |
Date currentDate = new Date(new Date().getTime() - 30 * 60 * 1000); |
571 |
|
|
572 |
0 |
QueryManager qm = context.getWiki().getStore().getQueryManager(); |
573 |
0 |
List<VisitStats> solist = null; |
574 |
0 |
final String sfieldValue = "fieldValue"; |
575 |
0 |
final String sdate = "date"; |
576 |
0 |
if (qm.hasLanguage(Query.XPATH)) { |
577 |
0 |
try { |
578 |
0 |
solist = |
579 |
|
qm.createQuery( |
580 |
|
"//element(*, xwiki:object)[@:{fieldName}=:{fieldValue}" |
581 |
|
+ " and @endDate>:{date}] order by @endDate descending", Query.XPATH) |
582 |
|
.bindValue("fieldName", fieldName).bindValue(sfieldValue, fieldValue) |
583 |
|
.bindValue(sdate, currentDate).execute(); |
584 |
|
} catch (Exception e) { |
585 |
0 |
LOGGER.error("Failed to search visit object in the jcr store from cookie name", e); |
586 |
|
} |
587 |
0 |
} else if (qm.hasLanguage(Query.HQL)) { |
588 |
0 |
try { |
589 |
0 |
solist = |
590 |
|
qm.createQuery( |
591 |
|
"from VisitStats as obj " + "where obj." + fieldName + "=:fieldValue and obj.endDate > :date" |
592 |
|
+ " order by obj.endDate desc", Query.HQL).bindValue(sfieldValue, fieldValue) |
593 |
|
.bindValue(sdate, currentDate).execute(); |
594 |
|
} catch (Exception e) { |
595 |
0 |
LOGGER.error("Failed to search visit object in the database from " + fieldName, e); |
596 |
|
} |
597 |
|
} else { |
598 |
0 |
throw new UnsupportedOperationException("The current storage engine does not support querying statistics"); |
599 |
|
} |
600 |
0 |
if (solist != null && solist.size() > 0) { |
601 |
0 |
visitStats = solist.get(0); |
602 |
|
} |
603 |
|
|
604 |
0 |
return visitStats; |
605 |
|
} |
606 |
|
|
607 |
|
|
608 |
|
|
609 |
|
|
610 |
|
@param |
611 |
|
@param |
612 |
|
@return |
613 |
|
@throws |
614 |
|
@since |
615 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
616 |
0 |
protected static VisitStats findVisitByCookie(String cookie, XWikiContext context) throws XWikiException... |
617 |
|
{ |
618 |
0 |
return findVisitByField("cookie", cookie, context); |
619 |
|
} |
620 |
|
|
621 |
|
|
622 |
|
|
623 |
|
|
624 |
|
@param |
625 |
|
@param |
626 |
|
@return |
627 |
|
@throws |
628 |
|
@since |
629 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
630 |
0 |
protected static VisitStats findVisitByIPUA(String uniqueID, XWikiContext context) throws XWikiException... |
631 |
|
{ |
632 |
0 |
return findVisitByField("uniqueID", uniqueID, context); |
633 |
|
} |
634 |
|
|
635 |
|
|
636 |
|
|
637 |
|
|
638 |
|
@param |
639 |
|
@return |
640 |
|
@since |
641 |
|
|
|
|
| 61.5% |
Uncovered Elements: 10 (26) |
Complexity: 5 |
Complexity Density: 0.28 |
|
642 |
924 |
protected static Cookie addCookie(XWikiContext context)... |
643 |
|
{ |
644 |
925 |
Cookie cookie = new Cookie(COOKPROP_VISITID, RandomStringUtils.randomAlphanumeric(32).toUpperCase()); |
645 |
924 |
cookie.setPath("/"); |
646 |
|
|
647 |
921 |
int time = (int) (getCookieExpirationDate().getTime() - (new Date()).getTime()) / 1000; |
648 |
922 |
cookie.setMaxAge(time); |
649 |
|
|
650 |
920 |
String cookieDomain = null; |
651 |
921 |
getCookieDomains(context); |
652 |
923 |
if (cookieDomains != null) { |
653 |
921 |
String servername = context.getRequest().getServerName(); |
654 |
922 |
for (String cookieDomain2 : cookieDomains) { |
655 |
0 |
if (servername.indexOf(cookieDomain2) != -1) { |
656 |
0 |
cookieDomain = cookieDomain2; |
657 |
0 |
break; |
658 |
|
} |
659 |
|
} |
660 |
|
} |
661 |
|
|
662 |
921 |
if (cookieDomain != null) { |
663 |
0 |
cookie.setDomain(cookieDomain); |
664 |
|
} |
665 |
|
|
666 |
921 |
if (LOGGER.isDebugEnabled()) { |
667 |
0 |
LOGGER.debug("Setting cookie " + cookie.getValue() + " for name " + cookie.getName() + " with domain " |
668 |
|
+ cookie.getDomain() + " and path " + cookie.getPath() + " and maxage " + cookie.getMaxAge()); |
669 |
|
} |
670 |
|
|
671 |
923 |
context.getResponse().addCookie(cookie); |
672 |
|
|
673 |
925 |
return cookie; |
674 |
|
} |
675 |
|
|
676 |
|
|
677 |
|
|
678 |
|
|
679 |
|
@param |
680 |
|
@return |
681 |
|
@since |
682 |
|
|
|
|
| 78.6% |
Uncovered Elements: 3 (14) |
Complexity: 3 |
Complexity Density: 0.3 |
|
683 |
925 |
public static boolean findCookie(XWikiContext context)... |
684 |
|
{ |
685 |
923 |
if (context.get(CONTPROP_STATS_COOKIE) != null) { |
686 |
0 |
return false; |
687 |
|
} |
688 |
|
|
689 |
922 |
Cookie cookie = Util.getCookie(COOKPROP_VISITID, context); |
690 |
924 |
boolean newcookie = false; |
691 |
|
|
692 |
|
|
693 |
922 |
if (cookie == null) { |
694 |
922 |
cookie = addCookie(context); |
695 |
924 |
newcookie = true; |
696 |
|
} |
697 |
|
|
698 |
924 |
context.put(CONTPROP_STATS_COOKIE, cookie); |
699 |
925 |
context.put(CONTPROP_STATS_NEWCOOKIE, Boolean.valueOf(newcookie)); |
700 |
|
|
701 |
925 |
return true; |
702 |
|
} |
703 |
|
|
704 |
|
|
705 |
|
@param |
706 |
|
@return |
707 |
|
@since |
708 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.38 |
|
709 |
0 |
public static String getReferer(XWikiContext context)... |
710 |
|
{ |
711 |
0 |
String referer = context.getRequest().getHeader(REQPROP_REFERER); |
712 |
|
|
713 |
0 |
try { |
714 |
0 |
URL url = new URL(referer); |
715 |
0 |
URL baseurl = context.getURL(); |
716 |
0 |
if (baseurl.getHost().equals(url.getHost())) { |
717 |
0 |
referer = null; |
718 |
|
} |
719 |
|
} catch (MalformedURLException e) { |
720 |
0 |
referer = null; |
721 |
|
} |
722 |
|
|
723 |
0 |
return referer; |
724 |
|
} |
725 |
|
|
726 |
|
|
727 |
|
|
728 |
|
|
729 |
|
@param |
730 |
|
@param |
731 |
|
@param |
732 |
|
@return |
733 |
|
@throws |
734 |
|
|
|
|
| 82.9% |
Uncovered Elements: 6 (35) |
Complexity: 8 |
Complexity Density: 0.38 |
|
735 |
7 |
private static Collection<DocumentReference> getFilteredUsers(String pref, String cfg, XWikiContext context)... |
736 |
|
throws XWikiException |
737 |
|
{ |
738 |
7 |
List<String> userList; |
739 |
|
|
740 |
7 |
String users = context.getWiki().getXWikiPreference(pref, "", context); |
741 |
|
|
742 |
7 |
if (StringUtils.isEmpty(users)) { |
743 |
7 |
users = context.getWiki().Param(cfg); |
744 |
|
} |
745 |
|
|
746 |
7 |
if (!StringUtils.isBlank(users)) { |
747 |
6 |
userList = new ArrayList<String>(); |
748 |
|
|
749 |
6 |
int begin = 0; |
750 |
6 |
boolean escaped = false; |
751 |
121 |
for (int i = 0; i < users.length(); ++i) { |
752 |
115 |
char c = users.charAt(i); |
753 |
|
|
754 |
115 |
if (!escaped) { |
755 |
115 |
if (c == '\\') { |
756 |
0 |
escaped = true; |
757 |
115 |
} else if (c == ',') { |
758 |
3 |
userList.add(users.substring(begin, i).replace(ESCAPED_LIST_SEPARATOR, LIST_SEPARATOR)); |
759 |
3 |
begin = i + 1; |
760 |
|
} |
761 |
|
} else { |
762 |
0 |
escaped = false; |
763 |
|
} |
764 |
|
} |
765 |
|
|
766 |
6 |
if (begin < users.length()) { |
767 |
6 |
userList.add(users.substring(begin).replace(ESCAPED_LIST_SEPARATOR, LIST_SEPARATOR)); |
768 |
|
} |
769 |
|
} else { |
770 |
1 |
userList = Collections.emptyList(); |
771 |
|
} |
772 |
|
|
773 |
7 |
return RightsManager.getInstance().resolveUsers(userList, context); |
774 |
|
} |
775 |
|
|
776 |
|
|
777 |
|
|
778 |
|
|
779 |
|
@param |
780 |
|
@return |
781 |
|
@throws |
782 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
783 |
0 |
public static Collection<DocumentReference> getStorageFilteredUsers(XWikiContext context) throws XWikiException... |
784 |
|
{ |
785 |
|
|
786 |
0 |
return getFilteredUsers(PREFPROP_EXCLUDEDUSERSANDGROUPS_STORAGE, CFGPROP_STATS_EXCLUDEDUSERSANDGROUPS_STORAGE, |
787 |
|
context); |
788 |
|
} |
789 |
|
|
790 |
|
|
791 |
|
|
792 |
|
|
793 |
|
@param |
794 |
|
@return |
795 |
|
@throws |
796 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
797 |
7 |
public static Collection<DocumentReference> getRequestFilteredUsers(XWikiContext context) throws XWikiException... |
798 |
|
{ |
799 |
|
|
800 |
7 |
Collection<DocumentReference> users = |
801 |
|
getFilteredUsers(PREFPROP_EXCLUDEDUSERSANDGROUPS_REQUEST, CFGPROP_STATS_EXCLUDEDUSERSANDGROUPS_REQUEST, |
802 |
|
context); |
803 |
|
|
804 |
7 |
return users != null ? users : getFilteredUsers(DEPRECATED_PREFPROP_EXCLUDEDUSERSANDGROUPS, |
805 |
|
DEPRECATED_CFGPROP_STATS_EXCLUDEDUSERSANDGROUPS, context); |
806 |
|
} |
807 |
|
} |