/** * Modifies a {@link TileLayer} via the {@link TileLayerDispatcher}, and logs the change. Only * affects the GeoWebCache configuration. * * @param layer The layer to save. */ public void save(final TileLayer layer) { checkNotNull(layer); log.info("Saving GeoSeverTileLayer " + layer.getName()); tld.modify(layer); }
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); } }
@Deprecated @RequestMapping(value = "/layers/{layerName}", method = RequestMethod.POST) public ResponseEntity<?> layerPost(@RequestBody TileLayer tl, @PathVariable String layerName) throws GeoWebCacheException, RestException, IOException { tl = checkLayer(layerName, tl); try { layerDispatcher.modify(tl); } catch (IllegalArgumentException e) { return new ResponseEntity<Object>( "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 ?", HttpStatus.BAD_REQUEST); } HttpHeaders headers = new HttpHeaders(); headers.add("Warning", "299: Deprecated API. Use PUT instead."); return new ResponseEntity<>(headers, HttpStatus.OK); }
@RequestMapping(value = "/layers/{layerName}", method = RequestMethod.PUT) public ResponseEntity<?> layerPut(@RequestBody TileLayer tl, @PathVariable String layerName) throws GeoWebCacheException, RestException, IOException { tl = checkLayer(layerName, tl); TileLayer testtl = null; try { testtl = findTileLayer(tl.getName(), layerDispatcher); } catch (RestException re) { // This is the expected behavior, it should not exist } if (testtl == null) { layerDispatcher.addLayer(tl); } else { layerDispatcher.modify(tl); } return new ResponseEntity<Object>("layer saved", HttpStatus.OK); }
/** * Renames an existing blob store. * * @param oldName The name of the existing blob store * @param newName The name to rename the blob store to * @throws IllegalArgumentException */ public synchronized void renameBlobStore(final String oldName, final String newName) throws NoSuchElementException, IllegalArgumentException { BlobStoreConfiguration config = getConfiguration(oldName); config.renameBlobStore(oldName, newName); // update layers for (TileLayer layer : layers.getLayerList()) { if (oldName.equals(layer.getBlobStoreId())) { layer.setBlobStoreId(newName); layers.modify(layer); } } }
/** * 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); } }
Configuration configuration = tld.modify(tileLayer); changedConfigs.add(configuration); } catch (IllegalArgumentException ignore) {
tld.modify(tileLayer); } catch (IllegalArgumentException ignore) {
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); } }
@Test public void testModifyBadLayer() { String layerName = "newLayer"; WMSLayer layer = new WMSLayer( layerName, new String[] {"http://example.com/"}, null, null, null, null, null, null, null, false, null); try { tileLayerDispatcher.modify(layer); fail("Expected exception when modifiying nonexistant layer"); } catch (IllegalArgumentException e) { } try { tileLayerDispatcher.modify(null); fail("Expected exception when modifiying null layer"); } catch (IllegalArgumentException e) { } }
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()); }
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("My4326"))).thenReturn(config); .deleteByGridSetId(eq(tileLayerGroup.getName()), eq("My4326")); verify(tld, times(1)).modify(same(tileLayer)); verify(tld, times(1)).modify(same(tileLayerGroup)); verify(tld, times(1)).removeGridset(eq("EPSG:4326")); verify(tld, times(1)).removeGridset(eq("My4326"));
@Test public void testModifyLayer() throws GeoWebCacheException { String modifiedLayerName = GWCConfigIntegrationTestData.LAYER_TOPP_STATES; TileLayer layer = tileLayerDispatcher.getTileLayer(modifiedLayerName); layer.removeGridSubset(GWCConfigIntegrationTestData.GRIDSET_EPSG2163); boolean advertised = !layer.isAdvertised(); layer.setAdvertised(advertised); tileLayerDispatcher.modify(layer); TileLayer modifiedLayer = tileLayerDispatcher.getTileLayer(modifiedLayerName); assertEquals(layer, modifiedLayer); assertEquals(advertised, modifiedLayer.isAdvertised()); assertNull(modifiedLayer.getGridSubset(GWCConfigIntegrationTestData.GRIDSET_EPSG2163)); }