Пример #1
0
  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;
  }
  @Test
  public void testCanRetrieveUsersEvents() throws Exception {
    us.registerUser(user);
    FeedEvent fe = new FeedEvent(user);
    fs.addEvent(fe);
    UserLoggedIn ule = new UserLoggedIn(user);
    fs.addEvent(ule);

    List<FeedEvent> list = fs.listByUser(user, 0, 0);
    assertEquals(3, list.size());
    for (FeedEvent feedEvent : list) {
      assertEquals(user, feedEvent.getUser());
    }
    assertTrue(list.contains(new UserRegistered(user)));
    assertTrue(list.contains(new FeedEvent(user)));
    assertTrue(list.contains(new UserLoggedIn(user)));
  }
 @Test
 public void testCanPersistFeedEvents() throws Exception {
   us.registerUser(user);
   FeedEvent e = new FeedEvent(user);
   assertFalse(e.isPersistent());
   fs.addEvent(e);
   assertTrue(e.isPersistent());
 }
  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;
  }