public Feed subscribe(User user, String url, String title, FeedCategory category) {

    final String pubUrl = applicationSettingsService.get().getPublicUrl();
    if (StringUtils.isBlank(pubUrl)) {
      throw new FeedSubscriptionException("Public URL of this CommaFeed instance is not set");
    }
    if (url.startsWith(pubUrl)) {
      throw new FeedSubscriptionException(
          "Could not subscribe to a feed from this CommaFeed instance");
    }

    Feed feed = feedService.findOrCreate(url);

    FeedSubscription sub = feedSubscriptionDAO.findByFeed(user, feed);
    if (sub == null) {
      sub = new FeedSubscription();
      sub.setFeed(feed);
      sub.setUser(user);
    }
    sub.setCategory(category);
    sub.setPosition(0);
    sub.setTitle(FeedUtils.truncate(title, 128));
    feedSubscriptionDAO.saveOrUpdate(sub);

    taskGiver.add(feed, false);
    cache.invalidateUserRootCategory(user);
    return feed;
  }
Esempio n. 2
0
  @Path("/metrics")
  @GET
  @ApiOperation(value = "Retrieve server metrics")
  public Response getMetrics(@QueryParam("backlog") @DefaultValue("false") boolean backlog) {
    Map<String, Object> map = Maps.newLinkedHashMap();
    map.put("lastMinute", metricsBean.getLastMinute());
    map.put("lastHour", metricsBean.getLastHour());
    if (backlog) {
      map.put("backlog", taskGiver.getUpdatableCount());
    }
    map.put("http_active", feedRefreshWorker.getActiveCount());
    map.put("http_queue", feedRefreshWorker.getQueueSize());
    map.put("database_active", feedRefreshUpdater.getActiveCount());
    map.put("database_queue", feedRefreshUpdater.getQueueSize());
    map.put("cache", metricsBean.getCacheStats());

    return Response.ok(map).build();
  }
  public Feed subscribe(User user, String url, String title, FeedCategory category) {

    final String pubUrl = applicationSettingsService.get().getPublicUrl();
    if (StringUtils.isBlank(pubUrl)) {
      throw new FeedSubscriptionException("Public URL of this CommaFeed instance is not set");
    }
    if (url.startsWith(pubUrl)) {
      throw new FeedSubscriptionException(
          "Could not subscribe to a feed from this CommaFeed instance");
    }

    Feed feed = feedService.findOrCreate(url);

    FeedSubscription sub = feedSubscriptionDAO.findByFeed(user, feed);
    boolean newSubscription = false;
    if (sub == null) {
      sub = new FeedSubscription();
      sub.setFeed(feed);
      sub.setUser(user);
      newSubscription = true;
    }
    sub.setCategory(category);
    sub.setPosition(0);
    sub.setTitle(FeedUtils.truncate(title, 128));
    feedSubscriptionDAO.saveOrUpdate(sub);

    if (newSubscription) {
      List<FeedEntryStatus> statuses = Lists.newArrayList();
      List<FeedEntry> allEntries = feedEntryDAO.findByFeed(feed, 0, 10);
      for (FeedEntry entry : allEntries) {
        FeedEntryStatus status = new FeedEntryStatus();
        status.setEntry(entry);
        status.setRead(false);
        status.setSubscription(sub);
        statuses.add(status);
      }
      feedEntryStatusDAO.saveOrUpdate(statuses);
    }
    taskGiver.add(feed);
    return feed;
  }