/** * Adds a layer to the {@link CatalogConfiguration} and saves it. */ public void add(GeoServerTileLayer tileLayer) { Configuration config = tld.addLayer(tileLayer); try { config.save(); } catch (IOException e) { propagate(getRootCause(e)); } }
/** * Completely and persistently eliminates, including the cached contents, the given tile layers. * * @param tileLayerNames */ public void removeTileLayers(final List<String> tileLayerNames) { checkNotNull(tileLayerNames); Set<Configuration> confsToSave = new HashSet<Configuration>(); for (String tileLayerName : tileLayerNames) { Configuration configuration = tld.removeLayer(tileLayerName); if (configuration != null) { confsToSave.add(configuration); } } for (Configuration conf : confsToSave) { try { conf.save(); } catch (IOException e) { log.log(Level.WARNING, "Error saving GWC Configuration " + conf.getIdentifier(), e); } } }
config.modifyLayer(layer); saveConfigurations.add(config); config.save();
public void save(final GeoServerTileLayer layer) { checkNotNull(layer); log.info("Saving GeoSeverTileLayer " + layer.getName()); Configuration modifiedConfig = tld.modify(layer); try { modifiedConfig.save(); } catch (IOException e) { Throwable rootCause = Throwables.getRootCause(e); throw Throwables.propagate(rootCause); } }
/** * DELETE removes an existing layer * * @param req * @param resp * @throws RestletException */ private void doDelete(Request req, Response resp) throws RestletException, GeoWebCacheException { String layerName = (String) req.getAttributes().get("layer"); findTileLayer(layerName, layerDispatcher); try { Configuration configuration = layerDispatcher.removeLayer(layerName); if (configuration == null) { throw new RestletException("Configuration to remove layer not found", Status.SERVER_ERROR_INTERNAL); } configuration.save(); } catch (IOException e) { throw new RestletException(e.getMessage(), Status.SERVER_ERROR_INTERNAL, e); } }
/** * POST overwrites an existing layer * * @param req * @param resp * @throws RestletException */ private void doPost(Request req, Response resp) throws RestletException, IOException, GeoWebCacheException { TileLayer tl = deserializeAndCheckLayer(req, resp, false); try { Configuration configuration = layerDispatcher.modify(tl); configuration.save(); } catch (IllegalArgumentException e) { throw new RestletException("Layer " + tl.getName() + " is not known by the configuration." + "Maybe it was loaded from another source, or you're trying to add a new " + "layer and need to do an HTTP PUT ?", Status.CLIENT_ERROR_BAD_REQUEST); } }
config.save();
public void testAddTileLayer() throws Exception { when(tld.addLayer(same(tileLayer))).thenThrow(new IllegalArgumentException("fake")); when(tld.addLayer(same(tileLayerGroup))).thenReturn(config); try { mediator.add(tileLayer); fail("Expected IAE"); } catch (IllegalArgumentException e) { assertTrue(true); } mediator.add(tileLayerGroup); verify(config, times(1)).save(); }
public void testRemoveTileLayers() throws Exception { try { mediator.removeTileLayers(null); } catch (NullPointerException e) { assertTrue(true); } when(tld.removeLayer(eq(tileLayer.getName()))).thenReturn(config); when(tld.removeLayer(eq(tileLayerGroup.getName()))).thenReturn(config); List<String> layerNames = Arrays.asList(tileLayer.getName(), tileLayerGroup.getName()); mediator.removeTileLayers(layerNames); verify(tld, times(1)).removeLayer(eq(tileLayer.getName())); verify(tld, times(1)).removeLayer(eq(tileLayerGroup.getName())); verify(config, times(1)).save(); }
/** * PUT creates a new layer * * @param req * @param resp * @throws RestletException */ private void doPut(Request req, Response resp) throws RestletException, IOException, GeoWebCacheException { TileLayer tl = deserializeAndCheckLayer(req, resp, true); TileLayer testtl = null; try { testtl = findTileLayer(tl.getName(), layerDispatcher); } catch (RestletException re) { // This is the expected behavior, it should not exist } if (testtl == null) { Configuration config = layerDispatcher.addLayer(tl); config.save(); } else { throw new RestletException("Layer with name " + tl.getName() + " already exists, " + "use POST if you want to replace it.", Status.CLIENT_ERROR_BAD_REQUEST); } }
public void testModifyTileLayer() throws Exception { try { mediator.save(null); fail(); } catch (NullPointerException e) { assertTrue(true); } when(tld.modify(same(tileLayer))).thenThrow(new IllegalArgumentException()); try { mediator.save(tileLayer); fail(); } catch (IllegalArgumentException e) { assertTrue(true); } when(tld.modify(same(tileLayerGroup))).thenReturn(config); mediator.save(tileLayerGroup); verify(config, times(1)).save(); when(tld.modify(same(tileLayer))).thenReturn(config); doThrow(new IOException()).when(config).save(); try { mediator.save(tileLayer); } catch (RuntimeException e) { assertTrue(true); } }
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()); }
verify(tld, times(1)).removeGridset(eq("My4326")); verify(config, times(1)).save();
verify(config, times(2)).save();
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(); }