Package org.rssowl.core.util

Examples of org.rssowl.core.util.SyncItem


              INews news = item.getResult().resolve();

              /* Item Exists */
              if (news != null && news.isVisible()) {
                if (SyncUtils.isSynchronized(news) && news.getLabels().contains(label)) {
                  SyncItem syncItem = SyncItem.toSyncItem(news);
                  syncItem.addLabel(newName);
                  syncItem.removeLabel(oldName);
                  syncItems.add(syncItem);
                }
              }

              /* Index Issue */
 
View Full Code Here


    INews currentNews = fFactory.createNews(null, feed, new Date());
    currentNews.setInReplyTo(feed.getLink().toString());
    currentNews.setGuid(fFactory.createGuid(currentNews, "tag:google.com/foo", true));

    SyncItem item = SyncItem.toSyncItem(filter, currentNews);
    assertNull(item);

    filter.addAction(fFactory.createFilterAction(MarkReadNewsAction.ID));
    item = SyncItem.toSyncItem(filter, currentNews);

    assertTrue(item.isMarkedRead());
    assertFalse(item.isMarkedUnread());
    assertFalse(item.isStarred());
    assertFalse(item.isUnStarred());
    assertTrue(item.getAddedLabels().isEmpty());
    assertTrue(item.getRemovedLabels().isEmpty());

    filter.addAction(fFactory.createFilterAction(MarkStickyNewsAction.ID));
    item = SyncItem.toSyncItem(filter, currentNews);

    assertTrue(item.isMarkedRead());
    assertFalse(item.isMarkedUnread());
    assertTrue(item.isStarred());
    assertFalse(item.isUnStarred());
    assertTrue(item.getAddedLabels().isEmpty());
    assertTrue(item.getRemovedLabels().isEmpty());

    filter.addAction(fFactory.createFilterAction(MarkUnreadNewsAction.ID));
    item = SyncItem.toSyncItem(filter, currentNews);

    assertFalse(item.isMarkedRead());
    assertTrue(item.isMarkedUnread());
    assertTrue(item.isStarred());
    assertFalse(item.isUnStarred());
    assertTrue(item.getAddedLabels().isEmpty());
    assertTrue(item.getRemovedLabels().isEmpty());

    IFilterAction action = fFactory.createFilterAction(LabelNewsAction.ID);
    action.setData(label1.getId());
    filter.addAction(action);
    item = SyncItem.toSyncItem(filter, currentNews);

    assertFalse(item.isMarkedRead());
    assertTrue(item.isMarkedUnread());
    assertTrue(item.isStarred());
    assertFalse(item.isUnStarred());
    assertEquals(1, item.getAddedLabels().size());
    assertEquals("Foo", item.getAddedLabels().get(0));
    assertTrue(item.getRemovedLabels().isEmpty());

    action = fFactory.createFilterAction(LabelNewsAction.ID);
    action.setData(label2.getId());
    filter.addAction(action);
    item = SyncItem.toSyncItem(filter, currentNews);

    assertFalse(item.isMarkedRead());
    assertTrue(item.isMarkedUnread());
    assertTrue(item.isStarred());
    assertFalse(item.isUnStarred());
    assertEquals(2, item.getAddedLabels().size());
    assertEquals("Foo", item.getAddedLabels().get(0));
    assertEquals("Bar", item.getAddedLabels().get(1));
    assertTrue(item.getRemovedLabels().isEmpty());

    action = fFactory.createFilterAction(DeleteNewsAction.ID);
    filter.addAction(action);
    item = SyncItem.toSyncItem(filter, currentNews);
    assertTrue(item.isMarkedRead());
    assertFalse(item.isMarkedUnread());
    assertTrue(item.isStarred());
    assertFalse(item.isUnStarred());
    assertEquals(2, item.getAddedLabels().size());
    assertEquals("Foo", item.getAddedLabels().get(0));
    assertEquals("Bar", item.getAddedLabels().get(1));
    assertTrue(item.getRemovedLabels().isEmpty());
  }
View Full Code Here

    INews news3 = fFactory.createNews(null, feed, new Date());
    news3.setInReplyTo(feed.getLink().toString());
    news3.setGuid(fFactory.createGuid(news3, "tag:google.com/foo", true));

    SyncItem item1 = SyncItem.toSyncItem(news1);
    SyncItem item2 = SyncItem.toSyncItem(news2);
    SyncItem item3 = SyncItem.toSyncItem(news3);

    item1.merge(item2);

    assertFalse(item1.isMarkedRead());
    assertFalse(item1.isMarkedUnread());
