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.DocumentStats; |
31 |
|
import com.xpn.xwiki.stats.impl.StatsUtil.PeriodType; |
32 |
|
import com.xpn.xwiki.store.XWikiHibernateStore; |
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
@version |
38 |
|
@since |
39 |
|
|
|
|
| 0% |
Uncovered Elements: 30 (30) |
Complexity: 8 |
Complexity Density: 0.38 |
|
40 |
|
public class DocumentStatsStoreItem extends AbstractStatsStoreItem |
41 |
|
{ |
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
private static final Logger LOGGER = LoggerFactory.getLogger(DocumentStatsStoreItem.class); |
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
private String action; |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
private boolean isVisit; |
56 |
|
|
57 |
|
|
58 |
|
@link |
59 |
|
|
60 |
|
@param |
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
@param |
67 |
|
@param |
68 |
|
@param |
69 |
|
@param |
70 |
|
@param |
71 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
72 |
0 |
public DocumentStatsStoreItem(String name, Date periodDate, PeriodType periodType, String action, boolean isVisit,... |
73 |
|
XWikiContext context) |
74 |
|
{ |
75 |
0 |
super(name, periodDate, periodType, context); |
76 |
|
|
77 |
0 |
this.action = action; |
78 |
0 |
this.isVisit = isVisit; |
79 |
|
} |
80 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
81 |
0 |
@Override... |
82 |
|
public String getId() |
83 |
|
{ |
84 |
0 |
return String.format("%s %s %s %s", getClass(), this.name, this.action, this.period); |
85 |
|
} |
86 |
|
|
|
|
| 0% |
Uncovered Elements: 23 (23) |
Complexity: 6 |
Complexity Density: 0.35 |
|
87 |
0 |
@Override... |
88 |
|
public void storeInternal(List<XWikiStatsStoreItem> stats) |
89 |
|
{ |
90 |
0 |
DocumentStatsStoreItem lastItem = (DocumentStatsStoreItem) stats.get(stats.size() - 1); |
91 |
|
|
92 |
0 |
XWikiHibernateStore store = this.context.getWiki().getHibernateStore(); |
93 |
0 |
if (store == null) { |
94 |
0 |
return; |
95 |
|
} |
96 |
|
|
97 |
0 |
DocumentStats documentStat = |
98 |
|
new DocumentStats(lastItem.name, lastItem.action, lastItem.periodDate, lastItem.periodType); |
99 |
|
|
100 |
|
|
101 |
0 |
try { |
102 |
|
|
103 |
0 |
store.loadXWikiCollection(documentStat, this.context, true); |
104 |
|
} catch (XWikiException e) { |
105 |
0 |
if (LOGGER.isDebugEnabled()) { |
106 |
0 |
LOGGER.debug("Failed to load document statistics object [{}]", getId(), e); |
107 |
|
} |
108 |
|
} |
109 |
|
|
110 |
|
|
111 |
0 |
documentStat.setIntValue("pageViews", documentStat.getPageViews() + stats.size()); |
112 |
0 |
for (XWikiStatsStoreItem statItem : stats) { |
113 |
0 |
DocumentStatsStoreItem docStat = (DocumentStatsStoreItem) statItem; |
114 |
|
|
115 |
0 |
if (docStat.isVisit) { |
116 |
0 |
documentStat.incVisits(); |
117 |
|
} |
118 |
|
} |
119 |
|
|
120 |
|
|
121 |
0 |
try { |
122 |
|
|
123 |
0 |
store.saveXWikiCollection(documentStat, this.context, true); |
124 |
|
} catch (XWikiException e) { |
125 |
0 |
LOGGER.error("Failed to save document statistics object [{}]", getId(), e); |
126 |
|
} |
127 |
|
} |
128 |
|
} |