Search in sources :

Example 16 with XWikiHibernateStore

use of com.xpn.xwiki.store.XWikiHibernateStore in project xwiki-platform by xwiki.

the class XWikiStatsReader method getDocumentStatistics.

/**
 * Retrieves document 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 documents are ordered by the number of times they have been viewed so far.
 * @param scope the set of documents for which to retrieve statistics.
 * @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 DocumentStats objects
 */
public List<DocumentStats> getDocumentStatistics(String action, Scope scope, Period period, Range range, XWikiContext context) {
    List<DocumentStats> documentStatsList;
    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 name, sum(pageViews) from DocumentStats" + " where ({0}) and action=? and ? <= period and period < ? group by name order" + " by sum(pageViews) {1}", nameFilter, sortOrder);
        paramList.add(action);
        paramList.add(period.getStartCode());
        paramList.add(period.getEndCode());
        List<?> solist = store.search(query, range.getAbsoluteSize(), range.getAbsoluteStart(), paramList, context);
        documentStatsList = getDocumentStatistics(solist, action);
        if (range.getSize() < 0) {
            Collections.reverse(documentStatsList);
        }
    } catch (XWikiException e) {
        documentStatsList = Collections.emptyList();
    }
    return documentStatsList;
}
Also used : DocumentStats(com.xpn.xwiki.stats.impl.DocumentStats) XWikiHibernateStore(com.xpn.xwiki.store.XWikiHibernateStore) ArrayList(java.util.ArrayList) XWikiException(com.xpn.xwiki.XWikiException)

Example 17 with XWikiHibernateStore

use of com.xpn.xwiki.store.XWikiHibernateStore 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)

Example 18 with XWikiHibernateStore

use of com.xpn.xwiki.store.XWikiHibernateStore 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;
}
Also used : RefererStats(com.xpn.xwiki.stats.impl.RefererStats) XWikiHibernateStore(com.xpn.xwiki.store.XWikiHibernateStore) ArrayList(java.util.ArrayList) XWikiException(com.xpn.xwiki.XWikiException)

Aggregations

XWikiHibernateStore (com.xpn.xwiki.store.XWikiHibernateStore)18 XWikiException (com.xpn.xwiki.XWikiException)15 ArrayList (java.util.ArrayList)7 XWikiContext (com.xpn.xwiki.XWikiContext)6 Session (org.hibernate.Session)6 DocumentStats (com.xpn.xwiki.stats.impl.DocumentStats)4 ActivityStreamException (com.xpn.xwiki.plugin.activitystream.api.ActivityStreamException)3 RefererStats (com.xpn.xwiki.stats.impl.RefererStats)2 VisitStats (com.xpn.xwiki.stats.impl.VisitStats)2 DataMigrationException (com.xpn.xwiki.store.migration.DataMigrationException)2 MalformedURLException (java.net.MalformedURLException)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 PersistentClass (org.hibernate.mapping.PersistentClass)2 Test (org.junit.Test)2 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 XWikiRCSNodeInfo (com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo)1 BaseObject (com.xpn.xwiki.objects.BaseObject)1 BaseObjectReference (com.xpn.xwiki.objects.BaseObjectReference)1 XWikiCacheStoreInterface (com.xpn.xwiki.store.XWikiCacheStoreInterface)1