/* 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();