@Override public String getId() { return delegate.getId(); }
int result = 1; result = prime * result + ((lg.getBounds() == null) ? 0 : lg.getBounds().hashCode()); result = prime * result + ((lg.getId() == null) ? 0 : lg.getId().hashCode()); result = prime * result + ((lg.getLayers() == null) ? 0 : lg.getLayers().hashCode()); result = prime * result + ((lg.getMetadata() == null) ? 0 : lg.getMetadata().hashCode());
private void registerContainedGroups(LayerGroupInfo lg) { lg.getLayers() .stream() .filter(IS_GROUP) .forEach( p -> { String containerId = lg.getId(); String containedId = p.getId(); LayerGroupSummary container = groupCache.get(containerId); LayerGroupSummary contained = groupCache.get(containedId); if (container != null && contained != null) { contained.containerGroups.add(container); } }); }
/** * 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; }
private void addGroupInfo(LayerGroupInfo lg) { LayerGroupSummary groupData = new LayerGroupSummary(lg); groupCache.put(lg.getId(), groupData); lg.getLayers() .stream() .filter(IS_LAYER) .forEach( p -> { String id = ((LayerInfo) p).getResource().getId(); Set<LayerGroupSummary> containers = resourceContainmentCache.computeIfAbsent( id, CONCURRENT_SET_BUILDER); containers.add(groupData); }); }
private void clearGroupInfo(LayerGroupInfo lg) { LayerGroupSummary data = groupCache.remove(lg.getId()); // clear the resource containment cache lg.getLayers() .stream() .filter(IS_LAYER) .forEach( p -> { String rid = ((LayerInfo) p).getResource().getId(); synchronized (rid) { Set<LayerGroupSummary> containers = resourceContainmentCache.get(rid); if (containers != null) { containers.remove(data); } } }); // this group does not contain anything anymore, remove from containment for (LayerGroupSummary d : groupCache.values()) { d.containerGroups.remove(lg); } }
/** * Between modification proxies and security buffering the list of layers of a group it's just * safer and more predictable to use a id comparison instead of a equals that accounts for each * and every field * * @param layerGroup * @param container * @return */ private int getLayerGroupIndex(LayerGroupInfo layerGroup, LayerGroupInfo container) { int idx = 0; final String id = layerGroup.getId(); for (PublishedInfo pi : container.getLayers()) { if (pi instanceof LayerGroupInfo && id.equals(pi.getId())) { return idx; } idx++; } return -1; }
@Override public LayerGroupAccessLimits getAccessLimits(Authentication user, LayerGroupInfo layerGroup) { if (user == null) { return null; } final String name = user.getName(); return (LayerGroupAccessLimits) getUserMap(name).get(layerGroup.getId()); }
LayerGroupSummary(LayerGroupInfo lg) { this.id = lg.getId(); this.workspace = lg.getWorkspace() != null ? lg.getWorkspace().getName() : null; this.name = lg.getName(); this.mode = lg.getMode(); containerGroups = CONCURRENT_SET_BUILDER.apply(null); }
if (nameIdx != -1) { String newName = (String) event.getNewValues().get(nameIdx); updateGroupName(lg.getId(), newName); updateGroupWorkspace(lg.getId(), newWorkspace); List<PublishedInfo> newLayers = (List<PublishedInfo>) event.getNewValues().get(layerIdx); updateContainedLayers(groupCache.get(lg.getId()), oldLayers, newLayers); updateGroupMode(lg.getId(), newMode);
@Test public void testChangeGroupMode() throws Exception { LayerGroupSummary summary = cc.groupCache.get(nature.getId()); assertEquals(Mode.SINGLE, summary.getMode()); nature.setMode(Mode.OPAQUE_CONTAINER); catalog.save(nature); summary = cc.groupCache.get(nature.getId()); assertEquals(Mode.OPAQUE_CONTAINER, summary.getMode()); } }
public void visit(LayerGroupInfo layerGroupToRemove) { // remove layerGroupToRemove references from other groups Filter associatedTo = Predicates.equal("layers.id", layerGroupToRemove.getId(), MatchAction.ANY); try (CloseableIterator<LayerGroupInfo> it = catalog.list(LayerGroupInfo.class, associatedTo)) { while (it.hasNext()) { LayerGroupInfo group = it.next(); // parallel remove of layer and styles int index = getLayerGroupIndex(layerGroupToRemove, group); while (index != -1) { group.getLayers().remove(index); group.getStyles().remove(index); index = getLayerGroupIndex(layerGroupToRemove, group); } if (group.getLayers().size() == 0) { // if group is empty, delete it visit(group); } else { catalog.save(group); } } } // finally remove the group catalog.remove(layerGroupToRemove); }
public void visit(LayerInfo layer) { // first update the groups, remove the layer, and if no // other layers remained, remove the group as well Filter groupContainsLayer = Predicates.equal("layers.id", layer.getId(), MatchAction.ANY); try (CloseableIterator<LayerGroupInfo> groups = catalog.list(LayerGroupInfo.class, groupContainsLayer)) { while (groups.hasNext()) { LayerGroupInfo group = groups.next(); // parallel remove of layer and styles int index = group.getLayers().indexOf(layer); while (index != -1) { group.getLayers().remove(index); group.getStyles().remove(index); index = group.getLayers().indexOf(layer); } // either update or remove the group if (group.getLayers().size() == 0) { visit(catalog.getLayerGroup(group.getId())); } else { catalog.save(group); } } } // remove the layer and (for the moment) its resource as well // TODO: change this to just remove the resource once the // resource/publish split is done ResourceInfo resource = layer.getResource(); catalog.remove(layer); catalog.remove(resource); }
@Test public void testRenameGroup() throws Exception { nature.setName("renamed"); catalog.save(nature); LayerGroupSummary summary = cc.groupCache.get(nature.getId()); assertEquals("renamed", summary.getName()); assertEquals(WS, summary.getWorkspace()); }
@After public void clearLayerGroups() throws Exception { CascadeDeleteVisitor remover = new CascadeDeleteVisitor(catalog); for (LayerGroupInfo lg : catalog.getLayerGroups()) { if (catalog.getLayerGroup(lg.getId()) != null) { remover.visit(lg); } } }
layerGroups.add(lg); expect(lg.getId()).andReturn(newId()).anyTimes(); expect(lg.getName()).andReturn(name).anyTimes();
@Test public void testRenameWorkspace() throws Exception { WorkspaceInfo ws = catalog.getDefaultWorkspace(); ws.setName("renamed"); try { catalog.save(ws); LayerGroupSummary summary = cc.groupCache.get(nature.getId()); assertEquals(NATURE_GROUP, summary.getName()); assertEquals("renamed", summary.getWorkspace()); } finally { ws.setName(WS); catalog.save(ws); } }
@Test public void testChangeWorkspace() throws Exception { DataStoreInfo store = catalog.getDataStores().get(0); try { WorkspaceInfo aws = catalog.getWorkspaceByName(ANOTHER_WS); store.setWorkspace(aws); catalog.save(store); nature.setWorkspace(aws); catalog.save(nature); LayerGroupSummary summary = cc.groupCache.get(nature.getId()); assertEquals(NATURE_GROUP, summary.getName()); assertEquals(ANOTHER_WS, summary.getWorkspace()); } finally { WorkspaceInfo ws = catalog.getWorkspaceByName(WS); store.setWorkspace(ws); catalog.save(store); } }