/** * Get list of WebsiteDisplay objects, ordered by number of hits. * * @param sinceDays Only consider weblogs updated in the last sinceDays * @param len Max number of results to return */ public List getHotWeblogs(int sinceDays, int length) { List results = new ArrayList(); try { WeblogEntryManager mgr = WebloggerFactory.getWeblogger().getWeblogEntryManager(); List hotBlogs = mgr.getHotWeblogs(sinceDays, 0, length); Iterator hitCounts = hotBlogs.iterator(); while (hitCounts.hasNext()) { WeblogHitCount hitCount = (WeblogHitCount) hitCounts.next(); StatCount statCount = new StatCount( hitCount.getWeblog().getId(), hitCount.getWeblog().getHandle(), hitCount.getWeblog().getName(), "statCount.weblogDayHits", hitCount.getDailyHits()); statCount.setWeblogHandle(hitCount.getWeblog().getHandle()); results.add(statCount); } } catch (Exception e) { log.error("ERROR: fetching hot weblog list", e); } return results; }
/** @inheritDoc */ public List<StatCount> getMostCommentedWeblogEntries( Weblog website, Date startDate, Date endDate, int offset, int length) throws WebloggerException { TypedQuery<WeblogEntryComment> query; List queryResults; Timestamp end = new Timestamp(endDate != null ? endDate.getTime() : new Date().getTime()); if (website != null) { if (startDate != null) { Timestamp start = new Timestamp(startDate.getTime()); query = strategy.getNamedQuery( "WeblogEntryComment.getMostCommentedWeblogEntryByWebsite&EndDate&StartDate", WeblogEntryComment.class); query.setParameter(1, website); query.setParameter(2, end); query.setParameter(3, start); } else { query = strategy.getNamedQuery( "WeblogEntryComment.getMostCommentedWeblogEntryByWebsite&EndDate", WeblogEntryComment.class); query.setParameter(1, website); query.setParameter(2, end); } } else { if (startDate != null) { Timestamp start = new Timestamp(startDate.getTime()); query = strategy.getNamedQuery( "WeblogEntryComment.getMostCommentedWeblogEntryByEndDate&StartDate", WeblogEntryComment.class); query.setParameter(1, end); query.setParameter(2, start); } else { query = strategy.getNamedQuery( "WeblogEntryComment.getMostCommentedWeblogEntryByEndDate", WeblogEntryComment.class); query.setParameter(1, end); } } if (offset != 0) { query.setFirstResult(offset); } if (length != -1) { query.setMaxResults(length); } queryResults = query.getResultList(); List<StatCount> results = new ArrayList<StatCount>(); if (queryResults != null) { for (Object obj : queryResults) { Object[] row = (Object[]) obj; StatCount sc = new StatCount( (String) row[1], // weblog handle (String) row[2], // entry anchor (String) row[3], // entry title "statCount.weblogEntryCommentCountType", // stat desc ((Long) row[0])); // count sc.setWeblogHandle((String) row[1]); results.add(sc); } } // Original query ordered by desc count. // JPA QL doesn't allow queries to be ordered by agregates; do it in memory Collections.sort(results, STAT_COUNT_COUNT_REVERSE_COMPARATOR); return results; }