Package org.rssowl.core.persist

Examples of org.rssowl.core.persist.ISearchMark


  private ISearchMark createSimpleSearchMark(IFolder parent, String name) {
    ISearchField field = fFactory.createSearchField(IEntity.ALL_FIELDS, INews.class.getName());
    ISearchCondition condition = fFactory.createSearchCondition(field, SearchSpecifier.CONTAINS, "foo bar");

    ISearchMark sm = fFactory.createSearchMark(null, parent, name);
    sm.addSearchCondition(condition);

    return sm;
  }
View Full Code Here


  private ISearchMark createAuthorSearchMark(IFolder parent, String name) {
    ISearchField field = fFactory.createSearchField(INews.AUTHOR, INews.class.getName());
    ISearchCondition condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, "bar");

    ISearchMark sm = fFactory.createSearchMark(null, parent, name);
    sm.addSearchCondition(condition);

    return sm;
  }
View Full Code Here

  private ISearchMark createLocationSearchMark(IFolder parent, String name) {
    ISearchField field = fFactory.createSearchField(INews.LOCATION, INews.class.getName());
    ISearchCondition condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, ModelUtils.toPrimitive(Collections.singletonList((IFolderChild) parent)));

    ISearchMark sm = fFactory.createSearchMark(null, parent, name);
    sm.addSearchCondition(condition);

    return sm;
  }