View Full Code Here

    INews news1 = fFactory.createNews(null, feed, new Date());
    news1.setInReplyTo(feed.getLink().toString());
    news1.setGuid(fFactory.createGuid(news1, "tag:google.com/foo", true));

    SyncItem sync = SyncItem.toSyncItem(news1);
    sync.applyTo(news1);

    assertTrue(news1.getState() == INews.State.NEW);
    assertNull(news1.getProperty(SyncUtils.GOOGLE_MARKED_READ));
    assertNull(news1.getProperty(SyncUtils.GOOGLE_MARKED_UNREAD));
    assertFalse(news1.isFlagged());
    assertTrue(news1.getLabels().isEmpty());

    sync.setMarkedRead();
    sync.applyTo(news1);

    assertTrue(news1.getState() == INews.State.NEW);
    assertNotNull(news1.getProperty(SyncUtils.GOOGLE_MARKED_READ));
    assertNull(news1.getProperty(SyncUtils.GOOGLE_MARKED_UNREAD));
    assertFalse(news1.isFlagged());
    assertTrue(news1.getLabels().isEmpty());

    sync.setMarkedUnread();
    sync.applyTo(news1);

    assertTrue(news1.getState() == INews.State.NEW);
    assertNull(news1.getProperty(SyncUtils.GOOGLE_MARKED_READ));
    assertNotNull(news1.getProperty(SyncUtils.GOOGLE_MARKED_UNREAD));
    assertFalse(news1.isFlagged());
    assertTrue(news1.getLabels().isEmpty());

    sync.setStarred();
    sync.applyTo(news1);

    assertTrue(news1.getState() == INews.State.NEW);
    assertNull(news1.getProperty(SyncUtils.GOOGLE_MARKED_READ));
    assertNotNull(news1.getProperty(SyncUtils.GOOGLE_MARKED_UNREAD));
    assertTrue(news1.isFlagged());
    assertTrue(news1.getLabels().isEmpty());

    sync.setUnStarred();
    sync.applyTo(news1);

    assertTrue(news1.getState() == INews.State.NEW);
    assertNull(news1.getProperty(SyncUtils.GOOGLE_MARKED_READ));
    assertNotNull(news1.getProperty(SyncUtils.GOOGLE_MARKED_UNREAD));
    assertFalse(news1.isFlagged());
    assertTrue(news1.getLabels().isEmpty());

    sync.addLabel("Foo");
    sync.addLabel("Hello World");
    sync.removeLabel("Bar");
    sync.applyTo(news1);

    assertTrue(news1.getState() == INews.State.NEW);
    assertNull(news1.getProperty(SyncUtils.GOOGLE_MARKED_READ));
    assertNotNull(news1.getProperty(SyncUtils.GOOGLE_MARKED_UNREAD));
    assertFalse(news1.isFlagged());
    assertTrue(news1.getLabels().isEmpty());

    Object labelsObj = news1.getProperty(SyncUtils.GOOGLE_LABELS);
    assertNotNull(labelsObj);
    assertTrue(labelsObj instanceof String[]);

    String[] labels = (String[]) labelsObj;
    assertEquals(2, labels.length);
    assertTrue(labels[0].equals("Foo") || labels[1].equals("Foo"));
    assertTrue(labels[0].equals("Hello World") || labels[1].equals("Hello World"));

    sync.removeLabel("Foo");
    sync.removeLabel("Hello World");
    sync.addLabel("Bar");
    sync.applyTo(news1);

    assertTrue(news1.getState() == INews.State.NEW);
    assertNull(news1.getProperty(SyncUtils.GOOGLE_MARKED_READ));
    assertNotNull(news1.getProperty(SyncUtils.GOOGLE_MARKED_UNREAD));
    assertFalse(news1.isFlagged());
