Package org.rssowl.core.persist

Examples of org.rssowl.core.persist.ISearchMark


        }
      };
      DynamicDAO.addEntityListener(IFeed.class, feedListener);

      /* Check SearchMark Deleted */
      ISearchMark searchMark1 = fFactory.createSearchMark(null, rootRef.resolve(), "Root SearchMark");
      root = DynamicDAO.save(searchMark1.getParent());
      searchMark1 = (ISearchMark) root.getMarks().get(root.getMarks().size() - 1);
      final SearchMarkReference searchMarkRef1 = new SearchMarkReference(searchMark1.getId());

      ISearchMark searchMark2 = fFactory.createSearchMark(null, rootChildRef.resolve(), "Root Child SearchMark");
      rootChild = DynamicDAO.save(searchMark2.getParent());
      searchMark2 = (ISearchMark) rootChild.getMarks().get(rootChild.getMarks().size() - 1);
      final SearchMarkReference searchMarkRef2 = new SearchMarkReference(searchMark2.getId());

      ISearchMark searchMark3 = fFactory.createSearchMark(null, rootChildChild1ChildRef.resolve(), "Root Child Child #1 Child SearchMark");
      rootChildChild1Child = DynamicDAO.save(searchMark3.getParent());
      searchMark3 = (ISearchMark) rootChildChild1Child.getMarks().get(rootChildChild1Child.getMarks().size() - 1);
      final SearchMarkReference searchMarkRef3 = new SearchMarkReference(searchMark3.getId());

      final boolean searchMarkEventsIssued[] = new boolean[3];

      searchMarkListener = new SearchMarkAdapter() {
        @Override
        public void entitiesDeleted(Set<SearchMarkEvent> events) {
          for (SearchMarkEvent event : events) {
            ISearchMark searchMark = event.getEntity();

            if (searchMarkRef1.references(searchMark))
              searchMarkEventsIssued[0] = true;

            else if (searchMarkRef2.references(searchMark))
View Full Code Here


    /* Create Default SearchMarks */
    String newsEntityName = INews.class.getName();

    /* SearchCondition: New and Updated News */
    {
      ISearchMark mark = factory.createSearchMark(null, folder, "New and Updated News");

      ISearchField field1 = factory.createSearchField(INews.STATE, newsEntityName);
      factory.createSearchCondition(null, mark, field1, SearchSpecifier.IS, EnumSet.of(State.NEW));
    }

    /* SearchCondition: Recent News */
    {
      ISearchMark mark = factory.createSearchMark(null, folder, "Recent News");

      ISearchField field1 = factory.createSearchField(INews.AGE_IN_DAYS, newsEntityName);
      factory.createSearchCondition(null, mark, field1, SearchSpecifier.IS_LESS_THAN, 2);
    }

    /* SearchCondition: News with Attachments */
    {
      ISearchMark mark = factory.createSearchMark(null, folder, "News with Attachments");

      ISearchField field = factory.createSearchField(INews.HAS_ATTACHMENTS, newsEntityName);
      factory.createSearchCondition(null, mark, field, SearchSpecifier.IS, true);
    }

    /* SearchCondition: Sticky News */
    {
      ISearchMark mark = factory.createSearchMark(null, folder, "Sticky News");

      ISearchField field = factory.createSearchField(INews.IS_FLAGGED, newsEntityName);
      factory.createSearchCondition(null, mark, field, SearchSpecifier.IS, true);
    }

    /*
     * Condition : +(State IS *new* OR State is *unread* OR State IS *updated*)
     * AND +((Entire News contains "Foo") OR Author is "Benjamin Pasero")
     */
    {
      ISearchMark mark = factory.createSearchMark(null, folder, "Complex Search");

      ISearchField field1 = factory.createSearchField(INews.STATE, newsEntityName);
      ISearchCondition cond1 = factory.createSearchCondition(null, mark, field1, SearchSpecifier.IS, EnumSet.of(INews.State.NEW, State.UNREAD, State.UPDATED));

      ISearchField field4 = factory.createSearchField(IEntity.ALL_FIELDS, newsEntityName);
      ISearchCondition cond4 = factory.createSearchCondition(null, mark, field4, SearchSpecifier.CONTAINS, "Foo");

      ISearchField field5 = factory.createSearchField(INews.AUTHOR, newsEntityName);
      ISearchCondition cond5 = factory.createSearchCondition(null, mark, field5, SearchSpecifier.IS, "Benjamin Pasero");
    }

    /*
     * Condition : +(State IS *new* OR State is *unread* OR State IS *updated*)
     * AND (Entire News contains "Foo") AND (Author is "Benjamin Pasero")
     */
    {
      ISearchMark mark = factory.createSearchMark(null, folder, "Complex Search");

      ISearchField field1 = factory.createSearchField(INews.STATE, newsEntityName);
      ISearchCondition cond1 = factory.createSearchCondition(null, mark, field1, SearchSpecifier.IS, EnumSet.of(INews.State.NEW, State.UNREAD, State.UPDATED));

      ISearchField field4 = factory.createSearchField(IEntity.ALL_FIELDS, newsEntityName);
      ISearchCondition cond4 = factory.createSearchCondition(null, mark, field4, SearchSpecifier.CONTAINS, "Foo");

      ISearchField field5 = factory.createSearchField(INews.AUTHOR, newsEntityName);
      ISearchCondition cond5 = factory.createSearchCondition(null, mark, field5, SearchSpecifier.CONTAINS, "Benjamin Pasero");
    }

    /*
     * Condition : (Entire News contains "Foo") AND (Title contains "Bar") AND
     * (Author is not "Benjamin Pasero")
     */
    {
      ISearchMark mark = factory.createSearchMark(null, folder, "Complex Search");

      ISearchField field1 = factory.createSearchField(IEntity.ALL_FIELDS, newsEntityName);
      ISearchCondition cond1 = factory.createSearchCondition(null, mark, field1, SearchSpecifier.CONTAINS, "fafa");

      ISearchField field2 = factory.createSearchField(INews.TITLE, newsEntityName);
      ISearchCondition cond2 = factory.createSearchCondition(null, mark, field2, SearchSpecifier.CONTAINS, "Bar");

      ISearchField field3 = factory.createSearchField(INews.AUTHOR, newsEntityName);
      ISearchCondition cond3 = factory.createSearchCondition(null, mark, field3, SearchSpecifier.IS_NOT, "Benjamin Pasero");
    }

    /*
     * Condition : +(State IS *new* OR State is *unread* OR State IS *updated*)
     * AND (Category IS Windows) AND (Category IS Apple)
     */
    {
      ISearchMark mark = factory.createSearchMark(null, folder, "Complex Search");

      ISearchField field1 = factory.createSearchField(INews.STATE, newsEntityName);
      ISearchCondition cond1 = factory.createSearchCondition(null, mark, field1, SearchSpecifier.IS, EnumSet.of(INews.State.NEW, State.UNREAD, State.UPDATED));

      ISearchField field4 = factory.createSearchField(INews.CATEGORIES, newsEntityName);
      ISearchCondition cond4 = factory.createSearchCondition(null, mark, field4, SearchSpecifier.IS, "windows");

      ISearchField field5 = factory.createSearchField(INews.CATEGORIES, newsEntityName);
      ISearchCondition cond5 = factory.createSearchCondition(null, mark, field5, SearchSpecifier.IS, "apple");
    }

    /*
     * Condition : +(State IS *new* OR State is *unread* OR State IS *updated*)
     * AND (Category IS Windows) AND (Category IS Apple) AND (Category IS NOT
     * Slashdot)
     */
    {
      ISearchMark mark = factory.createSearchMark(null, folder, "Complex Search");

      ISearchField field1 = factory.createSearchField(INews.STATE, newsEntityName);
      ISearchCondition cond1 = factory.createSearchCondition(null, mark, field1, SearchSpecifier.IS, EnumSet.of(INews.State.NEW, State.UNREAD, State.UPDATED));

      ISearchField field4 = factory.createSearchField(INews.CATEGORIES, newsEntityName);
      ISearchCondition cond4 = factory.createSearchCondition(null, mark, field4, SearchSpecifier.IS, "windows");

      ISearchField field5 = factory.createSearchField(INews.CATEGORIES, newsEntityName);
      ISearchCondition cond5 = factory.createSearchCondition(null, mark, field5, SearchSpecifier.IS, "apple");

      ISearchField field6 = factory.createSearchField(INews.CATEGORIES, newsEntityName);
      factory.createSearchCondition(null, mark, field6, SearchSpecifier.IS_NOT, "slashdot");
    }

    /*
     * Condition : +(State IS *new* OR State is *unread* OR State IS *updated*)
     * AND (Category IS NOT Windows)
     */
    {
      ISearchMark mark = factory.createSearchMark(null, folder, "Complex Search");

      ISearchField field1 = factory.createSearchField(INews.STATE, newsEntityName);
      ISearchCondition cond1 = factory.createSearchCondition(null, mark, field1, SearchSpecifier.IS, EnumSet.of(INews.State.NEW, State.UNREAD, State.UPDATED));

      ISearchField field4 = factory.createSearchField(INews.CATEGORIES, newsEntityName);
      ISearchCondition cond4 = factory.createSearchCondition(null, mark, field4, SearchSpecifier.IS_NOT, "windows");
    }

    /*
     * Condition : +(State IS *new* OR State is *unread* OR State IS *updated*)
     * AND (Age is Less than 5 Days)
     */
    {
      ISearchMark mark = factory.createSearchMark(null, folder, "Complex Search");

      ISearchField field1 = factory.createSearchField(INews.STATE, newsEntityName);
      ISearchCondition cond1 = factory.createSearchCondition(null, mark, field1, SearchSpecifier.IS, EnumSet.of(INews.State.NEW, State.UNREAD, State.UPDATED));

      ISearchField field4 = factory.createSearchField(INews.AGE_IN_DAYS, newsEntityName);
      ISearchCondition cond4 = factory.createSearchCondition(null, mark, field4, SearchSpecifier.IS_LESS_THAN, 5);
    }

    /*
     * Condition 5: (State IS *new* OR State is *unread* OR State IS *updated*)
     * AND All_Fields CONTAINS foo
     */
    {
      ISearchMark mark = factory.createSearchMark(null, folder, "Complex Search");

      ISearchField field1 = factory.createSearchField(INews.STATE, newsEntityName);
      ISearchCondition cond1 = factory.createSearchCondition(null, mark, field1, SearchSpecifier.IS, EnumSet.of(INews.State.NEW, State.UNREAD, State.UPDATED));

      ISearchField field4 = factory.createSearchField(IEntity.ALL_FIELDS, newsEntityName);
View Full Code Here

  private void processSavedSearch(Element savedSearchElement, IFolder folder, DateFormat dateFormat) {
    String name = savedSearchElement.getAttributeValue(Attributes.NAME.get());
    boolean matchAllConditions = Boolean.parseBoolean(savedSearchElement.getAttributeValue(Attributes.MATCH_ALL_CONDITIONS.get()));

    ISearchMark searchmark = Owl.getModelFactory().createSearchMark(null, folder, name);
    searchmark.setMatchAllConditions(matchAllConditions);

    /* Recursively Interpret Children */
    List<?> children = savedSearchElement.getChildren();
    for (Iterator<?> iter = children.iterator(); iter.hasNext();) {
      Element child = (Element) iter.next();
      String childName = child.getName().toLowerCase();

      /* Process Search Condition */
      if (Tag.SEARCH_CONDITION.get().equals(childName)) {
        try {
          ISearchCondition searchCondition = processSearchCondition(child, dateFormat);
          if (searchCondition != null)
            searchmark.addSearchCondition(searchCondition);
        } catch (NumberFormatException e) {
          Activator.getDefault().logError(e.getMessage(), e);
        } catch (ParseException e) {
          Activator.getDefault().logError(e.getMessage(), e);
        }
View Full Code Here

    IFolder folder = findFolder(search.getParent());
    if (folder != null) {
      List<IMark> marks = folder.getMarks();
      for (IMark mark : marks) {
        if (mark instanceof ISearchMark) {
          ISearchMark other = (ISearchMark) mark;
          if (isIdentical(search, other))
            return true;
        }
      }
    }
View Full Code Here

      mapFolderToElement.get(mark.getParent()).addContent(element);
    }

    /* Export SearchMark */
    else if (mark instanceof ISearchMark) {
      ISearchMark searchMark = (ISearchMark) mark;
      List<ISearchCondition> conditions = searchMark.getSearchConditions();

      element = new Element(Tag.SAVED_SEARCH.get(), RSSOWL_NS);
      element.setAttribute(Attributes.NAME.get(), name);
      element.setAttribute(Attributes.MATCH_ALL_CONDITIONS.get(), String.valueOf(searchMark.matchAllConditions()));
      element.setAttribute(Attributes.ID.get(), String.valueOf(mark.getId()), RSSOWL_NS);
      mapFolderToElement.get(mark.getParent()).addContent(element);

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

      fDb.delete(((NewsBin) entity).internalGetNewsContainer());

  }

  private void cascadeSearchConditionDeletion(ISearchCondition searchCondition) {
    ISearchMark searchMark = loadSearchMark(searchCondition);
    if (searchMark != null) {
      if (!itemsBeingDeletedContains(searchMark)) {
        if (searchMark.removeSearchCondition(searchCondition))
          fDb.ext().store(searchMark, 2);
      }
    }
    fDb.delete(searchCondition.getField());
  }
View Full Code Here

    }
    fDb.delete(searchCondition.getField());
  }

  private ISearchMark loadSearchMark(ISearchCondition searchCondition) {
    ISearchMark mark = Owl.getPersistenceService().getDAOService().getSearchMarkDAO().load(searchCondition);
    return mark;
  }
View Full Code Here

      BookMarkEvent eventTemplate = (BookMarkEvent) template;
      IFolder oldParent = eventTemplate == null ? null : eventTemplate.getOldParent();
      modelEvent = new BookMarkEvent(mark, oldParent, root);
    }
    else if (entity instanceof ISearchMark) {
      ISearchMark mark = (ISearchMark) entity;
      SearchMarkEvent eventTemplate = (SearchMarkEvent) template;
      IFolder oldParent = eventTemplate == null ? null : eventTemplate.getOldParent();
      modelEvent = new SearchMarkEvent(mark, oldParent, root);
    }
    else if (entity instanceof INewsBin) {
View Full Code Here

  @Test
  public void testLoadFromSearchCondition() {
    /* Add */
    IFolder folder = DynamicDAO.save(fFactory.createFolder(null, null, "Folder"));

    ISearchMark searchMark0 = DynamicDAO.save(fFactory.createSearchMark(null, folder, "SearchMark 0"));
    ISearchField field0 = fFactory.createSearchField(IEntity.ALL_FIELDS, INews.class.getName());
    ISearchCondition searchCondition0 = fFactory.createSearchCondition(null, searchMark0, field0, SearchSpecifier.CONTAINS, "Foo");
    DynamicDAO.save(searchCondition0);
    SearchConditionReference searchCondRef0 = new SearchConditionReference(searchCondition0.getId());

    ISearchField field1 = fFactory.createSearchField(IEntity.ALL_FIELDS, INews.class.getName());
    ISearchCondition searchCondition1 = fFactory.createSearchCondition(null, searchMark0, field1, SearchSpecifier.BEGINS_WITH, "Bar");
    DynamicDAO.save(searchCondition1);

    DynamicDAO.save(searchMark0);
    Long searchMark0Id = searchMark0.getId();

    ISearchMark searchMark1 = DynamicDAO.save(fFactory.createSearchMark(null, folder, "SearchMark 1"));
    ISearchField field2 = fFactory.createSearchField(IEntity.ALL_FIELDS, INews.class.getName());
    ISearchCondition searchCondition2 = fFactory.createSearchCondition(null, searchMark1, field2, SearchSpecifier.CONTAINS, "Foo");
    DynamicDAO.save(searchCondition2);

    DynamicDAO.save(searchMark1);
View Full Code Here

    };
    try {
      /* Add */
      IFolder folder = DynamicDAO.save(fFactory.createFolder(null, null, "Folder"));

      ISearchMark searchMark = DynamicDAO.save(fFactory.createSearchMark(null, folder, "SearchMark 0"));
      ISearchField field0 = fFactory.createSearchField(IEntity.ALL_FIELDS, INews.class.getName());
      fFactory.createSearchCondition(null, searchMark, field0, SearchSpecifier.CONTAINS, "Foo");

      ISearchField field1 = fFactory.createSearchField(IEntity.ALL_FIELDS, INews.class.getName());
      fFactory.createSearchCondition(null, searchMark, field1, SearchSpecifier.BEGINS_WITH, "Bar");

      DynamicDAO.save(searchMark);

      SearchMarkReference searchMarkRef = new SearchMarkReference(searchMark.getId());
      int popularity = searchMark.getPopularity();
      Date lastVisitDate = searchMark.getLastVisitDate();

      if (lastVisitDate == null) {
        lastVisitDate = new Date();
      }
      Thread.sleep(100);

      ISearchMarkDAO dao = DynamicDAO.getDAO(ISearchMarkDAO.class);
      DynamicDAO.addEntityListener(ISearchCondition.class, listener);
      dao.visited(searchMark);
      searchMark = null;
      System.gc();

      searchMark = searchMarkRef.resolve();
      assertEquals(popularity + 1, searchMark.getPopularity());
      assertTrue(searchMark.getLastVisitDate().compareTo(lastVisitDate) > 0);
      assertTrue(searchMark.getLastVisitDate().compareTo(new Date()) < 0);
    } finally {
      DynamicDAO.removeEntityListener(ISearchCondition.class, listener);
    }
  }
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.