View Full Code Here

    /* 2) State IS new, unread, updated */
    {
      ISearchField field = fFactory.createSearchField(INews.STATE, newsName);
      ISearchCondition condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, EnumSet.of(State.NEW, State.UNREAD, State.UPDATED));

      ISearchMark searchmark = fFactory.createSearchMark(null, parent, "Search");
      searchmark.addSearchCondition(condition);
    }

    /* 3) Entire News CONTAINS foo?bar */
    {
      ISearchField field = fFactory.createSearchField(IEntity.ALL_FIELDS, newsName);
      ISearchCondition condition = fFactory.createSearchCondition(field, SearchSpecifier.CONTAINS, "foo?bar");

      ISearchMark searchmark = fFactory.createSearchMark(null, parent, "Search");
      searchmark.addSearchCondition(condition);
    }

    /* 4) Age in Days is > 5 */
    {
      ISearchField field = fFactory.createSearchField(INews.AGE_IN_DAYS, newsName);
      ISearchCondition condition = fFactory.createSearchCondition(field, SearchSpecifier.IS_GREATER_THAN, 5);

      ISearchMark searchmark = fFactory.createSearchMark(null, parent, "Search");
      searchmark.addSearchCondition(condition);
    }

    /* 5) Publish Date is 26.12.1981 */
    {
      Calendar cal = DateUtils.getToday();
      cal.set(Calendar.YEAR, 1981);
      cal.set(Calendar.MONTH, Calendar.DECEMBER);
      cal.set(Calendar.DATE, 26);

      ISearchField field = fFactory.createSearchField(INews.PUBLISH_DATE, newsName);
      ISearchCondition condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, cal.getTime());

      ISearchMark searchmark = fFactory.createSearchMark(null, parent, "Search");
      searchmark.addSearchCondition(condition);
    }

    /* 6) Feed Links is not http://www.rssowl.org/node/feed */
    {
      ISearchField field = fFactory.createSearchField(INews.FEED, newsName);
      ISearchCondition condition = fFactory.createSearchCondition(field, SearchSpecifier.IS_NOT, "http://www.rssowl.org/node/feed");

      ISearchMark searchmark = fFactory.createSearchMark(null, parent, "Search");
      searchmark.addSearchCondition(condition);
    }

    /* 7) Has Attachments is TRUE */
    {
      ISearchField field = fFactory.createSearchField(INews.HAS_ATTACHMENTS, newsName);
      ISearchCondition condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, true);

      ISearchMark searchmark = fFactory.createSearchMark(null, parent, "Search");
      searchmark.addSearchCondition(condition);
    }

    /*
     * 8) Entire News CONTAINS foo?bar AND State ISnew AND Has Attachments is
     * TRUE
     */
    {
      ISearchMark searchmark = fFactory.createSearchMark(null, parent, "Search");

      ISearchField field = fFactory.createSearchField(IEntity.ALL_FIELDS, newsName);
      ISearchCondition condition = fFactory.createSearchCondition(field, SearchSpecifier.CONTAINS, "foo?bar");
      searchmark.addSearchCondition(condition);

      field = fFactory.createSearchField(INews.HAS_ATTACHMENTS, newsName);
      condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, true);
      searchmark.addSearchCondition(condition);

      field = fFactory.createSearchField(INews.STATE, newsName);
      condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, EnumSet.of(State.NEW));
      searchmark.addSearchCondition(condition);

      searchmark.setMatchAllConditions(true);
    }

    /* 9) Location is Default Set */
    {
      ISearchField field = fFactory.createSearchField(INews.LOCATION, newsName);
      ISearchCondition condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, ModelUtils.toPrimitive(Arrays.asList(new IFolderChild[] { fDefaultSet })));

      ISearchMark searchmark = fFactory.createSearchMark(null, parent, "Search");
      searchmark.addSearchCondition(condition);
    }

    /* 10) Location is Default Set OR Location is Custom Set */
    {
      ISearchField field = fFactory.createSearchField(INews.LOCATION, newsName);
      ISearchCondition condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, ModelUtils.toPrimitive(Arrays.asList(new IFolderChild[] { fDefaultSet, fCustomSet })));

      ISearchMark searchmark = fFactory.createSearchMark(null, parent, "Search");
      searchmark.addSearchCondition(condition);
    }

    /* 11) Location is Folder 1 */
    {
      ISearchField field = fFactory.createSearchField(INews.LOCATION, newsName);
      ISearchCondition condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, ModelUtils.toPrimitive(Arrays.asList(new IFolderChild[] { fDefaultFolder1 })));

      ISearchMark searchmark = fFactory.createSearchMark(null, parent, "Search");
      searchmark.addSearchCondition(condition);
    }

    /* 12) Location is BookMark 1 */
    {
      ISearchField field = fFactory.createSearchField(INews.LOCATION, newsName);
      ISearchCondition condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, ModelUtils.toPrimitive(Arrays.asList(new IFolderChild[] { fBookMark1 })));

      fSearchmarkWithLocation = fFactory.createSearchMark(null, parent, "Search");
      fSearchmarkWithLocation.addSearchCondition(condition);
    }

    /*
     * 13) Location is Default Set OR Location is Custom Set OR Location is
     * BookMark1
     */
    {
      ISearchMark searchmark = fFactory.createSearchMark(null, parent, "Search");

      ISearchField field = fFactory.createSearchField(INews.LOCATION, newsName);

      ISearchCondition condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, ModelUtils.toPrimitive(Arrays.asList(new IFolderChild[] { fDefaultSet })));
      searchmark.addSearchCondition(condition);

      condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, ModelUtils.toPrimitive(Arrays.asList(new IFolderChild[] { fCustomSet })));
      searchmark.addSearchCondition(condition);

      condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, ModelUtils.toPrimitive(Arrays.asList(new IFolderChild[] { fBookMark1 })));
      searchmark.addSearchCondition(condition);
    }

    /* 14) Location is Bin 1 */
    {
      ISearchField field = fFactory.createSearchField(INews.LOCATION, newsName);
      ISearchCondition condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, ModelUtils.toPrimitive(Arrays.asList(new IFolderChild[] { fNewsBin })));

      ISearchMark searchmark = fFactory.createSearchMark(null, parent, "Search");
      searchmark.addSearchCondition(condition);
    }

    /* 15) Entire News CONTAINS_ALL foo?bar */
    {
      ISearchField field = fFactory.createSearchField(IEntity.ALL_FIELDS, newsName);
      ISearchCondition condition = fFactory.createSearchCondition(field, SearchSpecifier.CONTAINS_ALL, "foo?bar");

      ISearchMark searchmark = fFactory.createSearchMark(null, parent, "Search");
      searchmark.addSearchCondition(condition);
    }

    /* 16) Entire News CONTAINS_NOT foo?bar */
    {
      ISearchField field = fFactory.createSearchField(IEntity.ALL_FIELDS, newsName);
      ISearchCondition condition = fFactory.createSearchCondition(field, SearchSpecifier.CONTAINS_NOT, "foo?bar");

      ISearchMark searchmark = fFactory.createSearchMark(null, parent, "Search");
      searchmark.addSearchCondition(condition);
    }
  }
