1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package com.xpn.xwiki.api

File StatsService.java

 

Coverage histogram

../../../../img/srcFileCovDistChart2.png
83% of files have more coverage

Code metrics

12
34
10
1
229
86
16
0.47
3.4
10
1.6

Classes

Class Line # Actions
StatsService 39 34 0% 16 47
0.1607142816.1%
 

Contributing tests

This file is covered by 26 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package com.xpn.xwiki.api;
21   
22    import java.util.Collections;
23    import java.util.List;
24    import java.util.Map;
25   
26    import com.xpn.xwiki.XWikiContext;
27    import com.xpn.xwiki.criteria.impl.Duration;
28    import com.xpn.xwiki.criteria.impl.Period;
29    import com.xpn.xwiki.criteria.impl.Range;
30    import com.xpn.xwiki.criteria.impl.Scope;
31    import com.xpn.xwiki.stats.api.XWikiStatsService;
32    import com.xpn.xwiki.stats.impl.StatsUtil;
33   
34    /**
35    * Statistics api. The Statistics module needs to be activated (xwiki.stats=1 in xwiki.cfg).
36    *
37    * @version $Id: a4ab447cf37d0e66a0b35eaa0f2c3626ebda4afc $
38    */
 
39    public class StatsService extends Api
40    {
41    /**
42    * Create new StatsService instance.
43    *
44    * @param context the XWiki context.
45    */
 
46  170769 toggle public StatsService(XWikiContext context)
47    {
48  170659 super(context);
49    }
50   
51    /**
52    * Indicate if statistics service is globally enabled. Note that it is possible for statistics to be enabled at the
53    * global level, yet disabled in most or even all wikis. When statistics are globally enabled, session statistics
54    * are available. To check if document statistics are enabled for the current wiki, use
55    * {@link #isEnabledForCurrentWiki()}.
56    * <p>
57    * To be true the <code>xwiki.stats</code> setting in xwiki.cfg has to be <code>1</code>.
58    * </p>
59    *
60    * @return {@code true} if the statistics module is enabled
61    */
 
62  0 toggle public boolean isEnabledGlobally()
63    {
64  0 return StatsUtil.isStatsEnabled(this.context);
65    }
66   
67    /**
68    * Indicate if statistics service is enabled for the current wiki.
69    * <p>
70    * To be true the <code>xwiki.stats</code> in xwiki.cfg has to be <code>1</code> and
71    * <code>xwiki.stats.default</code> too.
72    * </p>
73    * <p>
74    * <code>xwiki.stats.default</code> can be overwritten by <code>statistics</code> in <code>XWikiPreferences</code>.
75    * </p>
76    *
77    * @return true if statistics are enabled for the context's wiki.
78    */
 
79  0 toggle public boolean isEnabledForCurrentWiki()
80    {
81  0 return StatsUtil.isWikiStatsEnabled(this.context);
82    }
83   
84    /**
85    * Indicate if statistics service is enabled for the current wiki.
86    * <p>
87    * To be true the <code>xwiki.stats</code> in xwiki.cfg has to be <code>1</code> and
88    * <code>xwiki.stats.default</code> too.
89    * </p>
90    * <p>
91    * <code>xwiki.stats.default</code> can be overwritten by <code>statistics</code> in <code>XWikiPreferences</code>.
92    * </p>
93    *
94    * @return true if statistics are enabled for the context's wiki.
95    * @deprecated use {@link #isEnabledForCurrentWiki()}
96    */
 
97  0 toggle @Deprecated
98    public boolean isEnabled()
99    {
100  0 return StatsUtil.isWikiStatsEnabled(this.context);
101    }
102   
103    /**
104    * Retrieves document statistics.
105    *
106    * @param action The action the results should be ordered by. It can be one of: "view", "save" or "download". If the
107    * action is "view" then the documents are ordered by the number of times they have been viewed so far.
108    * @param scope The set of documents for which to retrieve statistics
109    * @param period The period of time
110    * @param range The sub-range to return from the entire result set. Use this parameter for pagination
111    * @return A list of DocumentStats objects
112    */
 
113  0 toggle public List<?> getDocumentStatistics(String action, Scope scope, Period period, Range range)
114    {
115  0 List<?> stats = Collections.emptyList();
116   
117  0 XWikiStatsService statsService = getXWikiContext().getWiki().getStatsService(getXWikiContext());
118  0 if (statsService != null) {
119  0 stats = statsService.getDocumentStatistics(action, scope, period, range, getXWikiContext());
120    }
121   
122  0 return stats;
123    }
124   
125    /**
126    * Retrieves visit statistics.
127    *
128    * @param action The action the results should be ordered by. It can be one of: "view", "save" or "download". If the
129    * action is "view" then the visitors are ordered by the number of pages they have viewed so far.
130    * @param period The period of time
131    * @param range The sub-range to return from the entire result set. Use this parameter for pagination
132    * @return A list of VisitStats objects
133    */
 
134  0 toggle public List<?> getVisitStatistics(String action, Period period, Range range)
135    {
136  0 List<?> stats = Collections.emptyList();
137   
138  0 XWikiStatsService statsService = getXWikiContext().getWiki().getStatsService(getXWikiContext());
139  0 if (statsService != null) {
140  0 stats = statsService.getVisitStatistics(action, period, range, getXWikiContext());
141    }
142   
143  0 return stats;
144    }
145   
146    /**
147    * Retrieves referrer statistics.
148    *
149    * @param domain The domain for which to retrieve statistics. To retrieve statistics for all domains use the empty
150    * string.
151    * @param scope The scope of referred documents to use for filtering the results.
152    * @param period The period of time
153    * @param range The sub-range to return from the entire result set. Use this parameter for pagination
154    * @return A list of RefererStats objects
155    */
 
156  0 toggle public List<?> getRefererStatistics(String domain, Scope scope, Period period, Range range)
157    {
158  0 List<?> stats = Collections.emptyList();
159   
160  0 XWikiStatsService statsService = getXWikiContext().getWiki().getStatsService(getXWikiContext());
161  0 if (statsService != null) {
162  0 stats = statsService.getRefererStatistics(domain, scope, period, range, getXWikiContext());
163    }
164   
165  0 return stats;
166    }
167   
168    /**
169    * Retrieves back-link statistics.
170    *
171    * @param domain the domain used for filtering the results
172    * @param scope the scope of referred documents for which to retrieve statistics.
173    * @param period the period of time
174    * @param range the sub-range to return from the entire result set. Use this parameter for pagination
175    * @return a list of DocumentStats objects
176    */
 
177  0 toggle public List<?> getBackLinkStatistics(String domain, Scope scope, Period period, Range range)
178    {
179  0 List<?> stats = Collections.emptyList();
180   
181  0 XWikiStatsService statsService = getXWikiContext().getWiki().getStatsService(getXWikiContext());
182  0 if (statsService != null) {
183  0 stats = statsService.getBackLinkStatistics(domain, scope, period, range, getXWikiContext());
184    }
185   
186  0 return stats;
187    }
188   
189    /**
190    * Shows how the statistics for the specified action have evolved over the specified period of time.
191    *
192    * @param action the action for which to retrieve statistics.
193    * @param scope the set of documents to consider.
194    * @param period the period of time.
195    * @param step the step used for sampling the period.
196    * @return a map of (date, actionCount) pairs.
197    */
 
198  0 toggle public Map<?, ?> getActionStatistics(String action, Scope scope, Period period,
199    Duration step)
200    {
201  0 Map<?, ?> stats = Collections.emptyMap();
202   
203  0 XWikiStatsService statsService = getXWikiContext().getWiki().getStatsService(getXWikiContext());
204  0 if (statsService != null) {
205  0 stats = statsService.getActionStatistics(action, scope, period, step, getXWikiContext());
206    }
207   
208  0 return stats;
209    }
210   
211    /**
212    * Returns the recently visited pages for a specific action.
213    *
214    * @param action ("view" or "edit").
215    * @param size how many recent actions to retrieve.
216    * @return a ArrayList of document names.
217    */
 
218  27 toggle public java.util.Collection<?> getRecentActions(String action, int size)
219    {
220  27 java.util.Collection<?> stats = Collections.emptyList();
221   
222  27 XWikiStatsService statsService = getXWikiContext().getWiki().getStatsService(getXWikiContext());
223  27 if (statsService != null) {
224  27 stats = statsService.getRecentActions(action, size, getXWikiContext());
225    }
226   
227  27 return stats;
228    }
229    }