Compare commits

...

12 Commits

Author SHA1 Message Date
Davide Savazzi
c88fec8530 changed pom version 2013-01-24 11:32:50 +01:00
Davide Savazzi
a49473f542 Merge pull request #55 from svzdvd/1.5.1-release
fixed LayerGroup Encoder tests
2013-01-24 01:43:04 -08:00
Davide Savazzi
4e0ebffa3c fixed LayerGroup Encoder tests 2013-01-24 10:39:09 +01:00
Davide Savazzi
aef225d60e Merge pull request #54 from svzdvd/1.5.1-release
Backport of LayerGroup patch for branch 1.5.x
2013-01-23 13:06:55 -08:00
Davide Savazzi
a67e10dab3 fixed name of GeoServerRESTDatastoreManager file 2013-01-23 22:00:20 +01:00
Davide Savazzi
d00ad470e4 added LayerGroup encoder for GeoServer 2.2 and GeoServer 2.3 2013-01-23 21:55:04 +01:00
Davide Savazzi
552edbc9fe updated LayerGroup reader to support GeoServer 2.3.x 2013-01-23 21:54:45 +01:00
Carlo Cancellieri
4fc0a8dd99 Merge pull request #51 from geosolutions-it/1.5.x-StoreManager-improvements
1.5.x store manager improvements
2013-01-22 06:40:13 -08:00
ccancellieri
550f982701 refine backport 2013-01-22 14:43:44 +01:00
ccancellieri
0978997f9f backport to the 1.5.x branch 2013-01-21 19:03:10 +01:00
ccancellieri
46fbce4393 Remove specific datastore methods from manager implementing a generic StoreManager. Improving Store encoders and integration tests. 2013-01-21 18:35:42 +01:00
Damiano
0097264d42 changed pom version 2013-01-14 18:51:06 +01:00
27 changed files with 1624 additions and 469 deletions

View File

@ -20,7 +20,7 @@
<groupId>it.geosolutions</groupId> <groupId>it.geosolutions</groupId>
<artifactId>geoserver-manager</artifactId> <artifactId>geoserver-manager</artifactId>
<version>1.6-SNAPSHOT</version> <version>1.5.1</version>
<packaging>jar</packaging> <packaging>jar</packaging>

View File