View Full Code Here

      if (mark instanceof ISearchMark)
        searchmarks.add((ISearchMark) mark);
    }

    /* 1) State ISnew */
    ISearchMark searchmark = searchmarks.get(0);
    assertEquals("Search", searchmark.getName());
    List<ISearchCondition> conditions = searchmark.getSearchConditions();
    assertEquals(1, conditions.size());
    assertEquals(INews.STATE, conditions.get(0).getField().getId());
    assertEquals(SearchSpecifier.IS, conditions.get(0).getSpecifier());
    assertEquals(EnumSet.of(INews.State.NEW), conditions.get(0).getValue());
    if (isBackup)
      assertProperties(Owl.getPreferenceService().getEntityScope(searchmark));

    /* 2) State ISnewunreadupdated */
    searchmark = searchmarks.get(1);
    conditions = searchmark.getSearchConditions();
    assertEquals(1, conditions.size());
    assertEquals(INews.STATE, conditions.get(0).getField().getId());
    assertEquals(SearchSpecifier.IS, conditions.get(0).getSpecifier());
    assertEquals(EnumSet.of(INews.State.NEW, INews.State.UNREAD, INews.State.UPDATED), conditions.get(0).getValue());

    /* 3) Entire News CONTAINS foo?bar */
    searchmark = searchmarks.get(2);
    conditions = searchmark.getSearchConditions();
    assertEquals(1, conditions.size());
    assertEquals(IEntity.ALL_FIELDS, conditions.get(0).getField().getId());
    assertEquals(SearchSpecifier.CONTAINS, conditions.get(0).getSpecifier());
    assertEquals("foo?bar", conditions.get(0).getValue());

    /* 4) Age in Days is > 5 */
    searchmark = searchmarks.get(3);
    conditions = searchmark.getSearchConditions();
    assertEquals(1, conditions.size());
    assertEquals(INews.AGE_IN_DAYS, conditions.get(0).getField().getId());
    assertEquals(SearchSpecifier.IS_GREATER_THAN, conditions.get(0).getSpecifier());
    assertEquals(5, conditions.get(0).getValue());

    /* 5) Publish Date is 26.12.1981 */
    Calendar cal = DateUtils.getToday();
    cal.set(Calendar.YEAR, 1981);
    cal.set(Calendar.MONTH, Calendar.DECEMBER);
    cal.set(Calendar.DATE, 26);

    searchmark = searchmarks.get(4);
    conditions = searchmark.getSearchConditions();
    assertEquals(1, conditions.size());
    assertEquals(INews.PUBLISH_DATE, conditions.get(0).getField().getId());
    assertEquals(SearchSpecifier.IS, conditions.get(0).getSpecifier());
    assertEquals(cal.getTime(), conditions.get(0).getValue());

    /* 6) Feed Links is not http://www.rssowl.org/node/feed */
    searchmark = searchmarks.get(5);
    conditions = searchmark.getSearchConditions();
    assertEquals(1, conditions.size());
    assertEquals(INews.FEED, conditions.get(0).getField().getId());
    assertEquals(SearchSpecifier.IS_NOT, conditions.get(0).getSpecifier());
    assertEquals("http://www.rssowl.org/node/feed", conditions.get(0).getValue());

    /* 7) Has Attachments is TRUE */
    searchmark = searchmarks.get(6);
    conditions = searchmark.getSearchConditions();
    assertEquals(1, conditions.size());
    assertEquals(INews.HAS_ATTACHMENTS, conditions.get(0).getField().getId());
    assertEquals(SearchSpecifier.IS, conditions.get(0).getSpecifier());
    assertEquals(true, conditions.get(0).getValue());

    /*
     * 8) Entire News CONTAINS foo?bar AND State ISnew AND Has Attachments is
     * TRUE
     */
    searchmark = searchmarks.get(7);
    conditions = searchmark.getSearchConditions();
    assertEquals(3, conditions.size());
    assertEquals(true, searchmark.matchAllConditions());

    for (ISearchCondition condition : conditions) {
      switch (condition.getField().getId()) {
        case IEntity.ALL_FIELDS:
          assertEquals(SearchSpecifier.CONTAINS, condition.getSpecifier());
          assertEquals("foo?bar", condition.getValue());
          break;

        case INews.STATE:
          assertEquals(SearchSpecifier.IS, condition.getSpecifier());
          assertEquals(EnumSet.of(INews.State.NEW), condition.getValue());
          break;

        case INews.HAS_ATTACHMENTS:
          assertEquals(SearchSpecifier.IS, condition.getSpecifier());
          assertEquals(true, condition.getValue());
          break;

        default:
          fail();
      }
    }

    /* 9) Location is Default Set */
    searchmark = searchmarks.get(8);
    conditions = searchmark.getSearchConditions();
    assertEquals(1, conditions.size());
    assertEquals(INews.LOCATION, conditions.get(0).getField().getId());
    assertEquals(SearchSpecifier.IS, conditions.get(0).getSpecifier());
    assertEquals(Arrays.asList(new IFolderChild[] { fDefaultSet }), CoreUtils.toEntities((Long[][]) conditions.get(0).getValue()));

    /* 10) Location is Default Set OR Location is Custom Set */
    searchmark = searchmarks.get(9);
    conditions = searchmark.getSearchConditions();
    assertEquals(1, conditions.size());
    List<IFolderChild> locations = CoreUtils.toEntities((Long[][]) conditions.get(0).getValue());
    assertEquals(INews.LOCATION, conditions.get(0).getField().getId());
    assertEquals(SearchSpecifier.IS, conditions.get(0).getSpecifier());
    assertEquals(2, locations.size());
    assertContains("My Bookmarks", locations);
    assertContains("Custom", locations);

    /* 11) Location is Folder 1 */
    searchmark = searchmarks.get(10);
    conditions = searchmark.getSearchConditions();
    assertEquals(1, conditions.size());
    assertEquals(INews.LOCATION, conditions.get(0).getField().getId());
    assertEquals(SearchSpecifier.IS, conditions.get(0).getSpecifier());
    locations = CoreUtils.toEntities((Long[][]) conditions.get(0).getValue());
    assertEquals(1, locations.size());
    assertEquals(true, locations.get(0) instanceof IFolder);
    assertEquals("Default Folder 1", locations.get(0).getName());

    /* 12) Location is BookMark 1 */
    searchmark = searchmarks.get(11);
    conditions = searchmark.getSearchConditions();
    assertEquals(1, conditions.size());
    assertEquals(INews.LOCATION, conditions.get(0).getField().getId());
    assertEquals(SearchSpecifier.IS, conditions.get(0).getSpecifier());
    locations = CoreUtils.toEntities((Long[][]) conditions.get(0).getValue());
    assertEquals(1, locations.size());
    assertEquals(true, locations.get(0) instanceof IBookMark);
    assertEquals("Bookmark 1", locations.get(0).getName());

    /*
     * 13) Location is Default Set OR Location is Custom Set OR Location is
     * BookMark1
     */
    searchmark = searchmarks.get(12);
    conditions = searchmark.getSearchConditions();
    assertEquals(3, conditions.size());

    locations = new ArrayList<IFolderChild>();

    for (ISearchCondition condition : conditions) {
      assertEquals(INews.LOCATION, condition.getField().getId());
      assertEquals(SearchSpecifier.IS, condition.getSpecifier());

      locations.addAll(CoreUtils.toEntities((Long[][]) condition.getValue()));
    }

    assertEquals(3, locations.size());
    assertContains("My Bookmarks", locations);
    assertContains("Custom", locations);
    assertContains("Bookmark 1", locations);

    /* 14) Location is Bin 1 */
    searchmark = searchmarks.get(13);
    conditions = searchmark.getSearchConditions();
    assertEquals(1, conditions.size());
    assertEquals(INews.LOCATION, conditions.get(0).getField().getId());
    assertEquals(SearchSpecifier.IS, conditions.get(0).getSpecifier());
    locations = CoreUtils.toEntities((Long[][]) conditions.get(0).getValue());
    assertEquals(1, locations.size());
    assertEquals(true, locations.get(0) instanceof INewsBin);
    assertEquals(fNewsBin.getName(), locations.get(0).getName());

    /* 15) Entire News CONTAINS_ALL foo?bar */
    searchmark = searchmarks.get(14);
    conditions = searchmark.getSearchConditions();
    assertEquals(1, conditions.size());
    assertEquals(IEntity.ALL_FIELDS, conditions.get(0).getField().getId());
    assertEquals(SearchSpecifier.CONTAINS_ALL, conditions.get(0).getSpecifier());
    assertEquals("foo?bar", conditions.get(0).getValue());

    /* 16) Entire News CONTAINS_NOT foo?bar */
    searchmark = searchmarks.get(15);
    conditions = searchmark.getSearchConditions();
    assertEquals(1, conditions.size());
    assertEquals(IEntity.ALL_FIELDS, conditions.get(0).getField().getId());
    assertEquals(SearchSpecifier.CONTAINS_NOT, conditions.get(0).getSpecifier());
    assertEquals("foo?bar", conditions.get(0).getValue());
  }
