From 3846a6c1f5c3475b1614644a2492b8614c5416e0 Mon Sep 17 00:00:00 2001 From: Louis JOHANET Date: Tue, 20 Aug 2019 16:28:40 +0200 Subject: [PATCH 1/2] Add retrieving layers by workspace --- .../geoserver/rest/GeoServerRESTReader.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTReader.java b/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTReader.java index 5aa06eff..3cccb39f 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTReader.java +++ b/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTReader.java @@ -819,6 +819,20 @@ public RESTLayerList getLayers() { } return RESTLayerList.build(load(url)); } + + /** + * Get summary info about layers from a given workspace. + * + * @return summary info about Layers as a {@link RESTLayerList} + */ + public RESTLayerList getLayers(String workspace) { + String url = "/rest/workspaces/" + workspace + "/layers.xml"; + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("### Retrieving layers from " + url); + } + return RESTLayerList.build(load(url)); + } + /** * Get summary info about all FeatureTypes of a workspace. From 8fdeea788d33689c3407fa7bbe5a70f1cad0e7c9 Mon Sep 17 00:00:00 2001 From: Louis JOHANET Date: Tue, 20 Aug 2019 16:29:08 +0200 Subject: [PATCH 2/2] Add unit testing for layer retrieval by workspace --- .../rest/decoder/about/GSVersionDecoder.java | 1 + .../rest/GeoserverRESTReaderTest.java | 29 +++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/main/java/it/geosolutions/geoserver/rest/decoder/about/GSVersionDecoder.java b/src/main/java/it/geosolutions/geoserver/rest/decoder/about/GSVersionDecoder.java index 32e8ceb9..7ee9e2f7 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/decoder/about/GSVersionDecoder.java +++ b/src/main/java/it/geosolutions/geoserver/rest/decoder/about/GSVersionDecoder.java @@ -154,6 +154,7 @@ public enum VERSION { v26(26, "2\\.6([^0-9]|$).*"), v27(27, "2\\.7([^0-9]|$).*"), v28(28, "2\\.8([^0-9]|$).*"), + v213(213, "2\\.13([^0-9]|$).*"), ABOVE(9999, "2\\..+"), UNRECOGNIZED(-1, null); diff --git a/src/test/java/it/geosolutions/geoserver/rest/GeoserverRESTReaderTest.java b/src/test/java/it/geosolutions/geoserver/rest/GeoserverRESTReaderTest.java index ab2dc7b3..2cfdb5a0 100644 --- a/src/test/java/it/geosolutions/geoserver/rest/GeoserverRESTReaderTest.java +++ b/src/test/java/it/geosolutions/geoserver/rest/GeoserverRESTReaderTest.java @@ -30,14 +30,16 @@ import it.geosolutions.geoserver.rest.decoder.RESTLayerList; import it.geosolutions.geoserver.rest.decoder.RESTNamespaceList; import it.geosolutions.geoserver.rest.decoder.RESTWorkspaceList; +import it.geosolutions.geoserver.rest.decoder.about.GSVersionDecoder; import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem; - +import java.io.File; +import java.io.IOException; import java.util.List; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - +import org.springframework.core.io.ClassPathResource; import static org.junit.Assert.*; @@ -48,7 +50,6 @@ public class GeoserverRESTReaderTest extends GeoserverRESTTest { private final static Logger LOGGER = LoggerFactory.getLogger(GeoserverRESTReaderTest.class); - /** * Test of getLayers method, of class GeoServerRESTReader. */ @@ -72,6 +73,28 @@ public void testGetLayers() { // } LOGGER.debug(""); } + + /** + * Test of getLayers method with a given workspace, of class GeoServerRESTReader. + * Requires Geoserver > 2.13 + * @throws IOException + */ + @Test + public void testGetLayersWithWorkspace() throws IOException { + if(!enabled()) return; + // Skip the test if Geoserver < 2.13 + if(GSVersionDecoder.VERSION.v213.compareTo(GSVersionDecoder.VERSION.getVersion(GS_VERSION)) > 0) { + return; + } + deleteAllWorkspacesRecursively(); + + assertTrue(publisher.createWorkspace(DEFAULT_WS)); + File zipFile = new ClassPathResource("testdata/resttestshp.zip").getFile(); + // test insert + assertTrue(publisher.publishShp(DEFAULT_WS, "resttestshp", "cities", zipFile)); + assertTrue(reader.getLayers(DEFAULT_WS).size() == 1); + LOGGER.debug(""); + } /** * Test of getDatastores method, of class GeoServerRESTReader.