Package org.rssowl.core.persist.reference

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


  public NewsNotificationItem(INews news, RGB color) {
    super(makeText(news), makeImage(news));

    fNewsLink = CoreUtils.getLink(news);
    fFeedReference = news.getFeedReference();
    fNewsReference = new NewsReference(news.getId());
    fRecentNewsDate = DateUtils.getRecentDate(news);
    fIsNewsSticky = news.isFlagged();
    fIsNewsRead = (INews.State.READ == news.getState());

    if (color != null)
View Full Code Here


      final IAttachment attachment0 = fFactory.createAttachment(null, news);
      attachment0.setLink(new URI("http://www.attachment1.com"));
      final IAttachment attachment1 = fFactory.createAttachment(null, news);
      attachment1.setLink(new URI("http://www.attachment1.com"));
      DynamicDAO.save(feed);
      NewsReference newsRef = new NewsReference(feed.getNews().get(0).getId());
      AttachmentReference attachmentRef0 = new AttachmentReference(news.getAttachments().get(0).getId());
      AttachmentReference attachmentRef1 = new AttachmentReference(news.getAttachments().get(1).getId());

      final boolean[] newsDeleted = new boolean[1];
      newsListener = new NewsListener() {
        public void entitiesDeleted(Set<NewsEvent> events) {
          for (NewsEvent event : events) {
            assertFalse("Expected this Event to be no Root Event", event.isRoot());
            if (event.getEntity().getTitle().equals(news.getTitle()))
              newsDeleted[0] = true;

            try {
              assertEquals(new URI("http://www.foobar.com").toString(), event.getEntity().getFeedReference().getLink().toString());
            } catch (URISyntaxException e) {
              fail(e.getMessage());
            }
          }
        }

        public void entitiesUpdated(Set<NewsEvent> events) {
          fail("Unexpected event");
        }

        public void entitiesAdded(Set<NewsEvent> events) {
          fail("Unexpected event");
        }
      };
      DynamicDAO.addEntityListener(INews.class, newsListener);

      /* Check Attachments Added */
      final boolean attachmentDeleted[] = new boolean[2];
      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 (attachment.getLink().equals(attachment0.getLink()))
              attachmentDeleted[0] = true;
            if (attachment.getLink().equals(attachment1.getLink()))
              attachmentDeleted[1] = true;
          }
        }
      };
      DynamicDAO.addEntityListener(IAttachment.class, attachmentListener);

      DynamicDAO.delete(feed);
      assertNull(DynamicDAO.load(IFeed.class, feed.getId()));
      assertNull(DynamicDAO.load(INews.class, newsRef.getId()));
      assertNull(DynamicDAO.load(IAttachment.class, attachmentRef0.getId()));
      assertNull(DynamicDAO.load(IAttachment.class, attachmentRef1.getId()));

      assertTrue("Missed newsDeleted Event in NewsListener!", newsDeleted[0]);
      assertTrue("Missed attachmentDeleted Event in PersonListener!", attachmentDeleted[0]);
View Full Code Here

      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;
View Full Code Here

      fFactory.createAttachment(null, news);
      fFactory.createAttachment(null, news);
      fFactory.createAttachment(null, news);

      /* Save News */
      final NewsReference newsRef = new NewsReference(DynamicDAO.save(news).getId());

      final PersonReference personRef = new PersonReference(DynamicDAO.load(INews.class, newsRef.getId()).getAuthor().getId());
      final AttachmentReference attachmentRef1 = new AttachmentReference(DynamicDAO.load(INews.class, newsRef.getId()).getAttachments().get(0).getId());
      final AttachmentReference attachmentRef2 = new AttachmentReference(DynamicDAO.load(INews.class, newsRef.getId()).getAttachments().get(1).getId());
      final AttachmentReference attachmentRef3 = new AttachmentReference(DynamicDAO.load(INews.class, newsRef.getId()).getAttachments().get(2).getId());
      final CategoryReference categoryRef = new CategoryReference(DynamicDAO.load(INews.class, newsRef.getId()).getCategories().get(0).getId());

      /* Check News Deleted */
      final boolean newsDeleted[] = new boolean[1];
      newsListener = new NewsAdapter() {
        @Override
        public void entitiesDeleted(Set<NewsEvent> events) {
          for (NewsEvent event : events) {
            assertTrue("Expected this Event to be Root Event", event.isRoot());
            if (newsRef.references(event.getEntity()))
              newsDeleted[0] = true;

            try {
              assertEquals(new URI("http://www.foobar.com").toString(), event.getEntity().getFeedReference().getLink().toString());
            } catch (URISyntaxException e) {
              fail(e.getMessage());
            }
          }
        }
      };
      DynamicDAO.addEntityListener(INews.class, newsListener);

      /* Check Author Deleted */
      final boolean personDeleted[] = new boolean[1];
      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());
            if (personRef.references(event.getEntity()))
              personDeleted[0] = true;
          }
        }
      };
      DynamicDAO.addEntityListener(IPerson.class, personListener);

      /* Check Attachments Deleted */
      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 Category Deleted */
      final boolean categoryDeleted[] = new boolean[1];
      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());
            if (categoryRef.references(event.getEntity()))
              categoryDeleted[0] = true;
          }
        }
      };
      DynamicDAO.addEntityListener(ICategory.class, categoryListener);

      /* Delete News */
      DynamicDAO.delete(newsRef.resolve());

      /* Asserts Follow */
      assertTrue("Missed newsDeleted Event in NewsListener!", newsDeleted[0]);
      assertTrue("Missed personDeleted Event in PersonListener!", personDeleted[0]);
      assertTrue("Missed categoryDeleted Event in CategoryListener!", categoryDeleted[0]);