@ -26,6 +26,7 @@ package it.geosolutions.geoserver.rest;
import it.geosolutions.geoserver.rest.manager.GeoServerRESTAbstractManager; import it.geosolutions.geoserver.rest.manager.GeoServerRESTAbstractManager;
import it.geosolutions.geoserver.rest.manager.GeoServerRESTDatastoreManager; import it.geosolutions.geoserver.rest.manager.GeoServerRESTDatastoreManager;
import it.geosolutions.geoserver.rest.manager.GeoServerRESTStoreManager;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
@ -39,15 +40,17 @@ import java.net.URL;
* <li>getPublisher() simple, high-level pubhish methods. * <li>getPublisher() simple, high-level pubhish methods.
* <li>get<i>Foo</i>Manager, full-fledged management of catalog objects. * <li>get<i>Foo</i>Manager, full-fledged management of catalog objects.
* </ul> * </ul>
*
* @author Oscar Fonts * @author Oscar Fonts
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it * @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
*/ */
public class GeoServerRESTManager extends GeoServerRESTAbstractManager { public class GeoServerRESTManager extends GeoServerRESTAbstractManager {
private final GeoServerRESTPublisher publisher; private final GeoServerRESTPublisher publisher;
private final GeoServerRESTReader reader; private final GeoServerRESTReader reader;
private final GeoServerRESTDatastoreManager datastoreManager; private final GeoServerRESTStoreManager store;
/** /**
* Default constructor. * Default constructor.
@ -60,15 +63,14 @@ public class GeoServerRESTManager extends GeoServerRESTAbstractManager {
* @throws MalformedURLException {@link GeoServerRESTAbstractManager#GeoServerRESTAbstractManager(URL, String, String)} * @throws MalformedURLException {@link GeoServerRESTAbstractManager#GeoServerRESTAbstractManager(URL, String, String)}
* @throws IllegalArgumentException {@link GeoServerRESTAbstractManager#GeoServerRESTAbstractManager(URL, String, String)} * @throws IllegalArgumentException {@link GeoServerRESTAbstractManager#GeoServerRESTAbstractManager(URL, String, String)}
*/ */
public GeoServerRESTManager(URL restURL, String username, String password) throws IllegalArgumentException, MalformedURLException { public GeoServerRESTManager(URL restURL, String username, String password)
throws IllegalArgumentException, MalformedURLException {
super(restURL, username, password); super(restURL, username, password);
// Internal publisher and reader, provide simple access methods. // Internal publisher and reader, provide simple access methods.
publisher = new GeoServerRESTPublisher(restURL.toString(), username, password); publisher = new GeoServerRESTPublisher(restURL.toString(), username, password);
reader = new GeoServerRESTReader(restURL, username, password); reader = new GeoServerRESTReader(restURL, username, password);
store = new GeoServerRESTStoreManager(restURL, gsuser, gspass);
// Classes for fine-grained management of catalog components.
datastoreManager = new GeoServerRESTDatastoreManager(restURL, username, password);
} }
public GeoServerRESTPublisher getPublisher() { public GeoServerRESTPublisher getPublisher() {
@ -79,8 +81,16 @@ public class GeoServerRESTManager extends GeoServerRESTAbstractManager {
return reader; return reader;
} }
public GeoServerRESTStoreManager getStoreManager() {
return store;
}
/**
*
* @Deprecated use {GeoServerRESTManager#getStoreManager()}
*/
public GeoServerRESTDatastoreManager getDatastoreManager() { public GeoServerRESTDatastoreManager getDatastoreManager() {
return datastoreManager; return (GeoServerRESTDatastoreManager) store;
} }
} }

View File

@ -29,14 +29,15 @@ import it.geosolutions.geoserver.rest.decoder.RESTCoverageStore;
import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem; import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem;
import it.geosolutions.geoserver.rest.encoder.GSBackupEncoder; import it.geosolutions.geoserver.rest.encoder.GSBackupEncoder;
import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder; import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder;
import it.geosolutions.geoserver.rest.encoder.GSLayerGroupEncoder;
import it.geosolutions.geoserver.rest.encoder.GSNamespaceEncoder; import it.geosolutions.geoserver.rest.encoder.GSNamespaceEncoder;
import it.geosolutions.geoserver.rest.encoder.GSPostGISDatastoreEncoder;
import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder; import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder;
import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder.ProjectionPolicy; import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder.ProjectionPolicy;
import it.geosolutions.geoserver.rest.encoder.GSWorkspaceEncoder; import it.geosolutions.geoserver.rest.encoder.GSWorkspaceEncoder;
import it.geosolutions.geoserver.rest.encoder.coverage.GSCoverageEncoder; import it.geosolutions.geoserver.rest.encoder.coverage.GSCoverageEncoder;
import it.geosolutions.geoserver.rest.encoder.datastore.GSPostGISDatastoreEncoder;
import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureTypeEncoder; import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureTypeEncoder;
import it.geosolutions.geoserver.rest.manager.GeoServerRESTDatastoreManager; import it.geosolutions.geoserver.rest.manager.GeoServerRESTStoreManager;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@ -371,7 +372,7 @@ public class GeoServerRESTPublisher {
} }
LOGGER.debug("POSTing new style " + name + " to " + sUrl); LOGGER.debug("POSTing new style " + name + " to " + sUrl);
String result = HTTPUtils String result = HTTPUtils
.post(sUrl, sldFile, "application/vnd.ogc.sld+xml", gsuser, gspass); .post(sUrl, sldFile, Format.SLD.getContentType(), gsuser, gspass);
return result != null; return result != null;
} }
@ -583,15 +584,41 @@ public class GeoServerRESTPublisher {
} }
/** /**
* Get the type name of a DataStoreType. * Get the type name of a StoreType.
* *
* @param type the DataStoreType. * @param type the StoreType.
* @return "featuretypes.xml" for DATASTORES, "coverages.xml" otherwise. * @return "dataStore" for DATASTORES, "coverageStore" otherwise.
*/
public static String getType(StoreType type) {
switch (type) {
case COVERAGESTORES:
return "coverageStore"; // Format
case DATASTORES:
return "dataStore";
default:
return "coverageStore";
}
}
/**
* Get the type name of a StoreType.
*
* @return "featuretypes" for DATASTORES, "coverages" otherwise.
*/ */
public String getTypeName() { public String getTypeName() {
return getTypeName(this); return getTypeName(this);
} }
/**
* Get the type of a StoreType.
*
* @param type the StoreType.
* @return "dataStore" for DATASTORES, "coverageStore" otherwise.
*/
public String getType() {
return getType(this);
}
/** /**
* Returns a lowercase representation of the parameter value, suitable to construct the rest call. * Returns a lowercase representation of the parameter value, suitable to construct the rest call.
*/ */
@ -849,7 +876,7 @@ public class GeoServerRESTPublisher {
/** /**
* Create a PostGIS datastore. * Create a PostGIS datastore.
* *
* @deprecated Will be deleted in next version 1.5.x, use {@link GeoServerRESTDatastoreManager} instead. * @deprecated Will be deleted in next version 1.6.x, use {@link GeoServerRESTStoreManager} instead.
* *
* @param workspace Name of the workspace to contain the database. This will also be the prefix of any layer names created from tables in the * @param workspace Name of the workspace to contain the database. This will also be the prefix of any layer names created from tables in the
* database. * database.
@ -858,7 +885,7 @@ public class GeoServerRESTPublisher {
* @return <TT>true</TT> if the PostGIS datastore has been successfully created, <TT>false</TT> otherwise * @return <TT>true</TT> if the PostGIS datastore has been successfully created, <TT>false</TT> otherwise
*/ */
public boolean createPostGISDatastore(String workspace, public boolean createPostGISDatastore(String workspace,
GSPostGISDatastoreEncoder datastoreEncoder) { it.geosolutions.geoserver.rest.encoder.GSPostGISDatastoreEncoder datastoreEncoder) {
String sUrl = restURL + "/rest/workspaces/" + workspace + "/datastores/"; String sUrl = restURL + "/rest/workspaces/" + workspace + "/datastores/";
String xml = datastoreEncoder.toString(); String xml = datastoreEncoder.toString();
String result = HTTPUtils.postXml(sUrl, xml, gsuser, gspass); String result = HTTPUtils.postXml(sUrl, xml, gsuser, gspass);
@ -1342,6 +1369,16 @@ public class GeoServerRESTPublisher {
} }
} }
/**
* Gets the mime type from a format.
*
* @param f the format key.
* @return The content-type (mime), or {@code null} if not in the enum.
*/
public String getContentType() {
return getContentType(this);
}
/** /**
* Returns a lowercase representation of the parameter. Useful when constructing the REST request. * Returns a lowercase representation of the parameter. Useful when constructing the REST request.
*/ */
@ -2114,12 +2151,20 @@ public class GeoServerRESTPublisher {
/** /**
* Remove a layer group. * Remove a layer group.
* *
* @param workspace the layer group workspace.
* @param name the layer group name. * @param name the layer group name.
* @return true if succeeded. * @return true if succeeded.
*/ */
public boolean removeLayerGroup(String name) { public boolean removeLayerGroup(String workspace, String name) {
String url = restURL + "/rest";
if (workspace == null) {
url += "/layergroups/" + name;
} else {
url += "/workspaces/" + workspace + "/layergroups/" + name;
}
try { try {
URL deleteUrl = new URL(restURL + "/rest/layergroups/" + name); URL deleteUrl = new URL(url);
boolean deleted = HTTPUtils.delete(deleteUrl.toExternalForm(), gsuser, gspass); boolean deleted = HTTPUtils.delete(deleteUrl.toExternalForm(), gsuser, gspass);
if (!deleted) { if (!deleted) {
if (LOGGER.isWarnEnabled()) if (LOGGER.isWarnEnabled())
@ -2137,6 +2182,16 @@ public class GeoServerRESTPublisher {
} }
} }
/**
* Remove a layer group.
*
* @param name the layer group name.
* @return true if succeeded.
*/
public boolean removeLayerGroup(String name) {
return removeLayerGroup(null, name);
}
/** /**
* remove a generic given layer from a given workspace * remove a generic given layer from a given workspace
* *
@ -2298,6 +2353,89 @@ public class GeoServerRESTPublisher {
return sendResult != null; return sendResult != null;
} }
/**
* Create a new LayerGroup using the specified encoder
*
* @param name name of the layer group
* @param group group encoder
* @return true if operation was successful
*/
public boolean createLayerGroup(String name, GSLayerGroupEncoder group) {
return createLayerGroup(null, name, group);
}
/**
* Create a new LayerGroup using the specified encoder
*
* @param workspace name of the workspace
* @param name name of the layer group
* @param group group encoder
* @return true if operation was successful
*/
public boolean createLayerGroup(String workspace, String name, GSLayerGroupEncoder group) {
String url = restURL + "/rest";
if (workspace == null) {
url += "/layergroups/";
} else {
group.setWorkspace(workspace);
url += "/workspaces/" + workspace + "/layergroups/";
}
group.setName(name);
String sendResult = HTTPUtils.postXml(url, group.toString(), gsuser, gspass);
if (sendResult != null) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("LayerGroup successfully configured: " + name);
}
} else {
if (LOGGER.isWarnEnabled())
LOGGER.warn("Error configuring LayerGroup " + name + " (" + sendResult + ")");
}
return sendResult != null;
}
/**
* Update a LayerGroup using the specified encoder
*
* @param name name of the layer group
* @param group group encoder
* @return true if operation was successful
*/
public boolean configureLayerGroup(String name, GSLayerGroupEncoder group) {
return configureLayerGroup(null, name, group);
}
/**
* Update a LayerGroup using the specified encoder
*
* @param workspace name of the workspace
* @param name name of the layer group
* @param group group encoder
* @return true if operation was successful
*/
public boolean configureLayerGroup(String workspace, String name, GSLayerGroupEncoder group) {
String url = restURL + "/rest";
if (workspace == null) {
url += "/layergroups/" + name;
} else {
url += "/workspaces/" + workspace + "/layergroups/" + name;
}
String sendResult = HTTPUtils.putXml(url, group.toString(), gsuser, gspass);
if (sendResult != null) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("LayerGroup successfully configured: " + name);
}
} else {
if (LOGGER.isWarnEnabled())
LOGGER.warn("Error configuring LayerGroup " + name + " (" + sendResult + ")");
}
return sendResult != null;
}
/** /**
* Configure an existent coverage in a given workspace and coverage store * Configure an existent coverage in a given workspace and coverage store
* *

View File

@ -396,12 +396,19 @@ public class GeoServerRESTReader {
//========================================================================== //==========================================================================
/** /**
* Get summary info about all LayerGroups. * Get summary info about all LayerGroups in the given workspace.
* *
* @param workspace name of the workspace
* @return summary info about LayerGroups as a {@link RESTLayerGroupList} * @return summary info about LayerGroups as a {@link RESTLayerGroupList}
*/ */
public RESTLayerGroupList getLayerGroups() { public RESTLayerGroupList getLayerGroups(String workspace) {
String url = "/rest/layergroups.xml"; String url;
if (workspace == null) {
url = "/rest/layergroups.xml";
} else {
url = "/rest/workspaces/" + workspace + "/layergroups.xml";
}
if (LOGGER.isDebugEnabled()) { if (LOGGER.isDebugEnabled()) {
LOGGER.debug("### Retrieving layergroups from " + url); LOGGER.debug("### Retrieving layergroups from " + url);
} }
@ -411,17 +418,45 @@ public class GeoServerRESTReader {
/** /**
* Get detailed info about a given LayerGroup. * Get detailed info about a given LayerGroup.
* *
* @param name The name of the LayerGroup * @param workspace name of the workspace
* @param name the name of the LayerGroup
* @return LayerGroup details as a {@link RESTLayerGroup} * @return LayerGroup details as a {@link RESTLayerGroup}
*/ */
public RESTLayerGroup getLayerGroup(String name) { public RESTLayerGroup getLayerGroup(String workspace, String name) {
String url = "/rest/layergroups/" + name + ".xml"; String url;
if (workspace == null) {
url = "/rest/layergroups/" + name + ".xml";
} else {
url = "/rest/workspaces/" + workspace + "/layergroups/" + name + ".xml";
}
if (LOGGER.isDebugEnabled()) { if (LOGGER.isDebugEnabled()) {
LOGGER.debug("### Retrieving layergroup from " + url); LOGGER.debug("### Retrieving layergroup from " + url);
} }
return RESTLayerGroup.build(load(url)); return RESTLayerGroup.build(load(url));
} }
/**
* Get summary info about all LayerGroups.
*
* @return summary info about LayerGroups as a {@link RESTLayerGroupList}
*/
public RESTLayerGroupList getLayerGroups() {
return getLayerGroups(null);
}
/**
* Get detailed info about a given LayerGroup.
*
* @param name The name of the LayerGroup
* @return LayerGroup details as a {@link RESTLayerGroup}
*/
public RESTLayerGroup getLayerGroup(String name) {
return getLayerGroup(null, name);
}
//========================================================================== //==========================================================================
//=== LAYERS //=== LAYERS
//========================================================================== //==========================================================================

View File

@ -91,8 +91,50 @@ public class RESTLayerGroup {
return rootElem.getChildText("name"); return rootElem.getChildText("name");
} }
public String getWorkspace() {
Element rootLayer = rootElem.getChild("workspace");
if (rootLayer != null) {
return rootLayer.getChildText("name");
} else {
return null;
}
}
public String getMode() {
return rootElem.getChildText("mode");
}
public String getTitle() {
return rootElem.getChildText("title");
}
public String getAbstract() {
return rootElem.getChildText("abstractTxt");
}
public String getRootLayer() {
Element rootLayer = rootElem.getChild("rootLayer");
if (rootLayer != null) {
return rootLayer.getChildText("name");
} else {
return null;
}
}
public RESTLayerList getLayerList() { public RESTLayerList getLayerList() {
if (rootElem.getChild("layers") != null) {
return new RESTLayerList(rootElem.getChild("layers")); return new RESTLayerList(rootElem.getChild("layers"));
} else {
return null;
}
}
public RESTPublishedList getPublishedList() {
if (rootElem.getChild("publishables") != null) {
return new RESTPublishedList(rootElem.getChild("publishables"));
} else {
return null;
}
} }
public String getCRS() { public String getCRS() {

View File

@ -0,0 +1,59 @@
/*
* GeoServer-Manager - Simple Manager Library for GeoServer
*
* Copyright (C) 2013 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.decoder;
import org.jdom.Element;
import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem;
/**
* Parse a <TT>published</TT> returned as XML REST objects.
*
* This is the XML REST representation:
* <pre>{@code
<published type="layer">
<name>sfdem</name>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/layers/sfdem.xml" type="application/xml"/>
</published>
* }</pre>
*
* @author Davide Savazzi (geo-solutions.it)
*/
public class RESTPublished extends NameLinkElem {
private final String type;
public RESTPublished(Element elem) {
super(elem);
type = elem.getAttributeValue("type");
}
public String getType() {
return type;
}
}

View File

@ -0,0 +1,66 @@
/*
* GeoServer-Manager - Simple Manager Library for GeoServer
*
* Copyright (C) 2013 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.decoder;
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
import org.jdom.Element;
/**
* Parse <TT>published</TT>s returned as XML REST objects.
*
* This is the XML REST representation:
* <pre>{@code
<publishables>
<published type="layer">
<name>sfdem</name>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/layers/sfdem.xml" type="application/xml"/>
</published>
<published type="layer">
<name>bugsites</name>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/layers/bugsites.xml" type="application/xml"/>
</published>
</publishables>
* }</pre>
*
* @author Davide Savazzi (geo-solutions.it)
*/
public class RESTPublishedList extends RESTAbstractList<RESTPublished> {
public static RESTPublishedList build(String response) {
Element elem = JDOMBuilder.buildElement(response);
return elem == null ? null : new RESTPublishedList(elem);
}
protected RESTPublishedList(Element list) {
super(list);
}
protected RESTPublished createElement(Element el) {
return new RESTPublished(el);
}
}

View File

@ -0,0 +1,121 @@
/*
* 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.encoder;
import org.jdom.Element;
import it.geosolutions.geoserver.rest.GeoServerRESTPublisher;
import it.geosolutions.geoserver.rest.GeoServerRESTPublisher.StoreType;
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder;
/**
* Generic Store encoder.
*
* Provides getters and setters for parameters common to all CoverageStore.
*
* @author Carlo Cancellieri - GeoSolutions
*/
public abstract class GSAbstractStoreEncoder extends PropertyXMLEncoder {
private final GeoServerRESTPublisher.StoreType type;
protected GSAbstractStoreEncoder(GeoServerRESTPublisher.StoreType type, String storeName) {
super(type.getType());
this.type=type;
}
public StoreType getStoreType() {
return this.type;
}
public void setType(String type) {
set("type", type);
}
public String getType() {
return ElementUtils.contains(getRoot(), "name").getTextTrim();
}
public void setName(String name) {
ensureValidName(name);
set("name", name);
}
public String getName() {
Element e = ElementUtils.contains(getRoot(), "name");
return e!=null?e.getTextTrim():null;
}
public void setDescription(String description) {
set("description", description);
}
public String getDescription() {
Element e = ElementUtils.contains(getRoot(), "description");
return e!=null?e.getTextTrim():null;
}
public void setEnabled(boolean enabled) {
set("enabled", Boolean.toString(enabled));
}
public boolean getEnabled() {
Element e = ElementUtils.contains(getRoot(), "name");
if (e!=null)
return Boolean.parseBoolean(e.getTextTrim());
else
return false;
}
/**
* Check name validity.
*
* @param name the name
* @throws IllegalArgumentException if name is null or empty
*/
protected void ensureValidName(String name) {
if (name == null || name.isEmpty()) {
throw new IllegalArgumentException("Store name cannot be null or empty");
}
}
/**
* Check type validity.
*
* @param type the type.
* @throws IllegalArgumentException if type is not {@value #TYPE}
*/
protected void ensureValidType(String type) {
if (!type.equals(getValidType())) {
throw new IllegalArgumentException("The store type '" + type + "' is not valid");
}
}
/**
* The type of the implementing store.
*/
protected abstract String getValidType();
}

View File

@ -0,0 +1,123 @@
/*
* GeoServer-Manager - Simple Manager Library for GeoServer
*
* Copyright (C) 2013 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;
import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder;
import org.jdom.Element;
/**
* LayerGroup encoder for GeoServer < 2.3
*
* @author Davide Savazzi (geo-solutions.it)
*/
public class GSLayerGroupEncoder extends PropertyXMLEncoder {
protected Element nameElem;
protected Element workspaceElem;
protected Element boundsElem;
protected Element publishablesElem;
protected Element stylesElem;
public GSLayerGroupEncoder() {
super("layerGroup");
}
public void setWorkspace(String workspace) {
workspaceElem = elem("workspace", elem("name", workspace));
}
public void setName(String name) {
nameElem = elem("name", name);
}
public void addLayer(String layer) {
addLayer(layer, null);
}
public void addLayer(String layer, String styleName) {
initPublishables("layers");
publishablesElem.addContent(elem("layer", elem("name", layer)));
Element style = new Element("style");
stylesElem.addContent(style);
if (styleName != null) {
style.addContent(elem("name", styleName));
}
}
public void setBounds(String crs, double minx, double maxx, double miny, double maxy) {
boundsElem = elem("bounds",
elem("minx", Double.toString(minx)),
elem("maxx", Double.toString(maxx)),
elem("miny", Double.toString(miny)),
elem("maxy", Double.toString(maxy)),
elem("crs", "class", "projected").setText(crs));
}
protected void initPublishables(String publishablesTag) {
if (publishablesElem == null) {
publishablesElem = new Element(publishablesTag);
}
if (stylesElem == null) {
stylesElem = new Element("styles");
}
}
protected void addToRoot(Element ... elements) {
for (Element e : elements) {
if (e != null) {
getRoot().addContent(e);
}
}
}
protected Element elem(String tag, String attributeName, String attributeValue) {
return new Element(tag).setAttribute(attributeName, attributeValue);
}
protected Element elem(String tag, String text) {
return new Element(tag).setText(text);
}
protected Element elem(String tag, Element ... children) {
Element parent = new Element(tag);
for (Element child : children) {
parent.addContent(child);
}
return parent;
}
@Override
public String toString() {
addToRoot(nameElem, workspaceElem, boundsElem, publishablesElem, stylesElem);
return super.toString();
}
}

View File

@ -0,0 +1,110 @@
/*
* GeoServer-Manager - Simple Manager Library for GeoServer
*
* Copyright (C) 2013 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;
import java.util.HashSet;
import java.util.Set;
import org.jdom.Element;
/**
* LayerGroup encoder for GeoServer >= 2.3
*
* @author Davide Savazzi (geo-solutions.it)
*/
public class GSLayerGroupEncoder23 extends GSLayerGroupEncoder {
public static final String MODE_SINGLE = "SINGLE";
public static final String MODE_NAMED = "NAMED";
public static final String MODE_CONTAINER = "CONTAINER";
public static final String MODE_EO = "EO";
private static final Set<String> modes;
static {
modes = new HashSet<String>();
modes.add(MODE_SINGLE);
modes.add(MODE_NAMED);
modes.add(MODE_CONTAINER);
modes.add(MODE_EO);
}
private Element titleElem;
private Element abstractElem;
private Element modeElem;
private Element rootLayerElem;
private Element rootLayerStyleElem;
public void setTitle(String title) {
titleElem = elem("title", title);
}
public void setAbstract(String abstractTxt) {
abstractElem = elem("abstractTxt", abstractTxt);
}
public void setMode(String mode) {
if (!modes.contains(mode)) {
throw new IllegalArgumentException("Invalid mode: " + mode);
}
modeElem = elem("mode", mode);
}
public void setRootLayer(String layer, String style) {
rootLayerElem = elem("rootLayer", elem("name", layer));
rootLayerStyleElem = elem("rootLayerStyle", elem("name", style));
}
@Override
public void addLayer(String layer, String styleName) {
initPublishables("publishables");
publishablesElem.addContent(
new Element("published").setAttribute("type", "layer").addContent(
elem("name", layer)));
Element style = new Element("style");
stylesElem.addContent(style);
if (styleName != null) {
style.addContent(elem("name", styleName));
}
}
public void addLayerGroup(String group) {
initPublishables("publishables");
publishablesElem.addContent(
new Element("published").setAttribute("type", "layerGroup").addContent(
elem("name", group)));
stylesElem.addContent(new Element("style"));
}
@Override
public String toString() {
addToRoot(titleElem, abstractElem, modeElem, rootLayerElem, rootLayerStyleElem);
return super.toString();
}
}

View File

@ -35,7 +35,7 @@ import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder;
* @author ETj * @author ETj
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it * @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
* *
* @deprecated Will be removed in next version 1.5.x. * @deprecated Will be removed in next version 1.6.x.
* Use {@link it.geosolutions.geoserver.rest.encoder.datastore.GSPostGISDatastoreEncoder} instead. * Use {@link it.geosolutions.geoserver.rest.encoder.datastore.GSPostGISDatastoreEncoder} instead.
*/ */
public class GSPostGISDatastoreEncoder extends PropertyXMLEncoder { public class GSPostGISDatastoreEncoder extends PropertyXMLEncoder {

View File

@ -0,0 +1,49 @@
/*
* 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.encoder.coverage;
import it.geosolutions.geoserver.rest.GeoServerRESTPublisher.StoreType;
import it.geosolutions.geoserver.rest.encoder.GSAbstractStoreEncoder;
/**
* Generic CoverageStore encoder.
*
* Provides getters and setters for parameters common to all CoverageStore.
*
* @author Carlo Cancellieri - GeoSolutions
*
* @deprecated TODO complete specialization
*/
public abstract class GSAbstractCoveragestoreEncoder extends GSAbstractStoreEncoder {
protected GSAbstractCoveragestoreEncoder(String storeName) {
super(StoreType.COVERAGESTORES,storeName);
// Add mandatory parameter
ensureValidName(storeName);
setName(storeName);
}
}

View File

@ -24,30 +24,29 @@
*/ */
package it.geosolutions.geoserver.rest.encoder.datastore; package it.geosolutions.geoserver.rest.encoder.datastore;
import java.util.Map; import it.geosolutions.geoserver.rest.GeoServerRESTPublisher;
import it.geosolutions.geoserver.rest.decoder.RESTDataStore; import it.geosolutions.geoserver.rest.decoder.RESTDataStore;
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils; import it.geosolutions.geoserver.rest.encoder.GSAbstractStoreEncoder;
import it.geosolutions.geoserver.rest.encoder.utils.NestedElementEncoder; import it.geosolutions.geoserver.rest.encoder.utils.NestedElementEncoder;
import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder;
import java.util.Map;
/** /**
* Generic Datastore encoder. * Generic Datastore encoder.
* *
* Provides getters and setters for parameters common to all Datastores, * Provides getters and setters for parameters common to all Datastores, an internal placeholder for specific connection parameters, and a constructor
* an internal placeholder for specific connection parameters, and * to read parameters from a {@link RESTDataStore}.
* a constructor to read parameters from a {@link RESTDataStore}.
* *
* @author Oscar Fonts * @author Oscar Fonts
*/ */
public abstract class GSAbstractDatastoreEncoder extends PropertyXMLEncoder { public abstract class GSAbstractDatastoreEncoder extends GSAbstractStoreEncoder {
final static String ROOT = "dataStore"; final static String ROOT = "dataStore";
NestedElementEncoder connectionParameters = new NestedElementEncoder("connectionParameters"); NestedElementEncoder connectionParameters = new NestedElementEncoder("connectionParameters");
GSAbstractDatastoreEncoder(String storeName) { GSAbstractDatastoreEncoder(String storeName) {
super(ROOT); super(GeoServerRESTPublisher.StoreType.DATASTORES, ROOT);
// Add mandatory parameter // Add mandatory parameter
ensureValidName(storeName); ensureValidName(storeName);
setName(storeName); setName(storeName);
@ -67,7 +66,6 @@ public abstract class GSAbstractDatastoreEncoder extends PropertyXMLEncoder {
// Match datastore type // Match datastore type
ensureValidType(store.getStoreType()); ensureValidType(store.getStoreType());
setType(store.getStoreType());
// Copy store parameters // Copy store parameters
setDescription(store.getDescription()); setDescription(store.getDescription());
@ -80,67 +78,9 @@ public abstract class GSAbstractDatastoreEncoder extends PropertyXMLEncoder {
} }
} }
void setType(String type) {
set("type", type);
}
public String getType() {
return ElementUtils.contains(getRoot(), "type").getTextTrim();
}
public void setName(String name) {
ensureValidName(name);
set("name", name);
}
public String getName() {
return ElementUtils.contains(getRoot(), "name").getTextTrim();
}
public void setDescription(String description) {
set("description", description);
}
public String getDescription() {
return ElementUtils.contains(getRoot(), "description").getTextTrim();
}
public void setEnabled(boolean enabled) {
set("enabled", Boolean.toString(enabled));
}
public boolean getEnabled() {
return Boolean.parseBoolean(ElementUtils.contains(getRoot(), "enabled").getTextTrim());
}
/**
* Check name validity.
*
* @param name the name
* @throws IllegalArgumentException if name is null or empty
*/
void ensureValidName(String name) {
if (name == null || name.isEmpty()) {
throw new IllegalArgumentException(
"Store name cannot be null or empty");
}
}
/**
* Check type validity.
*
* @param type the type.
* @throws IllegalArgumentException if type is not {@value #TYPE}
*/
void ensureValidType(String type) {
if (!type.equals(getValidType())) {
throw new IllegalArgumentException(
"The store type '"+ type +"' is not valid");
}
}
/** /**
* The type of the implementing datastore. * The type of the implementing datastore.
*/ */
abstract String getValidType(); protected abstract String getValidType();
} }

View File

@ -66,7 +66,6 @@ public class GSArcSDEDatastoreEncoder extends GSAbstractDatastoreEncoder {
super(name); super(name);
// Set mandatory parameters // Set mandatory parameters
setType(TYPE);
setServer(server); setServer(server);
setUser(user); setUser(user);
@ -212,7 +211,7 @@ public class GSArcSDEDatastoreEncoder extends GSAbstractDatastoreEncoder {
/** /**
* @return {@value #TYPE} * @return {@value #TYPE}
*/ */
String getValidType() { protected String getValidType() {
return TYPE; return TYPE;
} }
} }

View File

@ -38,8 +38,7 @@ public class GSDirectoryOfShapefilesDatastoreEncoder extends GSShapefileDatastor
static final String TYPE = "Directory of spatial files (shapefiles)"; static final String TYPE = "Directory of spatial files (shapefiles)";
/** /**
* Create a {@value #TYPE} datastore with default connection parameters, * Create a {@value #TYPE} datastore with default connection parameters, given a store name and a url (the store location).
* given a store name and a url (the store location).
* *
* @param name New datastore name * @param name New datastore name
* @param url The shapefile location in the server, relative to $GEOSERVER_DATA_DIR. * @param url The shapefile location in the server, relative to $GEOSERVER_DATA_DIR.
@ -62,7 +61,7 @@ public class GSDirectoryOfShapefilesDatastoreEncoder extends GSShapefileDatastor
/** /**
* @return {@value #TYPE} * @return {@value #TYPE}
*/ */
String getValidType() { protected String getValidType() {
return TYPE; return TYPE;
} }
} }

View File

@ -181,7 +181,7 @@ public class GSOracleNGDatastoreEncoder extends GSAbstractDatastoreEncoder {
/** /**
* @return {@value #TYPE} * @return {@value #TYPE}
*/ */
String getValidType() { protected String getValidType() {
return TYPE; return TYPE;
} }
} }

View File

@ -44,6 +44,10 @@ public class GSPostGISDatastoreEncoder extends GSAbstractDatastoreEncoder {
static final boolean DEFAULT_PREPARED_STATEMENTS = false; static final boolean DEFAULT_PREPARED_STATEMENTS = false;
static final int DEFAULT_MAX_OPEN_PREPARED_STATEMENTS = 50; static final int DEFAULT_MAX_OPEN_PREPARED_STATEMENTS = 50;
/**
*
* @param name DataStore name
*/
public GSPostGISDatastoreEncoder(String name) { public GSPostGISDatastoreEncoder(String name) {
super(name); super(name);
@ -141,7 +145,7 @@ public class GSPostGISDatastoreEncoder extends GSAbstractDatastoreEncoder {
/** /**
* @return {@value #TYPE} * @return {@value #TYPE}
*/ */
String getValidType() { protected String getValidType() {
return TYPE; return TYPE;
} }
} }

View File

@ -157,7 +157,7 @@ public class GSShapefileDatastoreEncoder extends GSAbstractDatastoreEncoder {
/** /**
* @return {@value #TYPE} * @return {@value #TYPE}
*/ */
String getValidType() { protected String getValidType() {
return TYPE; return TYPE;
} }
} }

View File

@ -24,7 +24,7 @@
*/ */
package it.geosolutions.geoserver.rest.manager; package it.geosolutions.geoserver.rest.manager;
import it.geosolutions.geoserver.rest.HTTPUtils; import it.geosolutions.geoserver.rest.encoder.GSAbstractStoreEncoder;
import it.geosolutions.geoserver.rest.encoder.datastore.GSAbstractDatastoreEncoder; import it.geosolutions.geoserver.rest.encoder.datastore.GSAbstractDatastoreEncoder;
import java.net.MalformedURLException; import java.net.MalformedURLException;
@ -33,13 +33,14 @@ import java.net.URL;
/** /**
* Manage datastores. * Manage datastores.
* *
* To pass connection parameters, use the encoders derived from * To pass connection parameters, use the encoders derived from {@link GSAbstractDatastoreEncoder}.
* {@link GSAbstractDatastoreEncoder}.
* *
* @author Oscar Fonts * @author Oscar Fonts
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it * @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
*
* @deprecated currently this is only a {@link GeoServerRESTStoreManager} wrapper for datastore
*/ */
public class GeoServerRESTDatastoreManager extends GeoServerRESTAbstractManager { public class GeoServerRESTDatastoreManager extends GeoServerRESTStoreManager {
/** /**
* Default constructor. * Default constructor.
@ -56,38 +57,42 @@ public class GeoServerRESTDatastoreManager extends GeoServerRESTAbstractManager
} }
/** /**
* Create a datastore. * Create a store.
* *
* @param workspace Name of the workspace to contain the datastore. This * @param workspace Name of the workspace to contain the store. This will also be the prefix of any layer names contained in the store.
* will also be the prefix of any layer names contained in the * @param datastore the set of parameters to be set to the store (including connection parameters).
* datastore. * @return <TT>true</TT> if the store has been successfully created, <TT>false</TT> otherwise
* @param datastore the set of parameters to be set to the datastore *
* (including connection parameters). * @deprecated use {@link GeoServerRESTStoreManager#create(String, GSAbstractStoreEncoder)}
* @return <TT>true</TT> if the datastore has been successfully created,
* <TT>false</TT> otherwise
*/ */
public boolean create(String workspace, GSAbstractDatastoreEncoder store) {
public boolean create(String workspace, GSAbstractDatastoreEncoder datastore) { return super.create(workspace, store);
String sUrl = HTTPUtils.append(restURL, "/rest/workspaces/", workspace, "/datastores/").toString();
String xml = datastore.toString();
String result = HTTPUtils.postXml(sUrl, xml, gsuser, gspass);
return result != null;
} }
/** /**
* Update a datastore. * Update a store.
* *
* @param workspace Name of the workspace that contains the datastore. * @param workspace Name of the workspace that contains the store.
* @param datastore the set of parameters to be set to the datastore * @param datastore the set of parameters to be set to the store (including connection parameters).
* (including connection parameters). * @return <TT>true</TT> if the store has been successfully updated, <TT>false</TT> otherwise
* @return <TT>true</TT> if the datastore has been successfully updated, * @deprecated use {@link GeoServerRESTStoreManager#update(String, GSAbstractStoreEncoder)}
* <TT>false</TT> otherwise
*/ */
public boolean update(String workspace, GSAbstractDatastoreEncoder datastore) { public boolean update(String workspace, GSAbstractDatastoreEncoder store) {
String sUrl = HTTPUtils.append(restURL, "/rest/workspaces/", workspace, "/datastores/", return super.update(workspace, store);
datastore.getName()).toString(); }
String xml = datastore.toString();
String result = HTTPUtils.putXml(sUrl, xml, gsuser, gspass); /**
return result != null; * Remove a given CoverageStore in a given Workspace.
*
* @param workspace The name of the workspace
* @param storename The name of the CoverageStore to remove.
* @param recurse if remove should be performed recursively
* @return <TT>true</TT> if the CoverageStore was successfully removed.
* @throws MalformedURLException
*/
public boolean remove(final String workspace, final GSAbstractStoreEncoder store,
final boolean recurse) throws IllegalArgumentException, MalformedURLException {
return super.remove(workspace, store, recurse);
} }
} }

View File

@ -0,0 +1,123 @@
/*
* 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.GeoServerRESTPublisher.Format;
import it.geosolutions.geoserver.rest.HTTPUtils;
import it.geosolutions.geoserver.rest.encoder.GSAbstractStoreEncoder;
import it.geosolutions.geoserver.rest.encoder.datastore.GSAbstractDatastoreEncoder;
import java.net.MalformedURLException;
import java.net.URL;
/**
* Manage stores.
*
* To pass connection parameters, use the encoders derived from
* {@link GSAbstractDatastoreEncoder}.
*
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
*/
public class GeoServerRESTStoreManager 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
* @throws MalformedURLException
* @throws IllegalArgumentException
*/
public GeoServerRESTStoreManager(URL restURL, String username, String password)
throws IllegalArgumentException, MalformedURLException {
super(restURL, username, password);
}
/**
* Create a store.
*
* @param workspace Name of the workspace to contain the store. This
* will also be the prefix of any layer names contained in the
* store.
* @param datastore the set of parameters to be set to the store
* (including connection parameters).
* @return <TT>true</TT> if the store has been successfully created,
* <TT>false</TT> otherwise
*/
public boolean create(String workspace, GSAbstractStoreEncoder store) {
String sUrl = HTTPUtils.append(restURL, "/rest/workspaces/", workspace, "/", store.getStoreType().toString(),".",Format.XML.toString()).toString();
String xml = store.toString();
String result = HTTPUtils.postXml(sUrl, xml, gsuser, gspass);
return result != null;
}
/**
* Update a store.
*
* @param workspace Name of the workspace that contains the store.
* @param datastore the set of parameters to be set to the store
* (including connection parameters).
* @return <TT>true</TT> if the store has been successfully updated,
* <TT>false</TT> otherwise
*/
public boolean update(String workspace, GSAbstractStoreEncoder store) {
String sUrl = HTTPUtils.append(restURL, "/rest/workspaces/", workspace,"/", store.getStoreType().toString(),"/",
store.getName(),".",Format.XML.toString()).toString();
String xml = store.toString();
String result = HTTPUtils.putXml(sUrl, xml, gsuser, gspass);
return result != null;
}
/**
* Remove a given CoverageStore in a given Workspace.
*
* @param workspace The name of the workspace
* @param storename The name of the CoverageStore to remove.
* @param recurse if remove should be performed recursively
* @return <TT>true</TT> if the CoverageStore was successfully removed.
* @throws MalformedURLException
*/
public boolean remove(final String workspace, final GSAbstractStoreEncoder store,
final boolean recurse) throws IllegalArgumentException, MalformedURLException {
// if (workspace == null || storename == null)
// throw new IllegalArgumentException("Arguments may not be null!");
// if (workspace.isEmpty() || storename.isEmpty())
// throw new IllegalArgumentException("Arguments may not be empty!");
final StringBuffer url=HTTPUtils.append(restURL,"/rest/workspaces/",workspace,"/", store.getStoreType().toString(), "/",store.getName());
if (recurse)
url.append("?recurse=true");
final URL deleteStore = new URL(url.toString());
boolean deleted = HTTPUtils.delete(deleteStore.toExternalForm(), gsuser, gspass);
// if (!deleted) {
// LOGGER.warn("Could not delete CoverageStore " + workspace + ":" + storename);
// } else {
// LOGGER.info("CoverageStore successfully deleted " + workspace + ":" + storename);
// }
return deleted;
}
}

View File

@ -24,25 +24,24 @@
*/ */
package it.geosolutions.geoserver.rest.datastore; package it.geosolutions.geoserver.rest.datastore;
import it.geosolutions.geoserver.rest.GeoserverRESTTest; import java.net.MalformedURLException;
import it.geosolutions.geoserver.rest.decoder.RESTDataStore;
import it.geosolutions.geoserver.rest.encoder.datastore.GSArcSDEDatastoreEncoder;
import org.junit.Test; import it.geosolutions.geoserver.rest.GeoserverRESTTest;
import org.slf4j.Logger; import it.geosolutions.geoserver.rest.encoder.GSAbstractStoreEncoder;
import org.slf4j.LoggerFactory; import it.geosolutions.geoserver.rest.encoder.datastore.GSArcSDEDatastoreEncoder;
import it.geosolutions.geoserver.rest.encoder.datastore.GSOracleNGDatastoreEncoder;
/** /**
* Testcase for creating arcsde-based resources on geoserver. * Testcase for creating arcsde-based resources on geoserver.
* <P> * <P>
* Since these tests require a running arcsde instance, this is more like integration tests.<br/> * Since these tests require a running arcsde instance, this is more like integration tests.<br/>
* You may skip them by defining<tt> <pre> * You may skip them by defining<tt> <pre>
* -DpgIgnore=true </pre></tt> * -DpgIgnore=true </pre></tt> When <tt>pgIgnore</tt> is defined that way, failing tests will not break the build: they will be logged as
* When <tt>pgIgnore</tt> is defined that way, failing tests will not break * errors instead.
* the build: they will be logged as errors instead.
* *
* <P> * <P>
* The target arcsde instance can be customized by defining the following env vars: <ul> * The target arcsde instance can be customized by defining the following env vars:
* <ul>
* <LI><TT>pgHost</TT> (default <TT>localhost</TT>)</LI> * <LI><TT>pgHost</TT> (default <TT>localhost</TT>)</LI>
* <LI><TT>pgPort</TT> (default: <TT>5432</TT>)</LI> * <LI><TT>pgPort</TT> (default: <TT>5432</TT>)</LI>
* <LI><TT>pgDatabase</TT> (default: <TT>test</TT>)</LI> * <LI><TT>pgDatabase</TT> (default: <TT>test</TT>)</LI>
@ -54,72 +53,26 @@ import org.slf4j.LoggerFactory;
* @author etj * @author etj
* @author Eric Grosso * @author Eric Grosso
* @author Gianni Barrotta * @author Gianni Barrotta
* @author carlo cancellieri - GeoSolutions
* *
* @see GeoserverRESTTest * @see GeoserverRESTTest
*/ */
public class GSArcSDEDatastoreEncoderTest extends GeoserverRESTTest { public class GSArcSDEDatastoreEncoderTest extends StoreIntegrationTest {
private final static Logger LOGGER = LoggerFactory.getLogger(GSArcSDEDatastoreEncoderTest.class); public GSArcSDEDatastoreEncoderTest() throws IllegalArgumentException, MalformedURLException {
private static final String DEFAULT_WS = "it.geosolutions";
private final boolean pgIgnore; super(System.getProperty("Ignore", "false").equalsIgnoreCase("true"));
private final String pgServer;
private final int pgPort;
private final String pgInstance;
private final String pgUser;
private final String pgPassword;
public GSArcSDEDatastoreEncoderTest() {
pgIgnore = System.getProperty("pgIgnore", "false").equalsIgnoreCase("true");
pgServer = System.getProperty("pgServer", "localhost");
pgPort = Integer.parseInt(System.getProperty("pgPort", "5151"));
pgInstance = System.getProperty("pgInstance", "test");
pgUser = System.getProperty("pgUser", "utest");
pgPassword = System.getProperty("pgPassword", "ptest");
} }
@Test @Override
public void testCreateDeleteArcSDEDatastore() { public GSAbstractStoreEncoder getStoreEncoderTest() {
if (!enabled()) { GSArcSDEDatastoreEncoder datastoreEncoder = new GSArcSDEDatastoreEncoder(
return; System.getProperty("arcsdeHost", "localhost"),
} System.getProperty("arcsdeSchema", "public"), System.getProperty("arcsdePassword", "ptest"));
deleteAll(); datastoreEncoder.setNamespace(DEFAULT_WS);
datastoreEncoder.setPort(Integer.parseInt(System.getProperty("arcsdePort", "5432")));
String wsName = DEFAULT_WS; return datastoreEncoder;
String datastoreName = "resttestarcsde";
String description = "description";
String dsNamespace = "http://www.geo-solutions.it";
GSArcSDEDatastoreEncoder datastoreEncoder = new GSArcSDEDatastoreEncoder(datastoreName, pgServer, pgUser);
datastoreEncoder.setDescription(description);
datastoreEncoder.setNamespace(dsNamespace);
datastoreEncoder.setPort(pgPort);
datastoreEncoder.setInstance(pgInstance);
datastoreEncoder.setPassword(pgPassword);
assertTrue(publisher.createWorkspace(wsName));
// creation test
boolean created = manager.getDatastoreManager().create(wsName, datastoreEncoder);
if( ! pgIgnore )
assertTrue("arcsde datastore not created", created);
else if( ! created)
LOGGER.error("*** Datastore " + datastoreName + " has not been created.");
RESTDataStore datastore = reader.getDatastore(wsName, datastoreName);
LOGGER.info("The type of the created datastore is: " + datastore.getStoreType());
// removing test
boolean removed = publisher.removeDatastore(wsName, datastoreName, true);
if( ! pgIgnore )
assertTrue("arcsde datastore not removed", removed);
else if( ! removed )
LOGGER.error("*** Datastore " + datastoreName + " has not been removed.");
assertTrue(publisher.removeWorkspace(wsName, false));
} }
} }

View File

@ -24,8 +24,11 @@
*/ */
package it.geosolutions.geoserver.rest.datastore; package it.geosolutions.geoserver.rest.datastore;
import java.net.MalformedURLException;
import it.geosolutions.geoserver.rest.GeoserverRESTTest; import it.geosolutions.geoserver.rest.GeoserverRESTTest;
import it.geosolutions.geoserver.rest.decoder.RESTDataStore; import it.geosolutions.geoserver.rest.decoder.RESTDataStore;
import it.geosolutions.geoserver.rest.encoder.GSAbstractStoreEncoder;
import it.geosolutions.geoserver.rest.encoder.datastore.GSOracleNGDatastoreEncoder; import it.geosolutions.geoserver.rest.encoder.datastore.GSOracleNGDatastoreEncoder;
import org.junit.Test; import org.junit.Test;
@ -54,82 +57,37 @@ import org.slf4j.LoggerFactory;
* @author etj * @author etj
* @author Eric Grosso * @author Eric Grosso
* @author Gianni Barrotta * @author Gianni Barrotta
* @author carlo cancellieri - GeoSolutions
* *
* @see GeoserverRESTTest * @see GeoserverRESTTest
*/ */
public class GSOracleNGDatastoreEncoderTest extends GeoserverRESTTest { public class GSOracleNGDatastoreEncoderTest extends StoreIntegrationTest {
private final static Logger LOGGER = LoggerFactory.getLogger(GSOracleNGDatastoreEncoderTest.class); // private final static Logger LOGGER = LoggerFactory.getLogger(GSOracleNGDatastoreEncoderTest.class);
private static final String DEFAULT_WS = "it.geosolutions";
private final boolean pgIgnore; public GSOracleNGDatastoreEncoderTest() throws IllegalArgumentException, MalformedURLException {
private final String pgHost; super(System.getProperty("pgIgnore", "false").equalsIgnoreCase("true"));
private final int pgPort;
private final String pgDatabase;
private final String pgSchema;
private final String pgUser;
private final String pgPassword;
public GSOracleNGDatastoreEncoderTest() {
pgIgnore = System.getProperty("pgIgnore", "false").equalsIgnoreCase("true");
pgHost = System.getProperty("pgHost", "localhost");
pgPort = Integer.parseInt(System.getProperty("pgPort", "5432"));
pgDatabase = System.getProperty("pgDatabase", "test");
pgSchema = System.getProperty("pgSchema", "public");
pgUser = System.getProperty("pgUser", "utest");
pgPassword = System.getProperty("pgPassword", "ptest");
} }
@Test @Override
public void testCreateDeleteOracleNGDatastore() { public GSAbstractStoreEncoder getStoreEncoderTest() {
if (!enabled()) { GSOracleNGDatastoreEncoder datastoreEncoder = new GSOracleNGDatastoreEncoder(System.getProperty("oDataStoreName", "test"), System.getProperty("pgDatabase", "test"));
return; datastoreEncoder.setNamespace(DEFAULT_WS);
} datastoreEncoder.setHost(System.getProperty("pgHost", "localhost"));
deleteAll(); datastoreEncoder.setPort(Integer.parseInt(System.getProperty("pgPort", "5432")));
datastoreEncoder.setSchema(System.getProperty("pgUser", "postgres"));
datastoreEncoder.setUser(System.getProperty("pgSchema", "public"));
datastoreEncoder.setPassword(System.getProperty("pgPassword", "postgres"));
String wsName = DEFAULT_WS;
String datastoreName = "resttestOracleNG";
String description = "description";
String dsNamespace = "http://www.geo-solutions.it";
boolean exposePrimaryKeys = true; boolean exposePrimaryKeys = true;
boolean validateConnections = false; boolean validateConnections = false;
String primaryKeyMetadataTable = "test"; String primaryKeyMetadataTable = "test";
GSOracleNGDatastoreEncoder datastoreEncoder = new GSOracleNGDatastoreEncoder(datastoreName, pgDatabase);
datastoreEncoder.setDescription(description);
datastoreEncoder.setNamespace(dsNamespace);
datastoreEncoder.setHost(pgHost);
datastoreEncoder.setPort(pgPort);
datastoreEncoder.setSchema(pgSchema);
datastoreEncoder.setUser(pgUser);
datastoreEncoder.setPassword(pgPassword);
datastoreEncoder.setExposePrimaryKeys(exposePrimaryKeys); datastoreEncoder.setExposePrimaryKeys(exposePrimaryKeys);
datastoreEncoder.setValidateConnections(validateConnections); datastoreEncoder.setValidateConnections(validateConnections);
datastoreEncoder.setPrimaryKeyMetadataTable(primaryKeyMetadataTable); datastoreEncoder.setPrimaryKeyMetadataTable(primaryKeyMetadataTable);
assertTrue(publisher.createWorkspace(wsName)); return datastoreEncoder;
// creation test
boolean created = manager.getDatastoreManager().create(wsName, datastoreEncoder);
if( ! pgIgnore )
assertTrue("OracleNG datastore not created", created);
else if( ! created)
LOGGER.error("*** Datastore " + datastoreName + " has not been created.");
RESTDataStore datastore = reader.getDatastore(wsName, datastoreName);
LOGGER.info("The type of the created datastore is: " + datastore.getStoreType());
// removing test
boolean removed = publisher.removeDatastore(wsName, datastoreName, true);
if( ! pgIgnore )
assertTrue("OracleNG datastore not removed", removed);
else if( ! removed )
LOGGER.error("*** Datastore " + datastoreName + " has not been removed.");
assertTrue(publisher.removeWorkspace(wsName, false));
} }
} }

View File

@ -0,0 +1,114 @@
/*
* 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.datastore;
import java.net.MalformedURLException;
import it.geosolutions.geoserver.rest.GeoserverRESTTest;
import it.geosolutions.geoserver.rest.decoder.RESTDataStore;
import it.geosolutions.geoserver.rest.encoder.GSAbstractStoreEncoder;
import it.geosolutions.geoserver.rest.encoder.datastore.GSAbstractDatastoreEncoder;
import it.geosolutions.geoserver.rest.encoder.datastore.GSOracleNGDatastoreEncoder;
import it.geosolutions.geoserver.rest.manager.GeoServerRESTStoreManager;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* <P>
* Since these tests require a running Store instance, this is more like integration tests.<br/>
*
* @author carlo cancellieri - GeoSolutions
*
* @see GeoserverRESTTest
*/
public abstract class StoreIntegrationTest extends GeoserverRESTTest {
private final static Logger LOGGER = LoggerFactory.getLogger(StoreIntegrationTest.class);
private final GeoServerRESTStoreManager storeManager;
/**
* ignore integration tests
*/
private final boolean ignore;
public boolean isIgnore() {
return ignore;
}
/**
*
* @param ignore false if this test shoudl be disabled
* @throws IllegalArgumentException
* @throws MalformedURLException
*/
public StoreIntegrationTest(boolean ignore) throws IllegalArgumentException, MalformedURLException {
super();
this.storeManager = new GeoServerRESTStoreManager(URL, RESTUSER, RESTPW);
this.ignore=ignore;
}
public abstract GSAbstractStoreEncoder getStoreEncoderTest();
@Test
public void testCreateDeleteDatastore() throws IllegalArgumentException, MalformedURLException {
if (!enabled()) {
return;
}
deleteAll();
assertTrue(publisher.createWorkspace(DEFAULT_WS));
// creation test
GSAbstractStoreEncoder storeEncoder=getStoreEncoderTest();
String storeName = storeEncoder.getName();
// String description = storeEncoder.getDescription();
boolean created = storeManager.create(DEFAULT_WS, storeEncoder);
if( ! ignore )
assertTrue("Datastore not created", created);
else if( ! created)
LOGGER.error("*** store " + storeName + " has not been created.");
RESTDataStore datastore = reader.getDatastore(DEFAULT_WS, storeName);
assertNotNull(datastore);
LOGGER.info("The type of the created datastore is: " + datastore.getStoreType());
// removing test
boolean removed = storeManager.remove(DEFAULT_WS, storeEncoder, true);
if( ! ignore )
assertTrue("Datastore not removed", removed);
else if( ! removed )
LOGGER.error("*** Datastore " + storeName + " has not been removed.");
assertTrue(publisher.removeWorkspace(DEFAULT_WS, false));
}
}

View File

@ -0,0 +1,269 @@
package it.geosolutions.geoserver.rest.encoder;
import it.geosolutions.geoserver.rest.GeoserverRESTTest;
import it.geosolutions.geoserver.rest.decoder.RESTLayerGroup;
import it.geosolutions.geoserver.rest.decoder.RESTLayerList;
import it.geosolutions.geoserver.rest.decoder.RESTPublished;
import it.geosolutions.geoserver.rest.decoder.RESTPublishedList;
import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem;
import java.net.URI;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
public class GSLayerGroupEncoderTest extends GeoserverRESTTest {
@Before
public void setup() throws Exception {
String ws = "topp";
String storeName = "testshpcollection";
// Delete all resources except styles
deleteAllWorkspacesRecursively();
// Create workspace
assertTrue(publisher.createWorkspace(ws));
// Publish shp collection
URI location = new ClassPathResource("testdata/multipleshp.zip").getFile().toURI();
assertTrue(publisher.publishShpCollection(ws, storeName, location));
String storeType = reader.getDatastore(ws, storeName).getStoreType();
assertEquals(storeType, "Shapefile");
// Test published layer names
List<String> layers = reader.getLayers().getNames();
assertTrue(layers.contains("cities"));
assertTrue(layers.contains("boundaries"));
// Publish style
publisher.publishStyle(new ClassPathResource("testdata/default_line.sld").getFile(), "default_line");
}
@Test
public void testCreateLayerGroup() throws Exception {
String groupName = "my-tasmania";
GSLayerGroupEncoder groupWriter = new GSLayerGroupEncoder();
groupWriter.setBounds("EPSG:26713", 589425.93423656, 609518.6719560538, 4913959.224611808, 4928082.949945881);
groupWriter.addLayer("topp:boundaries");
groupWriter.addLayer("topp:cities");
assertTrue(publisher.createLayerGroup(groupName, groupWriter));
try {
RESTLayerGroup groupReader = reader.getLayerGroup(groupName);
assertNull(groupReader.getWorkspace());
assertEquals(groupName, groupReader.getName());
RESTPublishedList publishedList = groupReader.getPublishedList();
if (publishedList != null) {
// GeoServer >= 2.3
assertEquals(2, publishedList.size());
for (RESTPublished published : publishedList) {
assertEquals("layer", published.getType());
assertTrue("boundaries".equals(published.getName()) || "cities".equals(published.getName()));
}
} else {
RESTLayerList layerList = groupReader.getLayerList();
assertEquals(2, layerList.size());
for (NameLinkElem layer : layerList) {
assertTrue("boundaries".equals(layer.getName()) || "cities".equals(layer.getName()));
}
}
} finally {
assertTrue(publisher.removeLayerGroup(groupName));
}
}
@Test
public void testCreateLayerGroupInWorkspace() throws Exception {
String groupName = "my-tasmania-in-ws";
GSLayerGroupEncoder groupWriter = new GSLayerGroupEncoder();
groupWriter.setBounds("EPSG:26713", 589425.93423656, 609518.6719560538, 4913959.224611808, 4928082.949945881);
groupWriter.addLayer("topp:boundaries");
groupWriter.addLayer("topp:cities");
assertTrue(publisher.createLayerGroup("topp", groupName, groupWriter));
try {
RESTLayerGroup groupReader = reader.getLayerGroup("topp", groupName);
assertEquals("topp", groupReader.getWorkspace());
assertEquals(groupName, groupReader.getName());
RESTPublishedList publishedList = groupReader.getPublishedList();
if (publishedList != null) {
// GeoServer >= 2.3
assertEquals(2, publishedList.size());
for (RESTPublished published : publishedList) {
assertEquals("layer", published.getType());
assertTrue("boundaries".equals(published.getName()) || "cities".equals(published.getName()));
}
} else {
RESTLayerList layerList = groupReader.getLayerList();
assertEquals(2, layerList.size());
for (NameLinkElem layer : layerList) {
assertTrue("boundaries".equals(layer.getName()) || "cities".equals(layer.getName()));
}
}
} finally {
assertTrue(publisher.removeLayerGroup("topp", groupName));
}
}
private void createTestLayerGroup(String workspace, String groupName) {
GSLayerGroupEncoder groupWriter = new GSLayerGroupEncoder();
groupWriter.setBounds("EPSG:26713", 589425.93423656, 609518.6719560538, 4913959.224611808, 4928082.949945881);
groupWriter.addLayer("topp:boundaries");
groupWriter.addLayer("topp:cities");
assertTrue(publisher.createLayerGroup(workspace, groupName, groupWriter));
}
@Test
public void testConfigureLayerGroup() throws Exception {
String groupName = "my-tasmania";
createTestLayerGroup(null, groupName);
try {
GSLayerGroupEncoder groupWriter = new GSLayerGroupEncoder();
groupWriter.addLayer("topp:boundaries");
assertTrue(publisher.configureLayerGroup(groupName, groupWriter));
RESTLayerGroup groupReader = reader.getLayerGroup(groupName);
assertNull(groupReader.getWorkspace());
assertEquals(groupName, groupReader.getName());
RESTPublishedList publishedList = groupReader.getPublishedList();
if (publishedList != null) {
// GeoServer >= 2.3
assertEquals(1, publishedList.size());
for (RESTPublished published : publishedList) {
assertEquals("layer", published.getType());
assertTrue("boundaries".equals(published.getName()));
}
} else {
RESTLayerList layerList = groupReader.getLayerList();
assertEquals(1, layerList.size());
for (NameLinkElem layer : layerList) {
assertTrue("boundaries".equals(layer.getName()));
}
}
} finally {
assertTrue(publisher.removeLayerGroup(groupName));
}
}
@Test
public void testConfigureLayerGroupInWorkspace() throws Exception {
String groupName = "my-tasmania-in-ws";
createTestLayerGroup("topp", groupName);
try {
GSLayerGroupEncoder groupWriter = new GSLayerGroupEncoder();
groupWriter.addLayer("topp:boundaries");
assertTrue(publisher.configureLayerGroup("topp", groupName, groupWriter));
RESTLayerGroup groupReader = reader.getLayerGroup("topp", groupName);
assertEquals("topp", groupReader.getWorkspace());
assertEquals(groupName, groupReader.getName());
RESTPublishedList publishedList = groupReader.getPublishedList();
if (publishedList != null) {
// GeoServer >= 2.3
assertEquals(1, publishedList.size());
for (RESTPublished published : publishedList) {
assertEquals("layer", published.getType());
assertTrue("boundaries".equals(published.getName()));
}
} else {
RESTLayerList layerList = groupReader.getLayerList();
assertEquals(1, layerList.size());
for (NameLinkElem layer : layerList) {
assertTrue("boundaries".equals(layer.getName()));
}
}
} finally {
assertTrue(publisher.removeLayerGroup("topp", groupName));
}
}
@Test
public void testConfigureLayerGroup23() throws Exception {
String groupName = "my-tasmania-23";
createTestLayerGroup(null, groupName);
try {
GSLayerGroupEncoder23 groupWriter = new GSLayerGroupEncoder23();
groupWriter.addLayer("topp:boundaries");
groupWriter.setMode(GSLayerGroupEncoder23.MODE_NAMED);
groupWriter.setTitle("my title");
groupWriter.setAbstract("my abstract");
assertTrue(publisher.configureLayerGroup(groupName, groupWriter));
RESTLayerGroup groupReader = reader.getLayerGroup(groupName);
assertNull(groupReader.getWorkspace());
assertEquals(groupName, groupReader.getName());
assertEquals("my title", groupReader.getTitle());
assertEquals("my abstract", groupReader.getAbstract());
assertEquals(GSLayerGroupEncoder23.MODE_NAMED, groupReader.getMode());
RESTPublishedList publishedList = groupReader.getPublishedList();
assertEquals(1, publishedList.size());
for (RESTPublished published : publishedList) {
assertEquals("layer", published.getType());
assertTrue("boundaries".equals(published.getName()));
}
} finally {
assertTrue(publisher.removeLayerGroup(groupName));
}
}
/**
* This test only works with GeoServer >= 2.3
*/
@Test
public void testCreateNestedLayerGroup23() throws Exception {
String groupName = "my-tasmania-eo";
createTestLayerGroup(null, "tasmania");
try {
GSLayerGroupEncoder23 groupWriter = new GSLayerGroupEncoder23();
groupWriter.setTitle("my title");
groupWriter.setAbstract("my abstract");
groupWriter.setMode(GSLayerGroupEncoder23.MODE_EO);
groupWriter.setRootLayer("topp:boundaries", "default_line");
groupWriter.setBounds("EPSG:26713", 589425.93423656, 609518.6719560538, 4913959.224611808, 4928082.949945881);
groupWriter.addLayer("topp:cities");
groupWriter.addLayerGroup("tasmania");
assertTrue(publisher.createLayerGroup(groupName, groupWriter));
try {
RESTLayerGroup groupReader = reader.getLayerGroup(groupName);
assertNull(groupReader.getWorkspace());
assertEquals(groupName, groupReader.getName());
assertEquals("my title", groupReader.getTitle());
assertEquals("my abstract", groupReader.getAbstract());
assertEquals(GSLayerGroupEncoder23.MODE_EO, groupReader.getMode());
assertEquals("boundaries", groupReader.getRootLayer());
RESTPublishedList publishedList = groupReader.getPublishedList();
assertEquals(2, publishedList.size());
for (RESTPublished published : publishedList) {
if ("layer".equals(published.getType())) {
assertEquals("cities", published.getName());
} else {
assertEquals("layerGroup", published.getType());
assertEquals("tasmania", published.getName());
}
}
} finally {
assertTrue(publisher.removeLayerGroup(groupName));
}
} finally {
assertTrue(publisher.removeLayerGroup("tasmania"));
}
}
}

View File

@ -24,8 +24,9 @@
*/ */
package it.geosolutions.geoserver.rest.manager; package it.geosolutions.geoserver.rest.manager;
import it.geosolutions.geoserver.rest.GeoserverRESTTest; import it.geosolutions.geoserver.rest.datastore.StoreIntegrationTest;
import it.geosolutions.geoserver.rest.decoder.RESTDataStore; import it.geosolutions.geoserver.rest.decoder.RESTDataStore;
import it.geosolutions.geoserver.rest.encoder.GSAbstractStoreEncoder;
import it.geosolutions.geoserver.rest.encoder.datastore.GSAbstractDatastoreEncoder; import it.geosolutions.geoserver.rest.encoder.datastore.GSAbstractDatastoreEncoder;
import it.geosolutions.geoserver.rest.encoder.datastore.GSDirectoryOfShapefilesDatastoreEncoder; import it.geosolutions.geoserver.rest.encoder.datastore.GSDirectoryOfShapefilesDatastoreEncoder;
import it.geosolutions.geoserver.rest.encoder.datastore.GSShapefileDatastoreEncoder; import it.geosolutions.geoserver.rest.encoder.datastore.GSShapefileDatastoreEncoder;
@ -62,19 +63,82 @@ import org.junit.Test;
* *
* @author Oscar Fonts * @author Oscar Fonts
*/ */
public class GeoserverRESTDatastoreManagerTest extends GeoserverRESTTest { /*
* 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.
*/
/**
* Test datastore handling (create, read and update):
*
* <ul>
* <li>Tests all the constructors and setters from {@link GSDirectoryOfShapefilesDatastoreEncoder} and parent classes (
* {@link GSShapefileDatastoreEncoder}, {@link GSAbstractDatastoreEncoder}).
*
* <li>Tests constructors and getters from {@link RESTDataStore} (reader).
*
* <li>Tests {@link GeoServerRESTDatastoreManager} create and update methods.
* </ul>
*
* <p>
* The sequence is:
* <ol>
* <li>Create a DirectoryOfShapefilesDatastoreEncoder, with default parameters.
* <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 GeoServerRESTDatastoreManager.update.
* <li>Read again.
* <li>Test all new values.
* </ol>
*
* @author Oscar Fonts
*/
public class GeoserverRESTDatastoreManagerTest extends StoreIntegrationTest {
private static final String WS_NAME = DEFAULT_WS; private static final String WS_NAME = DEFAULT_WS;
private static final String DS_NAME = "testCreateDatastore"; private static final String DS_NAME = "testCreateDatastore";
private static final String DS_DESCRIPTION = "A description"; private static final String DS_DESCRIPTION = "A description";
private static URL LOCATION_1; private static URL LOCATION_1;
private static URL LOCATION_2; private static URL LOCATION_2;
public GeoserverRESTDatastoreManagerTest() throws Exception { public GeoserverRESTDatastoreManagerTest() throws Exception {
super(true);
LOCATION_1 = new URL("file:data/1"); LOCATION_1 = new URL("file:data/1");
LOCATION_2 = new URL("file:data/2"); LOCATION_2 = new URL("file:data/2");
} }
@Override
public GSAbstractStoreEncoder getStoreEncoderTest() {
return new GSDirectoryOfShapefilesDatastoreEncoder(DS_NAME, LOCATION_1);
}
@Test @Test
public void test() throws Exception { public void test() throws Exception {
if (!enabled()) { if (!enabled()) {
@ -88,8 +152,9 @@ public class GeoserverRESTDatastoreManagerTest extends GeoserverRESTTest {
assertTrue(publisher.createWorkspace(WS_NAME)); assertTrue(publisher.createWorkspace(WS_NAME));
// Create a directory of spatial files with default parameters // Create a directory of spatial files with default parameters
GSDirectoryOfShapefilesDatastoreEncoder create = new GSDirectoryOfShapefilesDatastoreEncoder(DS_NAME, LOCATION_1); GSDirectoryOfShapefilesDatastoreEncoder create = new GSDirectoryOfShapefilesDatastoreEncoder(
assertTrue(manager.getDatastoreManager().create(WS_NAME, create)); DS_NAME, LOCATION_1);
assertTrue(manager.getStoreManager().create(WS_NAME, create));
// Read the store from server; check all parameter values // Read the store from server; check all parameter values
RESTDataStore read = reader.getDatastore(WS_NAME, DS_NAME); RESTDataStore read = reader.getDatastore(WS_NAME, DS_NAME);
@ -105,7 +170,8 @@ public class GeoserverRESTDatastoreManagerTest extends GeoserverRESTTest {
assertEquals(connParams.get("cache and reuse memory maps"), "true"); assertEquals(connParams.get("cache and reuse memory maps"), "true");
// Change all parameter to non-default values // Change all parameter to non-default values
GSDirectoryOfShapefilesDatastoreEncoder update = new GSDirectoryOfShapefilesDatastoreEncoder(read); GSDirectoryOfShapefilesDatastoreEncoder update = new GSDirectoryOfShapefilesDatastoreEncoder(
read);
update.setDescription(DS_DESCRIPTION); update.setDescription(DS_DESCRIPTION);
update.setEnabled(false); update.setEnabled(false);
update.setUrl(LOCATION_2); update.setUrl(LOCATION_2);
@ -115,7 +181,7 @@ public class GeoserverRESTDatastoreManagerTest extends GeoserverRESTTest {
update.setCacheAndReuseMemoryMaps(false); update.setCacheAndReuseMemoryMaps(false);
// update the store // update the store
assertTrue(manager.getDatastoreManager().update(WS_NAME, update)); assertTrue(manager.getStoreManager().update(WS_NAME, update));
// Read again, check that all parameters have changed // Read again, check that all parameters have changed
read = reader.getDatastore(WS_NAME, DS_NAME); read = reader.getDatastore(WS_NAME, DS_NAME);

View File

@ -27,10 +27,13 @@ package it.geosolutions.geoserver.rest.publisher;
import it.geosolutions.geoserver.rest.GeoserverRESTTest; import it.geosolutions.geoserver.rest.GeoserverRESTTest;
import it.geosolutions.geoserver.rest.decoder.RESTDataStore; import it.geosolutions.geoserver.rest.datastore.StoreIntegrationTest;
import it.geosolutions.geoserver.rest.encoder.GSPostGISDatastoreEncoder; import it.geosolutions.geoserver.rest.encoder.GSAbstractStoreEncoder;
import it.geosolutions.geoserver.rest.encoder.datastore.GSPostGISDatastoreEncoder;
import it.geosolutions.geoserver.rest.manager.GeoServerRESTStoreManager;
import java.net.MalformedURLException;
import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -55,53 +58,39 @@ import org.slf4j.LoggerFactory;
* *
* @author etj * @author etj
* @author Eric Grosso * @author Eric Grosso
* @author carlo cancellieri - GeoSolutions
* *
* @see GeoserverRESTTest * @see GeoserverRESTTest
*/ */
public class GeoserverRESTPostgisDatastoreTest extends GeoserverRESTTest { public class GeoserverRESTPostgisDatastoreTest extends StoreIntegrationTest {
private final static Logger LOGGER = LoggerFactory.getLogger(GeoserverRESTPostgisDatastoreTest.class); public GeoserverRESTPostgisDatastoreTest()
private static final String DEFAULT_WS = "it.geosolutions"; throws IllegalArgumentException, MalformedURLException {
super(System.getProperty("pgIgnore", "false").equalsIgnoreCase("true"));
private final boolean pgIgnore;
private final String pgHost;
private final int pgPort;
private final String pgDatabase;
private final String pgSchema;
private final String pgUser;
private final String pgPassword;
public GeoserverRESTPostgisDatastoreTest() {
pgIgnore = System.getProperty("pgIgnore", "false").equalsIgnoreCase("true");
pgHost = System.getProperty("pgHost", "localhost");
pgPort = Integer.parseInt(System.getProperty("pgPort", "5432"));
pgDatabase = System.getProperty("pgDatabase", "test");
pgSchema = System.getProperty("pgSchema", "public");
pgUser = System.getProperty("pgUser", "utest");
pgPassword = System.getProperty("pgPassword", "ptest");
} }
@Test
public void testCreateDeletePostGISDatastore() {
if (!enabled()) {
return;
}
deleteAll();
String wsName = DEFAULT_WS; @Override
String datastoreName = "resttestpostgis"; public GSAbstractStoreEncoder getStoreEncoderTest(){
String description = "description";
String dsNamespace = "http://www.geo-solutions.it";
boolean exposePrimaryKeys = true; boolean exposePrimaryKeys = true;
boolean validateConnections = false; boolean validateConnections = false;
String primaryKeyMetadataTable = "test"; String primaryKeyMetadataTable = "test";
GSPostGISDatastoreEncoder datastoreEncoder = new GSPostGISDatastoreEncoder(); String datastoreName = "resttestpostgis";
datastoreEncoder.defaultInit(); String description = "description";
datastoreEncoder.setName(datastoreName); String dsNamespace = "http://www.geo-solutions.it";
GSPostGISDatastoreEncoder datastoreEncoder = new GSPostGISDatastoreEncoder(datastoreName);
datastoreEncoder.setDescription(description); datastoreEncoder.setDescription(description);
datastoreEncoder.setNamespace(dsNamespace); datastoreEncoder.setNamespace(dsNamespace);
String pgHost = System.getProperty("pgHost", "localhost");
int pgPort = Integer.parseInt(System.getProperty("pgPort", "5432"));
String pgDatabase = System.getProperty("pgDatabase", "test");
String pgSchema = System.getProperty("pgSchema", "public");
String pgUser = System.getProperty("pgUser", "utest");
String pgPassword = System.getProperty("pgPassword", "ptest");
datastoreEncoder.setHost(pgHost); datastoreEncoder.setHost(pgHost);
datastoreEncoder.setPort(pgPort); datastoreEncoder.setPort(pgPort);
datastoreEncoder.setDatabase(pgDatabase); datastoreEncoder.setDatabase(pgDatabase);
@ -111,29 +100,7 @@ public class GeoserverRESTPostgisDatastoreTest extends GeoserverRESTTest {
datastoreEncoder.setExposePrimaryKeys(exposePrimaryKeys); datastoreEncoder.setExposePrimaryKeys(exposePrimaryKeys);
datastoreEncoder.setValidateConnections(validateConnections); datastoreEncoder.setValidateConnections(validateConnections);
datastoreEncoder.setPrimaryKeyMetadataTable(primaryKeyMetadataTable); datastoreEncoder.setPrimaryKeyMetadataTable(primaryKeyMetadataTable);
return datastoreEncoder;
assertTrue(publisher.createWorkspace(wsName));
// creation test
boolean created = publisher.createPostGISDatastore(wsName, datastoreEncoder);
if( ! pgIgnore )
assertTrue("PostGIS datastore not created", created);
else if( ! created)
LOGGER.error("*** Datastore " + datastoreName + " has not been created.");
RESTDataStore datastore = reader.getDatastore(wsName, datastoreName);
LOGGER.info("The type of the created datastore is: " + datastore.getType());
// removing test
boolean removed = publisher.removeDatastore(wsName, datastoreName);
if( ! pgIgnore )
assertTrue("PostGIS datastore not removed", removed);
else if( ! removed )
LOGGER.error("*** Datastore " + datastoreName + " has not been removed.");
assertTrue(publisher.removeWorkspace(wsName));
} }
} }

View File

@ -60,15 +60,13 @@ public class GeoserverRESTShapeTest extends GeoserverRESTTest {
@After @After
public void cleanUp(){ public void cleanUp(){
if(enabled()){
deleteAllWorkspaces();
}
} }
@Test @Test
public void testReloadDataStore() throws FileNotFoundException, IOException { public void testReloadDataStore() throws FileNotFoundException, IOException {
if (!enabled()) if (!enabled())
return; return;
deleteAllWorkspacesRecursively();
assertTrue(publisher.createWorkspace(DEFAULT_WS)); assertTrue(publisher.createWorkspace(DEFAULT_WS));
@ -91,6 +89,7 @@ public class GeoserverRESTShapeTest extends GeoserverRESTTest {
if (!enabled()) { if (!enabled()) {
return; return;
} }
deleteAllWorkspacesRecursively();
assertTrue(publisher.createWorkspace(DEFAULT_WS)); assertTrue(publisher.createWorkspace(DEFAULT_WS));
@ -126,6 +125,7 @@ public class GeoserverRESTShapeTest extends GeoserverRESTTest {
if (!enabled()) { if (!enabled()) {
return; return;
} }
deleteAllWorkspacesRecursively();
// Assume.assumeTrue(enabled); // Assume.assumeTrue(enabled);
assertTrue(publisher.createWorkspace(DEFAULT_WS)); assertTrue(publisher.createWorkspace(DEFAULT_WS));
@ -159,6 +159,7 @@ public class GeoserverRESTShapeTest extends GeoserverRESTTest {
if (!enabled()) { if (!enabled()) {
return; return;
} }
deleteAllWorkspacesRecursively();
// Assume.assumeTrue(enabled); // Assume.assumeTrue(enabled);
assertTrue(publisher.createWorkspace(DEFAULT_WS)); assertTrue(publisher.createWorkspace(DEFAULT_WS));
@ -192,6 +193,7 @@ public class GeoserverRESTShapeTest extends GeoserverRESTTest {
if (!enabled()) { if (!enabled()) {
return; return;
} }
deleteAllWorkspacesRecursively();
// Assume.assumeTrue(enabled); // Assume.assumeTrue(enabled);
assertTrue(publisher.createWorkspace(DEFAULT_WS)); assertTrue(publisher.createWorkspace(DEFAULT_WS));
@ -236,6 +238,7 @@ public class GeoserverRESTShapeTest extends GeoserverRESTTest {
if (!enabled()) { if (!enabled()) {
return; return;
} }
deleteAllWorkspacesRecursively();
// Assume.assumeTrue(enabled); // Assume.assumeTrue(enabled);
assertTrue(publisher.createWorkspace(DEFAULT_WS)); assertTrue(publisher.createWorkspace(DEFAULT_WS));
@ -278,6 +281,7 @@ public class GeoserverRESTShapeTest extends GeoserverRESTTest {
public void testPublishShpUsingDeclaredNativeCRS() throws Exception { public void testPublishShpUsingDeclaredNativeCRS() throws Exception {
if (!enabled()) if (!enabled())
return; return;
deleteAllWorkspacesRecursively();
// layer publication params // layer publication params
String workspace = DEFAULT_WS; String workspace = DEFAULT_WS;
@ -315,6 +319,7 @@ public class GeoserverRESTShapeTest extends GeoserverRESTTest {
public void testPublishShpUsingWKTNativeCRS() throws Exception { public void testPublishShpUsingWKTNativeCRS() throws Exception {
if (!enabled()) if (!enabled())
return; return;
deleteAllWorkspacesRecursively();
// layer publication params // layer publication params
String workspace = DEFAULT_WS; String workspace = DEFAULT_WS;