DynamoFilterUtil { public static void removeFilters(Filter filter, String... propertyIds) { if (filter instanceof AbstractJunctionFilter) { AbstractJunctionFilter junction = (AbstractJunctionFilter) filter; removeFilterFormJunction(junction, propertyIds); cleanupEmptyFilters(junction); } else if (filter instanceof Not) { Not not = (Not) filter; if (not.getFilter() != null) { removeFilters(not.getFilter(), propertyIds); } Filter child = not.getFilter(); if (child instanceof PropertyFilter) { PropertyFilter pf = (PropertyFilter) child; for (String s : propertyIds) { if (pf.getPropertyId().equals(s)) { not.setFilter(null); } } } else if (child instanceof AbstractJunctionFilter) { AbstractJunctionFilter ajf = (AbstractJunctionFilter) child; if (ajf.getFilters().isEmpty()) { not.setFilter(null); } } } } private  DynamoFilterUtil(); static Filter extractFilter(Filter filter, String propertyId); static List<Filter> flattenAnd(And and); static void removeFilters(Filter filter, String... propertyIds); static void replaceMasterAndDetailFilters(Filter filter, EntityModel<?> entityModel); static void replaceFilter(Filter original, Filter newFilter, String propertyId, boolean firstOnly);  }
@Test public void testRemoveFilters() { com.ocs.dynamo.filter.Compare.Equal compare1 = new com.ocs.dynamo.filter.Compare.Equal("prop1", "someString"); com.ocs.dynamo.filter.Compare.Equal compare2 = new com.ocs.dynamo.filter.Compare.Equal("prop2", "someString"); com.ocs.dynamo.filter.Compare.Equal compare3 = new com.ocs.dynamo.filter.Compare.Equal("prop3", "someString"); And and = new And(compare1, compare2, compare3); DynamoFilterUtil.removeFilters(and, "prop1"); assertEquals(2, and.getFilters().size()); and = new And(compare1, compare2, compare3); DynamoFilterUtil.removeFilters(and, "prop4"); assertEquals(3, and.getFilters().size()); And nested = new And(compare1, new And(compare2, compare3)); DynamoFilterUtil.removeFilters(nested, "prop2", "prop3"); assertEquals(1, nested.getFilters().size()); and = new And(compare1, new Not(compare2)); DynamoFilterUtil.removeFilters(and, "prop2"); assertEquals(1, and.getFilters().size()); and = new And(compare1, new Not(new And(compare2, compare3))); DynamoFilterUtil.removeFilters(and, "prop2", "prop3"); assertEquals(1, and.getFilters().size()); }