Moved Datastore management to new architecture, using GeoServerRest[Foo]Managers
This commit is contained in:
parent
876727a6e2
commit
15341547f1
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||
*
|
||||
* Copyright (C) 2007,2012 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;
|
||||
|
||||
import it.geosolutions.geoserver.rest.manager.GeoServerRESTAbstractManager;
|
||||
import it.geosolutions.geoserver.rest.manager.GeoServerRESTDatastoreManager;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* <i>The</i> single entry point to all of geoserver-manager functionality.
|
||||
*
|
||||
* Instance this one, and use getters to use different components. These are:
|
||||
* <ul>
|
||||
* <li>getReader() simple, high-level access methods.
|
||||
* <li>getPublisher() simple, high-level pubhish methods.
|
||||
* <li>get<i>Foo</i>Manager, full-fledged management of catalog objects.
|
||||
* </ul>
|
||||
* @author Oscar Fonts
|
||||
*/
|
||||
public class GeoServerRESTManager extends GeoServerRESTAbstractManager {
|
||||
|
||||
private final GeoServerRESTPublisher publisher;
|
||||
private final GeoServerRESTReader reader;
|
||||
|
||||
private final GeoServerRESTDatastoreManager datastoreManager;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*
|
||||
* Indicates connection parameters to remote GeoServer instance.
|
||||
*
|
||||
* @param restURL GeoServer REST API endpoint
|
||||
* @param username GeoServer REST API authorized username
|
||||
* @param password GeoServer REST API password for the former username
|
||||
*/
|
||||
public GeoServerRESTManager(URL restURL, String username, String password) {
|
||||
super(restURL, username, password);
|
||||
|
||||
// Internal publisher and reader, provide simple access methods.
|
||||
publisher = new GeoServerRESTPublisher(restURL.toString(), username, password);
|
||||
reader = new GeoServerRESTReader(restURL, username, password);
|
||||
|
||||
// Classes for fine-grained management of catalog components.
|
||||
datastoreManager = new GeoServerRESTDatastoreManager(restURL, username, password);
|
||||
}
|
||||
|
||||
public GeoServerRESTPublisher getPublisher() {
|
||||
return publisher;
|
||||
}
|
||||
|
||||
public GeoServerRESTReader getReader() {
|
||||
return reader;
|
||||
}
|
||||
|
||||
public GeoServerRESTDatastoreManager getDatastoreManager() {
|
||||
return datastoreManager;
|
||||
}
|
||||
|
||||
}
|
||||
@ -34,7 +34,6 @@ import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder.ProjectionPolicy;
|
||||
import it.geosolutions.geoserver.rest.encoder.GSWorkspaceEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.coverage.GSCoverageEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.datastore.GSAbstractDatastoreEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.GSPostGISDatastoreEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureTypeEncoder;
|
||||
|
||||
@ -695,7 +694,7 @@ public class GeoServerRESTPublisher {
|
||||
* @return <TT>true</TT> if the PostGIS datastore has been successfully
|
||||
* created, <TT>false</TT> otherwise
|
||||
* @deprecated Will be deleted in next version 1.5.x.
|
||||
* Use {@link #createDatastore(String, GSAbstractDatastoreEncoder)} instead.
|
||||
* Use {@link GeoServerRESTDatastoreManager} instead.
|
||||
*/
|
||||
public boolean createPostGISDatastore(String workspace,
|
||||
GSPostGISDatastoreEncoder datastoreEncoder) {
|
||||
@ -706,47 +705,6 @@ public class GeoServerRESTPublisher {
|
||||
return result != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a datastore (any datastore extending {@link GSAbstractDatastoreEncoder}).
|
||||
*
|
||||
* @param workspace
|
||||
* Name of the workspace to contain the datastore. This will also
|
||||
* be the prefix of any layer names contained in the datastore.
|
||||
* @param datastore
|
||||
* the set of parameters to be set to the datastore (including
|
||||
* connection parameters).
|
||||
* @return <TT>true</TT> if the datastore has been successfully
|
||||
* created, <TT>false</TT> otherwise
|
||||
*/
|
||||
public boolean createDatastore(String workspace,
|
||||
GSAbstractDatastoreEncoder datastore) {
|
||||
String sUrl = restURL + "/rest/workspaces/" + workspace
|
||||
+ "/datastores/";
|
||||
String xml = datastore.toString();
|
||||
String result = HTTPUtils.postXml(sUrl, xml, gsuser, gspass);
|
||||
return result != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a datastore (any datastore extending {@link GSAbstractDatastoreEncoder}).
|
||||
*
|
||||
* @param workspace
|
||||
* Name of the workspace that contains the datastore.
|
||||
* @param datastore
|
||||
* the set of parameters to be set to the datastore (including
|
||||
* connection parameters).
|
||||
* @return <TT>true</TT> if the datastore has been successfully
|
||||
* updated, <TT>false</TT> otherwise
|
||||
*/
|
||||
public boolean updateDatastore(String workspace,
|
||||
GSAbstractDatastoreEncoder datastore) {
|
||||
String sUrl = restURL + "/rest/workspaces/" + workspace
|
||||
+ "/datastores/" + datastore.getName();
|
||||
String xml = datastore.toString();
|
||||
String result = HTTPUtils.putXml(sUrl, xml, gsuser, gspass);
|
||||
return result != null;
|
||||
}
|
||||
|
||||
// ==========================================================================
|
||||
// === SHAPEFILES
|
||||
// ==========================================================================
|
||||
|
||||
@ -54,7 +54,7 @@ import org.slf4j.LoggerFactory;
|
||||
/**
|
||||
* Low level HTTP utilities.
|
||||
*/
|
||||
class HTTPUtils {
|
||||
public class HTTPUtils {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(HTTPUtils.class);
|
||||
|
||||
/**
|
||||
|
||||
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||
*
|
||||
* Copyright (C) 2007,2012 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.manager;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* Abstract manager, common functionality and interface
|
||||
* for all GeoServerREST<i>Foo</i>Manager classes.
|
||||
*
|
||||
* @author Oscar Fonts
|
||||
*/
|
||||
public abstract class GeoServerRESTAbstractManager {
|
||||
|
||||
protected final URL restURL;
|
||||
protected final String gsuser;
|
||||
protected final String gspass;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*
|
||||
* Indicates connection parameters to remote GeoServer instance.
|
||||
*
|
||||
* @param restURL GeoServer REST API endpoint
|
||||
* @param username GeoServer REST API authorized username
|
||||
* @param password GeoServer REST API password for the former username
|
||||
*/
|
||||
public GeoServerRESTAbstractManager(URL restURL, String username, String password) {
|
||||
this.restURL = restURL;
|
||||
this.gsuser = username;
|
||||
this.gspass = password;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,92 @@
|
||||
/*
|
||||
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||
*
|
||||
* Copyright (C) 2007,2012 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.manager;
|
||||
|
||||
import it.geosolutions.geoserver.rest.HTTPUtils;
|
||||
import it.geosolutions.geoserver.rest.encoder.datastore.GSAbstractDatastoreEncoder;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* Manage datastores.
|
||||
*
|
||||
* To pass connection parameters, use the encoders derived from
|
||||
* {@link GSAbstractDatastoreEncoder}.
|
||||
*
|
||||
* @author Oscar Fonts
|
||||
*/
|
||||
public class GeoServerRESTDatastoreManager extends GeoServerRESTAbstractManager {
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*
|
||||
* @param restURL GeoServer REST API endpoint
|
||||
* @param username GeoServer REST API authorized username
|
||||
* @param password GeoServer REST API password for the former username
|
||||
*/
|
||||
public GeoServerRESTDatastoreManager(URL restURL, String username, String password) {
|
||||
super(restURL, username, password);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a datastore.
|
||||
*
|
||||
* @param workspace
|
||||
* Name of the workspace to contain the datastore. This will also
|
||||
* be the prefix of any layer names contained in the datastore.
|
||||
* @param datastore
|
||||
* the set of parameters to be set to the datastore (including
|
||||
* connection parameters).
|
||||
* @return <TT>true</TT> if the datastore has been successfully
|
||||
* created, <TT>false</TT> otherwise
|
||||
*/
|
||||
|
||||
public boolean create(String workspace, GSAbstractDatastoreEncoder datastore) {
|
||||
String sUrl = restURL + "/rest/workspaces/" + workspace
|
||||
+ "/datastores/";
|
||||
String xml = datastore.toString();
|
||||
String result = HTTPUtils.postXml(sUrl, xml, gsuser, gspass);
|
||||
return result != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a datastore.
|
||||
*
|
||||
* @param workspace
|
||||
* Name of the workspace that contains the datastore.
|
||||
* @param datastore
|
||||
* the set of parameters to be set to the datastore (including
|
||||
* connection parameters).
|
||||
* @return <TT>true</TT> if the datastore has been successfully
|
||||
* updated, <TT>false</TT> otherwise
|
||||
*/
|
||||
public boolean update(String workspace, GSAbstractDatastoreEncoder datastore) {
|
||||
String sUrl = restURL + "/rest/workspaces/" + workspace
|
||||
+ "/datastores/" + datastore.getName();
|
||||
String xml = datastore.toString();
|
||||
String result = HTTPUtils.putXml(sUrl, xml, gsuser, gspass);
|
||||
return result != null;
|
||||
}
|
||||
}
|
||||
@ -22,14 +22,15 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package it.geosolutions.geoserver.rest.publisher;
|
||||
package it.geosolutions.geoserver.rest.manager;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Map;
|
||||
|
||||
import it.geosolutions.geoserver.rest.GeoServerRESTPublisher;
|
||||
import it.geosolutions.geoserver.rest.GeoServerRESTManager;
|
||||
import it.geosolutions.geoserver.rest.GeoserverRESTTest;
|
||||
import it.geosolutions.geoserver.rest.decoder.RESTDataStore;
|
||||
import it.geosolutions.geoserver.rest.encoder.datastore.GSAbstractDatastoreEncoder;
|
||||
@ -45,25 +46,26 @@ import it.geosolutions.geoserver.rest.encoder.datastore.GSDirectoryOfShapefilesD
|
||||
*
|
||||
* <li>Tests constructors and getters from {@link RESTDataStore} (reader).
|
||||
*
|
||||
* <li>Tests {@link GeoServerRESTPublisher#createDatastore} and
|
||||
* {@link GeoServerRESTPublisher#updateDatastore} methods.</ul>
|
||||
* <li>Tests {@link GeoServerRESTDatastoreManager} create and update methods.</ul>
|
||||
*
|
||||
* <p>The sequence is:
|
||||
* <ol>
|
||||
* <li>Create a DirectoryOfShapefilesDatastoreEncoder, with default parameters.
|
||||
* <li>Publish via createDatastore.
|
||||
* <li>Publish via GeoServerRESTDatastoreManager.create.
|
||||
* <li>Read the datastore from server.
|
||||
* <li>Test all parameter values.
|
||||
* <li>Create a new Encoder from it.
|
||||
* <li>Change all datastore parameter to non-default ones.
|
||||
* <li>Update via updateDatastore.
|
||||
* <li>Update via GeoServerRESTDatastoreManager.update.
|
||||
* <li>Read again.
|
||||
* <li>Test all new values.
|
||||
* </ol>
|
||||
*
|
||||
* @author Oscar Fonts
|
||||
*/
|
||||
public class GeoserverRESTCreateReadUpdateDatastoreTest extends GeoserverRESTTest {
|
||||
public class GeoserverRESTDatastoreManagerTest extends GeoserverRESTTest {
|
||||
|
||||
public final GeoServerRESTManager manager;
|
||||
|
||||
private static final String WS_NAME = DEFAULT_WS;
|
||||
private static final String DS_NAME = "testCreateDatastore";
|
||||
@ -71,15 +73,19 @@ public class GeoserverRESTCreateReadUpdateDatastoreTest extends GeoserverRESTTes
|
||||
private static URL LOCATION_1;
|
||||
private static URL LOCATION_2;
|
||||
|
||||
public GeoserverRESTCreateReadUpdateDatastoreTest(String testName) throws Exception {
|
||||
public GeoserverRESTDatastoreManagerTest(String testName) throws Exception {
|
||||
super(testName);
|
||||
manager = new GeoServerRESTManager(new URL(RESTURL), RESTUSER, RESTPW);
|
||||
|
||||
LOCATION_1 = new URL("file:data/1");
|
||||
LOCATION_2 = new URL("file:data/2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
assertTrue(enabled());
|
||||
if (!enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Delete all resources except styles
|
||||
deleteAllWorkspacesRecursively();
|
||||
@ -89,7 +95,7 @@ public class GeoserverRESTCreateReadUpdateDatastoreTest extends GeoserverRESTTes
|
||||
|
||||
// Create a directory of spatial files with default parameters
|
||||
GSDirectoryOfShapefilesDatastoreEncoder create = new GSDirectoryOfShapefilesDatastoreEncoder(DS_NAME, LOCATION_1);
|
||||
assertTrue(publisher.createDatastore(WS_NAME, create));
|
||||
assertTrue(manager.getDatastoreManager().create(WS_NAME, create));
|
||||
|
||||
// Read the store from server; check all parameter values
|
||||
RESTDataStore read = reader.getDatastore(WS_NAME, DS_NAME);
|
||||
@ -115,7 +121,7 @@ public class GeoserverRESTCreateReadUpdateDatastoreTest extends GeoserverRESTTes
|
||||
update.setCacheAndReuseMemoryMaps(false);
|
||||
|
||||
//update the store
|
||||
assertTrue(publisher.updateDatastore(WS_NAME, update));
|
||||
assertTrue(manager.getDatastoreManager().update(WS_NAME, update));
|
||||
|
||||
// Read again, check that all parameters have changed
|
||||
read = reader.getDatastore(WS_NAME, DS_NAME);
|
||||
@ -45,7 +45,9 @@ public class GeoserverRESTPublishShpCollectionTest extends GeoserverRESTTest {
|
||||
|
||||
@Test
|
||||
public void testLocalZip() throws Exception {
|
||||
assertTrue(enabled());
|
||||
if (!enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
URI location = new ClassPathResource("testdata/multipleshp.zip").getFile().toURI();
|
||||
test(location);
|
||||
@ -53,7 +55,9 @@ public class GeoserverRESTPublishShpCollectionTest extends GeoserverRESTTest {
|
||||
|
||||
@Test
|
||||
public void testExternalDir() throws Exception {
|
||||
assertTrue(enabled());
|
||||
if (!enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
URI location = new ClassPathResource("testdata/multipleshapefiles").getFile().toURI();
|
||||
test(location);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user