From 84967563004e0a544b9b89b995bc63a990570c48 Mon Sep 17 00:00:00 2001 From: Carl Schroedl Date: Mon, 12 Sep 2016 17:26:09 -0500 Subject: [PATCH 01/12] First cut of private implementation for #199 --- .../rest/GeoServerRESTPublisher.java | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java b/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java index c68c5330..2816b6b5 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java +++ b/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java @@ -3206,4 +3206,75 @@ public void postImport(int i) throws Exception { importerManager.postImport(i); } + /** + * Defines multiple modes of recalculating bounding boxes. + * + * @author Carl Schroedl - cschroedl@usgs.gov + */ + public enum BBoxRecalculationMode { + /** + * Do not calculate any fields, regardless of the projection, projection + * policy, etc. This might be useful to avoid slow recalculation when + * operating against large datasets. + */ + NONE(""), + + /** + * Recalculate the native bounding box, but do not recalculate the + * lat/long bounding box. + */ + NATIVE_BBOX("nativebbox"), + + /** + * Recalculate both the native bounding box and the lat/long bounding + * box. + */ + NATIVE_AND_LAT_LON_BBOX("nativebbox,latlonbbox") + ; + + private final String paramValue; + + /** + * Associates the enum value with a URL query string parameter value + * @param paramValue + */ + BBoxRecalculationMode(String paramValue){ + this.paramValue = paramValue; + } + + /** + * Get the URL param value + * @return The query string parameter value + */ + public String getParamValue(){ + return paramValue; + } + } + + /** + * + * Recalculate the bounding box for a feature or a type + * + * @param type + * @param workspace + * @param storeName + * @param layerName + * @param calculationMode + * @return true if recalculation succeeded, false otherwise. + */ + private boolean recalculateBBox(StoreType type, String workspace, String storeName, String layerName, BBoxRecalculationMode calculationMode){ + + String sUrl = restURL + "/rest/workspaces/" + workspace + "/" + + type.getType() +"s/" + storeName + "/" + + type.getTypeName() + "/" + + layerName + "." + Format.XML.toString() + "?recalculate=" + + calculationMode.getParamValue(); + + LOGGER.debug("Constructed the following url for bounding box recalculation: "); + + String sendResult = HTTPUtils.put(sUrl, "", "text/plain", gsuser, + gspass); + + return sendResult != null; + } } From c9ef31f5430d43c86a639edc01cb11471fc57db5 Mon Sep 17 00:00:00 2001 From: Carl Schroedl Date: Tue, 13 Sep 2016 10:57:25 -0500 Subject: [PATCH 02/12] Added public wrapper methods #199 --- .../rest/GeoServerRESTPublisher.java | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java b/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java index 2816b6b5..873b44d2 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java +++ b/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java @@ -3253,7 +3253,7 @@ public String getParamValue(){ /** * - * Recalculate the bounding box for a feature or a type + * Recalculate the bounding box for a feature type or a coverage * * @param type * @param workspace @@ -3270,11 +3270,35 @@ private boolean recalculateBBox(StoreType type, String workspace, String storeNa layerName + "." + Format.XML.toString() + "?recalculate=" + calculationMode.getParamValue(); - LOGGER.debug("Constructed the following url for bounding box recalculation: "); + LOGGER.debug("Constructed the following url for bounding box recalculation: " + sUrl); String sendResult = HTTPUtils.put(sUrl, "", "text/plain", gsuser, gspass); - - return sendResult != null; + boolean success = sendResult != null; + return success; + } + + /** + * Recalculate a bounding box for a feature type + * @param workspace + * @param storeName + * @param layerName + * @param calculationMode + * @return + */ + public boolean recalculateFeatureTypeBBox(String workspace, String storeName, String layerName, BBoxRecalculationMode calculationMode){ + return recalculateBBox(StoreType.DATASTORES, workspace, storeName, layerName, calculationMode); + } + + /** + * Recalculate a bounding box for a coverage + * @param workspace + * @param storeName + * @param layerName + * @param calculationMode + * @return + */ + public boolean recalculateCoverageBBox(String workspace, String storeName, String layerName, BBoxRecalculationMode calculationMode){ + return recalculateBBox(StoreType.COVERAGESTORES, workspace, storeName, layerName, calculationMode); } } From ce3ee3339120006c4bef3e7641282748224f00fc Mon Sep 17 00:00:00 2001 From: Carl Schroedl Date: Tue, 20 Sep 2016 14:04:39 -0500 Subject: [PATCH 03/12] Fixed silent error due to url case-sensitivity. Adjusted request body accordingly. #199 --- .../rest/GeoServerRESTPublisher.java | 56 +++++---- .../GeoserverRESTRecalculateTest.java | 107 ++++++++++++++++++ 2 files changed, 141 insertions(+), 22 deletions(-) create mode 100644 src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTRecalculateTest.java diff --git a/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java b/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java index 873b44d2..92238443 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java +++ b/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java @@ -3212,13 +3212,6 @@ public void postImport(int i) throws Exception { * @author Carl Schroedl - cschroedl@usgs.gov */ public enum BBoxRecalculationMode { - /** - * Do not calculate any fields, regardless of the projection, projection - * policy, etc. This might be useful to avoid slow recalculation when - * operating against large datasets. - */ - NONE(""), - /** * Recalculate the native bounding box, but do not recalculate the * lat/long bounding box. @@ -3229,7 +3222,14 @@ public enum BBoxRecalculationMode { * Recalculate both the native bounding box and the lat/long bounding * box. */ - NATIVE_AND_LAT_LON_BBOX("nativebbox,latlonbbox") + NATIVE_AND_LAT_LON_BBOX("nativebbox,latlonbbox"), + + /** + * Do not calculate any fields, regardless of the projection, projection + * policy, etc. This might be useful to avoid slow recalculation when + * operating against large datasets. + */ + NONE(""), ; private final String paramValue; @@ -3256,24 +3256,36 @@ public String getParamValue(){ * Recalculate the bounding box for a feature type or a coverage * * @param type + * @param xmlElementName - either featureType or coverage * @param workspace * @param storeName * @param layerName * @param calculationMode * @return true if recalculation succeeded, false otherwise. */ - private boolean recalculateBBox(StoreType type, String workspace, String storeName, String layerName, BBoxRecalculationMode calculationMode){ + private boolean recalculateBBox(StoreType type, String xmlElementName, String workspace, String storeName, String layerName, BBoxRecalculationMode calculationMode, boolean enabled){ - String sUrl = restURL + "/rest/workspaces/" + workspace + "/" + - type.getType() +"s/" + storeName + "/" + - type.getTypeName() + "/" + - layerName + "." + Format.XML.toString() + "?recalculate=" + - calculationMode.getParamValue(); + String baseUrl = restURL + "/rest/workspaces/" + workspace + "/" + + type.getType().toLowerCase() +"s/" + storeName + "/" + + type.getTypeName().toLowerCase() + "/" + + layerName + "." + Format.XML.toString(); + +// LOGGER.debug("Retrieving current state of item from "+ baseUrl); +// String getResult = HTTPUtils.get(baseUrl, gsuser, gspass); + +// LOGGER.debug("Current state of item is:\n" + getResult); + + String sUrl = baseUrl + "?recalculate=" + calculationMode.getParamValue(); LOGGER.debug("Constructed the following url for bounding box recalculation: " + sUrl); + +// String body = getResult +// GSWorkspaceEncoder wsenc = new GSWorkspaceEncoder(workspace); - String sendResult = HTTPUtils.put(sUrl, "", "text/plain", gsuser, - gspass); +// String body = wsenc.toString(); + String body = "<" + xmlElementName +">" + layerName + "" + + "" + enabled + ""; + String sendResult = HTTPUtils.putXml(sUrl, body, gsuser, gspass); boolean success = sendResult != null; return success; } @@ -3284,10 +3296,10 @@ private boolean recalculateBBox(StoreType type, String workspace, String storeNa * @param storeName * @param layerName * @param calculationMode - * @return + * @return true if successful, false otherwise */ - public boolean recalculateFeatureTypeBBox(String workspace, String storeName, String layerName, BBoxRecalculationMode calculationMode){ - return recalculateBBox(StoreType.DATASTORES, workspace, storeName, layerName, calculationMode); + public boolean recalculateFeatureTypeBBox(String workspace, String storeName, String layerName, BBoxRecalculationMode calculationMode, boolean enabled){ + return recalculateBBox(StoreType.DATASTORES, "featureType", workspace, storeName, layerName, calculationMode, enabled); } /** @@ -3296,9 +3308,9 @@ public boolean recalculateFeatureTypeBBox(String workspace, String storeName, St * @param storeName * @param layerName * @param calculationMode - * @return + * @return true if successful, false otherwise */ - public boolean recalculateCoverageBBox(String workspace, String storeName, String layerName, BBoxRecalculationMode calculationMode){ - return recalculateBBox(StoreType.COVERAGESTORES, workspace, storeName, layerName, calculationMode); + public boolean recalculateCoverageBBox(String workspace, String storeName, String layerName, BBoxRecalculationMode calculationMode, boolean enabled){ + return recalculateBBox(StoreType.COVERAGESTORES, "coverage", workspace, storeName, layerName, calculationMode, enabled); } } diff --git a/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTRecalculateTest.java b/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTRecalculateTest.java new file mode 100644 index 00000000..1f94f2d9 --- /dev/null +++ b/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTRecalculateTest.java @@ -0,0 +1,107 @@ +/* + * GeoServer-Manager - Simple Manager Library for GeoServer + * + * Copyright (C) 2007,2011 GeoSolutions S.A.S. + * http://www.geo-solutions.it + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package it.geosolutions.geoserver.rest.publisher; + +import it.geosolutions.geoserver.rest.GeoServerRESTPublisher; +import it.geosolutions.geoserver.rest.GeoServerRESTPublisher.StoreType; +import it.geosolutions.geoserver.rest.GeoServerRESTPublisher.UploadMethod; +import it.geosolutions.geoserver.rest.GeoserverRESTTest; +import it.geosolutions.geoserver.rest.decoder.RESTLayer; +import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder.ProjectionPolicy; +import it.geosolutions.geoserver.rest.encoder.coverage.GSCoverageEncoderTest; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; + +import org.apache.commons.httpclient.NameValuePair; +import org.junit.After; +import org.junit.Test; +import static org.junit.Assert.*; +import org.junit.Before; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.core.io.ClassPathResource; + +/** + * Testcase for publishing layers on geoserver. + * We need a running GeoServer to properly run the tests. + * If such geoserver instance cannot be contacted, tests will be skipped. + * + * @author Carl Schroedl - cschroedl@usgs.gov + */ +public class GeoserverRESTRecalculateTest extends GeoserverRESTTest { + + private final static Logger LOGGER = LoggerFactory.getLogger(GeoserverRESTRecalculateTest.class); + + @Before + @Override + public void before(){ + super.before(); + deleteAll(); + assertTrue(publisher.createWorkspace(DEFAULT_WS)); + } + + @After + public void cleanUp(){ + deleteAll(); + } + + @Test + public void testRecalculateFeatureTypeBBox() throws FileNotFoundException, IOException { + if (!enabled()) + return; + + String storeName = "resttestshp"; + String layerName = "cities"; + + File zipFile = new ClassPathResource("testdata/resttestshp.zip").getFile(); + assertTrue(publisher.publishShp(DEFAULT_WS, storeName, layerName, zipFile)); + + for(GeoServerRESTPublisher.BBoxRecalculationMode recalcMode : GeoServerRESTPublisher.BBoxRecalculationMode.values()){ + boolean recalculated = publisher.recalculateFeatureTypeBBox(DEFAULT_WS,storeName, layerName, recalcMode, true); + assertTrue("recalculateBBox failed with recalculation mode '" +recalcMode.toString() + "'.", recalculated); + } + } + + @Test + public void testRecalculateCoverageBBox() throws FileNotFoundException, IOException { + if (!enabled()) + return; + + String storeName = "testRESTStoreArcGrid"; + String layerName = "resttestdem"; + + File arcgrid = new ClassPathResource("testdata/resttestdem.asc").getFile(); + + assertTrue(publisher.publishArcGrid(DEFAULT_WS, storeName, layerName, arcgrid)); + + for(GeoServerRESTPublisher.BBoxRecalculationMode recalcMode : GeoServerRESTPublisher.BBoxRecalculationMode.values()){ + boolean recalculated = publisher.recalculateCoverageBBox(DEFAULT_WS,storeName, layerName, recalcMode, true); + assertTrue("recalculateBBox failed with recalculation mode '" +recalcMode.toString() + "'.", recalculated); + } + } +} From e218762e8614205a06a8ad5fb9a0372c60bb819c Mon Sep 17 00:00:00 2001 From: Carl Schroedl Date: Tue, 20 Sep 2016 14:26:05 -0500 Subject: [PATCH 04/12] Switching to formal XML body construction via GS*Encoder classes. #199 --- .../rest/GeoServerRESTPublisher.java | 22 ++++++++++++++----- .../encoder/coverage/GSCoverageEncoder.java | 2 +- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java b/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java index 92238443..f4e157e5 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java +++ b/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java @@ -3263,7 +3263,7 @@ public String getParamValue(){ * @param calculationMode * @return true if recalculation succeeded, false otherwise. */ - private boolean recalculateBBox(StoreType type, String xmlElementName, String workspace, String storeName, String layerName, BBoxRecalculationMode calculationMode, boolean enabled){ + private boolean recalculateBBox(StoreType type, GSResourceEncoder renc, String workspace, String storeName, String layerName, BBoxRecalculationMode calculationMode){ String baseUrl = restURL + "/rest/workspaces/" + workspace + "/" + type.getType().toLowerCase() +"s/" + storeName + "/" + @@ -3283,8 +3283,12 @@ private boolean recalculateBBox(StoreType type, String xmlElementName, String wo // GSWorkspaceEncoder wsenc = new GSWorkspaceEncoder(workspace); // String body = wsenc.toString(); - String body = "<" + xmlElementName +">" + layerName + "" + - "" + enabled + ""; +// String body = "<" + xmlElementName +">" + layerName + "" + +// "" + enabled + ""; + renc.remove(GSResourceEncoder.KEYWORDS); + renc.remove(GSResourceEncoder.METADATA); + renc.remove(GSResourceEncoder.METADATALINKS); + String body = renc.toString(); String sendResult = HTTPUtils.putXml(sUrl, body, gsuser, gspass); boolean success = sendResult != null; return success; @@ -3299,7 +3303,11 @@ private boolean recalculateBBox(StoreType type, String xmlElementName, String wo * @return true if successful, false otherwise */ public boolean recalculateFeatureTypeBBox(String workspace, String storeName, String layerName, BBoxRecalculationMode calculationMode, boolean enabled){ - return recalculateBBox(StoreType.DATASTORES, "featureType", workspace, storeName, layerName, calculationMode, enabled); + GSFeatureTypeEncoder fenc = new GSFeatureTypeEncoder(); + fenc.remove(GSFeatureTypeEncoder.ATTRIBUTES); + fenc.setName(layerName); + fenc.setEnabled(enabled); + return recalculateBBox(StoreType.DATASTORES, fenc, workspace, storeName, layerName, calculationMode); } /** @@ -3311,6 +3319,10 @@ public boolean recalculateFeatureTypeBBox(String workspace, String storeName, St * @return true if successful, false otherwise */ public boolean recalculateCoverageBBox(String workspace, String storeName, String layerName, BBoxRecalculationMode calculationMode, boolean enabled){ - return recalculateBBox(StoreType.COVERAGESTORES, "coverage", workspace, storeName, layerName, calculationMode, enabled); + GSCoverageEncoder cenc = new GSCoverageEncoder(); + cenc.remove(GSCoverageEncoder.SUPPORTED_FORMATS); + cenc.setName(layerName); + cenc.setEnabled(enabled); + return recalculateBBox(StoreType.COVERAGESTORES, cenc, workspace, storeName, layerName, calculationMode); } } diff --git a/src/main/java/it/geosolutions/geoserver/rest/encoder/coverage/GSCoverageEncoder.java b/src/main/java/it/geosolutions/geoserver/rest/encoder/coverage/GSCoverageEncoder.java index 4b506e17..796e122e 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/encoder/coverage/GSCoverageEncoder.java +++ b/src/main/java/it/geosolutions/geoserver/rest/encoder/coverage/GSCoverageEncoder.java @@ -44,7 +44,7 @@ public class GSCoverageEncoder extends GSResourceEncoder { public final static String NATIVECOVERAGENAME = "nativeCoverageName"; private final static String NATIVE_FORMAT="nativeFormat"; - private final static String SUPPORTED_FORMATS="supportedFormats"; + public final static String SUPPORTED_FORMATS="supportedFormats"; private final static String REQUEST_SRS="requestSRS"; private final static String RESPONSE_SRS="responseSRS"; From cd511983c03db207d696f6ba88b28cf1b73f890d Mon Sep 17 00:00:00 2001 From: Carl Schroedl Date: Tue, 20 Sep 2016 14:27:53 -0500 Subject: [PATCH 05/12] Revert "Switching to formal XML body construction via GS*Encoder classes. #199" This reverts commit e218762e8614205a06a8ad5fb9a0372c60bb819c. --- .../rest/GeoServerRESTPublisher.java | 22 +++++-------------- .../encoder/coverage/GSCoverageEncoder.java | 2 +- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java b/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java index f4e157e5..92238443 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java +++ b/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java @@ -3263,7 +3263,7 @@ public String getParamValue(){ * @param calculationMode * @return true if recalculation succeeded, false otherwise. */ - private boolean recalculateBBox(StoreType type, GSResourceEncoder renc, String workspace, String storeName, String layerName, BBoxRecalculationMode calculationMode){ + private boolean recalculateBBox(StoreType type, String xmlElementName, String workspace, String storeName, String layerName, BBoxRecalculationMode calculationMode, boolean enabled){ String baseUrl = restURL + "/rest/workspaces/" + workspace + "/" + type.getType().toLowerCase() +"s/" + storeName + "/" + @@ -3283,12 +3283,8 @@ private boolean recalculateBBox(StoreType type, GSResourceEncoder renc, String w // GSWorkspaceEncoder wsenc = new GSWorkspaceEncoder(workspace); // String body = wsenc.toString(); -// String body = "<" + xmlElementName +">" + layerName + "" + -// "" + enabled + ""; - renc.remove(GSResourceEncoder.KEYWORDS); - renc.remove(GSResourceEncoder.METADATA); - renc.remove(GSResourceEncoder.METADATALINKS); - String body = renc.toString(); + String body = "<" + xmlElementName +">" + layerName + "" + + "" + enabled + ""; String sendResult = HTTPUtils.putXml(sUrl, body, gsuser, gspass); boolean success = sendResult != null; return success; @@ -3303,11 +3299,7 @@ private boolean recalculateBBox(StoreType type, GSResourceEncoder renc, String w * @return true if successful, false otherwise */ public boolean recalculateFeatureTypeBBox(String workspace, String storeName, String layerName, BBoxRecalculationMode calculationMode, boolean enabled){ - GSFeatureTypeEncoder fenc = new GSFeatureTypeEncoder(); - fenc.remove(GSFeatureTypeEncoder.ATTRIBUTES); - fenc.setName(layerName); - fenc.setEnabled(enabled); - return recalculateBBox(StoreType.DATASTORES, fenc, workspace, storeName, layerName, calculationMode); + return recalculateBBox(StoreType.DATASTORES, "featureType", workspace, storeName, layerName, calculationMode, enabled); } /** @@ -3319,10 +3311,6 @@ public boolean recalculateFeatureTypeBBox(String workspace, String storeName, St * @return true if successful, false otherwise */ public boolean recalculateCoverageBBox(String workspace, String storeName, String layerName, BBoxRecalculationMode calculationMode, boolean enabled){ - GSCoverageEncoder cenc = new GSCoverageEncoder(); - cenc.remove(GSCoverageEncoder.SUPPORTED_FORMATS); - cenc.setName(layerName); - cenc.setEnabled(enabled); - return recalculateBBox(StoreType.COVERAGESTORES, cenc, workspace, storeName, layerName, calculationMode); + return recalculateBBox(StoreType.COVERAGESTORES, "coverage", workspace, storeName, layerName, calculationMode, enabled); } } diff --git a/src/main/java/it/geosolutions/geoserver/rest/encoder/coverage/GSCoverageEncoder.java b/src/main/java/it/geosolutions/geoserver/rest/encoder/coverage/GSCoverageEncoder.java index 796e122e..4b506e17 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/encoder/coverage/GSCoverageEncoder.java +++ b/src/main/java/it/geosolutions/geoserver/rest/encoder/coverage/GSCoverageEncoder.java @@ -44,7 +44,7 @@ public class GSCoverageEncoder extends GSResourceEncoder { public final static String NATIVECOVERAGENAME = "nativeCoverageName"; private final static String NATIVE_FORMAT="nativeFormat"; - public final static String SUPPORTED_FORMATS="supportedFormats"; + private final static String SUPPORTED_FORMATS="supportedFormats"; private final static String REQUEST_SRS="requestSRS"; private final static String RESPONSE_SRS="responseSRS"; From 6b77579ec081025ce8b199ade8245a32b14f7bc0 Mon Sep 17 00:00:00 2001 From: Carl Schroedl Date: Tue, 20 Sep 2016 14:32:07 -0500 Subject: [PATCH 06/12] Cleanup #199 --- .../geoserver/rest/GeoServerRESTPublisher.java | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java b/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java index 92238443..73e58a6f 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java +++ b/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java @@ -3261,6 +3261,7 @@ public String getParamValue(){ * @param storeName * @param layerName * @param calculationMode + * @param enabled * @return true if recalculation succeeded, false otherwise. */ private boolean recalculateBBox(StoreType type, String xmlElementName, String workspace, String storeName, String layerName, BBoxRecalculationMode calculationMode, boolean enabled){ @@ -3269,22 +3270,18 @@ private boolean recalculateBBox(StoreType type, String xmlElementName, String wo type.getType().toLowerCase() +"s/" + storeName + "/" + type.getTypeName().toLowerCase() + "/" + layerName + "." + Format.XML.toString(); - - -// LOGGER.debug("Retrieving current state of item from "+ baseUrl); -// String getResult = HTTPUtils.get(baseUrl, gsuser, gspass); - -// LOGGER.debug("Current state of item is:\n" + getResult); String sUrl = baseUrl + "?recalculate=" + calculationMode.getParamValue(); LOGGER.debug("Constructed the following url for bounding box recalculation: " + sUrl); - -// String body = getResult -// GSWorkspaceEncoder wsenc = new GSWorkspaceEncoder(workspace); -// String body = wsenc.toString(); + /* + * If the 'enabled' element is not specified in the request body, it will be set to 'false' by GeoServer. + * To avoid unintentional disabling of layers, this method and its callers + * require that users specify whether the layer should be enabled. + */ String body = "<" + xmlElementName +">" + layerName + "" + "" + enabled + ""; + String sendResult = HTTPUtils.putXml(sUrl, body, gsuser, gspass); boolean success = sendResult != null; return success; From 53b602e399b0e7c8034695d0b0ecf37d243c9427 Mon Sep 17 00:00:00 2001 From: Carl Schroedl Date: Tue, 20 Sep 2016 15:05:32 -0500 Subject: [PATCH 07/12] Prevented setup from running outside of integration tests. --- .../publisher/GeoserverRESTRecalculateTest.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTRecalculateTest.java b/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTRecalculateTest.java index 1f94f2d9..841d8d47 100644 --- a/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTRecalculateTest.java +++ b/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTRecalculateTest.java @@ -26,18 +26,12 @@ package it.geosolutions.geoserver.rest.publisher; import it.geosolutions.geoserver.rest.GeoServerRESTPublisher; -import it.geosolutions.geoserver.rest.GeoServerRESTPublisher.StoreType; -import it.geosolutions.geoserver.rest.GeoServerRESTPublisher.UploadMethod; import it.geosolutions.geoserver.rest.GeoserverRESTTest; -import it.geosolutions.geoserver.rest.decoder.RESTLayer; -import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder.ProjectionPolicy; -import it.geosolutions.geoserver.rest.encoder.coverage.GSCoverageEncoderTest; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; -import org.apache.commons.httpclient.NameValuePair; import org.junit.After; import org.junit.Test; import static org.junit.Assert.*; @@ -61,12 +55,19 @@ public class GeoserverRESTRecalculateTest extends GeoserverRESTTest { @Override public void before(){ super.before(); + + if (!enabled()) + return; + deleteAll(); assertTrue(publisher.createWorkspace(DEFAULT_WS)); } @After public void cleanUp(){ + if (!enabled()) + return; + deleteAll(); } From 9c5fd05b43283a6be22c489358b597f8942ef0e4 Mon Sep 17 00:00:00 2001 From: Carl Schroedl Date: Tue, 20 Sep 2016 15:06:38 -0500 Subject: [PATCH 08/12] Doc improvement --- .../it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java b/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java index 73e58a6f..6b55686b 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java +++ b/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java @@ -3293,6 +3293,7 @@ private boolean recalculateBBox(StoreType type, String xmlElementName, String wo * @param storeName * @param layerName * @param calculationMode + * @param enabled * @return true if successful, false otherwise */ public boolean recalculateFeatureTypeBBox(String workspace, String storeName, String layerName, BBoxRecalculationMode calculationMode, boolean enabled){ @@ -3305,6 +3306,7 @@ public boolean recalculateFeatureTypeBBox(String workspace, String storeName, St * @param storeName * @param layerName * @param calculationMode + * @param enabled * @return true if successful, false otherwise */ public boolean recalculateCoverageBBox(String workspace, String storeName, String layerName, BBoxRecalculationMode calculationMode, boolean enabled){ From f251419bd19d372422717bdef76f3728c2ad58e9 Mon Sep 17 00:00:00 2001 From: Carl Schroedl Date: Tue, 20 Sep 2016 16:42:40 -0500 Subject: [PATCH 09/12] Revert "Revert "Switching to formal XML body construction via GS*Encoder classes. #199"" This reverts commit cd511983c03db207d696f6ba88b28cf1b73f890d. --- .../rest/GeoServerRESTPublisher.java | 30 ++++++++++++------- .../encoder/coverage/GSCoverageEncoder.java | 2 +- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java b/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java index 6b55686b..20231fd4 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java +++ b/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java @@ -3264,7 +3264,7 @@ public String getParamValue(){ * @param enabled * @return true if recalculation succeeded, false otherwise. */ - private boolean recalculateBBox(StoreType type, String xmlElementName, String workspace, String storeName, String layerName, BBoxRecalculationMode calculationMode, boolean enabled){ + private boolean recalculateBBox(StoreType type, GSResourceEncoder renc, String workspace, String storeName, String layerName, BBoxRecalculationMode calculationMode){ String baseUrl = restURL + "/rest/workspaces/" + workspace + "/" + type.getType().toLowerCase() +"s/" + storeName + "/" + @@ -3274,14 +3274,14 @@ private boolean recalculateBBox(StoreType type, String xmlElementName, String wo String sUrl = baseUrl + "?recalculate=" + calculationMode.getParamValue(); LOGGER.debug("Constructed the following url for bounding box recalculation: " + sUrl); - /* - * If the 'enabled' element is not specified in the request body, it will be set to 'false' by GeoServer. - * To avoid unintentional disabling of layers, this method and its callers - * require that users specify whether the layer should be enabled. - */ - String body = "<" + xmlElementName +">" + layerName + "" + - "" + enabled + ""; - + +// String body = wsenc.toString(); +// String body = "<" + xmlElementName +">" + layerName + "" + +// "" + enabled + ""; + renc.remove(GSResourceEncoder.KEYWORDS); + renc.remove(GSResourceEncoder.METADATA); + renc.remove(GSResourceEncoder.METADATALINKS); + String body = renc.toString(); String sendResult = HTTPUtils.putXml(sUrl, body, gsuser, gspass); boolean success = sendResult != null; return success; @@ -3297,7 +3297,11 @@ private boolean recalculateBBox(StoreType type, String xmlElementName, String wo * @return true if successful, false otherwise */ public boolean recalculateFeatureTypeBBox(String workspace, String storeName, String layerName, BBoxRecalculationMode calculationMode, boolean enabled){ - return recalculateBBox(StoreType.DATASTORES, "featureType", workspace, storeName, layerName, calculationMode, enabled); + GSFeatureTypeEncoder fenc = new GSFeatureTypeEncoder(); + fenc.remove(GSFeatureTypeEncoder.ATTRIBUTES); + fenc.setName(layerName); + fenc.setEnabled(enabled); + return recalculateBBox(StoreType.DATASTORES, fenc, workspace, storeName, layerName, calculationMode); } /** @@ -3310,6 +3314,10 @@ public boolean recalculateFeatureTypeBBox(String workspace, String storeName, St * @return true if successful, false otherwise */ public boolean recalculateCoverageBBox(String workspace, String storeName, String layerName, BBoxRecalculationMode calculationMode, boolean enabled){ - return recalculateBBox(StoreType.COVERAGESTORES, "coverage", workspace, storeName, layerName, calculationMode, enabled); + GSCoverageEncoder cenc = new GSCoverageEncoder(); + cenc.remove(GSCoverageEncoder.SUPPORTED_FORMATS); + cenc.setName(layerName); + cenc.setEnabled(enabled); + return recalculateBBox(StoreType.COVERAGESTORES, cenc, workspace, storeName, layerName, calculationMode); } } diff --git a/src/main/java/it/geosolutions/geoserver/rest/encoder/coverage/GSCoverageEncoder.java b/src/main/java/it/geosolutions/geoserver/rest/encoder/coverage/GSCoverageEncoder.java index 4b506e17..796e122e 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/encoder/coverage/GSCoverageEncoder.java +++ b/src/main/java/it/geosolutions/geoserver/rest/encoder/coverage/GSCoverageEncoder.java @@ -44,7 +44,7 @@ public class GSCoverageEncoder extends GSResourceEncoder { public final static String NATIVECOVERAGENAME = "nativeCoverageName"; private final static String NATIVE_FORMAT="nativeFormat"; - private final static String SUPPORTED_FORMATS="supportedFormats"; + public final static String SUPPORTED_FORMATS="supportedFormats"; private final static String REQUEST_SRS="requestSRS"; private final static String RESPONSE_SRS="responseSRS"; From 5163af60ff8ce703bc8ab432df17812da3ae797e Mon Sep 17 00:00:00 2001 From: Carl Schroedl Date: Thu, 22 Sep 2016 15:20:09 -0500 Subject: [PATCH 10/12] Adding recursive child xml node deletion to support GS*Encoder-centric implementation of #199. --- .../rest/GeoServerRESTPublisher.java | 8 +- .../rest/encoder/utils/XmlElement.java | 33 +++++ .../rest/encoder/utils/XmlElementTest.java | 119 ++++++++++++++++++ 3 files changed, 153 insertions(+), 7 deletions(-) create mode 100644 src/test/java/it/geosolutions/geoserver/rest/encoder/utils/XmlElementTest.java diff --git a/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java b/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java index 20231fd4..b0257025 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java +++ b/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java @@ -3273,14 +3273,8 @@ private boolean recalculateBBox(StoreType type, GSResourceEncoder renc, String w String sUrl = baseUrl + "?recalculate=" + calculationMode.getParamValue(); LOGGER.debug("Constructed the following url for bounding box recalculation: " + sUrl); - -// String body = wsenc.toString(); -// String body = "<" + xmlElementName +">" + layerName + "" + -// "" + enabled + ""; - renc.remove(GSResourceEncoder.KEYWORDS); - renc.remove(GSResourceEncoder.METADATA); - renc.remove(GSResourceEncoder.METADATALINKS); + renc.recursivelyRemoveEmptyChildren(); String body = renc.toString(); String sendResult = HTTPUtils.putXml(sUrl, body, gsuser, gspass); boolean success = sendResult != null; diff --git a/src/main/java/it/geosolutions/geoserver/rest/encoder/utils/XmlElement.java b/src/main/java/it/geosolutions/geoserver/rest/encoder/utils/XmlElement.java index 63c6d91b..aa7649df 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/encoder/utils/XmlElement.java +++ b/src/main/java/it/geosolutions/geoserver/rest/encoder/utils/XmlElement.java @@ -26,9 +26,13 @@ package it.geosolutions.geoserver.rest.encoder.utils; +import java.util.ArrayList; +import java.util.List; import org.jdom.Content; import org.jdom.Element; import org.jdom.Text; +import org.jdom.filter.ContentFilter; +import org.jdom.filter.ElementFilter; import org.jdom.output.Format; import org.jdom.output.XMLOutputter; @@ -122,6 +126,35 @@ public boolean remove(final String key){ return false; } + public void recursivelyRemoveEmptyChildren(){ + //must make a copy to avoid ConcurrentModificationException + List children = new ArrayList(this.root.getContent()); + + for(Content child : children){ + if(child instanceof Element){ + recursivelyRemoveEmptyChildren(this.root, (Element)child); + } + } + } + private void recursivelyRemoveEmptyChildren(Element grandparent, Element parent){ + //must make a copy to avoid ConcurrentModificationException + List childrenPreRemoval; + childrenPreRemoval = new ArrayList(parent.getContent()); + + //base case: the parent has no children + for(Content child : childrenPreRemoval){ + //recursive case: the parent has children + if(child instanceof Element){ + recursivelyRemoveEmptyChildren(parent, (Element)child); + } + } + + //if the parent node contains no children, remove it from the parent + List childrenPostRemoval = parent.getContent(); + if(childrenPostRemoval.isEmpty()){ + grandparent.removeContent(parent); + } + } /** * @return an xml String */ diff --git a/src/test/java/it/geosolutions/geoserver/rest/encoder/utils/XmlElementTest.java b/src/test/java/it/geosolutions/geoserver/rest/encoder/utils/XmlElementTest.java new file mode 100644 index 00000000..93751c06 --- /dev/null +++ b/src/test/java/it/geosolutions/geoserver/rest/encoder/utils/XmlElementTest.java @@ -0,0 +1,119 @@ +package it.geosolutions.geoserver.rest.encoder.utils; + +import java.io.IOException; +import java.io.StringReader; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.jdom.Document; +import org.jdom.Element; +import org.jdom.JDOMException; +import org.jdom.input.SAXBuilder; +import org.jdom.output.XMLOutputter; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; + +public class XmlElementTest { + + public XmlElementTest() { + } + + @BeforeClass + public static void setUpClass() { + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + private XmlElement makeElement(String docString){ + Document doc; + SAXBuilder builder = new SAXBuilder(); + try { + doc = builder.build(new StringReader(docString)); + } catch (JDOMException ex) { + throw new RuntimeException(ex); + } catch (IOException ex) { + throw new RuntimeException(ex); + } + Element root = doc.getRootElement(); + + return new XmlElement(root); + } + + private void assertEqualXml(String message, XmlElement expected, XmlElement actual){ + XMLOutputter out = new XMLOutputter(); + String expectedElementString = out.outputString(expected.getRoot()); + String actualElementString = out.outputString(actual.getRoot()); + assertEquals(message, expectedElementString, actualElementString); + } + + @Test + public void testRecursiveRemovalOnChildlessParent(){ + XmlElement root = makeElement(""); + root.recursivelyRemoveEmptyChildren(); + assertEqualXml("no child elements expected", makeElement(""), root); + } + + @Test + public void testRecursiveRemovalOfOneChild(){ + XmlElement root = makeElement(""); + root.recursivelyRemoveEmptyChildren(); + assertEqualXml("no child elements expected", makeElement(""), root); + } + + @Test + public void testRecursiveRemovalOfOneChildWithOneKeeper(){ + XmlElement root = makeElement("keep"); + root.recursivelyRemoveEmptyChildren(); + assertEqualXml("one child element expected", makeElement("keep"), root); + } + + @Test + public void testRecursiveRemovalOfOneParentAndOneChild() { + XmlElement root = makeElement(""); + root.recursivelyRemoveEmptyChildren(); + assertEqualXml("no child elements expected", makeElement(""), root); + } + + @Test + public void testRecursiveRemovalOfOneParentAndManyChildren() { + XmlElement root = makeElement(""); + root.recursivelyRemoveEmptyChildren(); + assertEqualXml("no child elements expected", makeElement(""), root); + } + + @Test + public void testRecursiveRemovalOfManyParentsWithOneChild() { + XmlElement root = makeElement(""); + root.recursivelyRemoveEmptyChildren(); + assertEqualXml("no child elements expected", makeElement(""), root); + } + + @Test + public void testRecursiveRemovalOfManyParentsAndManyChildren() { + XmlElement root = makeElement(""); + root.recursivelyRemoveEmptyChildren(); + assertEqualXml("no child elements expected", makeElement(""), root); + } + + @Test + public void testRecursiveRemovalOfManyParentsAndManyChildrenWithSomeKeepers() { + XmlElement root = makeElement("keepkeepkeepkeep"); + root.recursivelyRemoveEmptyChildren(); + assertEqualXml("only non-empty child elements should remain", makeElement("keepkeepkeepkeep"), root); + } + + +} \ No newline at end of file From 769db7ff11208da126a8920807b0a02966dd3b32 Mon Sep 17 00:00:00 2001 From: Carl Schroedl Date: Thu, 22 Sep 2016 15:25:51 -0500 Subject: [PATCH 11/12] Eliminating empty methods. --- .../rest/encoder/utils/XmlElementTest.java | 25 ------------------- 1 file changed, 25 deletions(-) diff --git a/src/test/java/it/geosolutions/geoserver/rest/encoder/utils/XmlElementTest.java b/src/test/java/it/geosolutions/geoserver/rest/encoder/utils/XmlElementTest.java index 93751c06..3345737e 100644 --- a/src/test/java/it/geosolutions/geoserver/rest/encoder/utils/XmlElementTest.java +++ b/src/test/java/it/geosolutions/geoserver/rest/encoder/utils/XmlElementTest.java @@ -2,41 +2,16 @@ import java.io.IOException; import java.io.StringReader; -import java.util.logging.Level; -import java.util.logging.Logger; import org.jdom.Document; import org.jdom.Element; import org.jdom.JDOMException; import org.jdom.input.SAXBuilder; import org.jdom.output.XMLOutputter; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; import static org.junit.Assert.*; public class XmlElementTest { - public XmlElementTest() { - } - - @BeforeClass - public static void setUpClass() { - } - - @AfterClass - public static void tearDownClass() { - } - - @Before - public void setUp() { - } - - @After - public void tearDown() { - } - private XmlElement makeElement(String docString){ Document doc; SAXBuilder builder = new SAXBuilder(); From bf2e203614531fe96d8ca776eeb214e301a07eea Mon Sep 17 00:00:00 2001 From: Carl Schroedl Date: Thu, 22 Sep 2016 16:01:50 -0500 Subject: [PATCH 12/12] Cleaned up documentation, eliminated unused imports and useless method calls, reverted a class member to previous visibility, renamed a variable. --- .../rest/GeoServerRESTPublisher.java | 2 - .../encoder/coverage/GSCoverageEncoder.java | 2 +- .../rest/encoder/utils/XmlElement.java | 6 ++- .../rest/encoder/utils/XmlElementTest.java | 44 ++++++++++++++++++- .../GeoserverRESTRecalculateTest.java | 8 ++-- 5 files changed, 51 insertions(+), 11 deletions(-) diff --git a/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java b/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java index b0257025..d77ac22d 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java +++ b/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java @@ -3292,7 +3292,6 @@ private boolean recalculateBBox(StoreType type, GSResourceEncoder renc, String w */ public boolean recalculateFeatureTypeBBox(String workspace, String storeName, String layerName, BBoxRecalculationMode calculationMode, boolean enabled){ GSFeatureTypeEncoder fenc = new GSFeatureTypeEncoder(); - fenc.remove(GSFeatureTypeEncoder.ATTRIBUTES); fenc.setName(layerName); fenc.setEnabled(enabled); return recalculateBBox(StoreType.DATASTORES, fenc, workspace, storeName, layerName, calculationMode); @@ -3309,7 +3308,6 @@ public boolean recalculateFeatureTypeBBox(String workspace, String storeName, St */ public boolean recalculateCoverageBBox(String workspace, String storeName, String layerName, BBoxRecalculationMode calculationMode, boolean enabled){ GSCoverageEncoder cenc = new GSCoverageEncoder(); - cenc.remove(GSCoverageEncoder.SUPPORTED_FORMATS); cenc.setName(layerName); cenc.setEnabled(enabled); return recalculateBBox(StoreType.COVERAGESTORES, cenc, workspace, storeName, layerName, calculationMode); diff --git a/src/main/java/it/geosolutions/geoserver/rest/encoder/coverage/GSCoverageEncoder.java b/src/main/java/it/geosolutions/geoserver/rest/encoder/coverage/GSCoverageEncoder.java index 796e122e..4b506e17 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/encoder/coverage/GSCoverageEncoder.java +++ b/src/main/java/it/geosolutions/geoserver/rest/encoder/coverage/GSCoverageEncoder.java @@ -44,7 +44,7 @@ public class GSCoverageEncoder extends GSResourceEncoder { public final static String NATIVECOVERAGENAME = "nativeCoverageName"; private final static String NATIVE_FORMAT="nativeFormat"; - public final static String SUPPORTED_FORMATS="supportedFormats"; + private final static String SUPPORTED_FORMATS="supportedFormats"; private final static String REQUEST_SRS="requestSRS"; private final static String RESPONSE_SRS="responseSRS"; diff --git a/src/main/java/it/geosolutions/geoserver/rest/encoder/utils/XmlElement.java b/src/main/java/it/geosolutions/geoserver/rest/encoder/utils/XmlElement.java index aa7649df..4e138761 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/encoder/utils/XmlElement.java +++ b/src/main/java/it/geosolutions/geoserver/rest/encoder/utils/XmlElement.java @@ -31,8 +31,6 @@ import org.jdom.Content; import org.jdom.Element; import org.jdom.Text; -import org.jdom.filter.ContentFilter; -import org.jdom.filter.ElementFilter; import org.jdom.output.Format; import org.jdom.output.XMLOutputter; @@ -126,6 +124,10 @@ public boolean remove(final String key){ return false; } + + /** + * Recursively removes all child nodes that have no contents. + */ public void recursivelyRemoveEmptyChildren(){ //must make a copy to avoid ConcurrentModificationException List children = new ArrayList(this.root.getContent()); diff --git a/src/test/java/it/geosolutions/geoserver/rest/encoder/utils/XmlElementTest.java b/src/test/java/it/geosolutions/geoserver/rest/encoder/utils/XmlElementTest.java index 3345737e..0c1e87d4 100644 --- a/src/test/java/it/geosolutions/geoserver/rest/encoder/utils/XmlElementTest.java +++ b/src/test/java/it/geosolutions/geoserver/rest/encoder/utils/XmlElementTest.java @@ -1,3 +1,28 @@ +/* + * GeoServer-Manager - Simple Manager Library for GeoServer + * + * Copyright (C) 2007,2011 GeoSolutions S.A.S. + * http://www.geo-solutions.it + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package it.geosolutions.geoserver.rest.encoder.utils; import java.io.IOException; @@ -10,13 +35,22 @@ import org.junit.Test; import static org.junit.Assert.*; +/** + * Tests XmlElements + * @author Carl Schroedl - cschroedl@usgs.gov + */ public class XmlElementTest { - private XmlElement makeElement(String docString){ + /** + * Creates an XmlElement from a String + * @param xmlString + * @return the specified String as an XmlElement + */ + private XmlElement makeElement(String xmlString){ Document doc; SAXBuilder builder = new SAXBuilder(); try { - doc = builder.build(new StringReader(docString)); + doc = builder.build(new StringReader(xmlString)); } catch (JDOMException ex) { throw new RuntimeException(ex); } catch (IOException ex) { @@ -27,6 +61,12 @@ private XmlElement makeElement(String docString){ return new XmlElement(root); } + /** + * Asserts that the serializations of two XmlElements are the same. + * @param message + * @param expected + * @param actual + */ private void assertEqualXml(String message, XmlElement expected, XmlElement actual){ XMLOutputter out = new XMLOutputter(); String expectedElementString = out.outputString(expected.getRoot()); diff --git a/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTRecalculateTest.java b/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTRecalculateTest.java index 841d8d47..d7461c6b 100644 --- a/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTRecalculateTest.java +++ b/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTRecalculateTest.java @@ -41,11 +41,11 @@ import org.springframework.core.io.ClassPathResource; /** - * Testcase for publishing layers on geoserver. - * We need a running GeoServer to properly run the tests. - * If such geoserver instance cannot be contacted, tests will be skipped. + * Test case for recalculating the bounding box for features and coverages on + * GeoServer. We need a running GeoServer to properly run the tests. + * If such GeoServer instance cannot be contacted, tests will be skipped. * - * @author Carl Schroedl - cschroedl@usgs.gov + * @author Carl Schroedl - cschroedl@usgs.gov */ public class GeoserverRESTRecalculateTest extends GeoserverRESTTest {