View Full Code Here

   * @throws Exception
   */
  @Test
  public void testRemoveSearchConditionWithoutSearchMark() throws Exception {
    IFolder folder = fFactory.createFolder(null, null, "Folder");
    ISearchMark searchMark = fFactory.createSearchMark(null, folder, "Mark");
    ISearchField searchField = fFactory.createSearchField(0, INews.class.getName());
    fFactory.createSearchCondition(null, searchMark, searchField, SearchSpecifier.BEGINS_WITH, "Some value");
    IFolder savedFolder = DynamicDAO.save(folder);
    ISearchMark savedMark = (ISearchMark) savedFolder.getMarks().get(0);
    DynamicDAO.delete(savedMark.getSearchConditions().get(0));
    assertNotNull(DynamicDAO.load(ISearchMark.class, savedMark.getId()));
  }
View Full Code Here

  @Test
  public void testRemoveSearchMarkWithoutFolder() throws Exception {
    IFolder folder = fFactory.createFolder(null, null, "Folder");
    fFactory.createSearchMark(null, folder, "Mark");
    IFolder savedFolder = DynamicDAO.save(folder);
    ISearchMark savedMark = (ISearchMark) savedFolder.getMarks().get(0);
    DynamicDAO.delete(savedMark);
    assertNotNull(DynamicDAO.load(IFolder.class, savedFolder.getId()));
  }
