use of com.xpn.xwiki.stats.impl.RefererStats in project xwiki-platform by xwiki.
the class Document method getCurrentMonthRefStats.
/**
* Get referer statistics for the current document during the current month.
*
* @return a list of referer statistics for the document's space
*/
public List<RefererStats> getCurrentMonthRefStats() {
Scope scope = ScopeFactory.createPageScope(this.getFullName());
Range range = RangeFactory.ALL;
Period period = PeriodFactory.getCurrentMonth();
XWikiStatsService statisticsService = getXWikiContext().getWiki().getStatsService(getXWikiContext());
List<RefererStats> stats = statisticsService.getRefererStatistics("", scope, period, range, this.context);
return stats;
}
use of com.xpn.xwiki.stats.impl.RefererStats in project xwiki-platform by xwiki.
the class XWikiStatsReader method getRefererStatistics.
/**
* Converts the rows retrieved from the database to a list of {@link com.xpn.xwiki.stats.impl.RefererStats}
* instances.
*
* @param resultSet The result of a database query for referer statistics
* @return A list of {@link com.xpn.xwiki.stats.impl.RefererStats} objects
* @see #getRefererStatistics(String, Scope, Period, Range , XWikiContext)
*/
private List<RefererStats> getRefererStatistics(List<?> resultSet) {
Date now = new Date();
List<RefererStats> stats = new ArrayList<RefererStats>(resultSet.size());
for (Object name : resultSet) {
Object[] result = (Object[]) name;
// We can't represent a custom period (e.g. year, week or some time interval) in the
// database and thus we use a default one, which sould be ignored
RefererStats refStats = new RefererStats("", (String) result[0], now, PeriodType.DAY);
refStats.setPageViews(((Number) result[1]).intValue());
stats.add(refStats);
}
return stats;
}
use of com.xpn.xwiki.stats.impl.RefererStats in project xwiki-platform by xwiki.
the class RefererStatsStoreItem method storeInternal.
@Override
public void storeInternal(List<XWikiStatsStoreItem> stats) {
RefererStatsStoreItem lastItem = (RefererStatsStoreItem) stats.get(stats.size() - 1);
XWikiHibernateStore store = this.context.getWiki().getHibernateStore();
if (store == null) {
return;
}
RefererStats refererStat = new RefererStats(lastItem.name, lastItem.referer, lastItem.periodDate, lastItem.periodType);
// Load old statistics object from database
try {
// TODO Fix use of deprecated call.
store.loadXWikiCollection(refererStat, this.context, true);
} catch (XWikiException e) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Failed to load referer statictics object [" + getId() + "]");
}
}
// Increment counters
refererStat.setIntValue("pageViews", refererStat.getPageViews() + stats.size());
// Re-save statistics object
try {
// TODO Fix use of deprecated call.
store.saveXWikiCollection(refererStat, this.context, true);
} catch (XWikiException e) {
LOGGER.error("Failed to save referer statictics object [" + getId() + "]");
}
}
use of com.xpn.xwiki.stats.impl.RefererStats in project xwiki-platform by xwiki.
the class XWikiStatsReader method getRefererStatistics.
/**
* Retrieves referrer statistics.
*
* @param domain the domain for which to retrieve statistics. To retrieve statistics for all domains use the empty
* string.
* @param scope the scope of referred documents to use for filtering the results.
* @param period the period of time, including its start date but excluding its end date.
* @param range the sub-range to return from the entire result set. Use this parameter for pagination.
* @param context the XWiki context.
* @return a list of RefererStats objects.
*/
public List<RefererStats> getRefererStatistics(String domain, Scope scope, Period period, Range range, XWikiContext context) {
List<RefererStats> refererList;
List<Object> paramList = new ArrayList<Object>(4);
String nameFilter = getHqlNameFilterFromScope(scope, paramList);
String sortOrder = getHqlSortOrderFromRange(range);
XWikiHibernateStore store = context.getWiki().getHibernateStore();
try {
String query = MessageFormat.format("select referer, sum(pageViews) from RefererStats" + " where ({0}) and referer like ? and ? <= period and period < ?" + " group by referer order by sum(pageViews) {1}", nameFilter, sortOrder);
paramList.add(getHqlValidDomain(domain));
paramList.add(period.getStartCode());
paramList.add(period.getEndCode());
List<?> solist = store.search(query, range.getAbsoluteSize(), range.getAbsoluteStart(), paramList, context);
refererList = getRefererStatistics(solist);
if (range.getSize() < 0) {
Collections.reverse(refererList);
}
} catch (XWikiException e) {
refererList = Collections.emptyList();
}
return refererList;
}
Aggregations