Beispiel #1
0
 public long getUserCount() {
   long count = 0;
   try {
     Weblogger roller = WebloggerFactory.getWeblogger();
     UserManager mgr = roller.getUserManager();
     count = mgr.getUserCount();
   } catch (WebloggerException e) {
     log.error("Error getting user count for site", e);
   }
   return count;
 }
Beispiel #2
0
 /**
  * Get map with 26 entries, one for each letter A-Z and containing integers reflecting the number
  * of users whose names start with each letter.
  */
 public Map getUserNameLetterMap() {
   Map results = new HashMap();
   try {
     Weblogger roller = WebloggerFactory.getWeblogger();
     UserManager umgr = roller.getUserManager();
     results = umgr.getUserNameLetterMap();
   } catch (Exception e) {
     log.error("ERROR: fetching username letter map", e);
   }
   return results;
 }
Beispiel #3
0
 /** Get User object by username */
 public UserWrapper getUser(String username) {
   UserWrapper wrappedUser = null;
   try {
     Weblogger roller = WebloggerFactory.getWeblogger();
     UserManager umgr = roller.getUserManager();
     User user = umgr.getUserByUserName(username, Boolean.TRUE);
     wrappedUser = UserWrapper.wrap(user);
   } catch (Exception e) {
     log.error("ERROR: fetching users by letter", e);
   }
   return wrappedUser;
 }
Beispiel #4
0
 /**
  * Get pinned entries.
  *
  * @param sinceDays Only consider weblogs updated in the last sinceDays
  * @param length Max number of results to return
  */
 public List getPinnedWeblogEntries(int length) {
   List results = new ArrayList();
   try {
     Weblogger roller = WebloggerFactory.getWeblogger();
     WeblogEntryManager wmgr = roller.getWeblogEntryManager();
     List weblogs = wmgr.getWeblogEntriesPinnedToMain(new Integer(length));
     for (Iterator it = weblogs.iterator(); it.hasNext(); ) {
       WeblogEntry entry = (WeblogEntry) it.next();
       results.add(WeblogEntryWrapper.wrap(entry, urlStrategy));
     }
   } catch (Exception e) {
     log.error("ERROR: fetching pinned weblog entries", e);
   }
   return results;
 }
Beispiel #5
0
 /**
  * Get most commented weblog entries across all weblogs, as StatCount objects, in descending order
  * by number of comments.
  *
  * @param sinceDays Only consider weblogs updated in the last sinceDays
  * @param cats To limit results to list of category names
  * @param len Max number of results to return
  */
 public List getMostCommentedWeblogEntries(List cats, int sinceDays, int length) {
   List results = new ArrayList();
   Calendar cal = Calendar.getInstance();
   cal.setTime(new Date());
   cal.add(Calendar.DATE, -1 * sinceDays);
   Date startDate = cal.getTime();
   try {
     Weblogger roller = WebloggerFactory.getWeblogger();
     WeblogEntryManager wmgr = roller.getWeblogEntryManager();
     results = wmgr.getMostCommentedWeblogEntries(null, startDate, new Date(), 0, length);
   } catch (Exception e) {
     log.error("ERROR: fetching commented weblog entries list", e);
   }
   return results;
 }
Beispiel #6
0
 /*
  * Get most recent User objects, in reverse chrono order by creationDate.
  * @param offset   Offset into results (for paging)
  * @param len      Max number of results to return
  */
 public List getNewUsers(int sinceDays, int length) {
   List results = new ArrayList();
   try {
     Weblogger roller = WebloggerFactory.getWeblogger();
     UserManager umgr = roller.getUserManager();
     List users = umgr.getUsers(Boolean.TRUE, null, null, 0, length);
     for (Iterator it = users.iterator(); it.hasNext(); ) {
       User user = (User) it.next();
       results.add(UserWrapper.wrap(user));
     }
   } catch (Exception e) {
     log.error("ERROR: fetching weblog list", e);
   }
   return results;
 }
Beispiel #7
0
 /** Return list of users that belong to website. */
 public List getWeblogsUsers(String handle) {
   List results = new ArrayList();
   try {
     Weblogger roller = WebloggerFactory.getWeblogger();
     UserManager umgr = roller.getUserManager();
     Weblog website = WebloggerFactory.getWeblogger().getWeblogManager().getWeblogByHandle(handle);
     List<WeblogPermission> perms = umgr.getWeblogPermissions(website);
     for (WeblogPermission perm : perms) {
       results.add(UserWrapper.wrap(perm.getUser()));
     }
   } catch (Exception e) {
     log.error("ERROR: fetching weblog list", e);
   }
   return results;
 }
Beispiel #8
0
 /** Return list of weblogs that user belongs to. */
 public List getUsersWeblogs(String userName) {
   List results = new ArrayList();
   try {
     Weblogger roller = WebloggerFactory.getWeblogger();
     UserManager umgr = roller.getUserManager();
     User user = umgr.getUserByUserName(userName);
     List<WeblogPermission> perms = umgr.getWeblogPermissions(user);
     for (WeblogPermission perm : perms) {
       results.add(WeblogWrapper.wrap(perm.getWeblog(), urlStrategy));
     }
   } catch (Exception e) {
     log.error("ERROR: fetching weblog list", e);
   }
   return results;
 }
