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.xwiki; |
21 |
|
|
22 |
|
import java.util.Date; |
23 |
|
import java.util.List; |
24 |
|
|
25 |
|
import org.slf4j.Logger; |
26 |
|
import org.slf4j.LoggerFactory; |
27 |
|
|
28 |
|
import com.xpn.xwiki.XWikiContext; |
29 |
|
import com.xpn.xwiki.XWikiException; |
30 |
|
import com.xpn.xwiki.stats.impl.StatsUtil.PeriodType; |
31 |
|
import com.xpn.xwiki.stats.impl.VisitStats; |
32 |
|
import com.xpn.xwiki.store.XWikiHibernateStore; |
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
@version |
38 |
|
@since |
39 |
|
|
|
|
| 0% |
Uncovered Elements: 28 (28) |
Complexity: 8 |
Complexity Density: 0.42 |
|
40 |
|
public class VisitStatsStoreItem extends AbstractStatsStoreItem |
41 |
|
{ |
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
private static final Logger LOGGER = LoggerFactory.getLogger(VisitStatsStoreItem.class); |
46 |
|
|
47 |
|
|
48 |
|
@link |
49 |
|
|
50 |
|
private VisitStats visitStats; |
51 |
|
|
52 |
|
|
53 |
|
@link |
54 |
|
|
55 |
|
@param@link |
56 |
|
@param |
57 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
58 |
0 |
public VisitStatsStoreItem(VisitStats visitStats, XWikiContext context)... |
59 |
|
{ |
60 |
0 |
super(visitStats.getName(), new Date(), PeriodType.MONTH, context); |
61 |
0 |
this.period = visitStats.getPeriod(); |
62 |
|
|
63 |
0 |
this.visitStats = (VisitStats) visitStats.clone(); |
64 |
|
} |
65 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
66 |
0 |
@Override... |
67 |
|
public String getId() |
68 |
|
{ |
69 |
0 |
return String.format("%s %s %s %s", getClass(), this.visitStats.getName(), this.visitStats.getUniqueID(), |
70 |
|
this.visitStats.getCookie()); |
71 |
|
} |
72 |
|
|
|
|
| 0% |
Uncovered Elements: 21 (21) |
Complexity: 6 |
Complexity Density: 0.4 |
|
73 |
0 |
@Override... |
74 |
|
public void storeInternal(List<XWikiStatsStoreItem> stats) |
75 |
|
{ |
76 |
0 |
VisitStatsStoreItem firstItem = (VisitStatsStoreItem) stats.get(0); |
77 |
0 |
VisitStats oldVisitStats = firstItem.visitStats.getOldObject(); |
78 |
|
|
79 |
0 |
VisitStatsStoreItem lastItem = (VisitStatsStoreItem) stats.get(stats.size() - 1); |
80 |
0 |
VisitStats newVisitStats = lastItem.visitStats; |
81 |
|
|
82 |
0 |
XWikiHibernateStore store = this.context.getWiki().getHibernateStore(); |
83 |
0 |
if (store == null) { |
84 |
0 |
return; |
85 |
|
} |
86 |
|
|
87 |
0 |
try { |
88 |
|
|
89 |
|
|
90 |
0 |
if (oldVisitStats != null) { |
91 |
0 |
try { |
92 |
|
|
93 |
0 |
store.deleteXWikiCollection(oldVisitStats, this.context, true, true); |
94 |
|
} catch (Exception e) { |
95 |
0 |
if (LOGGER.isWarnEnabled()) { |
96 |
0 |
LOGGER.error("Failed to delete old visit statistics object from database [{}]", getId(), e); |
97 |
|
} |
98 |
|
} |
99 |
|
} |
100 |
|
|
101 |
|
|
102 |
0 |
store.saveXWikiCollection(newVisitStats, this.context, true); |
103 |
|
} catch (XWikiException e) { |
104 |
0 |
LOGGER.error("Failed to save visit statistics object [{}]", getId(), e); |
105 |
|
} |
106 |
|
} |
107 |
|
} |