Compare commits

...

30 Commits

Author SHA1 Message Date
etj
645d79c2cb Release 1.5.2 2013-06-18 15:08:42 +02:00
carlo cancellieri
be329f8a55 Merge branch '1.5.x' of https://github.com/geosolutions-it/geoserver-manager into 1.5.x 2013-06-13 08:00:51 +02:00
carlo cancellieri
71132e3b9e fix #80: Considering several layers with the same name 2013-06-13 08:00:31 +02:00
Carlo Cancellieri
89e049baf7 Merge pull request #79 from geosolutions-it/77-1.5.x-missing-support-jp2k
fix: missing jp2k support. close 77
2013-06-12 03:57:37 -07:00
carlo cancellieri
f76434ea82 fix: missing jp2k support. close 77 2013-06-12 11:41:06 +02:00
mbarto
51fac5a674 Merge pull request #73 from eblondel/1.5.x-71-OracleNGDatastore-fix
#71 - 1.5.x - GSOracleNGDatastoreEncoder fix & tests (backport)
2013-05-02 23:59:57 -07:00
eblondel
695877041a #71 - 1.5.x - GSOracleNGDatastoreEncoder fix & tests (backport) 2013-05-02 20:15:24 +02:00
carlo cancellieri
75f03072d1 deprecate GSResourceEncoder.setMetadata in flavour of specializations 2013-04-15 16:31:59 +02:00
Carlo Cancellieri
b32ec90405 Merge pull request #70 from eblondel/1.5.x-65-VirtualTable-support
#65 VirtualTable support (1.5.x) - add encoder/decode + tests
2013-04-15 06:33:44 -07:00
eblondel
aba9f6b7e0 #65 VirtualTable support (1.5.x) - add encoder/decode + tests 2013-04-15 15:21:14 +02:00
Carlo Cancellieri
958485263f Merge pull request #69 from eblondel/1.5.x-62-MetadataLink-refactor
#62 - MetadataLinkInfo (1.5.x) - refactor encoder/decoder
2013-04-15 05:51:03 -07:00
eblondel
6332769557 MetadataLinkInfo (1.5.x) - refactor encoder/decoder 2013-04-15 14:43:55 +02:00
carlo cancellieri
2e6a972f28 clean GeoserverRESTDatastoreManagerTest license 2013-04-15 10:05:52 +02:00
Carlo Cancellieri
5158cd940c Merge pull request #66 from eblondel/1.5.x-62-Metadatalink-support
#62 MetadataLink support (1.5.x branch)
2013-04-12 00:30:09 -07:00
eblondel
54df100ea6 #62 MetadataLink support (1.5.x branch) - add encoder/decoder & tests 2013-04-11 19:40:18 +02:00
carlo cancellieri
ea6976dc19 fix: #61 LayerGroup tests are failing on master 2013-04-10 21:30:01 +02:00
ccancellieri
a96ecf4f1c added links to the mailing list on the README 2013-02-01 15:33:14 +01:00
Davide Savazzi
7760354b81 changed pom version 2013-01-24 11:48:56 +01:00
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
49 changed files with 3918 additions and 680 deletions

11
README
View File

