DynamoFilterUtil { public static void replaceMasterAndDetailFilters(Filter filter, EntityModel<?> entityModel) { for (AttributeModel am : entityModel.getAttributeModels()) { replaceMasterDetailFilter(filter, am); if (am.getNestedEntityModel() != null) { replaceMasterAndDetailFilters(filter, am.getNestedEntityModel()); } } } 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 testReplaceMasterAndDetailFilters1() { EntityModel<TestEntity> model = emf.getModel(TestEntity.class); And and = new And(new Compare.Equal("tags", Lists.newArrayList("abc"))); DynamoFilterUtil.replaceMasterAndDetailFilters(and, model); Filter replaced = and.getFilters().get(0); assertTrue(replaced instanceof Or); Or or = (Or) replaced; assertTrue(or.getFilters().get(0) instanceof Contains); Contains ct = (Contains) or.getFilters().get(0); assertEquals("abc", ct.getValue()); and = new And(new Compare.Equal("tags", "def")); DynamoFilterUtil.replaceMasterAndDetailFilters(and, model); replaced = and.getFilters().get(0); assertTrue(replaced instanceof Contains); ct = (Contains) replaced; assertEquals("def", ct.getValue()); }
@Test public void testReplaceMasterAndDetailFilters2() { EntityModel<TestEntity2> model = emf.getModel(TestEntity2.class); And and = new And(new Compare.Equal("testEntity", Lists.newArrayList(new TestEntity(), new TestEntity()))); DynamoFilterUtil.replaceMasterAndDetailFilters(and, model); Filter replaced = and.getFilters().get(0); assertTrue(replaced instanceof In); In in = (In) replaced; assertEquals(2, in.getValues().size()); and = new And(new Compare.Equal("testEntity", new TestEntity())); DynamoFilterUtil.replaceMasterAndDetailFilters(and, model); replaced = and.getFilters().get(0); assertTrue(replaced instanceof Compare.Equal); }
@Test public void testReplaceMasterAndDetailFilters3() { EntityModel<TestEntity2> model = emf.getModel(TestEntity2.class); And and = new And(new Compare.Equal("testEntity", Lists.newArrayList(new TestEntity(), new TestEntity()))); DynamoFilterUtil.replaceMasterAndDetailFilters(and, model); Filter replaced = and.getFilters().get(0); assertTrue(replaced instanceof In); In in = (In) replaced; assertEquals(2, in.getValues().size()); and = new And(new Compare.Equal("testEntity", new TestEntity())); DynamoFilterUtil.replaceMasterAndDetailFilters(and, model); replaced = and.getFilters().get(0); assertTrue(replaced instanceof Compare.Equal); }