private void removeRepositoryFromAllGroups(final Repository repositoryToRemove) throws Exception { for (Repository group : repositories.values()) { Optional<GroupFacet> groupFacet = group.optionalFacet(GroupFacet.class); if (groupFacet.isPresent() && groupFacet.get().member(repositoryToRemove)) { removeRepositoryFromGroup(repositoryToRemove, group); } } }
private void findContainingGroups(final String name, final SortedMap<Integer, List<String>> groupNamesByLevel, final int level) { final List<String> newContainingGroups = new ArrayList<>(); //find any groups that directly contain the desired repository name (and make sure to only include each name //once to save processing time) repositories.values().stream().filter(repository -> repository.optionalFacet(GroupFacet.class).filter(groupFacet -> groupFacet.member(name)).isPresent() && groupNamesByLevel.values().stream().noneMatch(repoNames -> repoNames.contains(repository.getName()))) .forEach(repository -> newContainingGroups.add(repository.getName())); List<String> groupNames = groupNamesByLevel.computeIfAbsent(level, newLevel -> new ArrayList<>()); groupNames.addAll(newContainingGroups); //now process each group we found and check if any groups contain it newContainingGroups.forEach( newName -> findContainingGroups(newName, groupNamesByLevel, level + 1)); }
@Subscribe @AllowConcurrentEvents public void on(final NpmSearchIndexInvalidatedEvent event) { if (facet(GroupFacet.class).member(event.getRepository())) { invalidateCachedSearchIndex(); } }