Beispiel #9
0
  /**
   * @param sinceDays
   * @param length
   * @return
   */
  public List getPopularTags(int sinceDays, int length) {
    List results = new ArrayList();
    Date startDate = null;
    if (sinceDays > 0) {
      Calendar cal = Calendar.getInstance();
      cal.setTime(new Date());
      cal.add(Calendar.DATE, -1 * sinceDays);
      startDate = cal.getTime();
    }

    try {
      Weblogger roller = WebloggerFactory.getWeblogger();
      WeblogEntryManager wmgr = roller.getWeblogEntryManager();
      results = wmgr.getPopularTags(null, startDate, 0, length);
    } catch (Exception e) {
      log.error("ERROR: fetching site tags list", e);
    }
    return results;
  }
  /** @inheritDoc */
  public void saveWeblogCategory(WeblogCategory cat) throws WebloggerException {
    boolean exists = getWeblogCategory(cat.getId()) != null;
    if (!exists && isDuplicateWeblogCategoryName(cat)) {
      throw new WebloggerException("Duplicate category name, cannot save category");
    }

    // update weblog last modified date.  date updated by saveWebsite()
    roller.getWeblogManager().saveWeblog(cat.getWeblog());
    this.strategy.store(cat);
  }
  /** @inheritDoc */
  public void removeWeblogCategory(WeblogCategory cat) throws WebloggerException {
    if (cat.retrieveWeblogEntries(false).size() > 0) {
      throw new WebloggerException("Cannot remove category with entries");
    }

    cat.getWeblog().getWeblogCategories().remove(cat);

    // remove cat
    this.strategy.remove(cat);

    if (cat.equals(cat.getWeblog().getBloggerCategory())) {
      cat.getWeblog().setBloggerCategory(null);
      this.strategy.store(cat.getWeblog());
    }

    // update weblog last modified date.  date updated by saveWebsite()
    roller.getWeblogManager().saveWeblog(cat.getWeblog());
  }
  /** @inheritDoc */
  public void removeWeblogEntry(WeblogEntry entry) throws WebloggerException {
    Weblog weblog = entry.getWebsite();

    CommentSearchCriteria csc = new CommentSearchCriteria();
    csc.setEntry(entry);

    // remove comments
    List<WeblogEntryComment> comments = getComments(csc);
    for (WeblogEntryComment comment : comments) {
      this.strategy.remove(comment);
    }

    // remove tag & tag aggregates
    if (entry.getTags() != null) {
      for (WeblogEntryTag tag : entry.getTags()) {
        removeWeblogEntryTag(tag);
      }
    }

    // remove attributes
    if (entry.getEntryAttributes() != null) {
      for (Iterator it = entry.getEntryAttributes().iterator(); it.hasNext(); ) {
        WeblogEntryAttribute att = (WeblogEntryAttribute) it.next();
        it.remove();
        this.strategy.remove(att);
      }
    }

    // remove entry
    this.strategy.remove(entry);

    // update weblog last modified date.  date updated by saveWebsite()
    if (entry.isPublished()) {
      roller.getWeblogManager().saveWeblog(weblog);
    }

    // remove entry from cache mapping
    this.entryAnchorToIdMap.remove(entry.getWebsite().getHandle() + ":" + entry.getAnchor());
  }
  // TODO: perhaps the createAnchor() and queuePings() items should go outside this method?
  public void saveWeblogEntry(WeblogEntry entry) throws WebloggerException {

    if (entry.getCategory() == null) {
      // Entry is invalid without category, so use weblog client cat
      WeblogCategory cat = entry.getWebsite().getBloggerCategory();
      if (cat == null) {
        // Still no category, so use first one found
        cat = entry.getWebsite().getWeblogCategories().iterator().next();
      }
      entry.setCategory(cat);
    }

    // Entry is invalid without local. if missing use weblog default
    if (entry.getLocale() == null) {
      entry.setLocale(entry.getWebsite().getLocale());
    }

    if (entry.getAnchor() == null || entry.getAnchor().trim().equals("")) {
      entry.setAnchor(this.createAnchor(entry));
    }

    if (entry.isPublished()) {
      // tag aggregates are updated only when entry published in order for
      // tag cloud counts to match published articles
      if (entry.getRefreshAggregates()) {
        // blog entry wasn't published before, so all tags need to be incremented
        for (WeblogEntryTag tag : entry.getTags()) {
          updateTagCount(tag.getName(), entry.getWebsite(), 1);
        }
      } else {
        // only new tags need to be incremented
        for (WeblogEntryTag tag : entry.getAddedTags()) {
          updateTagCount(tag.getName(), entry.getWebsite(), 1);
        }
      }
    } else {
      if (entry.getRefreshAggregates()) {
        // blog entry no longer published so need to reduce aggregate count
        for (WeblogEntryTag tag : entry.getTags()) {
          updateTagCount(tag.getName(), entry.getWebsite(), -1);
        }
      }
    }

    for (WeblogEntryTag tag : entry.getRemovedTags()) {
      removeWeblogEntryTag(tag);
    }

    // if the entry was published to future, set status as SCHEDULED
    // we only consider an entry future published if it is scheduled
    // more than 1 minute into the future
    if (PubStatus.PUBLISHED.equals(entry.getStatus())
        && entry
            .getPubTime()
            .after(new Date(System.currentTimeMillis() + RollerConstants.MIN_IN_MS))) {
      entry.setStatus(PubStatus.SCHEDULED);
    }

    // Store value object (creates new or updates existing)
    entry.setUpdateTime(new Timestamp(new Date().getTime()));

    this.strategy.store(entry);

    // update weblog last modified date.  date updated by saveWebsite()
    if (entry.isPublished()) {
      roller.getWeblogManager().saveWeblog(entry.getWebsite());
    }

    if (entry.isPublished()) {
      // Queue applicable pings for this update.
      roller.getAutopingManager().queueApplicableAutoPings(entry);
    }
  }
  /** @inheritDoc */
  public void removeComment(WeblogEntryComment comment) throws WebloggerException {
    this.strategy.remove(comment);

    // update weblog last modified date.  date updated by saveWebsite()
    roller.getWeblogManager().saveWeblog(comment.getWeblogEntry().getWebsite());
  }