@ -2,6 +2,15 @@ REST client library to interact with GeoServer (http://www.geoserver.org)
The purpose of this project is to hold a REST client library to interact with GeoServer; a requirement for this library is to depend as less as possible on external libraries. This library aims at being lean and mean.
For general questions about this project feel free to use the mailing lists.
Mailing Lists
USERS
https://groups.google.com/forum/?fromgroups#!forum/geoserver-manager-users
DEVELOPERS
https://groups.google.com/forum/?fromgroups#!forum/geoserver-manager-devs
For more information see this page:
https://github.com/geosolutions-it/geoserver-manager
https://github.com/geosolutions-it/geoserver-manager

View File

@ -20,7 +20,7 @@
<groupId>it.geosolutions</groupId>
<artifactId>geoserver-manager</artifactId>
<version>1.6-SNAPSHOT</version>
<version>1.5.2</version>
<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.GeoServerRESTDatastoreManager;
import it.geosolutions.geoserver.rest.manager.GeoServerRESTStoreManager;
import java.net.MalformedURLException;
import java.net.URL;
@ -39,48 +40,57 @@ import java.net.URL;
* <li>getPublisher() simple, high-level pubhish methods.
* <li>get<i>Foo</i>Manager, full-fledged management of catalog objects.
* </ul>
*
* @author Oscar Fonts
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
*/
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
* @throws MalformedURLException {@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 {
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;
}
private final GeoServerRESTPublisher publisher;
private final GeoServerRESTReader reader;
private final GeoServerRESTStoreManager store;
/**
* 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
* @throws MalformedURLException {@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 {
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);
store = new GeoServerRESTStoreManager(restURL, gsuser, gspass);
}
public GeoServerRESTPublisher getPublisher() {
return publisher;
}
public GeoServerRESTReader getReader() {
return reader;
}
public GeoServerRESTStoreManager getStoreManager() {
return store;
}
/**
*
* @Deprecated use {GeoServerRESTManager#getStoreManager()}
*/
public GeoServerRESTDatastoreManager getDatastoreManager() {
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.encoder.GSBackupEncoder;
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.GSPostGISDatastoreEncoder;
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.GSPostGISDatastoreEncoder;
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.FileNotFoundException;
@ -371,7 +372,7 @@ public class GeoServerRESTPublisher {
}
LOGGER.debug("POSTing new style " + name + " to " + sUrl);
String result = HTTPUtils
.post(sUrl, sldFile, "application/vnd.ogc.sld+xml", gsuser, gspass);
.post(sUrl, sldFile, Format.SLD.getContentType(), gsuser, gspass);
return result != null;
}
@ -583,14 +584,40 @@ public class GeoServerRESTPublisher {
}
/**
* Get the type name of a DataStoreType.
* Get the type name of a StoreType.
*
* @param type the DataStoreType.
* @return "featuretypes.xml" for DATASTORES, "coverages.xml" otherwise.
* @param type the StoreType.
* @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() {
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.
@ -849,7 +876,7 @@ public class GeoServerRESTPublisher {
/**
* 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
* database.
@ -858,7 +885,7 @@ public class GeoServerRESTPublisher {
* @return <TT>true</TT> if the PostGIS datastore has been successfully created, <TT>false</TT> otherwise
*/
public boolean createPostGISDatastore(String workspace,
GSPostGISDatastoreEncoder datastoreEncoder) {
it.geosolutions.geoserver.rest.encoder.GSPostGISDatastoreEncoder datastoreEncoder) {
String sUrl = restURL + "/rest/workspaces/" + workspace + "/datastores/";
String xml = datastoreEncoder.toString();
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.
*/
@ -2114,12 +2151,20 @@ public class GeoServerRESTPublisher {
/**
* Remove a layer group.
*
* @param workspace the layer group workspace.
* @param name the layer group name.
* @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 {
URL deleteUrl = new URL(restURL + "/rest/layergroups/" + name);
URL deleteUrl = new URL(url);
boolean deleted = HTTPUtils.delete(deleteUrl.toExternalForm(), gsuser, gspass);
if (!deleted) {
if (LOGGER.isWarnEnabled())
@ -2134,7 +2179,17 @@ public class GeoServerRESTPublisher {
if (LOGGER.isErrorEnabled())
LOGGER.error(ex.getLocalizedMessage(), ex);
return false;
}
}
}
/**
* Remove a layer group.
*
* @param name the layer group name.
* @return true if succeeded.
*/
public boolean removeLayerGroup(String name) {
return removeLayerGroup(null, name);
}
/**
@ -2298,6 +2353,89 @@ public class GeoServerRESTPublisher {
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
*

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}
*/
public RESTLayerGroupList getLayerGroups() {
String url = "/rest/layergroups.xml";
public RESTLayerGroupList getLayerGroups(String workspace) {
String url;
if (workspace == null) {
url = "/rest/layergroups.xml";
} else {
url = "/rest/workspaces/" + workspace + "/layergroups.xml";
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("### Retrieving layergroups from " + url);
}
@ -411,17 +418,45 @@ public class GeoServerRESTReader {
/**
* 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}
*/
public RESTLayerGroup getLayerGroup(String name) {
String url = "/rest/layergroups/" + name + ".xml";
public RESTLayerGroup getLayerGroup(String workspace, String name) {
String url;
if (workspace == null) {
url = "/rest/layergroups/" + name + ".xml";
} else {
url = "/rest/workspaces/" + workspace + "/layergroups/" + name + ".xml";
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("### Retrieving layergroup from " + 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
//==========================================================================
@ -441,6 +476,8 @@ public class GeoServerRESTReader {
/**
* Get detailed info about a given Layer.
*
* @deprecated use {@link #getLayer(String, String)}
*
* @param name The name of the Layer
* @return Layer details as a {@link RESTLayer}
@ -453,6 +490,25 @@ public class GeoServerRESTReader {
return RESTLayer.build(load(url));
}
/**
* Get detailed info about a given Layer.
*
* @param workspace the workspace name
* @param name the layer name
* @return a RESTLayer with layer information or null
*/
public RESTLayer getLayer(String workspace, String name) {
if (workspace == null || workspace.isEmpty())
throw new IllegalArgumentException("Workspace may not be null");
if (name == null || name.isEmpty())
throw new IllegalArgumentException("Layername may not be null");
String url = HTTPUtils.append("/rest/layers/",workspace,":",name,".xml").toString();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("### Retrieving layer from " + url);
}
return RESTLayer.build(load(url));
}
//==========================================================================
//=== NAMESPACES
//==========================================================================

View File

@ -91,10 +91,52 @@ public class RESTLayerGroup {
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() {
return new RESTLayerList(rootElem.getChild("layers"));
if (rootElem.getChild("layers") != null) {
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() {
Element bounds = rootElem.getChild("bounds");
return bounds.getChildText("crs");

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

@ -28,6 +28,8 @@ package it.geosolutions.geoserver.rest.decoder;
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
import it.geosolutions.geoserver.rest.encoder.feature.FeatureTypeAttribute;
import it.geosolutions.geoserver.rest.encoder.feature.GSAttributeEncoder;
import it.geosolutions.geoserver.rest.encoder.metadatalink.GSMetadataLinkInfoEncoder;
import it.geosolutions.geoserver.rest.encoder.metadatalink.ResourceMetadataLinkInfo;
import java.util.ArrayList;
import java.util.HashMap;
@ -154,6 +156,32 @@ public class RESTResource {
return attrsList;
}
/**
* Decodes the list of MetadataLinkInfo from the GeoServer Resource
*
* @return the list of GSMetadataLinkEncoder
*/
public List<GSMetadataLinkInfoEncoder> getEncodedMetadataLinkInfoList() {
List<GSMetadataLinkInfoEncoder> metaLinksList = null;
final Element metaLinksRoot = rootElem.getChild("metadataLinks");
final List<Element> metaLinks = metaLinksRoot.getChildren();
if (metaLinks != null) {
metaLinksList = new ArrayList<GSMetadataLinkInfoEncoder>(
metaLinks.size());
for (Element metaLink : metaLinks) {
final GSMetadataLinkInfoEncoder metaLinkEnc = new GSMetadataLinkInfoEncoder();
metaLinkEnc.setType(metaLink.getChildText(ResourceMetadataLinkInfo.type.name()));
metaLinkEnc.setMetadataType(metaLink.getChildText(ResourceMetadataLinkInfo.metadataType.name()));
metaLinkEnc.setContent(metaLink.getChildText(ResourceMetadataLinkInfo.content.name()));
metaLinksList.add(metaLinkEnc);
}
}
return metaLinksList;
}
// /**
// * @return the list of available attribute names
// */

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 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.
*/
public class GSPostGISDatastoreEncoder extends PropertyXMLEncoder {

View File

@ -29,6 +29,7 @@ import it.geosolutions.geoserver.rest.encoder.coverage.GSCoverageEncoder;
import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureTypeEncoder;
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder;
import it.geosolutions.geoserver.rest.encoder.metadata.GSFeatureDimensionInfoEncoder;
import it.geosolutions.geoserver.rest.encoder.metadatalink.GSMetadataLinkInfoEncoder;
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
import it.geosolutions.geoserver.rest.encoder.utils.NestedElementEncoder;
import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder;
@ -50,11 +51,14 @@ import org.jdom.filter.Filter;
public abstract class GSResourceEncoder
extends PropertyXMLEncoder {
public final static String NAME = "name";
public final static String NATIVENAME = "nativeName";
public final static String METADATA="metadata";
public final static String KEYWORDS="keywords";
public final static String METADATALINKS="metadataLinks";
final private GSMetadataEncoder metadata = new GSMetadataEncoder();
final private Element keywordsListEncoder = new Element(KEYWORDS);
final private Element metadataLinksListEncoder = new Element(METADATALINKS);
private class GSMetadataEncoder extends NestedElementEncoder{
public GSMetadataEncoder() {
@ -75,16 +79,13 @@ public abstract class GSResourceEncoder
// Link members to the parent
addContent(metadata.getRoot());
addContent(keywordsListEncoder);
addContent(metadataLinksListEncoder);
}
public void setEnabled(boolean enabled) {
set("enabled", (enabled) ? "true" : "false");
}
// TODO MetadataLink
// public void setMetadata(String key, String url){
// metadata.set(key, url);
// }
/**
* @param key
@ -94,10 +95,26 @@ public abstract class GSResourceEncoder
metadata.add(key, dimensionInfo.getRoot());
}
public void setMetadata(String key, XmlElement dimensionInfo) {
metadata.set(key, dimensionInfo.getRoot());
}
/**
* @deprecated Use {@link #setMetadataDimension(String, GSDimensionInfoEncoder)} this method will be set as protected for internal use only
* @param key
* @param dimensionInfo
*/
public void setMetadata(String key, XmlElement dimensionInfo) {
metadata.set(key, dimensionInfo.getRoot());
}
/**
* @param key
* @param dimensionInfo
*/
protected void addMetadataDimension(String key, GSDimensionInfoEncoder dimensionInfo) {
metadata.add(key, dimensionInfo.getRoot());
}
public void setMetadataDimension(String key, GSDimensionInfoEncoder dimensionInfo) {
metadata.set(key, dimensionInfo.getRoot());
}
/**
* @param key
@ -136,6 +153,46 @@ public abstract class GSResourceEncoder
})).size() == 0 ? false : true;
}
/**
* Adds a MetadataLinkInfo to the GeoServer Resource
*
* @param MetadataLink
*/
public void addMetadataLinkInfo(GSMetadataLinkInfoEncoder metadataLinkInfo) {
metadataLinksListEncoder.addContent(metadataLinkInfo.getRoot());
}
/**
* Adds quickly a MetadataLinkInfo to the GeoServer Resource
*
* @param type
* @param metadataType
* @param content
*/
public void addMetadataLinkInfo(String type, String metadataType,
String content) {
final GSMetadataLinkInfoEncoder mde = new GSMetadataLinkInfoEncoder(
type, metadataType, content);
metadataLinksListEncoder.addContent(mde.getRoot());
}
/**
* Deletes a metadataLinkInfo from the list using the metadataURL
* (MetadataLinkInfo content)
*
* @param metadataURL
* @return true if something is removed, false otherwise
*/
public boolean delMetadataLinkInfo(final String metadataURL) {
return (metadataLinksListEncoder
.removeContent(GSMetadataLinkInfoEncoder
.getFilterByContent(metadataURL))).size() == 0 ? false
: true;
}
/**
* Reprojection policy for a published layer. One of:
* <ul>
@ -196,6 +253,42 @@ public abstract class GSResourceEncoder
return null;
}
/**
* Add the 'nativename' node with a text value from 'name'
*
*
*/
protected void addNativeName(final String nativename) {
add(NATIVENAME, nativename);
}
/**
* Set or modify the 'nativename' node with a text value from 'name'
*
* @note if not specified, the nativeName will be set with the value of the
* 'name' node.
*
*/
public void setNativeName(final String nativename) {
set(NATIVENAME, nativename);
}
/**
* Get the nativeName
*
* @return
*/
public String getNativeName() {
final Element nameNode = ElementUtils.contains(getRoot(), NATIVENAME, 1);
if (nameNode != null)
return nameNode.getText();
else
return null;
}
private final static String DESCRIPTION = "description";
/**

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

@ -43,13 +43,19 @@ public class GSCoverageEncoder extends GSResourceEncoder {
}
/**
* @param key
* @param dimensionInfo
*/
* @param key
* @param dimensionInfo
* @deprecated Use {@link GSResourceEncoder#addMetadataDimension(String, GSDimensionInfoEncoder)} this method will be removed soon
*/
protected void addMetadata(String key, GSDimensionInfoEncoder dimensionInfo) {
super.addMetadata(key, dimensionInfo);
}
/**
* @deprecated Use {@link GSResourceEncoder#setMetadataDimension(String, GSDimensionInfoEncoder)} this method will be removed soon
* @param key
* @param dimensionInfo
*/
public void setMetadata(String key, GSDimensionInfoEncoder dimensionInfo) {
super.setMetadata(key, dimensionInfo);
}

View File

@ -35,191 +35,267 @@ import org.jdom.Element;
import org.jdom.filter.Filter;
/**
* Use this encoder for ImageMosaic coverages.
*
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
*
*
*/
public class GSImageMosaicEncoder extends GSCoverageEncoder {
final private static String STRING="string";
final private static String ENTRY="entry";
final private NestedElementEncoder parameters=new NestedElementEncoder("parameters");
public GSImageMosaicEncoder() {
final private static String STRING = "string";
final private static String ENTRY = "entry";
final private NestedElementEncoder parameters = new NestedElementEncoder("parameters");
public GSImageMosaicEncoder() {
// Link members to the parent
addContent(parameters.getRoot());
}
static class parametersFilter implements Filter {
final String name;
public parametersFilter(final String name){
this.name=name;
}
private static final long serialVersionUID = 1L;
public boolean matches(Object obj) {
if (obj instanceof Element) {
if (((Element)obj).getName().equals(ENTRY)){
final Element el=((Element)obj).getChild(STRING);
if (el==null)
return false;
if (el.getText().equals(this.name)){
return true;
}
}
}
return false;
}
};
private final boolean removeParameter(final Filter filter){
final Iterator<Element> it=ElementUtils.search(getRoot(), filter).iterator();
if (it.hasNext()){
final Element el=it.next();
// if (it.hasNext())
// return false;
// else
return ElementUtils.remove(el,el);
}
return false;
}
addContent(parameters.getRoot());
}
private final static String allowMultithreading="AllowMultithreading";
/**
* @param val
*/
protected void addAllowMultithreading(final boolean val){
final List<Element> list=new ArrayList<Element>(2);
list.add(new Element(STRING).setText(allowMultithreading));
list.add(new Element(STRING).setText((val)?"true":"false"));
parameters.add(null,list);
}
private final static Filter allowMultithreadingFilter=new parametersFilter(allowMultithreading);
public void setAllowMultithreading(final boolean val){
removeParameter(allowMultithreadingFilter);
addAllowMultithreading(val);
}
private final static String filter="Filter";
/**
* @param val
*/
protected void addFilter(final String val){
final List<Element> list=new ArrayList<Element>(2);
list.add(new Element(STRING).setText(filter));
list.add(new Element(STRING).setText(val));
parameters.add(null,list);
}
private final static Filter filterFilter=new parametersFilter(filter);
public void setFilter(final String val){
removeParameter(filterFilter);
addFilter(val);
}
static class parametersFilter implements Filter {
final String name;
private final static String maxAllowedTiles="MaxAllowedTiles";
/**
* @param val
*/
protected void addMaxAllowedTiles(final int val){
final List<Element> list=new ArrayList<Element>(2);
list.add(new Element(STRING).setText(maxAllowedTiles));
list.add(new Element(STRING).setText(String.valueOf(val)));
parameters.add(null,list);
}
private final static Filter maxAllowedTilesFilter=new parametersFilter(maxAllowedTiles);
public void setMaxAllowedTiles(final int val){
removeParameter(maxAllowedTilesFilter);
addMaxAllowedTiles(val);
}
private final static String inputTransparentColor="InputTransparentColor";
/**
* @param val
*/
protected void addInputTransparentColor(final String val){
final List<Element> list=new ArrayList<Element>(2);
list.add(new Element(STRING).setText(inputTransparentColor));
list.add(new Element(STRING).setText(val));
parameters.add(null,list);
}
private final static Filter inputTransparentColorFilter=new parametersFilter(inputTransparentColor);
public void setInputTransparentColor(final String val){
removeParameter(inputTransparentColorFilter);
addInputTransparentColor(val);
}
private final static String outputTransparentColor="OutputTransparentColor";
/**
* @param val
*/
protected void addOutputTransparentColor(final String val){
final List<Element> list=new ArrayList<Element>(2);
list.add(new Element(STRING).setText(outputTransparentColor));
list.add(new Element(STRING).setText(val));
parameters.add(null,list);
}
private final static Filter outputTransparentColorFilter=new parametersFilter(outputTransparentColor);
public void setOutputTransparentColor(final String val){
removeParameter(outputTransparentColorFilter);
addInputTransparentColor(val);
}
private final static String SUGGESTED_TILE_SIZE="SUGGESTED_TILE_SIZE";
/**
* @param val
*/
protected void addSUGGESTED_TILE_SIZE(final String val){
final List<Element> list=new ArrayList<Element>(2);
list.add(new Element(STRING).setText(SUGGESTED_TILE_SIZE));
list.add(new Element(STRING).setText(val));
parameters.add(null,list);
}
private final static Filter SUGGESTED_TILE_SIZEFilter=new parametersFilter(SUGGESTED_TILE_SIZE);
public void setSUGGESTED_TILE_SIZE(final String val){
removeParameter(SUGGESTED_TILE_SIZEFilter);
addSUGGESTED_TILE_SIZE(val);
}
private final static String USE_JAI_IMAGEREAD="USE_JAI_IMAGEREAD";
/**
* @param val
*/
protected void addUSE_JAI_IMAGEREAD(final boolean val){
final List<Element> list=new ArrayList<Element>(2);
list.add(new Element(STRING).setText(USE_JAI_IMAGEREAD));
list.add(new Element(STRING).setText((val)?"true":"false"));
parameters.add(null,list);
}
private final static Filter USE_JAI_IMAGEREADFilter=new parametersFilter(USE_JAI_IMAGEREAD);
public void setUSE_JAI_IMAGEREAD(final boolean val){
removeParameter(USE_JAI_IMAGEREADFilter);
addUSE_JAI_IMAGEREAD(val);
}
private final static String backgroundValues="BackgroundValues";
/**
* @param val
*/
protected void addBackgroundValues(final String val){
final List<Element> list=new ArrayList<Element>(2);
list.add(new Element(STRING).setText(backgroundValues));
list.add(new Element(STRING).setText(val));
parameters.add(null,list);
}
private final static Filter backgroundValuesFilter=new parametersFilter(backgroundValues);
public void setBackgroundValues(final String val){
removeParameter(backgroundValuesFilter);
addBackgroundValues(val);
}
public parametersFilter(final String name) {
this.name = name;
}
private static final long serialVersionUID = 1L;
public boolean matches(Object obj) {
if (obj instanceof Element) {
if (((Element) obj).getName().equals(ENTRY)) {
final Element el = ((Element) obj).getChild(STRING);
if (el == null)
return false;
if (el.getText().equals(this.name)) {
return true;
}
}
}
return false;
}
};
private final boolean removeParameter(final Filter filter) {
final Iterator<Element> it = ElementUtils.search(getRoot(), filter).iterator();
if (it.hasNext()) {
final Element el = it.next();
// if (it.hasNext())
// return false;
// else
return ElementUtils.remove(el, el);
}
return false;
}
private final Element getParameter(final Filter filter) {
final Iterator<Element> it = ElementUtils.search(getRoot(), filter).iterator();
if (it.hasNext()) {
final Element el = it.next();
return ElementUtils.contains(el, el);
}
return null;
}
private final static String allowMultithreading = "AllowMultithreading";
/**
* @param val
*/
protected void addAllowMultithreading(final boolean val) {
final List<Element> list = new ArrayList<Element>(2);
list.add(new Element(STRING).setText(allowMultithreading));
list.add(new Element(STRING).setText((val) ? "true" : "false"));
parameters.add(null, list);
}
private final static Filter allowMultithreadingFilter = new parametersFilter(
allowMultithreading);
public void setAllowMultithreading(final boolean val) {
removeParameter(allowMultithreadingFilter);
addAllowMultithreading(val);
}
public Boolean getAllowMultithreading() {
Element el = getParameter(allowMultithreadingFilter);
if (el != null) {
List<Element> values = el.getChildren();
for (Element elm : values) {
String value = elm.getValue();
if (!value.equalsIgnoreCase(allowMultithreading)) {
return Boolean.valueOf(value);
}
}
}
return null;
}
private final static String filter = "Filter";
/**
* @param val
*/
protected void addFilter(final String val) {
final List<Element> list = new ArrayList<Element>(2);
list.add(new Element(STRING).setText(filter));
list.add(new Element(STRING).setText(val));
parameters.add(null, list);
}
private final static Filter filterFilter = new parametersFilter(filter);
public void setFilter(final String val) {
removeParameter(filterFilter);
addFilter(val);
}
private final static String maxAllowedTiles = "MaxAllowedTiles";
/**
* @param val
*/
protected void addMaxAllowedTiles(final int val) {
final List<Element> list = new ArrayList<Element>(2);
list.add(new Element(STRING).setText(maxAllowedTiles));
list.add(new Element(STRING).setText(String.valueOf(val)));
parameters.add(null, list);
}
private final static Filter maxAllowedTilesFilter = new parametersFilter(maxAllowedTiles);
public void setMaxAllowedTiles(final int val) {
removeParameter(maxAllowedTilesFilter);
addMaxAllowedTiles(val);
}
private final static String inputTransparentColor = "InputTransparentColor";
/**
* @param val
*/
protected void addInputTransparentColor(final String val) {
final List<Element> list = new ArrayList<Element>(2);
list.add(new Element(STRING).setText(inputTransparentColor));
list.add(new Element(STRING).setText(val));
parameters.add(null, list);
}
private final static Filter inputTransparentColorFilter = new parametersFilter(
inputTransparentColor);
public void setInputTransparentColor(final String val) {
removeParameter(inputTransparentColorFilter);
addInputTransparentColor(val);
}
private final static String outputTransparentColor = "OutputTransparentColor";
/**
* @param val
*/
protected void addOutputTransparentColor(final String val) {
final List<Element> list = new ArrayList<Element>(2);
list.add(new Element(STRING).setText(outputTransparentColor));
list.add(new Element(STRING).setText(val));
parameters.add(null, list);
}
private final static Filter outputTransparentColorFilter = new parametersFilter(
outputTransparentColor);
public void setOutputTransparentColor(final String val) {
removeParameter(outputTransparentColorFilter);
addInputTransparentColor(val);
}
private final static String SUGGESTED_TILE_SIZE = "SUGGESTED_TILE_SIZE";
/**
* @param val
*/
protected void addSUGGESTED_TILE_SIZE(final String val) {
final List<Element> list = new ArrayList<Element>(2);
list.add(new Element(STRING).setText(SUGGESTED_TILE_SIZE));
list.add(new Element(STRING).setText(val));
parameters.add(null, list);
}
private final static Filter SUGGESTED_TILE_SIZEFilter = new parametersFilter(
SUGGESTED_TILE_SIZE);
public void setSUGGESTED_TILE_SIZE(final String val) {
removeParameter(SUGGESTED_TILE_SIZEFilter);
addSUGGESTED_TILE_SIZE(val);
}
public String getSuggestedTileSize() {
Element el = getParameter(SUGGESTED_TILE_SIZEFilter);
if (el != null) {
List<Element> values = el.getChildren();
for (Element elm : values) {
String value = elm.getValue();
if (!value.equalsIgnoreCase(SUGGESTED_TILE_SIZE)) {
return value;
}
}
}
return null;
}
private final static String USE_JAI_IMAGEREAD = "USE_JAI_IMAGEREAD";
/**
* @param val
*/
protected void addUSE_JAI_IMAGEREAD(final boolean val) {
final List<Element> list = new ArrayList<Element>(2);
list.add(new Element(STRING).setText(USE_JAI_IMAGEREAD));
list.add(new Element(STRING).setText((val) ? "true" : "false"));
parameters.add(null, list);
}
private final static Filter USE_JAI_IMAGEREADFilter = new parametersFilter(USE_JAI_IMAGEREAD);
public void setUSE_JAI_IMAGEREAD(final boolean val) {
removeParameter(USE_JAI_IMAGEREADFilter);
addUSE_JAI_IMAGEREAD(val);
}
public Boolean getUseJaiImageRead() {
Element el = getParameter(USE_JAI_IMAGEREADFilter);
if (el != null) {
List<Element> values = el.getChildren();
for (Element elm : values) {
String value = elm.getValue();
if (!value.equalsIgnoreCase(USE_JAI_IMAGEREAD)) {
return Boolean.valueOf(value);
}
}
}
return null;
}
private final static String backgroundValues = "BackgroundValues";
/**
* @param val
*/
protected void addBackgroundValues(final String val) {
final List<Element> list = new ArrayList<Element>(2);
list.add(new Element(STRING).setText(backgroundValues));
list.add(new Element(STRING).setText(val));
parameters.add(null, list);
}
private final static Filter backgroundValuesFilter = new parametersFilter(backgroundValues);
public void setBackgroundValues(final String val) {
removeParameter(backgroundValuesFilter);
addBackgroundValues(val);
}
}

View File

@ -0,0 +1,208 @@
/*
* GeoServer-Manager - Simple Manager Library for GeoServer
*
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
* http://www.geo-solutions.it
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package it.geosolutions.geoserver.rest.encoder.coverage;
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
import it.geosolutions.geoserver.rest.encoder.utils.NestedElementEncoder;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.jdom.Element;
import org.jdom.filter.Filter;
/**
* Should be used to encode a Jpeg2K coverage.
*
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
*
*/
public class GSJP2KEncoder extends GSCoverageEncoder {
final private static String STRING = "string";
final private static String ENTRY = "entry";
final private NestedElementEncoder parameters = new NestedElementEncoder("parameters");
public GSJP2KEncoder() {
// Link members to the parent
addContent(parameters.getRoot());
}
static class parametersFilter implements Filter {
final String name;
public parametersFilter(final String name) {
this.name = name;
}
private static final long serialVersionUID = 1L;
public boolean matches(Object obj) {
if (obj instanceof Element) {
if (((Element) obj).getName().equals(ENTRY)) {
List<Element> values=((Element) obj).getChildren(STRING);
for (Element el : values){
if (el == null)
return false;
if (el.getText().equals(this.name)) {
return true;
}
}
// final Element el = ((Element) obj).getChild(STRING);
// if (el == null)
// return false;
// if (el.getText().equals(this.name)) {
// return true;
// }
}
}
return false;
}
};
private final boolean removeParameter(final Filter filter) {
final Iterator<Element> it = ElementUtils.search(getRoot(), filter).iterator();
if (it.hasNext()) {
final Element el = it.next();
return ElementUtils.remove(el, el);
}
return false;
}
private final Element getParameter(final Filter filter) {
final Iterator<Element> it = ElementUtils.search(getRoot(), filter).iterator();
if (it.hasNext()) {
final Element el = it.next();
return ElementUtils.contains(el, el);
}
return null;
}
private final static String useMultithreading = "USE_MULTITHREADING";
/**
* @param val
*/
protected void addUseMultithreading(final boolean val) {
final List<Element> list = new ArrayList<Element>(2);
list.add(new Element(STRING).setText(useMultithreading));
list.add(new Element(STRING).setText((val) ? "true" : "false"));
parameters.add(null, list);
}
private final static Filter useMultithreadingFilter = new parametersFilter(useMultithreading);
public void setUseMultithreading(final boolean val) {
removeParameter(useMultithreadingFilter);
addUseMultithreading(val);
}
public Boolean getUseMultithreading() {
Element el=getParameter(useMultithreadingFilter);
if (el!=null){
List<Element> values=el.getChildren();
for (Element elm : values){
String value=elm.getValue();
if (!value.equalsIgnoreCase(useMultithreading)){
return Boolean.valueOf(value);
}
}
}
return null;
}
private final static String SUGGESTED_TILE_SIZE = "SUGGESTED_TILE_SIZE";
/**
* @param val
*/
protected void addSuggestedTileSize(final String val) {
final List<Element> list = new ArrayList<Element>(2);
list.add(new Element(STRING).setText(SUGGESTED_TILE_SIZE));
list.add(new Element(STRING).setText(val));
parameters.add(null, list);
}
private final static Filter SUGGESTED_TILE_SIZEFilter = new parametersFilter(
SUGGESTED_TILE_SIZE);
public void setSuggestedTileSize(final String val) {
removeParameter(SUGGESTED_TILE_SIZEFilter);
addSuggestedTileSize(val);
}
public String getSuggestedTileSize() {
Element el=getParameter(SUGGESTED_TILE_SIZEFilter);
if (el!=null){
List<Element> values=el.getChildren();
for (Element elm : values){
String value=elm.getValue();
if (!value.equalsIgnoreCase(SUGGESTED_TILE_SIZE)){
return value;
}
}
}
return null;
}
private final static String USE_JAI_IMAGEREAD = "USE_JAI_IMAGEREAD";
/**
* @param val
*/
protected void addUseJaiImageRead(final boolean val) {
final List<Element> list = new ArrayList<Element>(2);
list.add(new Element(STRING).setText(USE_JAI_IMAGEREAD));
list.add(new Element(STRING).setText((val) ? "true" : "false"));
parameters.add(null, list);
}
private final static Filter USE_JAI_IMAGEREADFilter = new parametersFilter(USE_JAI_IMAGEREAD);
public void setUseJaiImageRead(final boolean val) {
removeParameter(USE_JAI_IMAGEREADFilter);
addUseJaiImageRead(val);
}
public Boolean getUseJaiImageRead() {
Element el=getParameter(USE_JAI_IMAGEREADFilter);
if (el!=null){
List<Element> values=el.getChildren();
for (Element elm : values){
String value=elm.getValue();
if (!value.equalsIgnoreCase(USE_JAI_IMAGEREAD)){
return Boolean.valueOf(value);
}
}
}
return null;
}
}

View File

@ -24,38 +24,37 @@
*/
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.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.PropertyXMLEncoder;
import java.util.Map;
/**
* Generic Datastore encoder.
*
* Provides getters and setters for parameters common to all Datastores,
* an internal placeholder for specific connection parameters, and
* a constructor to read parameters from a {@link RESTDataStore}.
* Provides getters and setters for parameters common to all Datastores, an internal placeholder for specific connection parameters, and a constructor
* to read parameters from a {@link RESTDataStore}.
*
* @author Oscar Fonts
*/
public abstract class GSAbstractDatastoreEncoder extends PropertyXMLEncoder {
public abstract class GSAbstractDatastoreEncoder extends GSAbstractStoreEncoder {
final static String ROOT = "dataStore";
NestedElementEncoder connectionParameters = new NestedElementEncoder("connectionParameters");
GSAbstractDatastoreEncoder(String storeName) {
super(ROOT);
final static String ROOT = "dataStore";
NestedElementEncoder connectionParameters = new NestedElementEncoder("connectionParameters");
GSAbstractDatastoreEncoder(String storeName) {
super(GeoServerRESTPublisher.StoreType.DATASTORES, ROOT);
// Add mandatory parameter
ensureValidName(storeName);
setName(storeName);
ensureValidName(storeName);
setName(storeName);
// Add connection parameters
addContent(connectionParameters.getRoot());
}
addContent(connectionParameters.getRoot());
}
/**
* Create a {@value #TYPE} datastore encoder from a store read from server.
*
@ -63,84 +62,25 @@ public abstract class GSAbstractDatastoreEncoder extends PropertyXMLEncoder {
* @throws IllegalArgumentException if store type or mandatory parameters are not valid
*/
GSAbstractDatastoreEncoder(RESTDataStore store) {
this(store.getName());
// Match datastore type
ensureValidType(store.getStoreType());
setType(store.getStoreType());
// Copy store parameters
setDescription(store.getDescription());
setEnabled(store.isEnabled());
// Copy connection parameters - bulk
Map<String, String> params = store.getConnectionParameters();
for(String key : params.keySet()) {
connectionParameters.set(key, params.get(key));
}
}
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();
this(store.getName());
// Match datastore type
ensureValidType(store.getStoreType());
// Copy store parameters
setDescription(store.getDescription());
setEnabled(store.isEnabled());
// Copy connection parameters - bulk
Map<String, String> params = store.getConnectionParameters();
for (String key : params.keySet()) {
connectionParameters.set(key, params.get(key));
}
}
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.
*/
abstract String getValidType();
protected abstract String getValidType();
}

View File

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

View File

@ -35,19 +35,18 @@ import java.net.URL;
*/
public class GSDirectoryOfShapefilesDatastoreEncoder extends GSShapefileDatastoreEncoder {
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,
* given a store name and a url (the store location).
* Create a {@value #TYPE} datastore with default connection parameters, given a store name and a url (the store location).
*
* @param name New datastore name
* @param url The shapefile location in the server, relative to $GEOSERVER_DATA_DIR.
*/
public GSDirectoryOfShapefilesDatastoreEncoder(String name, URL url) {
super(name, url);
setType(TYPE);
}
public GSDirectoryOfShapefilesDatastoreEncoder(String name, URL url) {
super(name, url);
setType(TYPE);
}
/**
* Create a {@value #TYPE} datastore encoder from an existing store read from server.
@ -55,14 +54,14 @@ public class GSDirectoryOfShapefilesDatastoreEncoder extends GSShapefileDatastor
* @param store The existing store.
* @throws IllegalArgumentException if store type or mandatory parameters are not valid
*/
public GSDirectoryOfShapefilesDatastoreEncoder(RESTDataStore store) {
super(store);
}
public GSDirectoryOfShapefilesDatastoreEncoder(RESTDataStore store) {
super(store);
}
/**
* @return {@value #TYPE}
*/
String getValidType() {
return TYPE;
protected String getValidType() {
return TYPE;
}
}

View File

@ -36,6 +36,7 @@ public class GSOracleNGDatastoreEncoder extends GSAbstractDatastoreEncoder {
static final String TYPE = "Oracle NG";
static final String DEFAULT_DB_TYPE = "oracle";
static final int DEFAULT_MIN_CONNECTIONS = 1;
static final int DEFAULT_MAX_CONNECTIONS = 10;
static final int DEFAULT_FETCH_SIZE = 1000;
@ -68,6 +69,7 @@ public class GSOracleNGDatastoreEncoder extends GSAbstractDatastoreEncoder {
// Set mandatory parameter
setType(TYPE);
setDatabaseType(DEFAULT_DB_TYPE);
setDatabase(database);
// Set default values
@ -121,6 +123,11 @@ public class GSOracleNGDatastoreEncoder extends GSAbstractDatastoreEncoder {
connectionParameters.set("passwd", password);
}
public void setDatabaseType(String dbtype) {
connectionParameters.set("dbtype", dbtype);
}
public void setJndiReferenceName(String jndiReferenceName) {
connectionParameters.set("jndiReferenceName", jndiReferenceName);
}
@ -181,7 +188,7 @@ public class GSOracleNGDatastoreEncoder extends GSAbstractDatastoreEncoder {
/**
* @return {@value #TYPE}
*/
String getValidType() {
protected String getValidType() {
return TYPE;
}
}

View File

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

View File

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

View File

@ -26,7 +26,9 @@
package it.geosolutions.geoserver.rest.encoder.feature;
import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder;
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder;
import it.geosolutions.geoserver.rest.encoder.metadata.GSFeatureDimensionInfoEncoder;
import it.geosolutions.geoserver.rest.encoder.metadata.virtualtable.GSVirtualTableEncoder;
import org.jdom.Element;
@ -48,7 +50,9 @@ public class GSFeatureTypeEncoder extends GSResourceEncoder {
addContent(attributes);
}
/**
* @deprecated Use {@link GSResourceEncoder#addMetadataDimension(String, GSDimensionInfoEncoder)} this method will be removed soon
* @param key
* @param dimensionInfo
*/
@ -56,10 +60,46 @@ public class GSFeatureTypeEncoder extends GSResourceEncoder {
super.addMetadata(key, dimensionInfo);
}
/**
* @deprecated Use {@link GSResourceEncoder#setMetadataDimension(String, GSDimensionInfoEncoder)} this method will be removed soon
* @param key
* @param dimensionInfo
*
*/
public void setMetadata(String key, GSFeatureDimensionInfoEncoder dimensionInfo) {
super.setMetadata(key, dimensionInfo);
}
/**
* Add a VirtualTable (SQL View feature type)
*
* @param virtualtable
*/
protected void addMetadataVirtualTable(
final GSVirtualTableEncoder virtualtable) {
super.addMetadata("JDBC_VIRTUAL_TABLE", virtualtable);
}
/**
* Set a VirtualTable (SQL View feature type)
*
* @param virtualtable
*/
public void setMetadataVirtualTable(final GSVirtualTableEncoder virtualtable) {
super.setMetadata("JDBC_VIRTUAL_TABLE", virtualtable);
}
/**
* Deletes the VirtualTable metadata
*
* @return true if deleted, false otherwise
*/
public boolean delMetadataVirtualTable() {
return super.delMetadata("JDB_VIRTUAL_TABLE");
}
/**
* delete a keyword from the list
*

View File

@ -0,0 +1,341 @@
/*
* GeoServer-Manager - Simple Manager Library for GeoServer
*
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
* http://www.geo-solutions.it
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package it.geosolutions.geoserver.rest.encoder.metadata.virtualtable;
import java.util.List;
import org.jdom.Element;
import org.jdom.filter.Filter;
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
import it.geosolutions.geoserver.rest.encoder.utils.XmlElement;
/**
* GSVirtualTableEncoder - Encodes a metadata VirtualTable for a GeoServer
* featureType.
*
* Example (based on the example provided in the Geoserver documentation - see
* {@link http://docs.geoserver.org/latest/en/user/data/database/sqlview.html#
* parameterizing-sql-views}):
*
* <pre>
* {
* @code
* // Set-up the vtGeom
* final VTGeometryEncoder vtGeom = new VTGeometryEncoder();
* vtGeom.setName("the_geom");
* vtGeom.setType("MultiPolygon");
* vtGeom.setSrid("4326");
*
* // Set-up 2 virtual table parameters
* final VTParameterEncoder vtParam1 = new VTParameterEncoder("high",
* "100000000", "^[\\d]+$");
* final VTParameterEncoder vtParam2 = new VTParameterEncoder("low", "0",
* "^[\\d]+$");
*
* // sql
* String sql = "select gid, state_name, the_geom from pgstates where persons between %low% and %high%";
*
* // Set-up the virtual table
* final GSVirtualTableEncoder vte = new GSVirtualTableEncoder();
* vte.setName("popstates");
* vte.setSql("select gid, state_name, the_geom from pgstates where persons between %low% and %high%");
* vte.addKeyColumn("gid");
* vte.addVirtualTableGeometry(vtGeom);
* vte.addVirtualTableParameter(vtParam1);
* vte.addVirtualTableParameter(vtParam2);
* }
* </pre>
*
* For this example, the XML output is:
*
* <pre>
* {@code
* <virtualTable>
* <name>popstates</name>
* <sql>select gid, state_name, the_geom from pgstates where persons between %low% and %high%</sql>
* <geometry>
* <name>the_geom</name>
* <type>MultiPolygon</type>
* <srid>4326</srid>
* </geometry>
* <keyColumn>gid</keyColumn>
* <parameter>
* <name>high</name>
* <defaultValue>100000000</defaultValue>
* <regexpValidator>^[\d]+$</regexpValidator>
* </parameter>
* <parameter>
* <name>low</name>
* <defaultValue>0</defaultValue>
* <regexpValidator>^[\d]+$</regexpValidator>
* </parameter>
* </virtualTable>
* }
* </pre>
*
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com |
* emmanuel.blondel@fao.org
*
*/
public class GSVirtualTableEncoder extends XmlElement {
public final static String NAME = "name";
public final static String SQL = "sql";
public final static String KEYCOLUMN = "keyColumn";
/**
* Constructs a GSVirtualTableEncoder
*/
public GSVirtualTableEncoder() {
super("virtualTable");
}
/**
* Constructs directly a GSVirtualTableEncoder
*
* @param name (required)
* @param sql (required)
* @param keyColumns (optional)
* @param geomEncList (optional for geometryless sql view)
* @param paramEncList (optional)
*/
public GSVirtualTableEncoder(String name, String sql, List<String> keyColumns,
List<VTGeometryEncoder> geomEncList,
List<VTParameterEncoder> paramEncList){
super("virtualTable");
this.setup(name, sql, keyColumns, geomEncList, paramEncList);
}
/**
* Set-up quickly a GSVirtualTableEncoder
*
* @param name (must be the same as the featureType nativeName)
* @param sql
* @param keyColumns
* @param geomEncList
* @param paramEncList
*/
protected void setup(String name, String sql, List<String> keyColumns,
List<VTGeometryEncoder> geomEncList,
List<VTParameterEncoder> paramEncList) {
setName(name);
setSql(sql);
if (keyColumns != null) {
for (String pk : keyColumns) {
addKeyColumn(pk);
}
}
if (geomEncList != null) {
for (VTGeometryEncoder geomEnc : geomEncList) {
addVirtualTableGeometry(geomEnc);
}
}
if (paramEncList != null) {
for(VTParameterEncoder paramEnc : paramEncList){
addVirtualTableParameter(paramEnc);
}
}
}
/**
* Add the 'name' node with a text value from 'name'
*
* @note REQUIRED to configure a virtual table
*/
protected void addName(final String name){
add(NAME, name);
}
/**
* Set or modify the 'name' node with a text value from 'name'
*
* @note REQUIRED to configure a virtual table
*/
public void setName(final String name) {
set(NAME, name);
}
/**
* Get the name of the virtual table
*
* @return
*/
public String getName() {
final Element nameNode = ElementUtils.contains(getRoot(), NAME, 1);
if (nameNode != null)
return nameNode.getText();
else
return null;
}
/**
* Add the 'sql' node with a text value from 'sql'
*
* @note REQUIRED to configure a virtual table
*/
protected void addSql(final String sql){
add(SQL, sql);
}
/**
* Set or modify the 'sql' node with a text value from 'sql'
*
* @note REQUIRED to configure a virtual table
*/
public void setSql(final String sql) {
set(SQL, sql);
}
/**
* Get the sql query
*
* @return
*/
public String getSql() {
final Element sqlNode = ElementUtils.contains(getRoot(), SQL, 1);
if (sqlNode != null)
return sqlNode.getText();
else
return null;
}
/**
* Adds a keyColumn
*
* @param keycolumn
*/
public void addKeyColumn(String keycolumn){
final Element el = new Element(KEYCOLUMN);
el.setText(keycolumn);
this.getRoot().addContent(el);
}
/**
* Deletes a keyColumn
*
* @param keycolumn
* @return true if the keycolumn was removed
*/
public boolean delKeyColumn(final String keycolumn){
final Element el = new Element(KEYCOLUMN);
el.setText(keycolumn);
return (this.getRoot().removeContent(new Filter() {
private static final long serialVersionUID = 1L;
public boolean matches(Object obj) {
if (((Element) obj).getText().equals(keycolumn)) {
return true;
}
return false;
}
})).size() == 0 ? false : true;
}
/**
* Adds a geometry to the VirtualTable
*
* @param geomEnc
*/
public void addVirtualTableGeometry(VTGeometryEncoder geomEnc){
this.getRoot().addContent(geomEnc.getRoot());
}
/**
* Adds quickly a geometry to the virtual table
*
* @param name
* @param geometryType
* @param srid
*/
public void addVirtualTableGeometry(String name, String geometryType, String srid){
final VTGeometryEncoder gEnc = new VTGeometryEncoder();
gEnc.setup(name, geometryType, srid);
this.getRoot().addContent(gEnc.getRoot());
}
/**
* Deletes a geometry from the VirtualTable
*
* @param name
* @return true if the geometry was removed, otherwise false
*/
public boolean delVirtualTableGeometry(String name){
return (this.getRoot()
.removeContent(VTGeometryEncoder
.getFilterByName(name))).size() == 0 ? false
: true;
}
/**
* Adds a parameter to the VirtualTable
*
* @param paramEnc
*/
public void addVirtualTableParameter(VTParameterEncoder paramEnc){
this.getRoot().addContent(paramEnc.getRoot());
}
/**
* Adds quickly a parameter to the VirtualTable
*
* @param name
* @param defaultValue
* @param regexpValidator
*/
public void addVirtualTableParameter(String name, String defaultValue, String regexpValidator){
final VTParameterEncoder pEnc = new VTParameterEncoder();
pEnc.setup(name, defaultValue, regexpValidator);
this.getRoot().addContent(pEnc.getRoot());
}
/**
* Deletes a parameter from the VirtualTable
*
* @param name
* @return
*/
public boolean delVirtualTableParameter(String name){
return (this.getRoot()
.removeContent(VTParameterEncoder
.getFilterByName(name))).size() == 0 ? false
: true;
}
/*
* a method to check either the virtual parameters as specified in the sql
* query map those encoded in VTParameterEncoder, i.e. check the number and
* names of parameters.
*/
public boolean validate() throws IllegalStateException{
throw new UnsupportedOperationException("not yet implemented");
}
}

View File

@ -0,0 +1,36 @@
/*
* GeoServer-Manager - Simple Manager Library for GeoServer
*
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
* http://www.geo-solutions.it
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package it.geosolutions.geoserver.rest.encoder.metadata.virtualtable;
/**
* Enumeration of Virtual Table geometry members
*
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com |
* emmanuel.blondel@fao.org
*
*/
public enum VTGeometry {
name, type, srid
}

View File

@ -0,0 +1,247 @@
/*
* GeoServer-Manager - Simple Manager Library for GeoServer
*
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
* http://www.geo-solutions.it
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package it.geosolutions.geoserver.rest.encoder.metadata.virtualtable;
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
import it.geosolutions.geoserver.rest.encoder.utils.XmlElement;
import org.jdom.Element;
import org.jdom.filter.Filter;
/**
* VTGeometryEncoder - Encodes a metadata VirtualTable geometry for a
* GeoServer featureType, as follows:
*
* <pre>
* {
* @code
* final VTGeometryEncoder vtGeom = new VTGeometryEncoder();
* vtGeom.setName("the_geom");
* vtGeom.setType("MultiPolygon");
* vtGeom.setSrid("4326");
* }
* </pre>
*
* For this example, the XML output is:
*
* <pre>
* {@code
* <geometry>
* <name>the_geom</name>
* <type>MultiPolygon</type>
* <srid>4326</srid>
* </geometry>
* }
* </pre>
*
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com |
* emmanuel.blondel@fao.org
*
*/
public class VTGeometryEncoder extends XmlElement {
/**
* A class to filter the VirtualTable geometries by name
*
*/
private static class filterByName implements Filter {
final private String key;
public filterByName(String name) {
this.key = name;
}
private static final long serialVersionUID = 1L;
public boolean matches(Object obj) {
Element el = ((Element) obj)
.getChild(VTGeometry.name.toString());
if (el != null && el.getTextTrim().equals(key)) {
return true;
}
return false;
}
}
/**
* Get a Filter using the VTGeometry name
*
* @param name
* @return the filter
*/
public static Filter getFilterByName(String name) {
return new filterByName(name);
}
/**
* Constructs a GSVirtualTableGeomEncoder
*
*/
public VTGeometryEncoder() {
super("geometry");
}
/**
* Constructs quickly a VTGeometryEncoder
*
* @param name (required)
* @param geometryType (required)
* @param srid (required)
*/
public VTGeometryEncoder(String name, String geometryType, String srid) {
super("geometry");
this.setup(name, geometryType, srid);
}
/**
* Set-up quickly a GSVirtualTableGeomEncoder
*
* @param name
* @param geometryType
* @param srid
*/
protected void setup(String name, String geometryType, String srid) {
setName(name);
setType(geometryType);
setSrid(srid);
}
/**
* Set a VirtualTable Geometry member
*
* @param type
* @param value
*/
protected void setMember(VTGeometry type,
String value) {
set(type.toString(), value);
}
/**
* Set a geometry name
*
* @param name
*/
public void setName(String name){
this.setMember(VTGeometry.name, name);
}
/**
* Set a geometry type
*
* @param type
*/
public void setType(String type){
this.setMember(VTGeometry.type, type);
}
/**
* Set a geometry srid
*
* @param srid
*/
public void setSrid(String srid){
this.setMember(VTGeometry.srid, srid);
}
/**
* Deletes a VirtualTableGeometry member
*
* @param type
* @return true if removed, false otherwise
*/
protected boolean delMember(VTGeometry type) {
return ElementUtils.remove(this.getRoot(), this.getRoot().getChild(type.toString()));
}
/**
* Deletes the name
*
* @return true if removed, false otherwise
*/
public boolean delName(){
return this.delMember(VTGeometry.name);
}
/**
* Deletes the type
*
* @return true if removed, false otherwise
*/
public boolean delType(){
return this.delMember(VTGeometry.type);
}
/**
* Deletes the srid
*
* @return true if removed, false otherwise
*/
public boolean delSrid(){
return this.delMember(VTGeometry.srid);
}
/**
* Get the VirtualTableGeometry member value
*
* @param type
* @return
*/
protected String getMember(VTGeometry type) {
Element el = this.getRoot().getChild(type.toString());
if (el != null)
return el.getTextTrim();
else
return null;
}
/**
* Get the geometry column name
*
* @return
*/
public String getName(){
return this.getMember(VTGeometry.name);
}
/**
* Get the geometry column type
*
* @return
*/
public String getType(){
return this.getMember(VTGeometry.type);
}
/**
* Get the geometry column srid
*
* @return
*/
public String getSrid(){
return this.getMember(VTGeometry.srid);
}
}

View File

@ -0,0 +1,37 @@
/*
* GeoServer-Manager - Simple Manager Library for GeoServer
*
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
* http://www.geo-solutions.it
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package it.geosolutions.geoserver.rest.encoder.metadata.virtualtable;
/**
* Enumeration of SQL View featureType virtual table parameter members
*
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com |
* emmanuel.blondel@fao.org
*
*/
public enum VTParameter {
name, defaultValue, regexpValidator
}

View File

@ -0,0 +1,246 @@
/*
* GeoServer-Manager - Simple Manager Library for GeoServer
*
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
* http://www.geo-solutions.it
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package it.geosolutions.geoserver.rest.encoder.metadata.virtualtable;
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
import it.geosolutions.geoserver.rest.encoder.utils.XmlElement;
import org.jdom.Element;
import org.jdom.filter.Filter;
/**
* VTParameterEncoder - Encodes a metadata VirtualTable parameter for a
* GeoServer featureType, as follows:
*
* <pre>
* { @code
* final VTParameterEncoder vtParam = new VTParameterEncoder();
* vtParam.setName("fieldname");
* vtParam.setDefaultValue("default_value");
* vtParam.setRegexpValidator("^[\\w\\d\\s]+$");
* }
* </pre>
*
* For this example, the XML output is:
*
* <pre>
* { @code
* <parameter>
* <name>fieldname</name>
* <defaultValue>default_value</defaultValue>
* <regexpValidator>^[\w\d\s]+$</regexpValidator>
* </parameter>
* }
* </pre>
*
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com |
* emmanuel.blondel@fao.org
*
*/
public class VTParameterEncoder extends XmlElement {
/**
* A class to filter the VirtualTable parameters by name
*
*/
private static class filterByName implements Filter {
final private String key;
public filterByName(String name) {
this.key = name;
}
private static final long serialVersionUID = 1L;
public boolean matches(Object obj) {
Element el = ((Element) obj)
.getChild(VTParameter.name.toString());
if (el != null && el.getTextTrim().equals(key)) {
return true;
}
return false;
}
}
/**
* Get a Filter using the VTParameter name
*
* @param name
* @return the filter
*/
public static Filter getFilterByName(String name) {
return new filterByName(name);
}
/**
* Constructs a GSVirtualTableParamEncoder
*/
public VTParameterEncoder() {
super("parameter");
}
/**
* Constructs quickly a VTParameterEncoder
*
* @param name (required)
* @param defaultValue (required)
* @param regexpValidator (required)
*/
public VTParameterEncoder(String name, String defaultValue, String regexpValidator){
super("parameter");
this.setup(name, defaultValue, regexpValidator);
}
/**
* Set-up quickly a VirtualTable parameter
*
* @param name
* @param defaultValue
* @param regexpValidator
*/
protected void setup(String name, String defaultValue, String regexpValidator) {
setName(name);
setDefaultValue(defaultValue);
setRegexpValidator(regexpValidator);
}
/**
* Set a VirtualTableParameter member
*
* @param type
* @param value
*/
protected void setMember(VTParameter type,
String value) {
set(type.toString(), value);
}
/**
* Set the parameter name
*
* @param name
*/
public void setName(String name){
this.setMember(VTParameter.name, name);
}
/**
* Set the parameter default value
*
* @param value
*/
public void setDefaultValue(String value){
this.setMember(VTParameter.defaultValue, value);
}
/**
* Set the parameter regexp validator
*
* @param validator
*/
public void setRegexpValidator(String validator){
this.setMember(VTParameter.regexpValidator, validator);
}
/**
* Deletes a VirtualTableParameter member
*
* @param type
* @return
*/
protected boolean delMember(VTParameter type) {
return ElementUtils.remove(this.getRoot(), this.getRoot().getChild(type.toString()));
}
/**
* Deletes the name
*
* @return true if removed, false otherwise
*/
public boolean delName(){
return this.delMember(VTParameter.name);
}
/**
* Deletes the default value
*
* @return true if removed, false otherwise
*/
public boolean delDefaultValue(){
return this.delMember(VTParameter.defaultValue);
}
/**
* Deletes the Regexp validator
*
* @return true if removed, false otherwise
*/
public boolean delRegexpValidator(){
return this.delMember(VTParameter.regexpValidator);
}
/**
* Get a VirtualTableParameter member
*
* @param type
* @return
*/
protected String getMember(VTParameter type) {
Element el = getRoot().getChild(type.toString());
if (el != null)
return el.getTextTrim();
else
return null;
}
/**
* Get the parameter name
*
* @return
*/
public String getName(){
return this.getMember(VTParameter.name);
}
/**
* Get the parameter default value
*
* @return
*/
public String getDefaultValue(){
return this.getMember(VTParameter.defaultValue);
}
/**
* Get the parameter regexp validator
*
* @return
*/
public String getRegexpValidator(){
return this.getMember(VTParameter.regexpValidator);
}
}

View File

@ -0,0 +1,251 @@
/*
* GeoServer-Manager - Simple Manager Library for GeoServer
*
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
* http://www.geo-solutions.it
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package it.geosolutions.geoserver.rest.encoder.metadatalink;
import java.util.Map;
import java.util.Map.Entry;
import org.jdom.Element;
import org.jdom.filter.Filter;
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
import it.geosolutions.geoserver.rest.encoder.utils.XmlElement;
/**
* GSMetadataLinkEncoder - encodes a metadataLink for a given GeoServer Resource
* (feature type /coverage), as follows:
* <pre>
* {@code
* final GSMetadataLinkInfoEncoder mde = new GSMetadataLinkInfoEncoder();
* mde.setType("text/xml");
* mde.setMetadataType("ISO19115:2003");
* mde.setContent("http://www.organization.org/metadata");
* }
* </pre>
* For this example, the XML output is:
* <pre>
* {@code
* <metadataLink>
* <type>text/xml</type>
* <metadataType>ISO19115:2003</metadataType>
* <content>http://www.organization.org/metadata</content>
* </metadataLink>
* }
* </pre>
*
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com |
* emmanuel.blondel@fao.org
*
*/
public class GSMetadataLinkInfoEncoder extends XmlElement {
/** A class to filter the MetadataLinkInfo by content
*
*
*/
private static class filterByContent implements Filter {
final private String key;
public filterByContent(String content) {
this.key = content;
}
private static final long serialVersionUID = 1L;
public boolean matches(Object obj) {
Element el = ((Element) obj)
.getChild(ResourceMetadataLinkInfo.content.toString());
if (el != null && el.getTextTrim().equals(key)) {
return true;
}
return false;
}
}
/**
* Get a Filter using the MetadataLinkInfo content (metadataURL)
*
* @param content
* @return the filter
*/
public static Filter getFilterByContent(String content) {
return new filterByContent(content);
}
/**
* Constructs a new GSMetadataLinkInfoEncoder
*
*/
public GSMetadataLinkInfoEncoder() {
super("metadataLink");
}
/**
* Constructs quickly a MetadataLink info
*
* @param type (required)
* @param metadataType (required)
* @param content (required)
*/
public GSMetadataLinkInfoEncoder(String type, String metadataType, String content){
super("metadataLink");
this.setup(type, metadataType, content);
}
/**
* Set-up quickly a metadataLinkInfo
*
* @param type
* @param metadataType
* @param content
*/
protected void setup(String type, String metadataType, String content) {
set(ResourceMetadataLinkInfo.type.name(), type);
set(ResourceMetadataLinkInfo.metadataType.name(), metadataType);
set(ResourceMetadataLinkInfo.content.name(), content);
}
/**
* Set a MetadataLinkInfo member (type, metadataType or content)
*
* @param type
* @param value
*/
protected void setMember(ResourceMetadataLinkInfo type,
String value) {
set(type.toString(), value);
}
/**
* Set the mime type
*
* @param type
*/
public void setType(String type){
this.setMember(ResourceMetadataLinkInfo.type, type);
}
/**
* Set the metadata type
*
* @param metadataType
*/
public void setMetadataType(String metadataType){
this.setMember(ResourceMetadataLinkInfo.metadataType, metadataType);
}
/**
* Set the content
*
* @param content
*/
public void setContent(String content){
this.setMember(ResourceMetadataLinkInfo.content, content);
}
/**
* Deletes a MetadataLinkInfo member
*
* @param type
* @return true if the metadataLinkInfo member is removed
*/
protected boolean delMember(ResourceMetadataLinkInfo type) {
return ElementUtils.remove(this.getRoot(), this.getRoot().getChild(type.toString()));
}
/**
* Deletes the type
*
* @param type
* @return true if removed
*/
public boolean delType(){
return this.delMember(ResourceMetadataLinkInfo.type);
}
/**
* Deletes the metadata type
*
* @param metadata type
* @return true if removed
*/
public boolean delMetadataType(){
return this.delMember(ResourceMetadataLinkInfo.metadataType);
}
/**
* Deletes the content
*
* @param content
* @return true if removed
*/
public boolean delContent(){
return this.delMember(ResourceMetadataLinkInfo.content);
}
/**
* Get the value of the MetadataLinkInfo member
*
* @param type
* @return the value of the MetadataLinkInfo member
*/
protected String getMember(ResourceMetadataLinkInfo type) {
Element el = this.getRoot().getChild(type.toString());
if (el != null)
return el.getTextTrim();
else
return null;
}
/**
* Get the mime type
*
* @return
*/
public String getType(){
return this.getMember(ResourceMetadataLinkInfo.type);
}
/**
* Get the metadata type
*
* @return
*/
public String getMetadataType(){
return this.getMember(ResourceMetadataLinkInfo.metadataType);
}
/**
* Get the content
*
* @return
*/
public String getContent(){
return this.getMember(ResourceMetadataLinkInfo.content);
}
}

View File

@ -0,0 +1,37 @@
/*
* GeoServer-Manager - Simple Manager Library for GeoServer
*
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
* http://www.geo-solutions.it
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package it.geosolutions.geoserver.rest.encoder.metadatalink;
/**
* Enumeration of featureType metadataLink member
*
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com |
* emmanuel.blondel@fao.org
*
*/
public enum ResourceMetadataLinkInfo {
type, metadataType, content
}

View File

@ -24,7 +24,7 @@
*/
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 java.net.MalformedURLException;
@ -33,13 +33,14 @@ import java.net.URL;
/**
* Manage datastores.
*
* To pass connection parameters, use the encoders derived from
* {@link GSAbstractDatastoreEncoder}.
* To pass connection parameters, use the encoders derived from {@link GSAbstractDatastoreEncoder}.
*
* @author Oscar Fonts
* @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.
@ -51,43 +52,47 @@ public class GeoServerRESTDatastoreManager extends GeoServerRESTAbstractManager
* @throws IllegalArgumentException
*/
public GeoServerRESTDatastoreManager(URL restURL, String username, String password)
throws IllegalArgumentException, MalformedURLException {
throws IllegalArgumentException, MalformedURLException {
super(restURL, username, password);
}
/**
* Create a datastore.
* Create a store.
*
* @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
* @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
*
* @deprecated use {@link GeoServerRESTStoreManager#create(String, GSAbstractStoreEncoder)}
*/
public boolean create(String workspace, GSAbstractDatastoreEncoder datastore) {
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;
public boolean create(String workspace, GSAbstractDatastoreEncoder store) {
return super.create(workspace, store);
}
/**
* Update a datastore.
* Update a store.
*
* @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
* @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
* @deprecated use {@link GeoServerRESTStoreManager#update(String, GSAbstractStoreEncoder)}
*/
public boolean update(String workspace, GSAbstractDatastoreEncoder datastore) {
String sUrl = HTTPUtils.append(restURL, "/rest/workspaces/", workspace, "/datastores/",
datastore.getName()).toString();
String xml = datastore.toString();
String result = HTTPUtils.putXml(sUrl, xml, gsuser, gspass);
return result != null;
public boolean update(String workspace, GSAbstractDatastoreEncoder store) {
return super.update(workspace, store);
}
/**
* 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

@ -23,6 +23,8 @@ package it.geosolutions.geoserver.decoder;
import it.geosolutions.geoserver.rest.decoder.RESTCoverage;
import it.geosolutions.geoserver.rest.decoder.RESTDimensionInfo;
import it.geosolutions.geoserver.rest.encoder.metadatalink.GSMetadataLinkInfoEncoder;
import it.geosolutions.geoserver.rest.encoder.metadatalink.ResourceMetadataLinkInfo;
import java.io.File;
import java.io.IOException;
@ -65,10 +67,25 @@ public class MetadataDecoderTest {
Assert.assertEquals(el.isEnabled(),true);
}
}
}
@Test
public void testMetadataLinkInfo() throws IOException{
File coverageFile = new ClassPathResource("testdata/coverageExample.xml").getFile();
String coverageString = FileUtils.readFileToString(coverageFile);
RESTCoverage coverage = RESTCoverage.build(coverageString);
List<GSMetadataLinkInfoEncoder> list = coverage.getEncodedMetadataLinkInfoList();
GSMetadataLinkInfoEncoder metadataLinkInfo1 = list.get(0);
Assert.assertEquals("text/xml", metadataLinkInfo1.getType());
Assert.assertEquals("ISO19115:2003", metadataLinkInfo1.getMetadataType());
Assert.assertEquals("http://www.organization.org/metadata1", metadataLinkInfo1.getContent());
GSMetadataLinkInfoEncoder metadataLinkInfo2 = list.get(1);
Assert.assertEquals("text/html",metadataLinkInfo2.getType());
Assert.assertEquals("ISO19115:2003",metadataLinkInfo2.getMetadataType());
Assert.assertEquals("http://www.organization.org/metadata2",metadataLinkInfo2.getContent());
}
}

View File

@ -24,25 +24,24 @@
*/
package it.geosolutions.geoserver.rest.datastore;
import it.geosolutions.geoserver.rest.GeoserverRESTTest;
import it.geosolutions.geoserver.rest.decoder.RESTDataStore;
import it.geosolutions.geoserver.rest.encoder.datastore.GSArcSDEDatastoreEncoder;
import java.net.MalformedURLException;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import it.geosolutions.geoserver.rest.GeoserverRESTTest;
import it.geosolutions.geoserver.rest.encoder.GSAbstractStoreEncoder;
import it.geosolutions.geoserver.rest.encoder.datastore.GSArcSDEDatastoreEncoder;
import it.geosolutions.geoserver.rest.encoder.datastore.GSOracleNGDatastoreEncoder;
/**
* Testcase for creating arcsde-based resources on geoserver.
* <P>
* Since these tests require a running arcsde instance, this is more like integration tests.<br/>
* You may skip them by defining<tt> <pre>
* -DpgIgnore=true </pre></tt>
* When <tt>pgIgnore</tt> is defined that way, failing tests will not break
* the build: they will be logged as errors instead.
*
* -DpgIgnore=true </pre></tt> When <tt>pgIgnore</tt> is defined that way, failing tests will not break the build: they will be logged as
* errors instead.
*
* <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>pgPort</TT> (default: <TT>5432</TT>)</LI>
* <LI><TT>pgDatabase</TT> (default: <TT>test</TT>)</LI>
@ -50,76 +49,30 @@ import org.slf4j.LoggerFactory;
* <LI><TT>pgUser</TT> (default: <TT>utest</TT>)</LI>
* <LI><TT>pgPassword</TT> (default: <TT>ptest</TT>)</LI>
* </ul>
*
*
* @author etj
* @author Eric Grosso
* @author Gianni Barrotta
*
* @author carlo cancellieri - GeoSolutions
*
* @see GeoserverRESTTest
*/
public class GSArcSDEDatastoreEncoderTest extends GeoserverRESTTest {
public class GSArcSDEDatastoreEncoderTest extends StoreIntegrationTest {
private final static Logger LOGGER = LoggerFactory.getLogger(GSArcSDEDatastoreEncoderTest.class);
private static final String DEFAULT_WS = "it.geosolutions";
public GSArcSDEDatastoreEncoderTest() throws IllegalArgumentException, MalformedURLException {
private final boolean pgIgnore;
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");
super(System.getProperty("Ignore", "false").equalsIgnoreCase("true"));
}
@Test
public void testCreateDeleteArcSDEDatastore() {
if (!enabled()) {
return;
}
deleteAll();
String wsName = DEFAULT_WS;
String datastoreName = "resttestarcsde";
String description = "description";
String dsNamespace = "http://www.geo-solutions.it";
@Override
public GSAbstractStoreEncoder getStoreEncoderTest() {
GSArcSDEDatastoreEncoder datastoreEncoder = new GSArcSDEDatastoreEncoder(
System.getProperty("arcsdeHost", "localhost"),
System.getProperty("arcsdeSchema", "public"), System.getProperty("arcsdePassword", "ptest"));
datastoreEncoder.setNamespace(DEFAULT_WS);
datastoreEncoder.setPort(Integer.parseInt(System.getProperty("arcsdePort", "5432")));
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));
return datastoreEncoder;
}
}

View File

@ -24,8 +24,11 @@
*/
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.GSOracleNGDatastoreEncoder;
import org.junit.Test;
@ -54,82 +57,37 @@ import org.slf4j.LoggerFactory;
* @author etj
* @author Eric Grosso
* @author Gianni Barrotta
* @author carlo cancellieri - GeoSolutions
*
* @see GeoserverRESTTest
*/
public class GSOracleNGDatastoreEncoderTest extends GeoserverRESTTest {
public class GSOracleNGDatastoreEncoderTest extends StoreIntegrationTest {
private final static Logger LOGGER = LoggerFactory.getLogger(GSOracleNGDatastoreEncoderTest.class);
private static final String DEFAULT_WS = "it.geosolutions";
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 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");
// private final static Logger LOGGER = LoggerFactory.getLogger(GSOracleNGDatastoreEncoderTest.class);
public GSOracleNGDatastoreEncoderTest() throws IllegalArgumentException, MalformedURLException {
super(System.getProperty("pgIgnore", "false").equalsIgnoreCase("true"));
}
@Test
public void testCreateDeleteOracleNGDatastore() {
if (!enabled()) {
return;
}
deleteAll();
String wsName = DEFAULT_WS;
String datastoreName = "resttestOracleNG";
String description = "description";
String dsNamespace = "http://www.geo-solutions.it";
@Override
public GSAbstractStoreEncoder getStoreEncoderTest() {
GSOracleNGDatastoreEncoder datastoreEncoder = new GSOracleNGDatastoreEncoder(System.getProperty("oDataStoreName", "test"), System.getProperty("pgDatabase", "test"));
datastoreEncoder.setNamespace(DEFAULT_WS);
datastoreEncoder.setHost(System.getProperty("pgHost", "localhost"));
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"));
boolean exposePrimaryKeys = true;
boolean validateConnections = false;
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.setValidateConnections(validateConnections);
datastoreEncoder.setPrimaryKeyMetadataTable(primaryKeyMetadataTable);
assertTrue(publisher.createWorkspace(wsName));
// 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));
return datastoreEncoder;
}
}

View File

@ -0,0 +1,148 @@
/*
* 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.GSLayerEncoder;
import it.geosolutions.geoserver.rest.encoder.datastore.GSAbstractDatastoreEncoder;
import it.geosolutions.geoserver.rest.encoder.datastore.GSOracleNGDatastoreEncoder;
import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureTypeEncoder;
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/>
*
* For testing that a datastore is properly configured, a layer publication has
* to be attempted. For this, the 'states' data (states shapefile - available in
* testdata/states.zip) has to be imported in the corresponding store.
* Note: For Oracle NG this name has to be uppercase (STATES).
*
* @author carlo cancellieri - GeoSolutions
* @author emmanuel blondel
*
* @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());
// check if the datastore is properly configured in GS for publishing layers
String layername = "states";
if (storeEncoder instanceof GSOracleNGDatastoreEncoder)
layername = layername.toUpperCase();
GSFeatureTypeEncoder fte = new GSFeatureTypeEncoder();
fte.setName(layername);
fte.setTitle(layername);
fte.setNativeCRS("EPSG:4326");
fte.setDescription("desc");
fte.setEnabled(true);
GSLayerEncoder layerEncoder = new GSLayerEncoder();
layerEncoder.setEnabled(true);
layerEncoder.setQueryable(true);
layerEncoder.setDefaultStyle("polygon");
boolean published = publisher.publishDBLayer(DEFAULT_WS, storeName,
fte, layerEncoder);
if (!ignore) {
assertTrue("Test layer not published", published);
} else if (!published) {
LOGGER.error("*** Test layer "
+ layername
+ " has not been published. Problem in datastore configuration");
}
// 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,326 @@
/*
* 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 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.io.IOException;
import java.net.URI;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
/**
* @todo applied patch for https://github.com/geosolutions-it/geoserver-manager/issues/61
* still need to split test encoder from integration
*/
public class GSLayerGroupEncoderTest extends GeoserverRESTTest {
@Before
public void setup() throws Exception {
if (enabled()){
init();
}
}
private void init() throws IOException{
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 {
if (!enabled()) return;
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 {
if (!enabled()) return;
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) {
if (!enabled()) return;
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 {
if (!enabled()) return;
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 {
if (!enabled()) return;
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 {
if (!enabled()) return;
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 {
if (!enabled()) return;
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,9 +24,10 @@ import junit.framework.TestCase;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.Assert;
/**
*
*
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
*/
public class GSImageMosaicEncoderTest extends TestCase {
@ -38,22 +39,31 @@ public class GSImageMosaicEncoderTest extends TestCase {
* Default logger
*/
protected final static Logger LOGGER = LoggerFactory.getLogger(GSImageMosaicEncoderTest.class);
/**
* TODO implement this test
*/
@Test
public void testAll() {
final GSImageMosaicEncoder encoder=new GSImageMosaicEncoder();
encoder.addAllowMultithreading(true);
LOGGER.info(encoder.toString());
encoder.setAllowMultithreading(false);
LOGGER.info(encoder.toString());
encoder.addSUGGESTED_TILE_SIZE("512,512");
final GSImageMosaicEncoder encoder = new GSImageMosaicEncoder();
Assert.isNull(encoder.getUseJaiImageRead());
encoder.setAllowMultithreading(true);
Assert.isTrue(encoder.getAllowMultithreading());
encoder.setAllowMultithreading(false);
Assert.isTrue(!encoder.getAllowMultithreading());
encoder.setSUGGESTED_TILE_SIZE("512,512");
Assert.isTrue(encoder.getSuggestedTileSize().equalsIgnoreCase("512,512"));
LOGGER.info(encoder.toString());
encoder.addSUGGESTED_TILE_SIZE("512,512");
}
}

View File

@ -0,0 +1,67 @@
/*
* Copyright (C) 2007 - 2011 GeoSolutions S.A.S.
* http://www.geo-solutions.it
*
* GPLv3 + Classpath exception
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package it.geosolutions.geoserver.rest.encoder.coverage;
import junit.framework.TestCase;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.Assert;
/**
*
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
*/
public class GSJP2KEncoderTest extends TestCase {
public GSJP2KEncoderTest() {
}
/**
* Default logger
*/
protected final static Logger LOGGER = LoggerFactory.getLogger(GSJP2KEncoderTest.class);
/**
* TODO implement this test
*/
@Test
public void testAll() {
final GSJP2KEncoder encoder=new GSJP2KEncoder();
Assert.isNull(encoder.getUseJaiImageRead());
encoder.setUseMultithreading(true);
LOGGER.info(encoder.toString());
Assert.isTrue(encoder.getUseMultithreading());
encoder.setUseMultithreading(false);
Assert.isTrue(!encoder.getUseMultithreading());
encoder.setSuggestedTileSize("512,512");
Assert.isTrue(encoder.getSuggestedTileSize().equalsIgnoreCase("512,512"));
LOGGER.info(encoder.toString());
}
}

View File

@ -28,6 +28,10 @@ import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder;
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder.Presentation;
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder.PresentationDiscrete;
import it.geosolutions.geoserver.rest.encoder.metadata.GSFeatureDimensionInfoEncoder;
import it.geosolutions.geoserver.rest.encoder.metadata.virtualtable.GSVirtualTableEncoder;
import it.geosolutions.geoserver.rest.encoder.metadata.virtualtable.VTGeometryEncoder;
import it.geosolutions.geoserver.rest.encoder.metadata.virtualtable.VTParameterEncoder;
import it.geosolutions.geoserver.rest.encoder.metadatalink.GSMetadataLinkInfoEncoder;
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
import it.geosolutions.geoserver.rest.publisher.GeoserverRESTPublisherTest;
@ -70,6 +74,12 @@ public class GSFeatureEncoderTest extends GeoserverRESTPublisherTest {
fte.setNativeCRS("EPSG:4326");
fte.setDescription("desc");
fte.setEnabled(true);
//metadataLink
GSMetadataLinkInfoEncoder metadatalink = new GSMetadataLinkInfoEncoder(
"text/xml", "ISO19115:2003",
"http://www.organization.org/metadata1");
fte.addMetadataLinkInfo(metadatalink);
GSLayerEncoder layerEncoder = new GSLayerEncoder();
layerEncoder.setEnabled(true);
@ -187,6 +197,14 @@ public class GSFeatureEncoderTest extends GeoserverRESTPublisherTest {
Assert.assertTrue(encoder.delKeyword("KEYWORD_2"));
Assert.assertFalse(encoder.delKeyword("KEYWORD_M"));
//metadataLinkInfo
encoder.addMetadataLinkInfo("text/xml", "ISO19115:2003","http://www.organization.org/metadata1");
encoder.addMetadataLinkInfo("text/html", "ISO19115:2003","http://www.organization.org/metadata2");
Assert.assertTrue(encoder.delMetadataLinkInfo("http://www.organization.org/metadata2"));
Assert.assertFalse(encoder.delMetadataLinkInfo("http://www.organization.org/metadata3"));
//dimensions
final GSFeatureDimensionInfoEncoder elevationDimension = new GSFeatureDimensionInfoEncoder(
"elevation_field");
@ -214,4 +232,89 @@ public class GSFeatureEncoderTest extends GeoserverRESTPublisherTest {
LOGGER.info("REMOVED");
}
/**
* Test method for virtual table encoding / SQL view layer integration
*
* Settings information for integration tests
* - test is based on the data used in http://docs.geoserver.org/latest/en/user/data/database/sqlview.html#parameterizing-sql-views
* (states shapefile - available in testdata/states.zip)
* - create a postgis db
* - import the states shapefile (using shp2pgsql or Postgis shapefile uploader)
* - In Geoserver, create a postgis datastore for this DB, with the name "statesdb"
*
*/
@Test
public void testSQLViewIntegration() {
if (!enabled())
return;
deleteAll();
GeoServerRESTPublisher publisher = new GeoServerRESTPublisher(RESTURL,
RESTUSER, RESTPW);
String storeName = "statesdb"; // name of the datastore setup for tests
String layerName = "my_sqlviewlayer";
String nativeName = "popstates";
GSFeatureTypeEncoder fte = new GSFeatureTypeEncoder();
fte.setName(layerName);
fte.setNativeName(nativeName);
fte.setTitle("title");
fte.addKeyword("keyword1");
fte.addKeyword("keyword2");
fte.setNativeCRS("EPSG:4326");
fte.setDescription("desc");
fte.setEnabled(true);
// virtual table
// -------------
// Set-up the vtGeom
final VTGeometryEncoder vtGeom = new VTGeometryEncoder("the_geom",
"Point", "4326");
// Set-up 2 virtual table parameters
final VTParameterEncoder vtParam1 = new VTParameterEncoder("high",
"100000000", "^[\\d]+$");
final VTParameterEncoder vtParam2 = new VTParameterEncoder("low", "0",
"^[\\d]+$");
// sql
String sql = "select gid, state_name, the_geom from pgstates where persons between %low% and %high% and state_abbr = '%state%'";
// set-up the virtual table
final GSVirtualTableEncoder vte = new GSVirtualTableEncoder();
vte.setName(nativeName);
vte.setSql(sql);
vte.addVirtualTableGeometry(vtGeom);
vte.addVirtualTableParameter(vtParam1);
vte.addVirtualTableParameter(vtParam2);
fte.setMetadataVirtualTable(vte); // Set the virtual table
// modif the vte
vte.delVirtualTableGeometry("the_geom");
vte.addVirtualTableGeometry("the_geom", "MultiPolygon", "4326");
final VTParameterEncoder vtParam3 = new VTParameterEncoder("state",
"FL", "^[\\w\\d\\s]+$");
vte.addVirtualTableParameter(vtParam3);
vte.addKeyColumn("gid");
// Layer encoder
// -------------
GSLayerEncoder layerEncoder = new GSLayerEncoder();
layerEncoder.setEnabled(true);
layerEncoder.setQueryable(true);
layerEncoder.setDefaultStyle("polygon");
// test insert
// ------------
publisher.createWorkspace(DEFAULT_WS);
boolean published = publisher.publishDBLayer(DEFAULT_WS, storeName,
fte, layerEncoder);
assertTrue("Successfull publication", published);
assertTrue(existsLayer(layerName));
}
}

View File

@ -0,0 +1,98 @@
package it.geosolutions.geoserver.rest.encoder.feature;
import it.geosolutions.geoserver.rest.encoder.metadata.virtualtable.GSVirtualTableEncoder;
import it.geosolutions.geoserver.rest.encoder.metadata.virtualtable.VTGeometryEncoder;
import it.geosolutions.geoserver.rest.encoder.metadata.virtualtable.VTParameterEncoder;
import it.geosolutions.geoserver.rest.encoder.metadata.virtualtable.VTGeometry;
import it.geosolutions.geoserver.rest.encoder.metadata.virtualtable.VTParameter;
import it.geosolutions.geoserver.rest.encoder.utils.XmlElement;
import java.util.Arrays;
import junit.framework.Assert;
import org.jdom.Element;
import org.junit.Test;
/**
*
* @author eblondel
*
*/
public class GSVirtualTableEncoderTest {
@Test
public void virtualTableTest() {
// Set-up the vtGeom
final VTGeometryEncoder vtGeom = new VTGeometryEncoder("the_geom",
"MultiPolygon", "4326");
// Set-up 2 virtual table parameters
final VTParameterEncoder vtParam1 = new VTParameterEncoder(
"fieldname1", "default_value1", "^[\\w\\d\\s]+$");
final VTParameterEncoder vtParam2 = new VTParameterEncoder(
"fieldname2", "default_value2", "^[\\w\\d\\s]+$");
// sql
String sql = "select the_geom, id, field1, field2 from mytable where field1 = '%fieldname1%' and field2 = '%fieldname2%'";
// Set-up the virtual table
final GSVirtualTableEncoder vte = new GSVirtualTableEncoder();
vte.setName("mysqlview");
vte.setSql(sql);
vte.addKeyColumn("id");
vte.addVirtualTableGeometry(vtGeom);
vte.addVirtualTableParameter(vtParam1);
vte.addVirtualTableParameter(vtParam2);
// TESTS
Assert.assertEquals("mysqlview", vte.getName());
Assert.assertEquals(sql, vte.getSql());
Assert.assertEquals("id", vte.getRoot().getChildText("keyColumn"));
final Element ge = (Element) vte.getRoot().getChild("geometry");
Assert.assertEquals("the_geom",
ge.getChildText(VTGeometry.name.toString()));
Assert.assertEquals("MultiPolygon",
ge.getChildText(VTGeometry.type.toString()));
Assert.assertEquals("4326", ge.getChildText(VTGeometry.srid.toString()));
final Element p1 = (Element) vte.getRoot().getChildren("parameter")
.get(0);
final Element p2 = (Element) vte.getRoot().getChildren("parameter")
.get(1);
Assert.assertEquals("fieldname1",
p1.getChildText(VTParameter.name.toString()));
Assert.assertEquals("default_value1",
p1.getChildText(VTParameter.defaultValue.toString()));
Assert.assertEquals("^[\\w\\d\\s]+$",
p1.getChildText(VTParameter.regexpValidator.toString()));
Assert.assertEquals("fieldname2",
p2.getChildText(VTParameter.name.toString()));
Assert.assertEquals("default_value2",
p2.getChildText(VTParameter.defaultValue.toString()));
Assert.assertEquals("^[\\w\\d\\s]+$",
p2.getChildText(VTParameter.regexpValidator.toString()));
vte.delKeyColumn("id");
Assert.assertNull(vte.getRoot().getChildText("keyColumn"));
Assert.assertEquals("mysqlview", vte.getName());
Assert.assertEquals(sql, vte.getSql());
vtGeom.setType("Point");
vtParam1.setName("newfieldname");
Assert.assertEquals("Point",
((Element) vte.getRoot().getChildren("geometry").get(0))
.getChildText(VTGeometry.type.toString()));
Assert.assertEquals("newfieldname", ((Element) vte.getRoot()
.getChildren("parameter").get(0)).getChildText(VTParameter.name
.toString()));
Assert.assertTrue(vtGeom.delSrid());
Assert.assertTrue(vtParam1.delRegexpValidator());
}
}

View File

@ -0,0 +1,53 @@
/*
* Copyright (C) 2007 - 2011 GeoSolutions S.A.S.
* http://www.geo-solutions.it
*
* GPLv3 + Classpath exception
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package it.geosolutions.geoserver.rest.encoder.metadatalink;
import junit.framework.Assert;
import org.junit.Test;
/**
*
* @author eblondel
*
*/
public class GSMetadataLinkInfoEncoderTest {
@Test
public void metadataLinkInfoTest(){
GSMetadataLinkInfoEncoder encoder = new GSMetadataLinkInfoEncoder();
encoder.setup("text/xml", "ISO19115:2003","http://www.organization.org/metadata1");
Assert.assertEquals("text/xml", encoder.getType());
Assert.assertEquals("ISO19115:2003", encoder.getMetadataType());
Assert.assertEquals("http://www.organization.org/metadata1", encoder.getContent());
Assert.assertTrue(encoder.delContent());
Assert.assertNull(encoder.getContent());
encoder.setType("text/html");
encoder.setMetadataType("FGDC");
encoder.setContent("http://www.organization.org/metadata2");
Assert.assertEquals("text/html", encoder.getType());
Assert.assertEquals("FGDC", encoder.getMetadataType());
Assert.assertEquals("http://www.organization.org/metadata2", encoder.getContent());
}
}

View File

@ -24,8 +24,9 @@
*/
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.encoder.GSAbstractStoreEncoder;
import it.geosolutions.geoserver.rest.encoder.datastore.GSAbstractDatastoreEncoder;
import it.geosolutions.geoserver.rest.encoder.datastore.GSDirectoryOfShapefilesDatastoreEncoder;
import it.geosolutions.geoserver.rest.encoder.datastore.GSShapefileDatastoreEncoder;
@ -39,15 +40,17 @@ import org.junit.Test;
/**
* 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}).
* <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>
* <li>Tests {@link GeoServerRESTDatastoreManager} create and update methods.
* </ul>
*
* <p>The sequence is:
* <p>
* The sequence is:
* <ol>
* <li>Create a DirectoryOfShapefilesDatastoreEncoder, with default parameters.
* <li>Publish via GeoServerRESTDatastoreManager.create.
@ -62,70 +65,82 @@ import org.junit.Test;
*
* @author Oscar Fonts
*/
public class GeoserverRESTDatastoreManagerTest extends GeoserverRESTTest {
private static final String WS_NAME = DEFAULT_WS;
private static final String DS_NAME = "testCreateDatastore";
private static final String DS_DESCRIPTION = "A description";
private static URL LOCATION_1;
private static URL LOCATION_2;
public GeoserverRESTDatastoreManagerTest() throws Exception {
LOCATION_1 = new URL("file:data/1");
LOCATION_2 = new URL("file:data/2");
}
public class GeoserverRESTDatastoreManagerTest extends StoreIntegrationTest {
@Test
public void test() throws Exception {
private static final String WS_NAME = DEFAULT_WS;
private static final String DS_NAME = "testCreateDatastore";
private static final String DS_DESCRIPTION = "A description";
private static URL LOCATION_1;
private static URL LOCATION_2;
public GeoserverRESTDatastoreManagerTest() throws Exception {
super(true);
LOCATION_1 = new URL("file:data/1");
LOCATION_2 = new URL("file:data/2");
}
@Override
public GSAbstractStoreEncoder getStoreEncoderTest() {
return new GSDirectoryOfShapefilesDatastoreEncoder(DS_NAME, LOCATION_1);
}
@Test
public void test() throws Exception {
if (!enabled()) {
return;
}
// Delete all resources except styles
deleteAllWorkspacesRecursively();
// Delete all resources except styles
deleteAllWorkspacesRecursively();
// Create workspace
assertTrue(publisher.createWorkspace(WS_NAME));
// Create a directory of spatial files with default parameters
GSDirectoryOfShapefilesDatastoreEncoder create = new GSDirectoryOfShapefilesDatastoreEncoder(DS_NAME, LOCATION_1);
assertTrue(manager.getDatastoreManager().create(WS_NAME, create));
// Read the store from server; check all parameter values
RESTDataStore read = reader.getDatastore(WS_NAME, DS_NAME);
assertEquals(read.getName(), DS_NAME);
assertEquals(read.getWorkspaceName(), WS_NAME);
assertEquals(read.isEnabled(), true);
Map<String,String> connParams = read.getConnectionParameters();
assertEquals(connParams.get("url"), LOCATION_1.toString());
assertEquals(connParams.get("charset"), "ISO-8859-1");
assertEquals(connParams.get("create spatial index"), "true");
assertEquals(connParams.get("memory mapped buffer"), "false");
assertEquals(connParams.get("cache and reuse memory maps"), "true");
// Change all parameter to non-default values
GSDirectoryOfShapefilesDatastoreEncoder update = new GSDirectoryOfShapefilesDatastoreEncoder(read);
update.setDescription(DS_DESCRIPTION);
update.setEnabled(false);
update.setUrl(LOCATION_2);
update.setCharset(Charset.forName("UTF-8"));
update.setCreateSpatialIndex(false);
update.setMemoryMappedBuffer(true);
update.setCacheAndReuseMemoryMaps(false);
//update the store
assertTrue(manager.getDatastoreManager().update(WS_NAME, update));
// Read again, check that all parameters have changed
read = reader.getDatastore(WS_NAME, DS_NAME);
assertEquals(read.getWorkspaceName(), WS_NAME);
assertEquals(read.isEnabled(), false);
connParams = read.getConnectionParameters();
assertEquals(connParams.get("url"), LOCATION_2.toString());
assertEquals(connParams.get("charset"), "UTF-8");
assertEquals(connParams.get("create spatial index"), "false");
assertEquals(connParams.get("memory mapped buffer"), "true");
assertEquals(connParams.get("cache and reuse memory maps"), "false");
}
// Create a directory of spatial files with default parameters
GSDirectoryOfShapefilesDatastoreEncoder create = new GSDirectoryOfShapefilesDatastoreEncoder(
DS_NAME, LOCATION_1);
assertTrue(manager.getStoreManager().create(WS_NAME, create));
// Read the store from server; check all parameter values
RESTDataStore read = reader.getDatastore(WS_NAME, DS_NAME);
assertEquals(read.getName(), DS_NAME);
assertEquals(read.getWorkspaceName(), WS_NAME);
assertEquals(read.isEnabled(), true);
Map<String, String> connParams = read.getConnectionParameters();
assertEquals(connParams.get("url"), LOCATION_1.toString());
assertEquals(connParams.get("charset"), "ISO-8859-1");
assertEquals(connParams.get("create spatial index"), "true");
assertEquals(connParams.get("memory mapped buffer"), "false");
assertEquals(connParams.get("cache and reuse memory maps"), "true");
// Change all parameter to non-default values
GSDirectoryOfShapefilesDatastoreEncoder update = new GSDirectoryOfShapefilesDatastoreEncoder(
read);
update.setDescription(DS_DESCRIPTION);
update.setEnabled(false);
update.setUrl(LOCATION_2);
update.setCharset(Charset.forName("UTF-8"));
update.setCreateSpatialIndex(false);
update.setMemoryMappedBuffer(true);
update.setCacheAndReuseMemoryMaps(false);
// update the store
assertTrue(manager.getStoreManager().update(WS_NAME, update));
// Read again, check that all parameters have changed
read = reader.getDatastore(WS_NAME, DS_NAME);
assertEquals(read.getWorkspaceName(), WS_NAME);
assertEquals(read.isEnabled(), false);
connParams = read.getConnectionParameters();
assertEquals(connParams.get("url"), LOCATION_2.toString());
assertEquals(connParams.get("charset"), "UTF-8");
assertEquals(connParams.get("create spatial index"), "false");
assertEquals(connParams.get("memory mapped buffer"), "true");
assertEquals(connParams.get("cache and reuse memory maps"), "false");
}
}

View File

@ -27,10 +27,13 @@ package it.geosolutions.geoserver.rest.publisher;
import it.geosolutions.geoserver.rest.GeoserverRESTTest;
import it.geosolutions.geoserver.rest.decoder.RESTDataStore;
import it.geosolutions.geoserver.rest.encoder.GSPostGISDatastoreEncoder;
import it.geosolutions.geoserver.rest.datastore.StoreIntegrationTest;
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.LoggerFactory;
@ -55,53 +58,39 @@ import org.slf4j.LoggerFactory;
*
* @author etj
* @author Eric Grosso
* @author carlo cancellieri - GeoSolutions
*
* @see GeoserverRESTTest
*/
public class GeoserverRESTPostgisDatastoreTest extends GeoserverRESTTest {
public class GeoserverRESTPostgisDatastoreTest extends StoreIntegrationTest {
private final static Logger LOGGER = LoggerFactory.getLogger(GeoserverRESTPostgisDatastoreTest.class);
private static final String DEFAULT_WS = "it.geosolutions";
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");
public GeoserverRESTPostgisDatastoreTest()
throws IllegalArgumentException, MalformedURLException {
super(System.getProperty("pgIgnore", "false").equalsIgnoreCase("true"));
}
@Test
public void testCreateDeletePostGISDatastore() {
if (!enabled()) {
return;
}
deleteAll();
String wsName = DEFAULT_WS;
String datastoreName = "resttestpostgis";
String description = "description";
String dsNamespace = "http://www.geo-solutions.it";
@Override
public GSAbstractStoreEncoder getStoreEncoderTest(){
boolean exposePrimaryKeys = true;
boolean validateConnections = false;
String primaryKeyMetadataTable = "test";
GSPostGISDatastoreEncoder datastoreEncoder = new GSPostGISDatastoreEncoder();
datastoreEncoder.defaultInit();
datastoreEncoder.setName(datastoreName);
String datastoreName = "resttestpostgis";
String description = "description";
String dsNamespace = "http://www.geo-solutions.it";
GSPostGISDatastoreEncoder datastoreEncoder = new GSPostGISDatastoreEncoder(datastoreName);
datastoreEncoder.setDescription(description);
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.setPort(pgPort);
datastoreEncoder.setDatabase(pgDatabase);
@ -111,29 +100,7 @@ public class GeoserverRESTPostgisDatastoreTest extends GeoserverRESTTest {
datastoreEncoder.setExposePrimaryKeys(exposePrimaryKeys);
datastoreEncoder.setValidateConnections(validateConnections);
datastoreEncoder.setPrimaryKeyMetadataTable(primaryKeyMetadataTable);
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));
return datastoreEncoder;
}
}

View File

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

View File

@ -7,6 +7,18 @@
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/namespaces/topp.xml" type="application/xml"/>
</namespace>
<title>granuleTestMosaic</title>
<metadataLinks>
<metadataLink>
<type>text/xml</type>
<metadataType>ISO19115:2003</metadataType>
<content>http://www.organization.org/metadata1</content>
</metadataLink>
<metadataLink>
<type>text/html</type>
<metadataType>ISO19115:2003</metadataType>
<content>http://www.organization.org/metadata2</content>
</metadataLink>
</metadataLinks>
<nativeCRS>GEOGCS[&quot;WGS 84&quot;, &#xd;
DATUM[&quot;World Geodetic System 1984&quot;, &#xd;
SPHEROID[&quot;WGS 84&quot;, 6378137.0, 298.257223563, AUTHORITY[&quot;EPSG&quot;,&quot;7030&quot;]], &#xd;

BIN
src/test/resources/testdata/states.zip vendored Normal file

Binary file not shown.