View Full Code Here

        folderUpdatedCalled[0] = true;
      }
    };
    DynamicDAO.addEntityListener(IFolder.class, folderListener);
    try {
      ISearchMark savedMark = (ISearchMark) savedFolder.getMarks().get(0);
      DynamicDAO.delete(savedMark);
      assertTrue("folderUpdated was not called", folderUpdatedCalled[0]);
    } finally {
      DynamicDAO.removeEntityListener(IFolder.class, folderListener);
    }
View Full Code Here

    IFolderChild bookmark = fFactory.createBookMark(null, root, new FeedLinkReference(feed.getLink()), "Bookmark");
    DynamicDAO.save(root);

    ISearchField locationField = fFactory.createSearchField(INews.LOCATION, INews.class.getName());
    ISearchCondition condition = fFactory.createSearchCondition(locationField, SearchSpecifier.IS, ModelUtils.toPrimitive(Collections.singletonList(bookmark)));
    ISearchMark sm = fFactory.createSearchMark(null, root, "Search");
    sm.addSearchCondition(condition);

    DynamicDAO.save(root);

    Long bmId = bookmark.getId();

    root = null;
    feed = null;
    locationField = null;
    condition = null;
    sm = null;
    bookmark = null;

    Runtime.getRuntime().gc();

    Owl.getPersistenceService().shutdown(false);
    Owl.getPersistenceService().startup(new NullProgressLongOperationMonitor());

    Collection<ISearchMark> sms = DynamicDAO.loadAll(ISearchMark.class);
    assertEquals(1, sms.size());

    sm = sms.iterator().next();
    assertEquals(1, sm.getSearchConditions().size());

    condition = sm.getSearchConditions().get(0);
    assertNotNull(condition.getValue());
    assertEquals(true, condition.getValue() instanceof Long[][]);

    Long[][] value = (Long[][]) condition.getValue();
    assertEquals(1, value[1].length);
View Full Code Here

    DynamicDAO.save(root);

    ISearchField locationField = fFactory.createSearchField(INews.LOCATION, INews.class.getName());
    ISearchCondition condition = fFactory.createSearchCondition(locationField, SearchSpecifier.IS, ModelUtils.toPrimitive(Collections.singletonList(bin)));
    ISearchMark sm = fFactory.createSearchMark(null, root, "Search");
    sm.addSearchCondition(condition);

    DynamicDAO.save(root);

    Long binId = bin.getId();

    root = null;
    locationField = null;
    condition = null;
    sm = null;
    bin = null;

    Runtime.getRuntime().gc();

    Owl.getPersistenceService().shutdown(false);
    Owl.getPersistenceService().startup(new NullProgressLongOperationMonitor());

    Collection<ISearchMark> sms = DynamicDAO.loadAll(ISearchMark.class);
    assertEquals(1, sms.size());

    sm = sms.iterator().next();
    assertEquals(1, sm.getSearchConditions().size());

    condition = sm.getSearchConditions().get(0);
    assertNotNull(condition.getValue());
    assertEquals(true, condition.getValue() instanceof Long[][]);

    Long[][] value = (Long[][]) condition.getValue();
    assertEquals(1, value[2].length);
View Full Code Here

TOP

Related Classes of org.rssowl.core.persist.ISearchMark

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.