Package org.rssowl.core.persist

Examples of org.rssowl.core.persist.ISearch


    return search;
  }

  private ISearch createTitleSearch(String title) {
    ISearch search = fFactory.createSearch(null);
    ISearchField field = fFactory.createSearchField(INews.TITLE, INews.class.getName());

    ISearchCondition condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, title);
    search.addSearchCondition(condition);

    return search;
  }
View Full Code Here


    return search;
  }

  private ISearch createDescriptionSearch(String description) {
    ISearch search = fFactory.createSearch(null);
    ISearchField field = fFactory.createSearchField(INews.DESCRIPTION, INews.class.getName());

    ISearchCondition condition = fFactory.createSearchCondition(field, SearchSpecifier.CONTAINS, description);
    search.addSearchCondition(condition);

    return search;
  }
View Full Code Here

    return filterMatchedAll || !filteredNews.isEmpty();
  }

  private boolean needToIndexDescription(Set<ISearchFilter> filters) {
    for (ISearchFilter filter : filters) {
      ISearch search = filter.getSearch();
      if (search != null) {
        List<ISearchCondition> conditions = search.getSearchConditions();
        for (ISearchCondition condition : conditions) {
          int fieldId = condition.getField().getId();
          if (fieldId == IEntity.ALL_FIELDS || fieldId == INews.DESCRIPTION)
            return true;
        }
View Full Code Here

  }

  private void doTestAddUpdateGetAndDeleteSearchFilter(boolean gc) {
    /* Add */
    {
      ISearch search = fTypesFactory.createSearch(null);
      search.setMatchAllConditions(true);

      ISearchCondition condition1 = fTypesFactory.createSearchCondition(fTypesFactory.createSearchField(INews.TITLE, INews.class.getName()), SearchSpecifier.IS, "Foo");
      search.addSearchCondition(condition1);
      ISearchCondition condition2 = fTypesFactory.createSearchCondition(fTypesFactory.createSearchField(INews.ATTACHMENTS_CONTENT, INews.class.getName()), SearchSpecifier.CONTAINS, "Bar");
      search.addSearchCondition(condition2);

      ISearchFilter filter = fTypesFactory.createSearchFilter(null, search, "Filter");
      filter.setEnabled(true);
      filter.setOrder(5);

      IFilterAction action = fTypesFactory.createFilterAction("org.rssowl.ActionId1");
      action.setData(100);
      filter.addAction(action);

      action = fTypesFactory.createFilterAction("org.rssowl.ActionId2");
      action.setData(new Long[] { 1l, 2l, 3l });
      filter.addAction(action);

      filter = DynamicDAO.save(filter);
      if (gc)
        System.gc();

      Collection<ISearchFilter> filters = DynamicDAO.loadAll(ISearchFilter.class);
      assertEquals(1, filters.size());
      ISearchFilter savedFilter = filters.iterator().next();
      assertEquals(filter.getName(), savedFilter.getName());
      assertEquals(filter.getOrder(), savedFilter.getOrder());
      assertEquals(filter.isEnabled(), savedFilter.isEnabled());

      List<IFilterAction> actions = savedFilter.getActions();
      assertEquals(2, actions.size());
      assertEquals("org.rssowl.ActionId1", actions.get(0).getActionId());
      assertEquals(100, actions.get(0).getData());
      assertEquals("org.rssowl.ActionId2", actions.get(1).getActionId());
      assertEquals(true, Arrays.equals((Object[]) actions.get(1).getData(), new Long[] { 1l, 2l, 3l }));

      ISearch savedSearch = savedFilter.getSearch();
      assertEquals(search.matchAllConditions(), savedSearch.matchAllConditions());
      List<ISearchCondition> savedConditions = savedSearch.getSearchConditions();
      assertEquals(2, savedConditions.size());

      assertEquals(true, ((SearchCondition) savedConditions.get(0)).isIdentical(condition1));
      assertEquals(true, ((SearchCondition) savedConditions.get(1)).isIdentical(condition2));
    }

    /* Update */
    {
      Collection<ISearchFilter> filters = DynamicDAO.loadAll(ISearchFilter.class);
      ISearchFilter savedFilter = filters.iterator().next();

      savedFilter.setName("Disabled Filter");
      savedFilter.setEnabled(false);
      savedFilter.setOrder(1);

      List<IFilterAction> actions = savedFilter.getActions();
      savedFilter.removeAction(actions.get(0));
      actions.get(1).setData(new Long[] { 3l, 2l, 1l });
      IFilterAction action = fTypesFactory.createFilterAction("org.rssowl.ActionId3");
      action.setData(200);
      savedFilter.addAction(action);

      ISearch savedSearch = savedFilter.getSearch();
      savedSearch.setMatchAllConditions(false);
      List<ISearchCondition> savedConditions = savedSearch.getSearchConditions();

      ISearchCondition condition1 = savedConditions.get(0);
      condition1.setSpecifier(SearchSpecifier.CONTAINS_NOT);
      savedSearch.removeSearchCondition(savedConditions.get(1));

      ISearchCondition condition2 = fTypesFactory.createSearchCondition(fTypesFactory.createSearchField(INews.LOCATION, INews.class.getName()), SearchSpecifier.IS, new Long[][] { { 2l } });
      savedSearch.addSearchCondition(condition2);

      DynamicDAO.save(savedFilter);
      if (gc)
        System.gc();

      filters = DynamicDAO.loadAll(ISearchFilter.class);
      assertEquals(1, filters.size());
      ISearchFilter loadedFilter = filters.iterator().next();
      assertEquals(savedFilter.getName(), loadedFilter.getName());
      assertEquals(savedFilter.getOrder(), loadedFilter.getOrder());
      assertEquals(savedFilter.isEnabled(), loadedFilter.isEnabled());

      List<IFilterAction> loadedActions = loadedFilter.getActions();
      assertEquals(2, loadedActions.size());
      assertEquals("org.rssowl.ActionId2", loadedActions.get(0).getActionId());
      assertEquals(true, Arrays.equals((Object[]) actions.get(1).getData(), new Long[] { 3l, 2l, 1l }));
      assertEquals("org.rssowl.ActionId3", loadedActions.get(1).getActionId());
      assertEquals(200, loadedActions.get(1).getData());

      ISearch loadedSearch = loadedFilter.getSearch();
      assertEquals(savedSearch.matchAllConditions(), loadedSearch.matchAllConditions());
      List<ISearchCondition> loadedConditions = loadedSearch.getSearchConditions();
      assertEquals(2, loadedConditions.size());

      assertEquals(true, ((SearchCondition) loadedConditions.get(0)).isIdentical(condition1));
      assertEquals(true, ((SearchCondition) loadedConditions.get(1)).isIdentical(condition2));
    }
View Full Code Here

      filterElement.setAttribute(Attributes.ENABLED.get(), String.valueOf(isEnabled));
      filterElement.setAttribute(Attributes.MATCH_ALL_NEWS.get(), String.valueOf(matchAllNews));
      body.addContent(filterElement);

      /* Export Search if provided */
      ISearch search = filter.getSearch();
      if (search != null) {
        List<ISearchCondition> conditions = search.getSearchConditions();

        Element searchElement = new Element(Tag.SEARCH.get(), RSSOWL_NS);
        searchElement.setAttribute(Attributes.MATCH_ALL_CONDITIONS.get(), String.valueOf(search.matchAllConditions()));
        filterElement.addContent(searchElement);

        for (ISearchCondition condition : conditions) {
          Element conditionElement = new Element(Tag.SEARCH_CONDITION.get(), RSSOWL_NS);
          searchElement.addContent(conditionElement);
View Full Code Here

    int order = Integer.parseInt(filterElement.getAttributeValue(Attributes.ORDER.get()));
    boolean isEnabled = Boolean.parseBoolean(filterElement.getAttributeValue(Attributes.ENABLED.get()));
    boolean matchAllNews = Boolean.parseBoolean(filterElement.getAttributeValue(Attributes.MATCH_ALL_NEWS.get()));

    /* Search if provided */
    ISearch search = null;
    Element searchElement = filterElement.getChild(Tag.SEARCH.get(), RSSOWL_NS);
    if (searchElement != null) {
      search = factory.createSearch(null);
      search.setMatchAllConditions(Boolean.parseBoolean(searchElement.getAttributeValue(Attributes.MATCH_ALL_CONDITIONS.get())));

      /* Search Conditions */
      List<?> conditions = searchElement.getChildren(Tag.SEARCH_CONDITION.get(), RSSOWL_NS);
      for (int i = 0; i < conditions.size(); i++) {
        try {
          Element condition = (Element) conditions.get(i);

          ISearchCondition searchCondition = processSearchCondition(condition, dateFormat);
          if (searchCondition != null)
            search.addSearchCondition(searchCondition);
        } catch (NumberFormatException e) {
          Activator.getDefault().logError(e.getMessage(), e);
        } catch (ParseException e) {
          Activator.getDefault().logError(e.getMessage(), e);
        }
View Full Code Here

   */
  @Test
  public void testDeleteSearchFilter() throws Exception {
    ISearchField field = fFactory.createSearchField(INews.IS_FLAGGED, INews.class.getName());
    ISearchCondition condition = fFactory.createSearchCondition(field, SearchSpecifier.IS, true);
    ISearch search = fFactory.createSearch(null);
    search.addSearchCondition(condition);

    ISearchFilter filter = fFactory.createSearchFilter(null, search, "Filter");
    DynamicDAO.save(filter);

    assertNotNull(filter.toReference().resolve());
    assertNotNull(search.toReference().resolve());
    assertNotNull(condition.toReference().resolve());

    DynamicDAO.delete(filter);

    assertNull(filter.toReference().resolve());
    assertNull(search.toReference().resolve());
    assertNull(condition.toReference().resolve());
  }
View Full Code Here

    pref = new Preference("integer");
    pref.putIntegers(8);
    DynamicDAO.save(pref);

    /* ISearchFilter with ISearch */
    ISearch search = fFactory.createSearch(null);
    sc1 = fFactory.createSearchCondition(fFactory.createSearchField(INews.TITLE, INews.class.getName()), SearchSpecifier.IS, "foobar");
    sc2 = fFactory.createSearchCondition(fFactory.createSearchField(IEntity.ALL_FIELDS, INews.class.getName()), SearchSpecifier.CONTAINS, "test");
    sc3 = fFactory.createSearchCondition(fFactory.createSearchField(INews.PUBLISH_DATE, INews.class.getName()), SearchSpecifier.IS, new Date());
    search.addSearchCondition(sc1);
    search.addSearchCondition(sc2);
    search.addSearchCondition(sc3);

    ISearchFilter filter = fFactory.createSearchFilter(null, search, "filter");
    filter.addAction(fFactory.createFilterAction("action1"));
    filter.addAction(fFactory.createFilterAction("action2"));

View Full Code Here

        ISearchFilter otherFilter = (ISearchFilter) result.get(0);
        assertTrue(filter.getName().equals(otherFilter.getName()));
        assertEquals(filter.getActions().size(), otherFilter.getActions().size());

        ISearch search = filter.getSearch();
        ISearch otherSearch = otherFilter.getSearch();

        assertEquals(search.getSearchConditions().size(), otherSearch.getSearchConditions().size());
      }

      /* Assert Conditional Get */
      List<IConditionalGet> condGets = db.query(IConditionalGet.class);
      assertEquals(condGets.size(), defragmentedDb.query(IConditionalGet.class).size());
View Full Code Here

    filter.addAction(fFactory.createFilterAction("org.rssowl.core.MarkReadNewsAction"));
    filter.addAction(fFactory.createFilterAction("org.rssowl.core.MarkStickyNewsAction"));
    DynamicDAO.save(filter);

    /* 3) Entire News contains "Foo" - Enabled - Mark Read */
    ISearch search = fFactory.createSearch(null);
    ISearchField entireNewsField = fFactory.createSearchField(IEntity.ALL_FIELDS, INews.class.getName());
    search.addSearchCondition(fFactory.createSearchCondition(entireNewsField, SearchSpecifier.CONTAINS, "Foo"));
    filter = fFactory.createSearchFilter(null, search, "Filter 3");
    filter.setMatchAllNews(false);
    filter.setOrder(3);
    filter.addAction(fFactory.createFilterAction("org.rssowl.core.MarkReadNewsAction"));
    DynamicDAO.save(filter);

    /* 4) Entire News contains "Foo" or "Bar" - Enabled - Mark Read */
    search = fFactory.createSearch(null);
    search.setMatchAllConditions(true);
    search.addSearchCondition(fFactory.createSearchCondition(entireNewsField, SearchSpecifier.CONTAINS, "Foo"));
    search.addSearchCondition(fFactory.createSearchCondition(entireNewsField, SearchSpecifier.CONTAINS, "Bar"));
    filter = fFactory.createSearchFilter(null, search, "Filter 4");
    filter.setMatchAllNews(false);
    filter.setOrder(4);
    filter.addAction(fFactory.createFilterAction("org.rssowl.core.MarkReadNewsAction"));
    DynamicDAO.save(filter);

    /* 5) Location is "XY" - Enabled - Mark Read */
    search = fFactory.createSearch(null);
    ISearchField locationField = fFactory.createSearchField(INews.LOCATION, INews.class.getName());
    search.addSearchCondition(fFactory.createSearchCondition(locationField, SearchSpecifier.SCOPE, ModelUtils.toPrimitive(Arrays.asList(new IFolderChild[] { fBookMark1, fNewsBin }))));
    filter = fFactory.createSearchFilter(null, search, "Filter 5");
    filter.setMatchAllNews(false);
    filter.setOrder(8);
    filter.addAction(fFactory.createFilterAction("org.rssowl.core.MarkReadNewsAction"));
    DynamicDAO.save(filter);

    /* 6) Match All News - Enabled - Label News */
    filter = fFactory.createSearchFilter(null, null, "Filter 6");
    filter.setMatchAllNews(true);
    filter.setOrder(5);
    IFilterAction action = fFactory.createFilterAction(LabelNewsAction.ID);
    action.setData(fImportantLabel.getId());
    filter.addAction(action);
    DynamicDAO.save(filter);

    /* 7) Match All News - Enabled - Label News + Move News + Play Sound */
    filter = fFactory.createSearchFilter(null, null, "Filter 7");
    filter.setMatchAllNews(true);
    filter.setOrder(5);
    action = fFactory.createFilterAction(LabelNewsAction.ID);
    action.setData(fImportantLabel.getId());
    filter.addAction(action);

    action = fFactory.createFilterAction(MoveNewsAction.ID);
    action.setData(new Long[] { fNewsBin.getId() });
    filter.addAction(action);

    action = fFactory.createFilterAction("org.rssowl.ui.PlaySoundAction");
    action.setData("C:\\ProgramData\\Microsoft\\Windows & Help\\Start Menu");
    filter.addAction(action);

    DynamicDAO.save(filter);

    /* 8) Filter with Properties as Data */
    filter = fFactory.createSearchFilter(null, null, "Filter 8");
    filter.setMatchAllNews(true);
    filter.setOrder(5);

    action = fFactory.createFilterAction("org.rssowl.ui.PlaySoundAction");
    Properties props = new Properties();
    props.setProperty("foo", "bar");
    props.setProperty("hello world", " world hello ");
    props.setProperty("<some xml>tags</a>", "foo & bar");
    action.setData(props);
    filter.addAction(action);

    DynamicDAO.save(filter);

    /* 9) Location is DELETED - Enabled - Mark Read */
    search = fFactory.createSearch(null);
    locationField = fFactory.createSearchField(INews.LOCATION, INews.class.getName());
    Long[][] result = new Long[3][];
    result[0] = new Long[] { 99999l };
    search.addSearchCondition(fFactory.createSearchCondition(locationField, SearchSpecifier.SCOPE, result));
    filter = fFactory.createSearchFilter(null, search, "Filter 9");
    filter.setMatchAllNews(false);
    filter.setOrder(9);
    filter.addAction(fFactory.createFilterAction("org.rssowl.core.MarkReadNewsAction"));
    DynamicDAO.save(filter);
View Full Code Here

TOP

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

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.