Package org.rssowl.core.persist.reference

Examples of org.rssowl.core.persist.reference.FeedReference


    NewsListener newsListener = null;
    AttachmentListener attachmentListener = null;
    try {
      final URI feedURI = new URI("http://www.foobar.com");
      IFeed feed = fFactory.createFeed(null, feedURI);
      FeedReference feedReference = new FeedReference(DynamicDAO.save(feed).getId());

      /* Check News Added */
      final INews news = fFactory.createNews(null, feedReference.resolve(), new Date());
      news.setTitle("News Title");
      final IAttachment attachment1 = fFactory.createAttachment(null, news);
      attachment1.setLink(new URI("http://www.attachment1.com"));
      DynamicDAO.save(news);

View Full Code Here


      };
      DynamicDAO.addEntityListener(IFolder.class, folderListener);

      /* Check BookMark Deleted */
      final IFeed feed = fFactory.createFeed(null, new URI("http://www.feed.com"));
      final FeedReference feedRef = new FeedReference(DynamicDAO.save(feed).getId());

      IBookMark bookMark1 = fFactory.createBookMark(null, rootRef.resolve(), new FeedLinkReference(feed.getLink()), "Root BookMark");
      root = DynamicDAO.save(bookMark1.getParent());
      final BookMarkReference bookMarkRef1 = new BookMarkReference(root.getMarks().get(0).getId());

      IBookMark bookMark2 = fFactory.createBookMark(null, rootChildRef.resolve(), new FeedLinkReference(feed.getLink()), "Root Child BookMark");
      rootChild = DynamicDAO.save(bookMark2.getParent());
      final BookMarkReference bookMarkRef2 = new BookMarkReference(rootChild.getMarks().get(0).getId());

      IBookMark bookMark3 = fFactory.createBookMark(null, rootChildChild1Ref.resolve(), new FeedLinkReference(feed.getLink()), "Root Child Child #1 BookMark");
      rootChildChild1 = DynamicDAO.save(bookMark3.getParent());
      final BookMarkReference bookMarkRef3 = new BookMarkReference(rootChildChild1.getMarks().get(0).getId());

      final boolean bookMarkEventsIssued[] = new boolean[3];
      final boolean feedEventsIssued[] = new boolean[1];

      bookMarkListener = new BookMarkAdapter() {
        @Override
        public void entitiesDeleted(Set<BookMarkEvent> events) {
          for (BookMarkEvent event : events) {
            IBookMark bookMark = event.getEntity();

            if (bookMarkRef1.references(bookMark))
              bookMarkEventsIssued[0] = true;

            else if (bookMarkRef2.references(bookMark))
              bookMarkEventsIssued[1] = true;

            else if (bookMarkRef3.references(bookMark))
              bookMarkEventsIssued[2] = true;
          }
        }
      };
      DynamicDAO.addEntityListener(IBookMark.class, bookMarkListener);

      feedListener = new FeedAdapter() {
        @Override
        public void entitiesDeleted(Set<FeedEvent> events) {
          for (FeedEvent event : events) {
            assertFalse("Already received feed deleted event!", feedEventsIssued[0]);
            if (feedRef.references(event.getEntity()))
              feedEventsIssued[0] = true;
          }
        }
      };
      DynamicDAO.addEntityListener(IFeed.class, feedListener);