View Full Code Here

    /* Show News Downloaded while Minimized */
    if (!fTeasingNewsCache.isEmpty()) {
      synchronized (fTeasingNewsCache) {
        int counter = 0;
        for (int i = fTeasingNewsCache.size() - 1; i >= 0; i--) {
          NewsReference reference = new NewsReference(fTeasingNewsCache.get(i));
          INews newsitem = reference.resolve();
          if (newsitem != null) {
            newsToShow.add(newsitem);

            if (++counter >= TEASE_LIMIT)
              break;
          }

          /* Return early if Notifier already showing */
          if (service.isPopupVisible())
            return;
        }
      }
      mode = Mode.INCOMING_MANUAL;
    }

    /* Show Recent News */
    else {

      /* Build the Search if not yet done */
      if (fTodaysNewsSearch == null) {
        IModelFactory factory = Owl.getModelFactory();

        String newsClassName = INews.class.getName();
        ISearchField ageInDaysField = factory.createSearchField(INews.AGE_IN_DAYS, newsClassName);
        ISearchField ageInMinutesField = factory.createSearchField(INews.AGE_IN_MINUTES, newsClassName);

        ISearchCondition dayCondition = factory.createSearchCondition(ageInDaysField, SearchSpecifier.IS_LESS_THAN, 1); // From Today after Midnight
        ISearchCondition recentCondition = factory.createSearchCondition(ageInMinutesField, SearchSpecifier.IS_LESS_THAN, -60 * 6); // Up to 6 Hours Ago

        fTodaysNewsSearch = factory.createSearch(null);
        fTodaysNewsSearch.setMatchAllConditions(false);
        fTodaysNewsSearch.addSearchCondition(dayCondition);
        fTodaysNewsSearch.addSearchCondition(recentCondition);
      }

      /* Sort by Id (simulate sorting by date) */
      List<SearchHit<NewsReference>> result = Owl.getPersistenceService().getModelSearch().searchNews(fTodaysNewsSearch);
      Set<NewsReference> recentNews = new TreeSet<NewsReference>(new Comparator<NewsReference>() {
        public int compare(NewsReference ref1, NewsReference ref2) {
          if (ref1.equals(ref2))
            return 0;

          return ref1.getId() > ref2.getId() ? -1 : 1;
        }
      });

      for (SearchHit<NewsReference> hit : result) {
        recentNews.add(hit.getResult());
      }

      /* Resolve and Add News from Result */
      int counter = 0;
      for (NewsReference reference : recentNews) {
        INews newsitem = reference.resolve();
        if (newsitem != null && newsitem.isVisible()) {
          newsToShow.add(newsitem);

          if (++counter >= TEASE_LIMIT)
            break;
View Full Code Here

      explorer.reveal(lastOpenedNewsMark, false);
    }
  }

  private void openAndSelect(IWorkbenchPage page, INews news, INewsMark newsmark) {
    PerformAfterInputSet perform = PerformAfterInputSet.selectNews(new NewsReference(news.getId()));
    perform.setActivate(false);

    /* Open this Bookmark */
    FeedViewInput fvInput = new FeedViewInput(newsmark, perform);
    FeedView feedview = null;
View Full Code Here

        if (end < 0)
          end = parameters.length();

        StringTokenizer tokenizer = new StringTokenizer(parameters.substring(start, end), ",");//$NON-NLS-1$
        while (tokenizer.hasMoreElements()) {
          NewsReference ref = new NewsReference(Long.valueOf((String) tokenizer.nextElement()));
          elements.addAll(Arrays.asList(newsContentProvider.getElements(ref)));
        }
      }
    }
View Full Code Here

  /* getNews(states) is synchronized so this method does not need to be */
  public List<NewsReference> getNewsRefs(Set<State> states) {
    List<INews> news = getNews(states);
    List<NewsReference> newsRefs = new ArrayList<NewsReference>();
    for (INews newsItem : news) {
      newsRefs.add(new NewsReference(newsItem.getId()));
    }
    return newsRefs;
  }
View Full Code Here

      int index = state.ordinal();
      LongArrayList newsIds = fNewsIds[index];
      for (int i = 0, c = newsIds.size(); i < c; ++i) {
        long newsId = newsIds.get(i);
        Assert.isLegal(newsId != 0);
        newsRefs.add(new NewsReference(newsId));
      }
    }

    return newsRefs;
  }
View Full Code Here

      fLock.releaseWriteLock();
    }
  }

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

TOP

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

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.