DynamoFilterUtil { public static Filter extractFilter(Filter filter, String propertyId) { if (filter instanceof AbstractJunctionFilter) { AbstractJunctionFilter junction = (AbstractJunctionFilter) filter; for (Filter child : junction.getFilters()) { Filter found = extractFilter(child, propertyId); if (found != null) { return found; } } } else if (filter instanceof Compare) { Compare compare = (Compare) filter; if (compare.getPropertyId().equals(propertyId)) { return compare; } } else if (filter instanceof Like) { Like like = (Like) filter; if (like.getPropertyId().equals(propertyId)) { return like; } } else if (filter instanceof In) { In in = (In) filter; if (in.getPropertyId().equals(propertyId)) { return in; } } else if (filter instanceof Contains) { Contains c = (Contains) filter; if (c.getPropertyId().equals(propertyId)) { return c; } } else if (filter instanceof Between) { Between between = (Between) filter; if (between.getPropertyId().equals(propertyId)) { return between; } } else if (filter instanceof Not) { Not not = (Not) filter; return extractFilter(not.getFilter(), propertyId); } return 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 testExtractFilter_Contains() { com.ocs.dynamo.filter.Contains contains = new com.ocs.dynamo.filter.Contains("prop1", "a"); com.ocs.dynamo.filter.And and = new com.ocs.dynamo.filter.And(contains, new com.ocs.dynamo.filter.Compare.Equal("prop3", "someString")); com.ocs.dynamo.filter.Filter f1 = DynamoFilterUtil.extractFilter(and, "prop1"); assertTrue(f1 instanceof Contains); }
@Test public void testExtractFilter_Compare2() { com.ocs.dynamo.filter.Compare.Equal compare = new com.ocs.dynamo.filter.Compare.Equal("prop1", "someString"); com.ocs.dynamo.filter.Filter f1 = DynamoFilterUtil.extractFilter(compare, "prop1"); assertNotNull(f1); com.ocs.dynamo.filter.Filter f2 = DynamoFilterUtil.extractFilter(compare, "prop2"); assertNull(f2); }
@Test public void testExtractFilter_Like2() { com.ocs.dynamo.filter.Like like = new com.ocs.dynamo.filter.Like("prop1", "someString"); com.ocs.dynamo.filter.Filter f1 = DynamoFilterUtil.extractFilter(like, "prop1"); assertNotNull(f1); com.ocs.dynamo.filter.Filter f2 = DynamoFilterUtil.extractFilter(like, "prop2"); assertNull(f2); }
@Test public void testExtractFilter_Between() { Between between = new Between("prop1", 100, 200); com.ocs.dynamo.filter.Filter f1 = DynamoFilterUtil.extractFilter(between, "prop1"); assertNotNull(f1); com.ocs.dynamo.filter.Filter f2 = DynamoFilterUtil.extractFilter(between, "prop2"); assertNull(f2); }
@Test public void testExtractFilter_Complex2() { com.ocs.dynamo.filter.Like compare = new com.ocs.dynamo.filter.Like("prop1", "someString"); com.ocs.dynamo.filter.And and = new com.ocs.dynamo.filter.And(compare, new com.ocs.dynamo.filter.Compare.Equal("prop3", "someString")); com.ocs.dynamo.filter.Filter f1 = DynamoFilterUtil.extractFilter(and, "prop1"); assertNotNull(f1); com.ocs.dynamo.filter.Filter f3 = DynamoFilterUtil.extractFilter(and, "prop3"); assertNotNull(f3); com.ocs.dynamo.filter.Filter f2 = DynamoFilterUtil.extractFilter(compare, "prop2"); assertNull(f2); }
@Test public void testExtractFilter_In() { com.ocs.dynamo.filter.In in = new com.ocs.dynamo.filter.In("prop1", Lists.newArrayList("a", "b")); com.ocs.dynamo.filter.And and = new com.ocs.dynamo.filter.And(in, new com.ocs.dynamo.filter.Compare.Equal("prop3", "someString")); com.ocs.dynamo.filter.Filter f1 = DynamoFilterUtil.extractFilter(and, "prop1"); assertTrue(f1 instanceof In); }