View Full Code Here

      /* Check Feed Deleted and News Deleted */
      final IFeed feed = fFactory.createFeed(null, new URI("http://www.foobar.com"));
      final IPerson person1 = fFactory.createPerson(null, feed);
      person1.setName("Person1");
      final FeedReference feedRef = new FeedReference(DynamicDAO.save(feed).getId());
      final PersonReference personRef1 = new PersonReference(feedRef.resolve().getAuthor().getId());
      final boolean feedDeleted[] = new boolean[1];
      final boolean newsDeletedFromFeed[] = new boolean[1];
      feedListener = new FeedAdapter() {
        @Override
        public void entitiesDeleted(Set<FeedEvent> events) {
          for (FeedEvent event : events) {
            assertFalse("Already received feedDeleted Event", feedDeleted[0]);
            assertTrue("Expected this Event to be Root Event", event.isRoot());

            if (feedRef.references(event.getEntity()))
              feedDeleted[0] = true;
          }
        }
      };
      DynamicDAO.addEntityListener(IFeed.class, feedListener);

      /* Check News Deleted */
      final INews news1 = fFactory.createNews(null, feedRef.resolve(), new Date());
      news1.setTitle("News1 Title");
      news1.setLink(new URI("http://www.news.com/news1.html"));
      final IPerson person2 = fFactory.createPerson(null, news1);
      person2.setName("Person2");
      fFactory.createSource(news1).setLink(new URI("http://www.source1.com"));
      fFactory.createGuid(news1, "Guid1", null);

      final NewsReference[] newsRef = new NewsReference[1];
      newsAdapter = new NewsAdapter() {
        @Override
        public void entitiesAdded(Set<NewsEvent> events) {
          assertEquals(1, events.size());
          newsRef[0] = new NewsReference(events.iterator().next().getEntity().getId());
        }
      };
      DynamicDAO.addEntityListener(INews.class, newsAdapter);
      /* Must save parent because it gets changed during creation of news */
      DynamicDAO.save(feedRef.resolve());
      final NewsReference newsRef1 = newsRef[0];
      final PersonReference personRef2 = new PersonReference(newsRef1.resolve().getAuthor().getId());

      final INews news2 = fFactory.createNews(null, feedRef.resolve(), new Date());
      news2.setTitle("News2 Title");
      news2.setLink(new URI("http://www.news.com/news2.html"));
      fFactory.createSource(news2).setLink(new URI("http://www.source2.com"));
      fFactory.createGuid(news2, "Guid2", null);
      /* Must save parent because it gets changed during creation of news */
      DynamicDAO.save(feedRef.resolve());
      final NewsReference newsRef2 = newsRef[0];

      final INews news3 = fFactory.createNews(null, feedRef.resolve(), new Date());
      news3.setTitle("News3 Title");
      news3.setLink(new URI("http://www.news.com/news3.html"));
      fFactory.createSource(news3).setLink(new URI("http://www.source3.com"));
      fFactory.createGuid(news3, "Guid3", null);
      /* Must save parent because it gets changed during creation of news */
      DynamicDAO.save(feedRef.resolve());
      final NewsReference newsRef3 = newsRef[0];

      final boolean newsDeleted[] = new boolean[3];
      newsListener = new NewsAdapter() {
        @Override
        public void entitiesDeleted(Set<NewsEvent> events) {
          for (NewsEvent event : events) {
            assertFalse("Expected this Event to be no Root Event", event.isRoot());

            NewsReference newsRef = new NewsReference(event.getEntity().getId());

            if (newsRef.equals(newsRef1))
              newsDeleted[0] = true;

            else if (newsRef.equals(newsRef2))
              newsDeleted[1] = true;

            else if (newsRef.equals(newsRef3))
              newsDeleted[2] = true;
          }

          if (events.size() == 3)
            newsDeletedFromFeed[0] = true;
        }
      };
      DynamicDAO.addEntityListener(INews.class, newsListener);

      /* Check Attachment Deleted */
      final IAttachment attachment1 = fFactory.createAttachment(null, newsRef1.resolve());
      final AttachmentReference attachmentRef1 = new AttachmentReference(DynamicDAO.save(attachment1).getId());
      final IAttachment attachment2 = fFactory.createAttachment(null, newsRef2.resolve());
      final AttachmentReference attachmentRef2 = new AttachmentReference(DynamicDAO.save(attachment2).getId());
      final IAttachment attachment3 = fFactory.createAttachment(null, newsRef3.resolve());
      final AttachmentReference attachmentRef3 = new AttachmentReference(DynamicDAO.save(attachment3).getId());

      final boolean attachmentDeleted[] = new boolean[3];
      attachmentListener = new AttachmentAdapter() {
        @Override
        public void entitiesDeleted(Set<AttachmentEvent> events) {
          for (AttachmentEvent event : events) {
            assertFalse("Expected this Event to be no Root Event", event.isRoot());

            IAttachment attachment = event.getEntity();

            if (attachmentRef1.references(attachment))
              attachmentDeleted[0] = true;

            else if (attachmentRef2.references(attachment))
              attachmentDeleted[1] = true;

            else if (attachmentRef3.references(attachment))
              attachmentDeleted[2] = true;
          }
        }
      };
      DynamicDAO.addEntityListener(IAttachment.class, attachmentListener);

      /* Check Person Deleted */
      final boolean personDeleted[] = new boolean[2];
      personListener = new PersonAdapter() {
        @Override
        public void entitiesDeleted(Set<PersonEvent> events) {
          for (PersonEvent event : events) {
            assertFalse("Expected this Event to be no Root Event", event.isRoot());

            IPerson person = event.getEntity();
            if (personRef1.references(person))
              personDeleted[0] = true;

            else if (personRef2.references(person))
              personDeleted[1] = true;
          }
        }
      };
      DynamicDAO.addEntityListener(IPerson.class, personListener);

      /* Check Category Deleted */
      final ICategory category1 = fFactory.createCategory(null, newsRef1.resolve());
      final CategoryReference categoryRef1 = new CategoryReference(DynamicDAO.save(category1).getId());
      final ICategory category2 = fFactory.createCategory(null, newsRef2.resolve());
      final CategoryReference categoryRef2 = new CategoryReference(DynamicDAO.save(category2).getId());

      final boolean categoryDeleted[] = new boolean[2];
      categoryListener = new CategoryAdapter() {
        @Override
        public void entitiesDeleted(Set<CategoryEvent> events) {
          for (CategoryEvent event : events) {
            assertFalse("Expected this Event to be no Root Event", event.isRoot());

            ICategory category = event.getEntity();

            if (categoryRef1.references(category))
              categoryDeleted[0] = true;

            else if (categoryRef2.references(category))
              categoryDeleted[1] = true;
          }
        }
      };
      DynamicDAO.addEntityListener(ICategory.class, categoryListener);

      /* Delete Feed */
      DynamicDAO.delete(feedRef.resolve());

      /* Asserts Follow */
      assertTrue("Missed feedDeleted Event in FeedListener!", feedDeleted[0]);
      assertTrue("Set<NewsEvent> in feedDeleted of FeedListener did not contain 3 News-References!", newsDeletedFromFeed[0]);

