@Test void filter() { PolicyFilter filter = new PolicyFilter(); Bundle filteredBundle = new Bundle(); Folder folder1 = createFolder("folder1", "1", null); Folder folder3 = createFolder("folder3", "3", folder1); filteredBundle.addEntity(folder1); filteredBundle.addEntity(createFolder("folder2", "2", folder3)); filteredBundle.addEntity(folder3); filteredBundle.addEntity(createFolder("folder4", "4", folder1)); Bundle bundle = FilterTestUtils.getBundle(); bundle.setDependencyMap( ImmutableMap.of( new Dependency("1", Policy.class, "policy1", EntityTypes.POLICY_TYPE), Arrays.asList(new Dependency("2", Policy.class, "policy2", EntityTypes.POLICY_TYPE), new Dependency("3", Policy.class, "policy3", EntityTypes.POLICY_TYPE)), new Dependency("2", Policy.class, "policy2", EntityTypes.POLICY_TYPE), Collections.singletonList(new Dependency("4", Policy.class, "policy4", EntityTypes.POLICY_TYPE)))); bundle.addEntity(createPolicy("policy1", "1", "", "2", null, "")); bundle.addEntity(createPolicy("policy2", "2", "", "5", null, "")); bundle.addEntity(createPolicy("policy3", "3", "", null, null, "")); bundle.addEntity(createPolicy("policy4", "4", "", "1", null, "")); bundle.addEntity(createPolicy("policy5", "5", "", "4", null, "")); List<Policy> filteredEntities = filter.filter("/my/folder/path", new FilterConfiguration(), bundle, filteredBundle); assertEquals(3, filteredEntities.size()); assertTrue(filteredEntities.stream().anyMatch(c -> "policy1".equals(c.getName()))); assertTrue(filteredEntities.stream().anyMatch(c -> "policy4".equals(c.getName()))); assertTrue(filteredEntities.stream().anyMatch(c -> "policy5".equals(c.getName()))); }
@Override public List<Policy> filter(String folderPath, FilterConfiguration filterConfiguration, Bundle bundle, Bundle filteredBundle) { Map<String, Folder> folders = filteredBundle.getEntities(Folder.class); return bundle.getEntities(Policy.class).values().stream() .filter(p -> folders.containsKey(p.getParentFolderId())).collect(Collectors.toList()); }
PolicyFilter implements EntityFilter<Policy> { @Override public List<Policy> filter(String folderPath, FilterConfiguration filterConfiguration, Bundle bundle, Bundle filteredBundle) { Map<String, Folder> folders = filteredBundle.getEntities(Folder.class); return bundle.getEntities(Policy.class).values().stream() .filter(p -> folders.containsKey(p.getParentFolderId())).collect(Collectors.toList()); } }
PolicyFilter implements EntityFilter<Policy> { @Override public List<Policy> filter(String folderPath, FilterConfiguration filterConfiguration, Bundle bundle, Bundle filteredBundle) { Map<String, Folder> folders = filteredBundle.getEntities(Folder.class); return bundle.getEntities(Policy.class).values().stream() .filter(p -> folders.containsKey(p.getParentFolderId())).collect(Collectors.toList()); }  }
PolicyFilter implements EntityFilter<Policy> { @Override public List<Policy> filter(String folderPath, FilterConfiguration filterConfiguration, Bundle bundle, Bundle filteredBundle) { Map<String, Folder> folders = filteredBundle.getEntities(Folder.class); return bundle.getEntities(Policy.class).values().stream() .filter(p -> folders.containsKey(p.getParentFolderId())).collect(Collectors.toList()); }  @Override @NotNull Collection<Class<? extends EntityFilter>> getDependencyEntityFilters(); @Override List<Policy> filter(String folderPath, FilterConfiguration filterConfiguration, Bundle bundle, Bundle filteredBundle); }
PolicyFilter implements EntityFilter<Policy> { @Override public List<Policy> filter(String folderPath, FilterConfiguration filterConfiguration, Bundle bundle, Bundle filteredBundle) { Map<String, Folder> folders = filteredBundle.getEntities(Folder.class); return bundle.getEntities(Policy.class).values().stream() .filter(p -> folders.containsKey(p.getParentFolderId())).collect(Collectors.toList()); }  @Override @NotNull Collection<Class<? extends EntityFilter>> getDependencyEntityFilters(); @Override List<Policy> filter(String folderPath, FilterConfiguration filterConfiguration, Bundle bundle, Bundle filteredBundle);  }