/** * Recursively collects the group and all its containers in the <data>groups</data> collection * * @param lg * @param groups */ private void collectContainers(LayerGroupSummary lg, Set<LayerGroupSummary> groups) { if (!groups.contains(lg)) { if (lg.getMode() != LayerGroupInfo.Mode.SINGLE) { groups.add(lg); } for (LayerGroupSummary container : lg.containerGroups) { collectContainers(container, groups); } } }
/** * Returns all groups containing directly or indirectly containing the resource * * @param resource * @return */ public Collection<LayerGroupSummary> getContainerGroupsFor(ResourceInfo resource) { String id = resource.getId(); Set<LayerGroupSummary> groups = resourceContainmentCache.get(id); if (groups == null) { return Collections.emptyList(); } Set<LayerGroupSummary> result = new HashSet<>(); for (LayerGroupSummary lg : groups) { collectContainers(lg, result); } return result; }
/** * Returns all groups containing directly or indirectly the specified group, and relevant for * security (e.g., anything but {@link LayerGroupInfo.Mode#SINGLE} ones * * @param lg * @return */ public Collection<LayerGroupSummary> getContainerGroupsFor(LayerGroupInfo lg) { String id = lg.getId(); if (id == null) { return Collections.emptyList(); } LayerGroupSummary summary = groupCache.get(id); if (summary == null) { return Collections.emptyList(); } Set<LayerGroupSummary> result = new HashSet<>(); for (LayerGroupSummary container : summary.getContainerGroups()) { collectContainers(container, result); } return result; }