View Full Code Here

    CategoryListener categoryListener = null;
    try {

      /* Store a Feed */
      IFeed feed = fFactory.createFeed(null, new URI("http://www.foobar.com"));
      FeedReference feedRef = new FeedReference(DynamicDAO.save(feed).getId());

      /* Create a News */
      final INews news = fFactory.createNews(null, feedRef.resolve(), new Date());
      news.setTitle("News Title");
      final IPerson person = fFactory.createPerson(null, news);
      person.setName("Person Name");
      fFactory.createCategory(null, news);
      fFactory.createSource(news);
View Full Code Here

    /* Save some Feeds first */
    final List<FeedReference> feedRefs = new ArrayList<FeedReference>();
    final List<IFeed> feeds = interpretFeedsHelper();
    final int limit = feeds.size() / 2;
    for (int i = 0; i < limit; i++)
      feedRefs.add(new FeedReference(DynamicDAO.save(feeds.get(i)).getId()));

    /* Tasks to resolve Feeds */
    for (int i = 0; i < limit; i++) {
      final int a = i;

View Full Code Here

  private List<FeedReference> saveFeedsHelper() throws PersistenceException {
    List<IFeed> feeds = interpretFeedsHelper();
    List<FeedReference> feedRefs = new ArrayList<FeedReference>();
    for (IFeed feed : feeds)
      feedRefs.add(new FeedReference(DynamicDAO.save(feed).getId()));

    return feedRefs;
  }
View Full Code Here

  public synchronized boolean removeNews(INews news) {
    return fNews.remove(news);
  }

  public FeedReference toReference() {
    return new FeedReference(getIdAsPrimitive());
  }
View Full Code Here

    /* Initial Add News */
    String url = "http://www.feed-case1.com";
    IFeed feed = createFeed(url);
    final String newsTitle = "News Title Case_1";
    fFactory.createNews(null, feed, new Date()).setTitle(newsTitle);
    FeedReference feedRef = new FeedReference(DynamicDAO.save(feed).getId());

    /*
     * Recreate the feed because the existing one got changed when it was saved
     */
    feed = createFeed(url);

    /* a) Different publish date and news to be merged is in NEW state */
    INews news = fFactory.createNews(null, feed, new Date());
    news.setTitle(newsTitle);
    news.setPublishDate(new Date());

    IFeed mergedFeed = feedRef.resolve();
    mergedFeed.merge(feed);
    feedRef = new FeedReference(DynamicDAO.save(mergedFeed).getId());
    assertEquals("Same News was added twice!", 1, feedRef.resolve().getNews().size());
    assertEquals("Existing News State changed unexpectedly!", INews.State.NEW, feedRef.resolve().getNews().get(0).getState());

    /* b) Different publish date and news to be merged is in DELETED state */
    feed = createFeed(url);
    news = fFactory.createNews(null, feed, new Date());
    news.setTitle(newsTitle);
    news.setPublishDate(new Date());
    news.setState(State.DELETED);

    mergedFeed = feedRef.resolve();
    mergedFeed.merge(feed);
    feedRef = new FeedReference(DynamicDAO.save(mergedFeed).getId());
    assertEquals("Same News was added twice!", 1, feedRef.resolve().getNews().size());
    assertEquals("Existing News State changed unexpectedly!", INews.State.DELETED, feedRef.resolve().getNews().get(0).getState());

    /* c) Different publish date and news to be merged is in HIDDEN state */
    feed = createFeed(url);
    news = fFactory.createNews(null, feed, new Date());
    news.setTitle(newsTitle);
    news.setPublishDate(new Date());
    news.setState(State.HIDDEN);

    mergedFeed = feedRef.resolve();
    mergedFeed.merge(feed);
    feedRef = new FeedReference(DynamicDAO.save(mergedFeed).getId());
    assertEquals("Same News was added twice!", 1, feedRef.resolve().getNews().size());
    assertEquals("Existing News State changed unexpectedly!", INews.State.HIDDEN, feedRef.resolve().getNews().get(0).getState());

    /* d) Different publish date and news to be merged is in READ state */
    feed = createFeed(url);
    news = fFactory.createNews(null, feed, new Date());
    news.setTitle(newsTitle);
    news.setPublishDate(new Date());
    news.setState(State.READ);

    mergedFeed = feedRef.resolve();
    mergedFeed.merge(feed);
    feedRef = new FeedReference(DynamicDAO.save(mergedFeed).getId());
    assertEquals("Same News was added twice!", 1, feedRef.resolve().getNews().size());
    assertEquals("Existing News State changed unexpectedly!", INews.State.READ, feedRef.resolve().getNews().get(0).getState());

    /* e) Different publish date and news to be merged is in UNREAD state */
    feed = createFeed(url);
    news = fFactory.createNews(null, feed, new Date());
    news.setTitle(newsTitle);
    news.setPublishDate(new Date());
    news.setState(State.UNREAD);

    mergedFeed = feedRef.resolve();
    mergedFeed.merge(feed);
    feedRef = new FeedReference(DynamicDAO.save(mergedFeed).getId());
    assertEquals("Same News was added twice!", 1, feedRef.resolve().getNews().size());
    assertEquals("Existing News State changed unexpectedly!", INews.State.UNREAD, feedRef.resolve().getNews().get(0).getState());

    /* f) Different publish date and news to be merged is in UPDATED state */
    feed = createFeed(url);
    news = fFactory.createNews(null, feed, new Date());
    news.setTitle(newsTitle);
    news.setPublishDate(new Date());
    news.setState(State.UPDATED);

    mergedFeed = feedRef.resolve();
    mergedFeed.merge(feed);
    feedRef = new FeedReference(DynamicDAO.save(mergedFeed).getId());
    assertEquals("Same News was added twice!", 1, feedRef.resolve().getNews().size());
    assertEquals("Existing News State changed unexpectedly!", INews.State.UPDATED, feedRef.resolve().getNews().get(0).getState());

    /*
     * g) Different publish date and news to be merged is in NEW state, but
     * existing News is in UPDATED state
     */
    feed = createFeed(url);
    news = fFactory.createNews(null, feed, new Date());
    news.setTitle(newsTitle);
    news.setPublishDate(new Date());
    news.setState(State.NEW);

    mergedFeed = feedRef.resolve();
    mergedFeed.merge(feed);
    feedRef = new FeedReference(DynamicDAO.save(mergedFeed).getId());
    assertEquals("Same News was added twice!", 1, feedRef.resolve().getNews().size());
    assertEquals("Existing News State changed unexpectedly!", INews.State.UPDATED, feedRef.resolve().getNews().get(0).getState());
  }
View Full Code Here

  public void testHandleFeedReloadWithRetentionStrategy() throws Exception {
    IFeed feed = fFactory.createFeed(null, new URI("http://www.rssowl.org"));
    IFolder folder = fFactory.createFolder(null, null, "Folder");
    IBookMark mark = fFactory.createBookMark(null, folder, new FeedLinkReference(feed.getLink()), "Mark");
    DynamicDAO.save(feed);
    FeedReference feedRef = new FeedReference(feed.getId());
    DynamicDAO.save(folder);

    IFeed emptyFeed = fFactory.createFeed(null, feed.getLink());
    INews news = fFactory.createNews(null, emptyFeed, new Date());
    news.setState(INews.State.READ);

    Owl.getPreferenceService().getEntityScope(mark).putBoolean(DefaultPreferences.DEL_READ_NEWS_STATE, true);
    fAppService.handleFeedReload(mark, emptyFeed, null, false, new NullProgressMonitor());

    feed = null;
    System.gc();

    feed = feedRef.resolve();
    assertEquals(1, feed.getNews().size());
    assertEquals(0, feed.getVisibleNews().size());
    assertEquals(INews.State.DELETED, DynamicDAO.load(INews.class, news.getId()).getState());
  }
View Full Code Here

      news.setGuid(fFactory.createGuid(news, String.valueOf(i), true));
    }
    IFolder folder = fFactory.createFolder(null, null, "Folder");
    IBookMark mark = fFactory.createBookMark(null, folder, new FeedLinkReference(feed.getLink()), "Mark");
    DynamicDAO.save(feed);
    FeedReference feedRef = new FeedReference(feed.getId());
    DynamicDAO.save(folder);

    int i = 0;
    int deletedNewsCount = 40;
    for (INews news : feed.getNews()) {
      if (i == deletedNewsCount)
        break;

      news.setState(State.DELETED);
      ++i;
    }

    IFeed emptyFeed = fFactory.createFeed(null, feed.getLink());

    fAppService.handleFeedReload(mark, emptyFeed, null, false, new NullProgressMonitor());

    feed = null;
    System.gc();

    feed = feedRef.resolve();
    int expectedNewsCount = totalNews - deletedNewsCount;
    assertEquals(expectedNewsCount, feed.getNews().size());
    assertEquals(expectedNewsCount, DynamicDAO.loadAll(INews.class).size());
  }
View Full Code Here

TOP

Related Classes of org.rssowl.core.persist.reference.FeedReference

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.