View Full Code Here

    INews news2 = fFactory.createNews(null, feed, new Date());
    news2.setInReplyTo(feed.getLink().toString());
    news2.setGuid(fFactory.createGuid(news2, "tag:google.com/foo", true));

    SyncItem item1 = SyncItem.toSyncItem(news1);
    SyncItem item2 = SyncItem.toSyncItem(news2);

    assertTrue(item1.isEquivalent(item2));

    item2.setMarkedRead();
    assertFalse(item1.isEquivalent(item2));
    item1.setMarkedRead();
    assertTrue(item1.isEquivalent(item2));

    item2.setMarkedUnread();
    assertFalse(item1.isEquivalent(item2));
    item1.setMarkedUnread();
    assertTrue(item1.isEquivalent(item2));

    item2.setStarred();
    assertFalse(item1.isEquivalent(item2));
    item1.setStarred();
    assertTrue(item1.isEquivalent(item2));

    item2.setUnStarred();
    assertFalse(item1.isEquivalent(item2));
    item1.setUnStarred();
    assertTrue(item1.isEquivalent(item2));

    item2.addLabel("Foo");
    assertFalse(item1.isEquivalent(item2));
    item1.addLabel("Foo");
    assertTrue(item1.isEquivalent(item2));

    item2.addLabel("Bar");
    assertFalse(item1.isEquivalent(item2));
    item1.addLabel("Bar");
    assertTrue(item1.isEquivalent(item2));

    item2.removeLabel("Hello");
    assertFalse(item1.isEquivalent(item2));
    item1.removeLabel("Hello");
    assertTrue(item1.isEquivalent(item2));

    item2.removeLabel("World");
    assertFalse(item1.isEquivalent(item2));
    item1.removeLabel("World");
    assertTrue(item1.isEquivalent(item2));
  }
View Full Code Here

    INews news2 = fFactory.createNews(null, feed, new Date());
    news2.setInReplyTo(feed.getLink().toString());
    news2.setGuid(fFactory.createGuid(news2, "tag:google.com/bar", true));

    SyncItem item1 = SyncItem.toSyncItem(news1);
    item1.setMarkedRead();

    SyncItem item2 = SyncItem.toSyncItem(news2);
    item2.addLabel("Foo");
    item2.addLabel("Bar");
    item2.removeLabel("Hello World");

    manager.addUncommitted(Arrays.asList(item1, item2));

    assertTrue(manager.hasUncommittedItems());

    manager.shutdown();
    assertFalse(manager.hasUncommittedItems());
    manager.startup();
    assertTrue(manager.hasUncommittedItems());

    Collection<SyncItem> uncommittedItems = manager.getUncommittedItems().values();
    assertEquals(2, uncommittedItems.size());

    Iterator<SyncItem> iterator = uncommittedItems.iterator();
    SyncItem loadedItem1 = iterator.next();
    SyncItem loadedItem2 = iterator.next();

    assertTrue(item1.isEquivalent(loadedItem1));
    assertTrue(item2.isEquivalent(loadedItem2));

    SyncItem item3 = SyncItem.toSyncItem(news1);
    item3.setMarkedUnread();
    item3.setStarred();

    manager.addUncommitted(Collections.singleton(item3));

    uncommittedItems = manager.getUncommittedItems().values();
    assertEquals(2, uncommittedItems.size());
View Full Code Here

    List<SyncItem> filteredEvents = new ArrayList<SyncItem>();
    for (INews item : news) {
      if (!SyncUtils.isSynchronized(item))
        continue;

      SyncItem syncItem = SyncItem.toSyncItem(filter, item);
      if (syncItem != null)
        filteredEvents.add(syncItem);
    }

    return filteredEvents;
View Full Code Here

    List<SyncItem> filteredEvents = new ArrayList<SyncItem>();
    for (NewsEvent event : events) {
      if (event.isMerged() || event.getOldNews() == null || !SyncUtils.isSynchronized(event.getEntity()))
        continue;

      SyncItem syncItem = SyncItem.toSyncItem(event);
      if (syncItem != null)
        filteredEvents.add(syncItem);
    }

    return filteredEvents;
View Full Code Here

   * @param items the uncommitted {@link SyncItem} to add.
   */
  public void addUncommitted(Collection<SyncItem> items) {
    synchronized (fLock) {
      for (SyncItem item : items) {
        SyncItem existingItem = fItems.get(item.getId());
        if (existingItem != null)
          existingItem.merge(item);
        else
          fItems.put(item.getId(), item);
      }
    }
  }
View Full Code Here

        for (INews item : news) {
          if (item.getGuid() == null || item.getGuid().getValue() == null)
            continue;

          /* Check for Existing Uncommitted SyncItem */
          SyncItem syncItem = uncommittedItems.get(item.getGuid().getValue());
          if (syncItem == null)
            continue;

          /* Apply State from SyncItem to News */
          syncItem.applyTo(item);
        }
      }
    }

    return Triple.create(feed, conditionalGet, link);
View Full Code Here

TOP

Related Classes of org.rssowl.core.util.SyncItem

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.