Search in sources :

Example 1 with VisitStats

use of com.xpn.xwiki.stats.impl.VisitStats in project xwiki-platform by xwiki.

the class StopStatsStoreException method addStats.

/**
 * Add all the statistics to the save queue.
 *
 * @param doc the document.
 * @param action the user action.
 * @param context the XWiki context.
 */
public void addStats(XWikiDocument doc, String action, XWikiContext context) {
    VisitStats vobject = StatsUtil.findVisit(context);
    synchronized (vobject) {
        if (action.equals(ViewAction.VIEW_ACTION)) {
            // We count page views in the sessions only for the "view" action
            vobject.incPageViews();
        } else if (action.equals(SaveAction.ACTION_NAME)) {
            // We count "save" and "download" actions separately
            vobject.incPageSaves();
        } else if (action.equals(DownloadAction.ACTION_NAME)) {
            // We count "save" and "download" actions separately
            vobject.incDownloads();
        }
        addVisitStats(vobject, context);
        boolean isVisit = (vobject.getPageViews() == 1) && (action.equals(ViewAction.VIEW_ACTION));
        addDocumentStats(doc, action, isVisit, context);
    }
    // In case of a "view" action we want to store referer info
    if (action.equals(ViewAction.VIEW_ACTION)) {
        addRefererStats(doc, context);
    }
}
Also used : VisitStats(com.xpn.xwiki.stats.impl.VisitStats)

Example 2 with VisitStats

use of com.xpn.xwiki.stats.impl.VisitStats in project xwiki-platform by xwiki.

the class VisitStatsStoreItem method storeInternal.

@Override
public void storeInternal(List<XWikiStatsStoreItem> stats) {
    VisitStatsStoreItem firstItem = (VisitStatsStoreItem) stats.get(0);
    VisitStats oldVisitStats = firstItem.visitStats.getOldObject();
    VisitStatsStoreItem lastItem = (VisitStatsStoreItem) stats.get(stats.size() - 1);
    VisitStats newVisitStats = lastItem.visitStats;
    XWikiHibernateStore store = this.context.getWiki().getHibernateStore();
    if (store == null) {
        return;
    }
    try {
        // other one because the ID info have changed
        if (oldVisitStats != null) {
            try {
                // TODO Fix use of deprecated call.
                store.deleteXWikiCollection(oldVisitStats, this.context, true, true);
            } catch (Exception e) {
                if (LOGGER.isWarnEnabled()) {
                    LOGGER.error("Failed to delete old visit statistics object from database [{}]", getId(), e);
                }
            }
        }
        // TODO Fix use of deprecated call.
        store.saveXWikiCollection(newVisitStats, this.context, true);
    } catch (XWikiException e) {
        LOGGER.error("Failed to save visit statistics object [{}]", getId(), e);
    }
}
Also used : XWikiHibernateStore(com.xpn.xwiki.store.XWikiHibernateStore) VisitStats(com.xpn.xwiki.stats.impl.VisitStats) XWikiException(com.xpn.xwiki.XWikiException) XWikiException(com.xpn.xwiki.XWikiException)

Example 3 with VisitStats

use of com.xpn.xwiki.stats.impl.VisitStats in project xwiki-platform by xwiki.

the class XWikiStatsReader method getVisitStatistics.

/**
 * Converts the rows retrieved from the database to a list of VisitStats instances.
 *
 * @param resultSet the result of a database query for visitor statistics.
 * @param startDate the start date used in the query.
 * @param endDate the end date used in the query.
 * @return a list of {@link com.xpn.xwiki.stats.impl.VisitStats} objects.
 * @see #getVisitStatistics(String, Period, Range, XWikiContext)
 */
private List<VisitStats> getVisitStatistics(List<?> resultSet, DateTime startDate, DateTime endDate) {
    List<VisitStats> stats = new ArrayList<VisitStats>(resultSet.size());
    for (Object name2 : resultSet) {
        Object[] result = (Object[]) name2;
        String name = (String) result[0];
        String uniqueID = "";
        String cookie = "";
        String ip = "";
        String userAgent = "";
        int pageSaves = ((Number) result[1]).intValue();
        int pageViews = ((Number) result[2]).intValue();
        int downloads = ((Number) result[3]).intValue();
        VisitStats vs = new VisitStats(name, uniqueID, cookie, ip, userAgent, new Date(startDate.getMillis()), PeriodType.DAY);
        vs.setStartDate(new Date(startDate.getMillis()));
        vs.setEndDate(new Date(endDate.getMillis()));
        vs.setPageSaves(pageSaves);
        vs.setPageViews(pageViews);
        vs.setDownloads(downloads);
        stats.add(vs);
    }
    return stats;
}
Also used : VisitStats(com.xpn.xwiki.stats.impl.VisitStats) ArrayList(java.util.ArrayList) Date(java.util.Date)

Example 4 with VisitStats

use of com.xpn.xwiki.stats.impl.VisitStats in project xwiki-platform by xwiki.

the class XWikiStatsReader method getVisitStatistics.

/**
 * Retrieves visit statistics.
 *
 * @param action the action the results should be ordered by. It can be one of: "view", "save" or "download". If the
 *            action is "view" then the visitors are ordered by the number of pages they have viewed so far.
 * @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 VisitStats objects.
 */
public List<VisitStats> getVisitStatistics(String action, Period period, Range range, XWikiContext context) {
    List<VisitStats> visiStatList;
    List<Object> paramList = new ArrayList<Object>(2);
    String query = createVisitStatisticsQuery(action, period, range, paramList, context);
    XWikiHibernateStore store = context.getWiki().getHibernateStore();
    try {
        List<?> solist = store.search(query, range.getAbsoluteSize(), range.getAbsoluteStart(), paramList, context);
        visiStatList = getVisitStatistics(solist, new DateTime(period.getStart()), new DateTime(period.getEnd()));
        if (range.getSize() < 0) {
            Collections.reverse(visiStatList);
        }
    } catch (XWikiException e) {
        LOGGER.error("Faild to search for vist statistics", e);
        visiStatList = Collections.emptyList();
    }
    return visiStatList;
}
Also used : XWikiHibernateStore(com.xpn.xwiki.store.XWikiHibernateStore) VisitStats(com.xpn.xwiki.stats.impl.VisitStats) ArrayList(java.util.ArrayList) DateTime(org.joda.time.DateTime) XWikiException(com.xpn.xwiki.XWikiException)

Aggregations

VisitStats (com.xpn.xwiki.stats.impl.VisitStats)4 XWikiException (com.xpn.xwiki.XWikiException)2 XWikiHibernateStore (com.xpn.xwiki.store.XWikiHibernateStore)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)1 DateTime (org.joda.time.DateTime)1