/** * Renames an existing layer. * * @param oldName The name of the existing layer * @param newName The name to rename the layer to * @throws IllegalArgumentException */ public synchronized void rename(final String oldName, final String newName) throws NoSuchElementException, IllegalArgumentException { TileLayerConfiguration config = getConfiguration(oldName); config.renameLayer(oldName, newName); }
/** * Replaces the given layer and returns the Layer's configuration, saving the configuration. * * @param tl The layer to modify * @throws IllegalArgumentException */ public synchronized void modify(final TileLayer tl) throws IllegalArgumentException { TileLayerConfiguration config = getConfiguration(tl); // TODO: this won't work with GetCapabilitiesConfiguration config.modifyLayer(tl); }
public TileLayerConfiguration getConfiguration(TileLayer tl) throws IllegalArgumentException { Assert.notNull(tl, "layer is null"); return getConfiguration(tl.getName()); }
/** * Completely and persistently eliminates, including the cached contents, the given tile layers. * * @param tileLayerNames */ public void removeTileLayers(final List<String> tileLayerNames) { checkNotNull(tileLayerNames); for (String tileLayerName : tileLayerNames) { try { tld.removeLayer(tileLayerName); } catch (IllegalArgumentException e) { log.log( Level.WARNING, "Error saving GWC Configuration " + tld.getConfiguration(tileLayerName).getIdentifier(), e); } } }
private void mockTileLayerDispatcher() throws Exception { when(tld.getConfiguration(same(tileLayer))).thenReturn(config); when(tld.getConfiguration(same(tileLayerGroup))).thenReturn(config); when(tld.getConfiguration(eq(tileLayer.getName()))).thenReturn(config); when(tld.getConfiguration(eq(tileLayerGroup.getName()))).thenReturn(config); when(tld.getTileLayer(eq(tileLayer.getName()))).thenReturn(tileLayer); when(tld.getTileLayer(eq(tileLayerGroup.getName()))).thenReturn(tileLayerGroup); when(tld.getLayerNames()).thenReturn( ImmutableSet.of(tileLayer.getName(), tileLayerGroup.getName())); Iterable<TileLayer> tileLayers = ImmutableList.of((TileLayer) tileLayer, (TileLayer) tileLayerGroup); when(tld.getLayerList()).thenReturn(tileLayers); when(tld.layerExists(eq(tileLayer.getName()))).thenReturn(true); when(tld.layerExists(eq(tileLayerGroup.getName()))).thenReturn(true); }
public void testModifyGridsetTruncates() throws Exception { final String oldName = "EPSG:4326"; final String newName = "MyEPSG:4326"; final GridSet oldGridset = gridSetBroker.get(oldName); final GridSet newGridset; { XMLGridSet xmlGridSet = new XMLGridSet(oldGridset); xmlGridSet.setName(newName); // make it so the gridset forces truncation xmlGridSet.setAlignTopLeft(!xmlGridSet.getAlignTopLeft()); newGridset = xmlGridSet.makeGridSet(); } XMLConfiguration xmlConfig = mock(XMLConfiguration.class); mediator = spy(mediator); when(mediator.getXmlConfiguration()).thenReturn(xmlConfig); when(tld.getConfiguration(same(tileLayer))).thenReturn(config); when(tld.getConfiguration(same(tileLayerGroup))).thenReturn(config); mediator.modifyGridSet(oldName, newGridset); verify(storageBroker, times(1)).deleteByGridSetId(eq(tileLayer.getName()), eq(oldName)); verify(storageBroker, times(1)) .deleteByGridSetId(eq(tileLayerGroup.getName()), eq(oldName)); }
public void testRemoveAllLayerGridsetsDisablesLayer() throws Exception { when(tld.getConfiguration(same(tileLayer))).thenReturn(config); when(tld.getConfiguration(same(tileLayerGroup))).thenReturn(config); when(tld.modify(same(tileLayer))).thenReturn(config); when(tld.modify(same(tileLayerGroup))).thenReturn(config); when(tld.removeGridset(eq("EPSG:4326"))).thenReturn(config); when(tld.removeGridset(eq("EPSG:900913"))).thenReturn(config); // sanity check before modification assertTrue(tileLayer.getInfo().isEnabled()); assertTrue(tileLayer.getInfo().isEnabled()); mediator.removeGridSets(ImmutableSet.of("EPSG:900913", "EPSG:4326")); verify(config, times(1)).save();// all other checks are in testRemoveGridsets verify(storageBroker, times(1)).deleteByGridSetId(eq(tileLayer.getName()), eq("EPSG:4326")); verify(storageBroker, times(1)).deleteByGridSetId(eq(tileLayerGroup.getName()), eq("EPSG:900913")); verify(storageBroker, times(1)).deleteByGridSetId(eq(tileLayer.getName()), eq("EPSG:4326")); verify(storageBroker, times(1)).deleteByGridSetId(eq(tileLayerGroup.getName()), eq("EPSG:900913")); assertTrue(tileLayer.getGridSubsets().isEmpty()); assertTrue(tileLayerGroup.getGridSubsets().isEmpty()); // layers ended up with no gridsubsets, shall have been disabled assertFalse(tileLayer.getInfo().isEnabled()); assertFalse(tileLayerGroup.getInfo().isEnabled()); }
layer.addGridSubset(newGridSubset); TileLayerConfiguration config = tld.getConfiguration(layer); config.modifyLayer(layer); saveConfigurations.add(config);
/** * @param source either a {@link LayerInfo} or a {@link LayerGroupInfo} * @return {@code true} if source has a tile layer associated, false otherwise, even if source * is not an instance of {@link LayerInfo} or {@link LayerGroupInfo} */ public boolean hasTileLayer(CatalogInfo source) { final String tileLayerName; if (source instanceof ResourceInfo) { LayerInfo layerInfo = getCatalog().getLayerByName(((ResourceInfo) source).prefixedName()); if (layerInfo == null) { return false; } tileLayerName = tileLayerName(layerInfo); } else if (source instanceof LayerInfo) { tileLayerName = tileLayerName((LayerInfo) source); } else if (source instanceof LayerGroupInfo) { tileLayerName = tileLayerName((LayerGroupInfo) source); } else { return false; } BaseConfiguration configuration; try { configuration = tld.getConfiguration(tileLayerName); } catch (IllegalArgumentException notFound) { return false; } return configuration instanceof CatalogConfiguration; }
/** * @param source * either a {@link LayerInfo} or a {@link LayerGroupInfo} * @return {@code true} if source has a tile layer associated, false otherwise, even if source * is not an instance of {@link LayerInfo} or {@link LayerGroupInfo} */ public boolean hasTileLayer(CatalogInfo source) { final String tileLayerId; if (source instanceof ResourceInfo) { LayerInfo layerInfo = getCatalog().getLayerByName( ((ResourceInfo) source).prefixedName()); if (layerInfo == null) { return false; } tileLayerId = layerInfo.getId(); } else if (source instanceof LayerInfo) { tileLayerId = ((LayerInfo) source).getId(); } else if (source instanceof LayerGroupInfo) { tileLayerId = ((LayerGroupInfo) source).getId(); } else { return false; } Configuration configuration; try { configuration = tld.getConfiguration(tileLayerId); } catch (IllegalArgumentException notFound) { return false; } return configuration instanceof CatalogConfiguration; }
when(tld.getConfiguration(same(tileLayer))).thenReturn(config); when(tld.getConfiguration(same(tileLayerGroup))).thenReturn(config); when(tld.modify(same(tileLayer))).thenReturn(config); when(tld.modify(same(tileLayerGroup))).thenReturn(config);
layer.addGridSubset(newGridSubset); Configuration config = tld.getConfiguration(layer); config.modifyLayer(layer); saveConfigurations.add(config);
public void testModifyGridsetNoNeedToTruncate() throws Exception { final String oldName = "EPSG:4326"; final String newName = "MyEPSG:4326"; final GridSet oldGridset = gridSetBroker.get(oldName); final GridSet newGridset; { XMLGridSet xmlGridSet = new XMLGridSet(oldGridset); xmlGridSet.setName(newName); newGridset = xmlGridSet.makeGridSet(); } XMLConfiguration xmlConfig = mock(XMLConfiguration.class); mediator = spy(mediator); when(mediator.getXmlConfiguration()).thenReturn(xmlConfig); assertNotNull(tileLayer.getGridSubset(oldName)); assertNotNull(tileLayerGroup.getGridSubset(oldName)); when(tld.getConfiguration(same(tileLayer))).thenReturn(config); when(tld.getConfiguration(same(tileLayerGroup))).thenReturn(config); mediator.modifyGridSet(oldName, newGridset); assertNull(tileLayer.getGridSubset(oldName)); assertNull(tileLayerGroup.getGridSubset(oldName)); assertNotNull(tileLayer.getGridSubset(newName)); assertNotNull(tileLayerGroup.getGridSubset(newName)); verify(xmlConfig, times(1)).removeGridset(eq(oldName)); verify(xmlConfig, times(1)).addOrReplaceGridSet(eq(new XMLGridSet(newGridset))); verify(xmlConfig, times(1)).save(); assertNull(gridSetBroker.get(oldName)); assertEquals(newGridset, gridSetBroker.get(newName)); verify(config, times(1)).save(); }