DynamoFilterUtil { public static void replaceFilter(Filter original, Filter newFilter, String propertyId, boolean firstOnly) { try { replaceFilter(null, original, newFilter, propertyId, firstOnly); } catch (RuntimeException ex) { } } 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 testReplaceFilter() { And and = new And(new Compare.Equal("a", 12), new Compare.Equal("b", 24)); DynamoFilterUtil.replaceFilter(and, new Compare.Equal("c", 13), "b", false); Filter f = and.getFilters().get(1); assertTrue(f instanceof Compare.Equal); assertEquals("c", ((Compare.Equal) f).getPropertyId()); }
@Test public void testReplaceFilterAll() { And and = new And(new Compare.Equal("a", 12), new Compare.Equal("a", 12)); DynamoFilterUtil.replaceFilter(and, new Compare.Equal("c", 13), "a", false); Filter f0 = and.getFilters().get(0); assertTrue(f0 instanceof Compare.Equal); assertEquals("c", ((Compare.Equal) f0).getPropertyId()); Filter f1 = and.getFilters().get(1); assertTrue(f1 instanceof Compare.Equal); assertEquals("c", ((Compare.Equal) f1).getPropertyId()); }
@Test public void testReplaceFilterFirstOnly() { And and = new And(new Compare.Equal("a", 12), new Compare.Equal("a", 12)); DynamoFilterUtil.replaceFilter(and, new Compare.Equal("c", 13), "a", true); Filter f0 = and.getFilters().get(0); assertTrue(f0 instanceof Compare.Equal); assertEquals("c", ((Compare.Equal) f0).getPropertyId()); Filter f1 = and.getFilters().get(1); assertTrue(f1 instanceof Compare.Equal); assertEquals("a", ((Compare.Equal) f1).getPropertyId()); }
@Test public void testReplaceNot() { Not not = new Not(new Compare.Equal("a", 12)); DynamoFilterUtil.replaceFilter(not, new Compare.Equal("d", 13), "a", false); Filter f = not.getFilter(); assertTrue(f instanceof Compare.Equal); assertEquals("d", ((Compare.Equal) f).getPropertyId()); }
@Test public void testReplaceComplex() { Not not = new Not(new Compare.Equal("a", 12)); And and = new And(new Compare.Equal("b", 12), new Compare.Equal("c", 24)); Or or = new Or(not, and); DynamoFilterUtil.replaceFilter(or, new And(new Compare.Greater("f", 4), new Compare.Less("g", 7)), "b", false); Filter f = or.getFilters().get(1); assertTrue(f instanceof And); And inner = (And) ((And) f).getFilters().get(0); assertEquals("f", ((PropertyFilter) inner.getFilters().get(0)).getPropertyId()); }