Compare commits

...

54 Commits

Author SHA1 Message Date
mbarto
b8ecffaa0b Merge pull request #156 from xandros6/v1.5.1-patch
Added additional WCS informations to publish GeoTIFF
2015-11-23 17:03:04 +01:00
Xandros
b4c2ab8d3d Added additional WCS informations to publish GeoTIFF 2015-11-20 12:52:21 +01:00
Carlo Cancellieri
545acc425a Merge pull request #117 from eblondel/1.5.x-114-GSLayerEncoder21-fix
1.5.x -  #114 - GSLayerEncoder21 fix
2013-11-22 13:35:05 -08:00
eblondel
6fc77c7936 1.5.x #114 - fix GSLayerEncoder21 (identifiers) 2013-11-21 13:36:16 +01:00
Carlo Cancellieri
5c1569c129 Merge pull request #113 from eblondel/1.5.x-102-GSLayer-AuthorityURL-Identifier-advertise
#102 - 1.5.x - support for AuthorityURL/Identifier/advertise + tests
2013-10-21 09:42:09 -07:00
eblondel
9d72c4665d #102 - 1.5.x - support for AuthorityURL/Identifier/advertise + tests 2013-10-21 17:38:21 +02:00
Carlo Cancellieri
cb6fc418f2 Merge pull request #111 from geosolutions-it/1.5.x-110-IllegalArgument-getVersion
close 110. IllegalArgument on getVersion on Geoserver 2.1
2013-10-21 06:50:00 -07:00
carlo cancellieri
6979d0d435 close 110. IllegalArgument on getVersion on Geoserver 2.1 2013-10-21 11:19:07 +02:00
Carlo Cancellieri
7f232a1168 Merge pull request #108 from wumpz/1.5.x-FeatureTypeList-backport
1.5.x feature type list backport this time with the right target branch
2013-10-19 10:50:42 -07:00
wumpz
500043ba1f FeatureTypeList included 2013-10-18 22:11:33 +02:00
wumpz
47acfa9f1a FeatureTypeList included 2013-10-18 22:11:24 +02:00
carlo cancellieri
11a75c3ae4 fix commit for #105. add integration tests 2013-10-18 16:09:09 +02:00
carlo cancellieri
0c6823057b close #105. add getVersion capabilities 2013-10-18 14:35:50 +02:00
etj
a610bc3de9 RESTLayer: provide workspace info in default style. Close #100. 2013-10-08 11:49:56 +02:00
Carlo Cancellieri
71b46e2745 Merge pull request #99 from geosolutions-it/1.5.x-RESTFeatureTypes-attributes
fix inheritance for RESTFeatureTyle getAttribute methods
2013-09-30 08:00:31 -07:00
carlo cancellieri
8414e18ee5 fix inheritance for RESTFeatureTyle getAttribute methods
Conflicts:

	src/main/java/it/geosolutions/geoserver/rest/decoder/RESTFeatureType.java
	src/main/java/it/geosolutions/geoserver/rest/decoder/RESTResource.java
2013-09-30 16:34:21 +02:00
Carlo Cancellieri
539edf5429 Merge pull request #97 from eblondel/1.5.x-95-keywords-decoder
1.5.x - #95 - keywords decoder
2013-09-30 05:25:46 -07:00
eblondel
fca8dd65bc #95 - add keyword decoder + ResourceDecoderTest 2013-09-30 14:13:38 +02:00
Carlo Cancellieri
cc206bc730 Merge pull request #86 from eblondel/1.5.x-84-GSLayerEncoder-multiple-styles
#84 - 1.5.x - support encoding of multiple styles + tests
2013-07-05 00:27:00 -07:00
eblondel
93b4aa8041 #84 - 1.5.x - support encoding of multiple styles + tests 2013-07-05 08:21:54 +02:00
carlo cancellieri
c61a5055cd port: simplify the publisher 2013-07-02 16:49:31 +02:00
Carlo Cancellieri
124b2b9aca Merge pull request #83 from eblondel/1.5.x-81-DatastoreEncoder-EstimatedExtends-fix
#81 - 1.5.x - fix PostGIS / OracleNG Estimated extends param
2013-06-25 06:26:00 -07:00
eblondel
ee6b428e63 #81 - 1.5.x - fix PostGIS / OracleNG Estimated extends param 2013-06-25 14:04:20 +02:00
etj
c9d181e473 Back to SNAPSHOT version 2013-06-18 15:18:03 +02:00
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
74 changed files with 6410 additions and 825 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-SNAPSHOT</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;
@ -370,8 +371,7 @@ public class GeoServerRESTPublisher {
sUrl += "?name=" + encode(name);
}
LOGGER.debug("POSTing new style " + name + " to " + sUrl);
String result = HTTPUtils
.post(sUrl, sldFile, "application/vnd.ogc.sld+xml", gsuser, gspass);
String result = HTTPUtils.post(sUrl, sldFile, Format.SLD.getContentType(), gsuser, gspass);
return result != null;
}
@ -512,7 +512,7 @@ public class GeoServerRESTPublisher {
* @return
*/
public static String getTypeName(StoreType type) {
return StoreType.getTypeNameWithFormat(type,Format.XML);
return StoreType.getTypeNameWithFormat(type, Format.XML);
}
/**
@ -551,9 +551,9 @@ public class GeoServerRESTPublisher {
* @return "featureTypes.{xml|html|...}" for DATASTORES, "coverages.{xml|html|...}" otherwise.
*/
public static String getTypeNameWithFormat(StoreType type, Format format) {
return getTypeName(type)+"."+format;
return getTypeName(type) + "." + format;
}
/**
* Get the type name of a StoreType with the specified format.
*
@ -562,9 +562,9 @@ public class GeoServerRESTPublisher {
* @return "featuretypes.{xml|html|...}" for DATASTORES, "coverages.{xml|html|...}" otherwise.
*/
public String getTypeNameWithFormat(Format format) {
return getTypeName(this).toLowerCase()+"."+format;
return getTypeName(this).toLowerCase() + "." + format;
}
/**
* Get the type name of a StoreType.
*
@ -581,17 +581,43 @@ public class GeoServerRESTPublisher {
return "coverages";
}
}
/**
* 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.
*/
@ -747,7 +773,7 @@ public class GeoServerRESTPublisher {
ParameterConfigure configure, NameValuePair... params) throws FileNotFoundException,
IllegalArgumentException {
if (workspace == null || dsType == null || storeName == null || method == null
| extension == null || mimeType == null || uri == null) {
|| extension == null || mimeType == null || uri == null) {
throw new IllegalArgumentException("Null argument");
}
StringBuilder sbUrl = new StringBuilder(restURL).append("/rest/workspaces/")
@ -1341,7 +1367,17 @@ public class GeoServerRESTPublisher {
return null;
}
}
/**
* 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.
*/
@ -1514,7 +1550,14 @@ public class GeoServerRESTPublisher {
coverageEncoder.setName(coverageName);
coverageEncoder.setTitle(coverageName);
coverageEncoder.setSRS(srs);
coverageEncoder.setNativeFormat("GeoTIFF");
coverageEncoder.addSupportedFormats("GEOTIFF");
coverageEncoder.addKeyword("geoTiff");
coverageEncoder.addKeyword("WCS");
coverageEncoder.setNativeCRS(srs);
coverageEncoder.setProjectionPolicy(policy);
coverageEncoder.setRequestSRS(srs);
coverageEncoder.setResponseSRS(srs);
if (bbox != null && bbox.length == 4) {
coverageEncoder.setLatLonBoundingBox(bbox[0], bbox[1], bbox[2], bbox[3], DEFAULT_CRS);
}
@ -1971,32 +2014,7 @@ public class GeoServerRESTPublisher {
*/
public boolean removeDatastore(String workspace, String storename, final boolean recurse)
throws IllegalArgumentException {
try {
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 StringBuilder url = new StringBuilder(restURL);
url.append("/rest/workspaces/").append(workspace).append("/datastores/")
.append(storename);
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 datastore " + workspace + ":" + storename);
} else {
LOGGER.info("Datastore successfully deleted " + workspace + ":" + storename);
}
return deleted;
} catch (MalformedURLException ex) {
if (LOGGER.isErrorEnabled())
LOGGER.error(ex.getLocalizedMessage(), ex);
return false;
}
return removeStore(workspace, storename, StoreType.DATASTORES, recurse);
}
/**
@ -2008,13 +2026,7 @@ public class GeoServerRESTPublisher {
* @deprecated use {@link #removeCoverageStore(String, String, boolean)}
*/
public boolean removeCoverageStore(String workspace, String storename) {
try {
return removeCoverageStore(workspace, storename, true);
} catch (IllegalArgumentException e) {
if (LOGGER.isErrorEnabled())
LOGGER.error("Arguments may not be null or empty!", e);
}
return false;
return removeCoverageStore(workspace, storename, true);
}
/**
@ -2027,6 +2039,21 @@ public class GeoServerRESTPublisher {
*/
public boolean removeCoverageStore(final String workspace, final String storename,
final boolean recurse) throws IllegalArgumentException {
return removeStore(workspace, storename, StoreType.COVERAGESTORES, recurse);
}
/**
* Remove a given Datastore in a given Workspace.
*
* @param workspace The name of the workspace
* @param storename The name of the Datastore to remove.
* @param the {@link StoreType} type
* @param recurse if remove should be performed recursively
* @throws IllegalArgumentException if workspace or storename are null or empty
* @return <TT>true</TT> if the store was successfully removed.
*/
private boolean removeStore(String workspace, String storename, StoreType type,
final boolean recurse) throws IllegalArgumentException {
try {
if (workspace == null || storename == null)
throw new IllegalArgumentException("Arguments may not be null!");
@ -2034,7 +2061,7 @@ public class GeoServerRESTPublisher {
throw new IllegalArgumentException("Arguments may not be empty!");
final StringBuilder url = new StringBuilder(restURL);
url.append("/rest/workspaces/").append(workspace).append("/coveragestores/")
url.append("/rest/workspaces/").append(workspace).append("/").append(type).append("/")
.append(storename);
if (recurse)
url.append("?recurse=true");
@ -2042,12 +2069,12 @@ public class GeoServerRESTPublisher {
boolean deleted = HTTPUtils.delete(deleteStore.toExternalForm(), gsuser, gspass);
if (!deleted) {
LOGGER.warn("Could not delete CoverageStore " + workspace + ":" + storename);
LOGGER.warn("Could not delete store " + workspace + ":" + storename);
} else {
LOGGER.info("CoverageStore successfully deleted " + workspace + ":" + storename);
LOGGER.info("Store successfully deleted " + workspace + ":" + storename);
}
return deleted;
return deleted;
} catch (MalformedURLException ex) {
if (LOGGER.isErrorEnabled())
LOGGER.error(ex.getLocalizedMessage(), ex);
@ -2064,13 +2091,7 @@ public class GeoServerRESTPublisher {
* @deprecated {@link #removeWorkspace(String, boolean)}
*/
public boolean removeWorkspace(String workspace) {
try {
return removeWorkspace(workspace, false);
} catch (IllegalArgumentException e) {
if (LOGGER.isErrorEnabled())
LOGGER.error("Arguments may not be null or empty!", e);
}
return false;
return removeWorkspace(workspace, false);
}
/**
@ -2114,12 +2135,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())
@ -2137,6 +2166,16 @@ public class GeoServerRESTPublisher {
}
}
/**
* Remove a layer group.
*
* @param name the layer group name.
* @return true if succeeded.
*/
public boolean removeLayerGroup(String name) {
return removeLayerGroup(null, name);
}
/**
* remove a generic given layer from a given workspace
*
@ -2206,17 +2245,17 @@ public class GeoServerRESTPublisher {
final String store = HTTPUtils.get(url, this.gsuser, this.gspass);
if (store != null) {
String storeTag=storeType.getTypeName();
// switch (storeType) {
// case COVERAGESTORES:
// storeTag = storeType.toString().replaceAll("store", "");
// break;
// case DATASTORES:
// storeTag = "featureTypes";
// break;
// default:
// throw new IllegalArgumentException("Unrecognized type");
// }
String storeTag = storeType.getTypeName();
// switch (storeType) {
// case COVERAGESTORES:
// storeTag = storeType.toString().replaceAll("store", "");
// break;
// case DATASTORES:
// storeTag = "featureTypes";
// break;
// default:
// throw new IllegalArgumentException("Unrecognized type");
// }
String startTag = "<" + storeTag + ">";
int start = store.indexOf(startTag);
@ -2298,6 +2337,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
*
@ -2400,7 +2522,7 @@ public class GeoServerRESTPublisher {
*
* configured - Only setup or configured feature types are returned. This is the default value. available - Only unconfigured feature types
* (not yet setup) but are available from the specified datastore will be returned. available_with_geom - Same as available but only
* includes feature types that have a geometry attribute. all - The union of configured and available.
* includes feature types that have a geometry granule. all - The union of configured and available.
*
*
* @return true if success

View File

@ -32,7 +32,9 @@ import it.geosolutions.geoserver.rest.decoder.RESTCoverageStoreList;
import it.geosolutions.geoserver.rest.decoder.RESTDataStore;
import it.geosolutions.geoserver.rest.decoder.RESTDataStoreList;
import it.geosolutions.geoserver.rest.decoder.RESTFeatureType;
import it.geosolutions.geoserver.rest.decoder.RESTFeatureTypeList;
import it.geosolutions.geoserver.rest.decoder.RESTLayer;
import it.geosolutions.geoserver.rest.decoder.RESTLayer21;
import it.geosolutions.geoserver.rest.decoder.RESTLayerGroup;
import it.geosolutions.geoserver.rest.decoder.RESTLayerGroupList;
import it.geosolutions.geoserver.rest.decoder.RESTLayerList;
@ -41,6 +43,7 @@ import it.geosolutions.geoserver.rest.decoder.RESTNamespaceList;
import it.geosolutions.geoserver.rest.decoder.RESTResource;
import it.geosolutions.geoserver.rest.decoder.RESTStyleList;
import it.geosolutions.geoserver.rest.decoder.RESTWorkspaceList;
import it.geosolutions.geoserver.rest.decoder.about.GSVersionDecoder;
import java.net.MalformedURLException;
import java.net.URL;
@ -166,6 +169,21 @@ public class GeoServerRESTReader {
public boolean existGeoserver() {
return HTTPUtils.httpPing(baseurl + "/rest/", username, password);
}
/**
* Return the version of the target GeoServer
*/
public GSVersionDecoder getGeoserverVersion() {
final String url = "/rest/about/version.xml";
String xml = load(url);
if (xml == null) {
GSVersionDecoder v = new GSVersionDecoder();
v.getGeoServer().setVersion(GSVersionDecoder.VERSION.UNRECOGNIZED.toString());
return v;
} else {
return GSVersionDecoder.build(load(url));
}
}
//==========================================================================
//=== STYLES
@ -396,12 +414,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 +436,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
//==========================================================================
@ -438,9 +491,24 @@ public class GeoServerRESTReader {
}
return RESTLayerList.build(load(url));
}
/**
* Get summary info about all FeatureTypes of a workspace.
*
* @return summary info about Layers as a {@link RESTLayerList}
*/
public RESTFeatureTypeList getFeatureTypes(String workspace) {
String url = "/rest/workspaces/" + workspace + "/featuretypes.xml";
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("### Retrieving featuretypes from " + url);
}
return RESTFeatureTypeList.build(load(url));
}
/**
* 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 +521,33 @@ 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);
}
RESTLayer layer = null;
if (this.getGeoserverVersion().getVersion()
.equals(GSVersionDecoder.VERSION.UNRECOGNIZED)) {
layer = RESTLayer21.build(load(url));
} else {
layer = RESTLayer.build(load(url));
}
return layer;
}
//==========================================================================
//=== NAMESPACES
//==========================================================================

View File

@ -27,8 +27,14 @@ package it.geosolutions.geoserver.rest.decoder;
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
import it.geosolutions.geoserver.rest.decoder.utils.JDOMListIterator;
import it.geosolutions.geoserver.rest.encoder.feature.FeatureTypeAttribute;
import it.geosolutions.geoserver.rest.encoder.feature.GSAttributeEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.jdom.Element;
/**
@ -244,4 +250,50 @@ public class RESTFeatureType extends RESTResource {
}
};
}
/**
* @return
*/
public List<Map<FeatureTypeAttribute, String>> getAttributeList() {
List<Map<FeatureTypeAttribute, String>> attrsList = null;
final Element attrsRoot = rootElem.getChild("attributes");
if(attrsRoot!=null){
final List<Element> attrs = attrsRoot.getChildren();
if (attrs != null) {
attrsList = new ArrayList<Map<FeatureTypeAttribute, String>>(attrs.size());
for (Element attr : attrs) {
Map<FeatureTypeAttribute, String> attrsMap = new HashMap<FeatureTypeAttribute, String>();
attrsList.add(attrsMap);
for (FeatureTypeAttribute at : FeatureTypeAttribute.values()) {
String key = at.toString();
attrsMap.put(at, attr.getChildText(key));
}
}
}
}
return attrsList;
}
public List<GSAttributeEncoder> getEncodedAttributeList() {
List<GSAttributeEncoder> attrsList = null;
final Element attrsRoot = rootElem.getChild("attributes");
if(attrsRoot!=null){
final List<Element> attrs = attrsRoot.getChildren();
if (attrs != null) {
attrsList = new ArrayList<GSAttributeEncoder>(attrs.size());
for (Element attr : attrs) {
final GSAttributeEncoder attrEnc = new GSAttributeEncoder();
for (FeatureTypeAttribute at : FeatureTypeAttribute.values()) {
String key = at.toString();
attrEnc.setAttribute(at, attr.getChildText(key));
}
attrsList.add(attrEnc);
}
}
}
return attrsList;
}
}

View File

@ -0,0 +1,62 @@
/*
* 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.decoder;
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem;
import org.jdom.Element;
/**
* Parses list of summary data about FeatureTypes.
*
*
* FeatureType summary info.
* <BR>This is an XML fragment:
* <PRE>
*{@code
<featureType>
<name>states</name>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate"
href="http://localhost:8080/geoserver/rest/workspaces/topp/featuretypes/states.xml"
type="application/xml"/>
</featureType>
* }
* </PRE>
*
* @author wumpz
*/
public class RESTFeatureTypeList extends RESTAbstractList<NameLinkElem> {
public static RESTFeatureTypeList build(String response) {
Element elem = JDOMBuilder.buildElement(response);
return elem == null? null : new RESTFeatureTypeList(elem);
}
protected RESTFeatureTypeList(Element list) {
super(list);
}
}

View File

@ -25,7 +25,15 @@
package it.geosolutions.geoserver.rest.decoder;
import java.util.ArrayList;
import java.util.List;
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
import it.geosolutions.geoserver.rest.encoder.authorityurl.AuthorityURLInfo;
import it.geosolutions.geoserver.rest.encoder.authorityurl.GSAuthorityURLInfoEncoder;
import it.geosolutions.geoserver.rest.encoder.identifier.GSIdentifierInfoEncoder;
import it.geosolutions.geoserver.rest.encoder.identifier.IdentifierInfo;
import org.jdom.Element;
import org.jdom.Namespace;
@ -48,16 +56,31 @@ import org.jdom.Namespace;
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/workspaces/topp/datastores/taz_shapes/featuretypes/tasmania_cities.xml" type="application/xml"/>
</resource>
<enabled>true</enabled>
<queryable>true</queryable>
<advertised>true</advertised>
<attribution>
<logoWidth>0</logoWidth>
<logoHeight>0</logoHeight>
</attribution>
<authorityURLs>
<AuthorityURL>
<name>authority1</name>
<href>http://www.authority1.org</href>
</AuthorityURL>
</authorityURLs>
<identifiers>
<Identifier>
<authority>authority1</authority>
<identifier>identifier1</identifier>
</Identifier>
</identifiers>
</layer>
* }</PRE>
* @author etj
* @author eblondel
*/
public class RESTLayer {
private final Element layerElem;
protected final Element layerElem;
public enum Type {
VECTOR("VECTOR"),
@ -96,6 +119,18 @@ public class RESTLayer {
this.layerElem = layerElem;
}
public boolean getEnabled() {
return Boolean.parseBoolean(layerElem.getChildText("enabled"));
}
public boolean getQueryable() {
return Boolean.parseBoolean(layerElem.getChildText("queryable"));
}
public boolean getAdvertised() {
return Boolean.parseBoolean(layerElem.getChildText("advertised"));
}
public String getName() {
return layerElem.getChildText("name");
}
@ -113,6 +148,14 @@ public class RESTLayer {
return defaultStyle == null? null : defaultStyle.getChildText("name");
}
/**
* @see <a href="https://github.com/geosolutions-it/geoserver-manager/issues/100">this issue</a>
*/
public String getDefaultStyleWorkspace() {
Element defaultStyle = layerElem.getChild("defaultStyle");
return defaultStyle == null? null : defaultStyle.getChildText("workspace");
}
public String getTitle() {
Element resource = layerElem.getChild("resource");
return resource.getChildText("title");
@ -159,6 +202,60 @@ public class RESTLayer {
return atom.getAttributeValue("href");
}
/**
* Decodes the list of AuthorityURLInfo from the GeoServer Layer
*
* @return the list of GSAuthorityURLInfoEncoder
*/
public List<GSAuthorityURLInfoEncoder> getEncodedAuthorityURLInfoList() {
List<GSAuthorityURLInfoEncoder> authorityURLList = null;
final Element authorityURLsRoot = layerElem.getChild("authorityURLs");
if (authorityURLsRoot != null) {
final List<Element> authorityURLs = authorityURLsRoot.getChildren();
if (authorityURLs != null) {
authorityURLList = new ArrayList<GSAuthorityURLInfoEncoder>(
authorityURLs.size());
for (Element authorityURL : authorityURLs) {
final GSAuthorityURLInfoEncoder authEnc = new GSAuthorityURLInfoEncoder();
authEnc.setName(authorityURL
.getChildText(AuthorityURLInfo.name.name()));
authEnc.setHref(authorityURL
.getChildText(AuthorityURLInfo.href.name()));
authorityURLList.add(authEnc);
}
}
}
return authorityURLList;
}
/**
* Decodes the list of IdentifierInfo from the GeoServer Layer
*
* @return the list of IdentifierInfoEncoder
*/
public List<GSIdentifierInfoEncoder> getEncodedIdentifierInfoList() {
List<GSIdentifierInfoEncoder> idList = null;
final Element idRoot = layerElem.getChild("identifiers");
if (idRoot != null) {
final List<Element> identifiers = idRoot.getChildren();
if (identifiers != null) {
idList = new ArrayList<GSIdentifierInfoEncoder>(
identifiers.size());
for (Element identifier : identifiers) {
final GSIdentifierInfoEncoder idEnc = new GSIdentifierInfoEncoder();
idEnc.setAuthority(identifier
.getChildText(IdentifierInfo.authority.name()));
idEnc.setIdentifier(identifier
.getChildText(IdentifierInfo.identifier.name()));
idList.add(idEnc);
}
}
}
return idList;
}
// protected double getLatLonEdge(String edge) {
// Element resource = layerElem.getChild("resource");
// Element elBBox = resource.getChild("latLonBoundingBox");

View File

@ -0,0 +1,175 @@
package it.geosolutions.geoserver.rest.decoder;
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
import it.geosolutions.geoserver.rest.encoder.authorityurl.GSAuthorityURLInfoEncoder;
import it.geosolutions.geoserver.rest.encoder.identifier.GSIdentifierInfoEncoder;
import java.util.ArrayList;
import java.util.List;
import org.jdom.Element;
/**
* Parse <TT>Layer</TT>s returned as XML REST objects. Applicable to GS 2.1 for
* decoding: - AuthorityURLs - Identifiers - advertised property value
*
* <P>
* This is the XML REST representation:
*
* <PRE>
* {@code
* <layer>
* <name>tasmania_cities</name>
* <path>/</path>
* <type>VECTOR</type>
* <defaultStyle>
* <name>capitals</name>
* <atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/styles/capitals.xml" type="application/xml"/>
* </defaultStyle>
* <resource class="featureType">
* <name>tasmania_cities</name>
* <atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/workspaces/topp/datastores/taz_shapes/featuretypes/tasmania_cities.xml" type="application/xml"/>
* </resource>
* <enabled>true</enabled>
* <queryable>true</queryable>
* <advertised>true</advertised>
* <attribution>
* <logoWidth>0</logoWidth>
* <logoHeight>0</logoHeight>
* </attribution>
* <metadata>
* <entry key="identifiers">
* [{"authority":"authority1","identifier":"identifier1"},]
* </entry>
* <entry key="authorityURLs">
* [{"name":"authority1","href":"http://www.authority1.org"},]
* </entry>
* <entry key="advertised">true</entry>
* </metadata>
* </layer>
* }
* </PRE>
*
* @author eblondel
*/
public class RESTLayer21 extends RESTLayer {
public RESTLayer21(Element layerElem) {
super(layerElem);
}
public static RESTLayer21 build(String response) {
if (response == null)
return null;
Element pb = JDOMBuilder.buildElement(response);
if (pb != null)
return new RESTLayer21(pb);
else
return null;
}
/**
* Decodes the advertised property from the Geoserver Layer
*
*/
public boolean getAdvertised() {
boolean advertised = true;
final Element metadataRoot = layerElem.getChild("metadata");
if (metadataRoot != null) {
final List<Element> metaElements = metadataRoot.getChildren();
if (metaElements != null) {
for (Element el : metaElements) {
String key = el.getAttributeValue("key");
if (key.matches("advertised")) {
advertised = Boolean.parseBoolean(el.getValue());
}
}
}
}
return advertised;
}
/**
* Decodes the list of AuthorityURLInfo from the GeoServer Layer
*
* @return the list of GSAuthorityURLInfoEncoder
*/
public List<GSAuthorityURLInfoEncoder> getEncodedAuthorityURLInfoList() {
List<GSAuthorityURLInfoEncoder> authorityURLList = null;
final Element metadataRoot = layerElem.getChild("metadata");
if (metadataRoot != null) {
final List<Element> metaElements = metadataRoot.getChildren();
if (metaElements != null) {
for (Element element : metaElements) {
String key = element.getAttributeValue("key");
if (key.matches("authorityURLs")) {
String jsonStr = element.getValue();
jsonStr = jsonStr.substring(2);
jsonStr = jsonStr.substring(0, jsonStr.length() - 3);
String[] items = jsonStr.split("\\}(,)\\{");
authorityURLList = new ArrayList<GSAuthorityURLInfoEncoder>(
items.length);
for (String item : items) {
String[] props = item.split(",");
String[] kvp1 = props[0].split("\":");
String name = kvp1[1].replace("\"", "");
String[] kvp2 = props[1].split("\":");
String href = kvp2[1].replace("\"", "");
authorityURLList.add(new GSAuthorityURLInfoEncoder(
name, href));
}
}
}
}
}
return authorityURLList;
}
/**
* Decodes the list of IdentifierInfo from the GeoServer Layer
*
* @return the list of IdentifierInfoEncoder
*/
public List<GSIdentifierInfoEncoder> getEncodedIdentifierInfoList() {
List<GSIdentifierInfoEncoder> identifierList = null;
final Element metadataRoot = layerElem.getChild("metadata");
if (metadataRoot != null) {
final List<Element> metaElements = metadataRoot.getChildren();
if (metaElements != null) {
for (Element element : metaElements) {
String key = element.getAttributeValue("key");
if (key.matches("identifiers")) {
String jsonStr = element.getValue();
jsonStr = jsonStr.substring(2);
jsonStr = jsonStr.substring(0, jsonStr.length() - 3);
String[] items = jsonStr.split("\\}(,)\\{");
identifierList = new ArrayList<GSIdentifierInfoEncoder>(
items.length);
for (String item : items) {
String[] props = item.split(",");
String[] kvp1 = props[0].split("\":");
String authority = kvp1[1].replace("\"", "");
String[] kvp2 = props[1].split("\":");
String identifier = kvp2[1].replace("\"", "");
identifierList.add(new GSIdentifierInfoEncoder(
authority, identifier));
}
}
}
}
}
return identifierList;
}
}

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;
@ -69,6 +71,22 @@ public class RESTResource {
public String getAbstract() {
return rootElem.getChildText("abstract");
}
public List<String> getKeywords(){
List<String> kwdsList = null;
final Element keywordsRoot = rootElem.getChild("keywords");
if(keywordsRoot != null){
final List<Element> keywords = keywordsRoot.getChildren();
if(keywords != null){
kwdsList = new ArrayList<String>(keywords.size());
for(Element keyword : keywords){
kwdsList.add(keyword.getValue());
}
}
}
return kwdsList;
}
public String getNameSpace() {
return rootElem.getChild("namespace").getChildText("name");
@ -115,82 +133,48 @@ public class RESTResource {
return getLatLonEdge("maxy");
}
/**
* @deprecated use {@link RESTFeatureType#getAttributeList()}
* @return
* @throws UnsupportedOperationException
*/
public List<Map<FeatureTypeAttribute, String>> getAttributeList() {
List<Map<FeatureTypeAttribute, String>> attrsList = null;
final Element attrsRoot = rootElem.getChild("attributes");
final List<Element> attrs = attrsRoot.getChildren();
if (attrs != null) {
attrsList = new ArrayList<Map<FeatureTypeAttribute, String>>(attrs.size());
for (Element attr : attrs) {
Map<FeatureTypeAttribute, String> attrsMap = new HashMap<FeatureTypeAttribute, String>();
attrsList.add(attrsMap);
for (FeatureTypeAttribute at : FeatureTypeAttribute.values()) {
String key = at.toString();
attrsMap.put(at, attr.getChildText(key));
}
}
}
return attrsList;
throw new UnsupportedOperationException("This method is specific for RESTFeatureType");
}
/**
* @deprecated use {@link RESTFeatureType#getEncodedAttributeList()}
* @return
* @throws UnsupportedOperationException
*/
public List<GSAttributeEncoder> getEncodedAttributeList() {
List<GSAttributeEncoder> attrsList = null;
final Element attrsRoot = rootElem.getChild("attributes");
final List<Element> attrs = attrsRoot.getChildren();
if (attrs != null) {
attrsList = new ArrayList<GSAttributeEncoder>(attrs.size());
for (Element attr : attrs) {
final GSAttributeEncoder attrEnc = new GSAttributeEncoder();
for (FeatureTypeAttribute at : FeatureTypeAttribute.values()) {
String key = at.toString();
attrEnc.setAttribute(at, attr.getChildText(key));
}
attrsList.add(attrEnc);
}
}
return attrsList;
throw new UnsupportedOperationException("This method is specific for RESTFeatureType");
}
// /**
// * @return the list of available attribute names
// */
// public List<String> getAttributeNames() {
// return getAttributes("name");
// }
//
// /**
// * @return a list of object which are String representation of Classes
// */
// public List<String> getAttributeBinding() {
// return getAttributes("binding");
// }
/**
* Decodes the list of MetadataLinkInfo from the GeoServer Resource
*
* @return the list of GSMetadataLinkEncoder
*/
public List<GSMetadataLinkInfoEncoder> getEncodedMetadataLinkInfoList() {
List<GSMetadataLinkInfoEncoder> metaLinksList = null;
// /**
// * <attribute><br>
// * <name>NATION</name><br>
// * <minOccurs>0</minOccurs><br>
// * <maxOccurs>1</maxOccurs><br>
// * <nillable>true</nillable><br>
// * <binding>java.lang.Integer</binding><br>
// * <length>3</length><br>
// * </attribute><br>
// *
// * @param name
// * @return
// */
// private List<String> getAttributes(String name) {
// final Element attrsRoot = rootElem.getChild("attributes");
// final List<Element> attrs = attrsRoot.getChildren();
// List<String> attrNames = null;
// if (attrs != null) {
// attrNames = new ArrayList<String>(attrs.size());
// for (Element attr : attrs) {
// attrNames.add(attr.getChildText(name));
// }
// }
// return attrNames;
// }
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;
}
}

View File

@ -0,0 +1,180 @@
/*
* 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.decoder.about;
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
import it.geosolutions.geoserver.rest.encoder.utils.XmlElement;
import org.jdom.Attribute;
import org.jdom.Element;
/**
* Encode an XML for about/version.xml
*
*
*
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
*
*/
public class GSVersionDecoder extends XmlElement {
public final static String ABOUT = "about";
private GSAboutResource geoserver;
public class GSAboutResource extends XmlElement {
public final static String RESOURCE = "resource";
public final static String NAME = "name";
public final static String VERSION = "Version";
private Element version;
public GSAboutResource() {
create();
}
private void create(){
setRoot(RESOURCE);
version = new Element(VERSION);
addContent(version);
}
public void setName(String name) {
final Attribute _name = this.getRoot().getAttribute(GSAboutResource.NAME);
if (name!=null)
_name.setValue(name);
else
this.getRoot().setAttribute(GSAboutResource.NAME, name);
}
public String getName() {
final Attribute name = this.getRoot().getAttribute(GSAboutResource.NAME);
if (name!=null)
return name.getValue();
else
return null;
}
public GSAboutResource(Element el) {
super();
if (el!=null){
setRoot(el);
version = ElementUtils.contains(el, GSAboutResource.VERSION);
} else {
create();
setVersion(GSVersionDecoder.VERSION.UNRECOGNIZED.toString());
}
}
public void setVersion(String v){
version.setText(v);
}
}
/**
* Load the string representation into this encoder
*
* @param document
*/
public GSVersionDecoder(String document) {
Element root=JDOMBuilder.buildElement(document);
if (root!=null){
setRoot(root);
geoserver = new GSAboutResource(ElementUtils.contains(this.getRoot(),
GSAboutResource.RESOURCE));
}else {
create();
}
}
public GSVersionDecoder() {
create();
}
private void create(){
setRoot("about");
geoserver = new GSAboutResource();
addContent(geoserver.getRoot());
}
public GSAboutResource getGeoServer(){
return geoserver;
}
public VERSION getVersion() {
Element e = ElementUtils.contains(geoserver.version, GSAboutResource.VERSION);
return VERSION.getVersion(e.getTextTrim());
}
public static GSVersionDecoder build(String response) {
return new GSVersionDecoder(response);
}
public enum VERSION {
v22(22), v23(23), v24(24), v25(25), ABOVE(9999), UNRECOGNIZED(-1);
final private int version;
private VERSION(int val) {
version = val;
}
public int getVersion() {
return version;
}
public String toString(){
return Integer.toString(version);
}
public static VERSION getVersion(String v) {
if (v==null) {
return UNRECOGNIZED;
} else if (v.matches("2\\.2.*")) {
return v22;
} else if (v.matches("2\\.3.*")) {
return v23;
} else if (v.matches("2\\.4.*")) {
return v24;
} else if (v.matches("2\\.5.*")) {
return v25;
} else if (v.matches("2\\..+")) {
return ABOVE;
} else {
return UNRECOGNIZED;
}
}
public static String print(){
return "["+v22+", "+v23+", "+v24+", "+v25+", "+ABOVE+", "+UNRECOGNIZED+"]";
}
}
}

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

@ -26,22 +26,39 @@
package it.geosolutions.geoserver.rest.encoder;
import org.jdom.Element;
import org.jdom.filter.Filter;
import it.geosolutions.geoserver.rest.encoder.authorityurl.GSAuthorityURLInfoEncoder;
import it.geosolutions.geoserver.rest.encoder.identifier.GSIdentifierInfoEncoder;
import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder;
/**
*
* Layer encoder for Geoserver >= 2.2
*
* @author ETj (etj at geo-solutions.it)
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com |
* emmanuel.blondel@fao.org
*
* The layer encoder is enabled by default
*
*/
public class GSLayerEncoder extends PropertyXMLEncoder {
public final static String STYLES = "styles";
public final static String AUTHORITY_URLS="authorityURLs";
public final static String IDENTIFIERS="identifiers";
final private Element stylesEncoder = new Element(STYLES);
final private Element authorityURLListEncoder = new Element(AUTHORITY_URLS);
final private Element identifierListEncoder = new Element(IDENTIFIERS);
public GSLayerEncoder() {
super("layer");
addEnabled();
addContent(stylesEncoder);
addContent(authorityURLListEncoder);
addContent(identifierListEncoder);
}
/**
@ -130,4 +147,90 @@ public class GSLayerEncoder extends PropertyXMLEncoder {
throw new IllegalArgumentException("Unable to set an empty or null parameter");
set("defaultStyle", defaultStyle);
}
/**
* Adds a style
*
* @param style
*/
public void addStyle(String style) {
final Element el = new Element("style");
el.setText(style);
stylesEncoder.addContent(el);
}
/**
* delete a style from the list
*
* @param style
* @return true if something is removed, false otherwise
*/
public boolean delStyle(final String style) {
final Element el = new Element("style");
el.setText(style);
return (stylesEncoder.removeContent(new Filter() {
private static final long serialVersionUID = 1L;
public boolean matches(Object obj) {
if (((Element) obj).getText().equals(style)) {
return true;
}
return false;
}
})).size() == 0 ? false : true;
}
/**
*
* @param advertised
* true if the layer should be advertised
*/
public void setAdvertised(boolean advertised) {
if (advertised)
set("advertised", "true");
else
set("advertised", "false");
}
/**
* Add an authorityURLInfo to the GeoServer layer
*
* @param authorityURLInfo
*/
public void addAuthorityURL(GSAuthorityURLInfoEncoder authorityURLInfo) {
authorityURLListEncoder.addContent(authorityURLInfo.getRoot());
}
/**
* Deletes a AuthorityURLInfo from the list using the authorityURL
* (AuthorityURLInfo href)
*
* @param authorityURL
* @return true if something is removed, false otherwise
*/
public boolean delAuthorityURL(final String authorityURL) {
return (authorityURLListEncoder.removeContent(GSAuthorityURLInfoEncoder
.getFilterByHref(authorityURL))).size() == 0 ? false : true;
}
/**
* Add an identifierInfo to the GeoServer layer
*
* @param identifierInfo
*/
public void addIdentifier(GSIdentifierInfoEncoder identifierInfo) {
identifierListEncoder.addContent(identifierInfo.getRoot());
}
/**
* Deletes a IdentifierInfo from the list using the authority name
* (IdentifierInfo authority)
*
* @param authority
* @return true if something is removed, false otherwise
*/
public boolean delIdentifier(final String authority) {
return (identifierListEncoder.removeContent(GSIdentifierInfoEncoder
.getFilterByHref(authority))).size() == 0 ? false : true;
}
}

View File

@ -0,0 +1,209 @@
/*
* 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;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import it.geosolutions.geoserver.rest.encoder.authorityurl.AuthorityURLInfo;
import it.geosolutions.geoserver.rest.encoder.authorityurl.GSAuthorityURLInfoEncoder;
import it.geosolutions.geoserver.rest.encoder.identifier.GSIdentifierInfoEncoder;
import it.geosolutions.geoserver.rest.encoder.identifier.IdentifierInfo;
import it.geosolutions.geoserver.rest.encoder.utils.NestedElementEncoder;
import it.geosolutions.geoserver.rest.encoder.utils.XmlElement;
/**
* Layer encoder for Geoserver = 2.1
*
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com
*
* The layer encoder is enabled by default
*
*/
public class GSLayerEncoder21 extends GSLayerEncoder {
public final static String METADATA = "metadata";
final private GSMetadataEncoder metadata = new GSMetadataEncoder();
public Map<String, String> authorityURLList;
public Map<String, List<String>> identifierList;
private class GSMetadataEncoder extends NestedElementEncoder {
public GSMetadataEncoder() {
super(METADATA);
}
}
public GSLayerEncoder21() {
super();
addContent(metadata.getRoot());
addAdvertised();
}
/**
* @param key
* @param dimensionInfo
*/
protected void addMetadata(String key, XmlElement dimensionInfo) {
metadata.add(key, dimensionInfo.getRoot());
}
/**
* advertise the layer
*/
protected void addAdvertised() {
metadata.add("advertised", "true");
}
/**
*
* @param advertised
* true if the layer should be advertised
*/
public void setAdvertised(boolean advertised) {
if (advertised) {
metadata.add("advertised", "true");
} else {
metadata.add("advertised", "false");
}
}
/**
* Add an authorityURLInfo to the GeoServer layer
*
* @param authorityURLInfo
*/
public void addAuthorityURL(GSAuthorityURLInfoEncoder authorityURLInfo) {
if (authorityURLList == null) {
authorityURLList = new HashMap<String, String>();
}
authorityURLList.put(authorityURLInfo.getHref(),
authorityURLInfo.getName());
String jsonStr = "";
for (Entry<String, String> entry : authorityURLList.entrySet()) {
jsonStr += "{" + "\"" + AuthorityURLInfo.name.name() + "\":\""
+ entry.getValue() + "\"," + "\""
+ AuthorityURLInfo.href.name() + "\":\"" + entry.getKey()
+ "\"" + "},";
}
metadata.set("authorityURLs", "[" + jsonStr + "]");
}
/**
* Deletes a AuthorityURLInfo from the list using the authorityURL
* (AuthorityURLInfo href)
*
* @param authorityURL
* @return true if something is removed, false otherwise
*/
public boolean delAuthorityURL(final String authorityURL) {
boolean delete = false;
if (!(authorityURLList == null || authorityURLList.isEmpty())) {
if (authorityURLList.containsKey(authorityURL)) {
identifierList.remove(authorityURL);
String jsonStr = "";
for (Entry<String, List<String>> entry : identifierList
.entrySet()) {
for (String value : entry.getValue()) {
jsonStr += "{" + "\"" + AuthorityURLInfo.name.name()
+ "\":\"" + value + "\"," + "\""
+ AuthorityURLInfo.href.name() + "\":\""
+ entry.getKey() + "\"" + "},";
}
}
metadata.set("identifiers", "[" + jsonStr + "]");
delete = true;
}
}
return delete;
}
/**
* Add an identifierInfo to the GeoServer layer
*
* @param identifierInfo
*/
public void addIdentifier(GSIdentifierInfoEncoder identifierInfo) {
if (identifierList == null) {
identifierList = new HashMap<String, List<String>>();
}
String authority = identifierInfo.getAuthority();
if (!identifierList.containsKey(authority)) {
List<String> ids = new ArrayList<String>();
ids.add(identifierInfo.getIdentifier());
identifierList.put(authority, ids);
} else {
List<String> ids = identifierList.get(authority);
ids.add(identifierInfo.getIdentifier());
identifierList.put(authority, ids);
}
String jsonStr = "";
for (Entry<String, List<String>> entry : identifierList.entrySet()) {
for (String value : entry.getValue()) {
jsonStr += "{" + "\"" + IdentifierInfo.authority.name()
+ "\":\"" + entry.getKey() + "\"," + "\""
+ IdentifierInfo.identifier.name() + "\":\"" + value
+ "\"" + "},";
}
}
metadata.set("identifiers", "[" + jsonStr + "]");
}
/**
* Deletes a IdentifierInfo from the list using the authority name
* (IdentifierInfo authority)
*
* @param authority
* @return true if something is removed, false otherwise
*/
public boolean delIdentifier(final String authority) {
boolean delete = false;
if (!(identifierList == null || identifierList.isEmpty())) {
if (identifierList.containsKey(authority)) {
identifierList.remove(authority);
String jsonStr = "";
for (Entry<String, List<String>> entry : identifierList
.entrySet()) {
for (String value : entry.getValue()) {
jsonStr += "{" + "\"" + IdentifierInfo.authority.name()
+ "\":\"" + entry.getKey() + "\"," + "\""
+ IdentifierInfo.identifier.name() + "\":\""
+ value + "\"" + "},";
}
}
metadata.set("identifiers", "[" + jsonStr + "]");
delete = true;
}
}
return delete;
}
}

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,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.authorityurl;
/**
* Enumeration of layer authorityURL members
*
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com |
* emmanuel.blondel@fao.org
*
*/
public enum AuthorityURLInfo {
name, href;
}

View File

@ -0,0 +1,219 @@
/*
* 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.authorityurl;
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;
/**
* GSAuthorityURLInfoEncoder - encodes an authorityURL for a given GeoServer
* layer as follows:
*
* <pre>
* {
* &#064;code
* final GSAuthorityURLInfoEncoder ae = new GSAuthorityURLInfoEncoder();
* ae.setName(&quot;an authority&quot;);
* ae.setHref(&quot;http://www.organization.org&quot;);
* }
* </pre>
*
* For this example, the XML output is:
*
* <pre>
* {@code
* <AuthorityURL>
* <name>an authority</name>
* <href>http://www.organization.org</href>
* </AuthorityURL>
* }
* </pre>
*
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com |
* emmanuel.blondel@fao.org
*
*/
public class GSAuthorityURLInfoEncoder extends XmlElement {
/**
* A class to filter the AuthorityURL by href
*
*
*/
private static class filterByHref implements Filter {
final private String key;
public filterByHref(String href) {
this.key = href;
}
private static final long serialVersionUID = 1L;
public boolean matches(Object obj) {
Element el = ((Element) obj).getChild(AuthorityURLInfo.href
.toString());
if (el != null && el.getTextTrim().equals(key)) {
return true;
}
return false;
}
}
/**
* Get a Filter using the AuthorityURLInfo href (authorityURL)
*
* @param href
* @return the filter
*/
public static Filter getFilterByHref(String href) {
return new filterByHref(href);
}
/**
* Constructs a new GSAuthorityURLInfoEncoder
*
*/
public GSAuthorityURLInfoEncoder() {
super("AuthorityURL");
}
/**
* Constructs quickly an AuthorityURL info
*
* @param name
* (required)
* @param href
* (required)
*/
public GSAuthorityURLInfoEncoder(String name, String href) {
super("AuthorityURL");
this.setup(name, href);
}
/**
* Set-up quickly an AuthorityURL info
*
* @param name
* @param href
*/
protected void setup(String name, String href) {
set(AuthorityURLInfo.name.name(), name);
set(AuthorityURLInfo.href.name(), href);
}
/**
* Set an AuthorityURLInfo member (name, href)
*
* @param type
* @param value
*/
protected void setMember(AuthorityURLInfo type, String value) {
set(type.toString(), value);
}
/**
* Set the name
*
* @param name
*/
public void setName(String name) {
this.setMember(AuthorityURLInfo.name, name);
}
/**
* Set the href
*
* @param href
*/
public void setHref(String href) {
this.setMember(AuthorityURLInfo.href, href);
}
/**
* Deletes an AuthorityURLInfo member
*
* @param type
* @return true if the AuthorityURLInfo member is removed
*/
protected boolean delMember(AuthorityURLInfo type) {
return ElementUtils.remove(this.getRoot(),
this.getRoot().getChild(type.toString()));
}
/**
* Deletes the authority name
*
* @return true if removed
*/
public boolean delName() {
return this.delMember(AuthorityURLInfo.name);
}
/**
* Deletes the href
*
* @return true if removed
*/
public boolean delHref() {
return this.delMember(AuthorityURLInfo.href);
}
/**
* Get the value of the AuthorityURLInfo member
*
* @param type
* @return the value of the AuthorityURLInfo member
*/
protected String getMember(AuthorityURLInfo type) {
Element el = this.getRoot().getChild(type.toString());
if (el != null)
return el.getTextTrim();
else
return null;
}
/**
* Get the name
*
* @return
*/
public String getName() {
return this.getMember(AuthorityURLInfo.name);
}
/**
* Get the href
*
* @return
*/
public String getHref() {
return this.getMember(AuthorityURLInfo.href);
}
}

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

@ -28,6 +28,8 @@ package it.geosolutions.geoserver.rest.encoder.coverage;
import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder;
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder;
import org.jdom.Element;
/**
* Creates an XML
@ -38,19 +40,57 @@ import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder;
*/
public class GSCoverageEncoder extends GSResourceEncoder {
final private static String NATIVE_FORMAT="nativeFormat";
final private static String SUPPORTED_FORMATS="supportedFormats";
final private static String REQUEST_SRS="requestSRS";
final private static String RESPONSE_SRS="responseSRS";
final private Element supportedFormatsListEncoder = new Element(SUPPORTED_FORMATS);
public GSCoverageEncoder() {
super("coverage");
super("coverage");
addContent(supportedFormatsListEncoder);
}
/**
* @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);
}
public void setNativeFormat(String format) {
set(NATIVE_FORMAT, format);
}
public void addSupportedFormats(String format) {
final Element el = new Element("string");
el.setText(format);
supportedFormatsListEncoder.addContent(el);
}
public void setRequestSRS(String srs) {
final Element el = new Element("string");
el.setText(srs);
set(REQUEST_SRS, el);
}
public void setResponseSRS(String srs) {
final Element el = new Element("string");
el.setText(srs);
set(RESPONSE_SRS, el);
}
}

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;
@ -43,6 +44,7 @@ public class GSOracleNGDatastoreEncoder extends GSAbstractDatastoreEncoder {
static final boolean DEFAULT_LOOSE_BBOX = true;
static final boolean DEFAULT_PREPARED_STATEMENTS = true;
static final int DEFAULT_MAX_OPEN_PREPARED_STATEMENTS = 50;
static final boolean DEFAULT_ESTIMATED_EXTENDS = false;
/**
* Create an {@value #TYPE} datastore with default connection parameters,
@ -68,6 +70,7 @@ public class GSOracleNGDatastoreEncoder extends GSAbstractDatastoreEncoder {
// Set mandatory parameter
setType(TYPE);
setDatabaseType(DEFAULT_DB_TYPE);
setDatabase(database);
// Set default values
@ -78,6 +81,7 @@ public class GSOracleNGDatastoreEncoder extends GSAbstractDatastoreEncoder {
setLooseBBox(DEFAULT_LOOSE_BBOX);
setPreparedStatements(DEFAULT_PREPARED_STATEMENTS);
setMaxOpenPreparedStatements(DEFAULT_MAX_OPEN_PREPARED_STATEMENTS);
setEstimatedExtends(DEFAULT_ESTIMATED_EXTENDS);
}
/**
@ -121,6 +125,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);
}
@ -165,6 +174,10 @@ public class GSOracleNGDatastoreEncoder extends GSAbstractDatastoreEncoder {
connectionParameters.set("Max open prepared statements", Integer.toString(maxOpenPreparedStatements));
}
public void setEstimatedExtends(boolean estimatedExtends){
connectionParameters.set("Estimated extends", Boolean.toString(estimatedExtends));
}
/**
* Check database validity.
*
@ -181,7 +194,7 @@ public class GSOracleNGDatastoreEncoder extends GSAbstractDatastoreEncoder {
/**
* @return {@value #TYPE}
*/
String getValidType() {
protected String getValidType() {
return TYPE;
}
}

View File

@ -43,7 +43,12 @@ public class GSPostGISDatastoreEncoder extends GSAbstractDatastoreEncoder {
static final boolean DEFAULT_LOOSE_BBOX = true;
static final boolean DEFAULT_PREPARED_STATEMENTS = false;
static final int DEFAULT_MAX_OPEN_PREPARED_STATEMENTS = 50;
static final boolean DEFAULT_ESTIMATED_EXTENDS = false;
/**
*
* @param name DataStore name
*/
public GSPostGISDatastoreEncoder(String name) {
super(name);
@ -59,6 +64,7 @@ public class GSPostGISDatastoreEncoder extends GSAbstractDatastoreEncoder {
setLooseBBox(DEFAULT_LOOSE_BBOX);
setPreparedStatements(DEFAULT_PREPARED_STATEMENTS);
setMaxOpenPreparedStatements(DEFAULT_MAX_OPEN_PREPARED_STATEMENTS);
setEstimatedExtends(DEFAULT_ESTIMATED_EXTENDS);
}
@ -138,10 +144,14 @@ public class GSPostGISDatastoreEncoder extends GSAbstractDatastoreEncoder {
connectionParameters.set("Max open prepared statements", Integer.toString(maxOpenPreparedStatements));
}
public void setEstimatedExtends(boolean estimatedExtends){
connectionParameters.set("Estimated extends", Boolean.toString(estimatedExtends));
}
/**
* @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,219 @@
/*
* 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.identifier;
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;
/**
* GSIdentifierInfoEncoder - encodes an Identifier for a given GeoServer layer
* as follows:
*
* <pre>
* {
* &#064;code
* final GSIdentifierInfoEncoder ie = new GSIdentifierInfoEncoder();
* ie.setAuthority(&quot;an authority&quot;);
* ie.setIdentifier(&quot;an identifier&quot;);
* }
* </pre>
*
* For this example, the XML output is:
*
* <pre>
* {@code
* <Identifier>
* <authority>an authority</authority>
* <identifier>an identifier</identifier>
* </Identifier>
* }
* </pre>
*
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com |
* emmanuel.blondel@fao.org
*
*/
public class GSIdentifierInfoEncoder extends XmlElement {
/**
* A class to filter the Idenfiers by authority
*
*
*/
private static class filterByAuthority implements Filter {
final private String key;
public filterByAuthority(String authority) {
this.key = authority;
}
private static final long serialVersionUID = 1L;
public boolean matches(Object obj) {
Element el = ((Element) obj).getChild(IdentifierInfo.authority
.toString());
if (el != null && el.getTextTrim().equals(key)) {
return true;
}
return false;
}
}
/**
* Get a Filter using the IdentifierInfo authority
*
* @param authority
* @return the filter
*/
public static Filter getFilterByHref(String authority) {
return new filterByAuthority(authority);
}
/**
* Constructs a new GSIdentifierInfoEncoder
*
*/
public GSIdentifierInfoEncoder() {
super("Identifier");
}
/**
* Constructs quickly an Identifier info
*
* @param authority
* (required)
* @param identifier
* (required)
*/
public GSIdentifierInfoEncoder(String authority, String identifier) {
super("Identifier");
this.setup(authority, identifier);
}
/**
* Set-up quickly an Identifier info
*
* @param authority
* @param identifier
*/
protected void setup(String authority, String identifier) {
set(IdentifierInfo.authority.name(), authority);
set(IdentifierInfo.identifier.name(), identifier);
}
/**
* Set an IdentifierInfo member (authority, identifier)
*
* @param type
* @param value
*/
protected void setMember(IdentifierInfo type, String value) {
set(type.toString(), value);
}
/**
* Set the authority
*
* @param authority
*/
public void setAuthority(String authority) {
this.setMember(IdentifierInfo.authority, authority);
}
/**
* Set the identifier
*
* @param identifier
*/
public void setIdentifier(String identifier) {
this.setMember(IdentifierInfo.identifier, identifier);
}
/**
* Deletes an IdentifierInfo member
*
* @param type
* @return true if the IdentifierInfo member is removed
*/
protected boolean delMember(IdentifierInfo type) {
return ElementUtils.remove(this.getRoot(),
this.getRoot().getChild(type.toString()));
}
/**
* Deletes the authority
*
* @return true if removed
*/
public boolean delAuthority() {
return this.delMember(IdentifierInfo.authority);
}
/**
* Deletes the identifier
*
* @return true if removed
*/
public boolean delIdentifier() {
return this.delMember(IdentifierInfo.identifier);
}
/**
* Get the value of the IdentifierInfo member
*
* @param type
* @return the value of the IdentifierInfo member
*/
protected String getMember(IdentifierInfo type) {
Element el = this.getRoot().getChild(type.toString());
if (el != null)
return el.getTextTrim();
else
return null;
}
/**
* Get the authority
*
* @return
*/
public String getAuthority() {
return this.getMember(IdentifierInfo.authority);
}
/**
* Get the identifier
*
* @return
*/
public String getIdentifier() {
return this.getMember(IdentifierInfo.identifier);
}
}

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.identifier;
/**
* Enumeration of layer authorityURL members
*
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com |
* emmanuel.blondel@fao.org
*
*/
public enum IdentifierInfo {
authority, identifier;
}

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

@ -39,23 +39,48 @@ import org.jdom.output.XMLOutputter;
*/
public class XmlElement{
private final Element root;
private Element root;
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;
private final static XMLOutputter OUTPUTTER = new XMLOutputter(Format.getCompactFormat());
public XmlElement(final String name){
root=new Element(name);
}
public XmlElement(final Element e) {
root = e;
}
/**
* Empty constructor:<br/>
* Use {@link #setRoot()} to initialize the root
*/
protected XmlElement() {
}
/**
* update the root of this node
* @param root
*/
protected void setRoot(final Element root) {
this.root = root;
}
/**
* update the root of this node
* @param name is the name of the root node
*/
protected void setRoot(final String name){
root=new Element(name);
}
public Element getRoot(){
return root;
}
@SuppressWarnings("unused")
private XmlElement(){root=null;};
protected void add(final String nodename, final String nodetext) {
add(nodename,new Text(nodetext));
}

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,126 @@
/*
* 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.GeoServerRESTPublisher.StoreType;
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

@ -0,0 +1,65 @@
package it.geosolutions.geoserver.decoder;
import it.geosolutions.geoserver.rest.decoder.RESTLayer21;
import it.geosolutions.geoserver.rest.encoder.authorityurl.GSAuthorityURLInfoEncoder;
import it.geosolutions.geoserver.rest.encoder.identifier.GSIdentifierInfoEncoder;
import java.io.File;
import java.io.IOException;
import java.util.List;
import junit.framework.Assert;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
/**
*
* Apply Layer decoder tests on a GS 2.1 layer REST config
*
* @author eblondel
*
*/
public class LayerDecoder21Test {
RESTLayer21 layer;
@Before
public void setUp() throws IOException {
File layerFile = new ClassPathResource("testdata/layerExample21.xml")
.getFile();
String layerString = FileUtils.readFileToString(layerFile);
layer = (RESTLayer21) RESTLayer21.build(layerString);
}
@Test
public void testAdvertised() {
Assert.assertEquals(true, layer.getAdvertised());
}
@Test
public void testAuthorityURLs() {
List<GSAuthorityURLInfoEncoder> authorityURLs = layer
.getEncodedAuthorityURLInfoList();
System.out.println(authorityURLs.size());
Assert.assertEquals("authority1", authorityURLs.get(0).getName());
Assert.assertEquals("http://www.authority1.org", authorityURLs.get(0)
.getHref());
Assert.assertEquals("authority2", authorityURLs.get(1).getName());
Assert.assertEquals("http://www.authority2.org", authorityURLs.get(1)
.getHref());
}
@Test
public void testIdentifiers() {
List<GSIdentifierInfoEncoder> authorityURLs = layer
.getEncodedIdentifierInfoList();
Assert.assertEquals("authority1", authorityURLs.get(0).getAuthority());
Assert.assertEquals("identifier1", authorityURLs.get(0).getIdentifier());
Assert.assertEquals("authority2", authorityURLs.get(1).getAuthority());
Assert.assertEquals("identifier2", authorityURLs.get(1).getIdentifier());
}
}

View File

@ -0,0 +1,99 @@
package it.geosolutions.geoserver.decoder;
import it.geosolutions.geoserver.rest.decoder.RESTLayer;
import it.geosolutions.geoserver.rest.encoder.authorityurl.GSAuthorityURLInfoEncoder;
import it.geosolutions.geoserver.rest.encoder.identifier.GSIdentifierInfoEncoder;
import java.io.File;
import java.io.IOException;
import java.util.List;
import junit.framework.Assert;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
/**
*
* @author eblondel
*
*/
public class LayerDecoderTest {
RESTLayer layer;
@Before
public void setUp() throws IOException {
File layerFile = new ClassPathResource("testdata/layerExample.xml")
.getFile();
String layerString = FileUtils.readFileToString(layerFile);
layer = RESTLayer.build(layerString);
}
@Test
public void testEnabled() {
Assert.assertEquals(true, layer.getEnabled());
}
@Test
public void testQueryable() {
Assert.assertEquals(true, layer.getQueryable());
}
@Test
public void testAdvertised() {
Assert.assertEquals(true, layer.getAdvertised());
}
@Test
public void testName() {
Assert.assertEquals("tasmania_cities", layer.getName());
}
@Test
public void testTypeString() {
Assert.assertEquals("VECTOR", layer.getTypeString());
}
@Test
public void testType() {
Assert.assertEquals(RESTLayer.Type.VECTOR, layer.getType());
}
@Test
public void testDefaultStyle() {
Assert.assertEquals("capitals", layer.getDefaultStyle());
}
@Test
public void testResourceUrl() {
Assert.assertEquals(
"http://localhost:8080/geoserver/rest/workspaces/topp/datastores/taz_shapes/featuretypes/tasmania_cities.xml",
layer.getResourceUrl());
}
@Test
public void testAuthorityURLs() {
List<GSAuthorityURLInfoEncoder> authorityURLs = layer
.getEncodedAuthorityURLInfoList();
Assert.assertEquals("authority1", authorityURLs.get(0).getName());
Assert.assertEquals("http://www.authority1.org", authorityURLs.get(0)
.getHref());
Assert.assertEquals("authority2", authorityURLs.get(1).getName());
Assert.assertEquals("http://www.authority2.org", authorityURLs.get(1)
.getHref());
}
@Test
public void testIdentifiers() {
List<GSIdentifierInfoEncoder> authorityURLs = layer
.getEncodedIdentifierInfoList();
Assert.assertEquals("authority1", authorityURLs.get(0).getAuthority());
Assert.assertEquals("identifier1", authorityURLs.get(0).getIdentifier());
Assert.assertEquals("authority2", authorityURLs.get(1).getAuthority());
Assert.assertEquals("identifier2", authorityURLs.get(1).getIdentifier());
}
}

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,6 @@ public class MetadataDecoderTest {
Assert.assertEquals(el.isEnabled(),true);
}
}
}
}

View File

@ -0,0 +1,120 @@
package it.geosolutions.geoserver.decoder;
import it.geosolutions.geoserver.rest.decoder.RESTCoverage;
import it.geosolutions.geoserver.rest.encoder.metadatalink.GSMetadataLinkInfoEncoder;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
/**
* ResourceDecoderTest
*
* @author eblondel
*
*/
public class ResourceDecoderTest {
RESTCoverage coverage;
@Before
public void setup() throws IOException {
File coverageFile = new ClassPathResource(
"testdata/coverageExample.xml").getFile();
String coverageString = FileUtils.readFileToString(coverageFile);
coverage = RESTCoverage.build(coverageString);
}
@Test
public void testName() {
Assert.assertEquals(coverage.getName(), "granuleTestMosaic");
}
@Test
public void testNativeName() {
Assert.assertEquals(coverage.getNativeName(), "granuleTestMosaic");
}
@Test
public void testTitle() {
Assert.assertEquals(coverage.getNativeName(), "granuleTestMosaic");
}
@Test
public void testAbstract() {
Assert.assertEquals(coverage.getAbstract(), "this is an abstract");
}
@Test
public void testKeywords() {
List<String> keywords = coverage.getKeywords();
Assert.assertEquals(keywords.get(0), "keyword1");
Assert.assertEquals(keywords.get(1), "keyword2");
Assert.assertEquals(keywords.get(2), "keyword3");
}
@Test
public void testNameSpace() {
Assert.assertEquals(coverage.getNameSpace(), "topp");
}
@Test
public void testStoreName() {
Assert.assertEquals(coverage.getStoreName(), "granuleTestMosaic");
}
@Test
public void testStoreType() {
Assert.assertEquals(coverage.getStoreType(), "coverageStore");
}
@Test
public void testStoreUrl() {
Assert.assertEquals(
coverage.getStoreUrl(),
"http://localhost:8080/geoserver/rest/workspaces/topp/coveragestores/granuleTestMosaic.xml");
}
@Test
public void testCRS() {
Assert.assertEquals(coverage.getCRS(), "EPSG:4326");
}
@Test
public void testBoundingBox() {
Assert.assertEquals(coverage.getMinX(), -180.0, 0);
Assert.assertEquals(coverage.getMaxX(), 180.0, 0);
Assert.assertEquals(coverage.getMinY(), -90, 0);
Assert.assertEquals(coverage.getMaxY(), 90, 0);
}
@Test
public void testMetadataLinkInfo() throws IOException {
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

@ -0,0 +1,94 @@
/*
* GeoBatch - Open Source geospatial batch processing system
* https://github.com/nfms4redd/nfms-geobatch
* Copyright (C) 2007-2012 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.decoder;
import it.geosolutions.geoserver.rest.GeoServerRESTPublisher;
import it.geosolutions.geoserver.rest.GeoServerRESTReader;
import it.geosolutions.geoserver.rest.GeoserverRESTTest;
import it.geosolutions.geoserver.rest.decoder.about.GSVersionDecoder;
import it.geosolutions.geoserver.rest.decoder.about.GSVersionDecoder.VERSION;
import junit.framework.Assert;
import org.jdom.Element;
import org.jdom.output.XMLOutputter;
import org.junit.Test;
/**
* @author Carlo Cancellieri {@code
* <about>
* <resource name="GeoServer">
* <Build-Timestamp>10-Oct-2013 03:08</Build-Timestamp>
* <Git-Revision>32db076555e57cc5f826b0361d1af4efe6d3f01b</Git-Revision>
* <Version>2.2-ENTERPRISE-SNAPSHOT</Version>
* </resource>
* <resource name="GeoTools">
* <Build-Timestamp>10-Oct-2013 03:01</Build-Timestamp>
* <Git-Revision>da12effd42a9545628bd6e8ec20494607fbfe3a4</Git-Revision>
* <Version>8-ENTERPRISE-SNAPSHOT</Version>
* </resource>
* </about>
* }
*/
public class VersionDecoderTest extends GeoserverRESTTest {
private final String version = "<about><resource name=\"GeoServer\"><Build-Timestamp>10-Oct-2013 03:08</Build-Timestamp>"
+ "<Git-Revision>32db076555e57cc5f826b0361d1af4efe6d3f01b</Git-Revision><Version>2.2-ENTERPRISE-SNAPSHOT</Version></resource></about>";
@Test
public void testVersionDecoder() {
GSVersionDecoder dec=new GSVersionDecoder(version);
Assert.assertEquals(GSVersionDecoder.VERSION.v22, dec.getVersion());
Assert.assertEquals("GeoServer", dec.getGeoServer().getName());
GSVersionDecoder.GSAboutResource geoserver=dec.getGeoServer();
geoserver.setVersion("2.3-SNAPSHOT");
geoserver.setName("_CustomGeoServerName_");
Assert.assertEquals(GSVersionDecoder.VERSION.v23, dec.getVersion());
Assert.assertEquals("_CustomGeoServerName_", dec.getGeoServer().getName());
dec=new GSVersionDecoder(null);
Assert.assertEquals(GSVersionDecoder.VERSION.UNRECOGNIZED, dec.getVersion());
Assert.assertEquals(null, dec.getGeoServer().getName());
//print(dec.getRoot());
}
@Test
public void testIntegrationVersionDecoder() {
if (!enabled())
return;
GSVersionDecoder geoserver = reader.getGeoserverVersion();
if (GSVersionDecoder.VERSION.v22.equals(GSVersionDecoder.VERSION.getVersion(VERSION))) {
Assert.assertEquals(geoserver.getVersion(), GSVersionDecoder.VERSION.v22);
} else if (GSVersionDecoder.VERSION.UNRECOGNIZED.equals(GSVersionDecoder.VERSION
.getVersion(VERSION))) {
Assert.assertEquals(geoserver.getVersion(), GSVersionDecoder.VERSION.UNRECOGNIZED);
}
// print(dec.getRoot());
}
public String print(Element e){
return new XMLOutputter().outputString(e);
}
}

View File

@ -31,6 +31,7 @@ import it.geosolutions.geoserver.rest.decoder.RESTDataStore;
import it.geosolutions.geoserver.rest.decoder.RESTFeatureType;
import it.geosolutions.geoserver.rest.decoder.RESTLayer;
import it.geosolutions.geoserver.rest.decoder.RESTLayerGroup;
import it.geosolutions.geoserver.rest.decoder.about.GSVersionDecoder;
import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem;
import java.net.MalformedURLException;
@ -68,6 +69,9 @@ public abstract class GeoserverRESTTest extends Assert {
public static final String RESTPW;
// geoserver target version
public static final String VERSION;
public static URL URL;
public static GeoServerRESTManager manager;
@ -84,6 +88,7 @@ public abstract class GeoserverRESTTest extends Assert {
RESTURL = getenv("gsmgr_resturl", "http://localhost:8080/geoserver");
RESTUSER = getenv("gsmgr_restuser", "admin");
RESTPW = getenv("gsmgr_restpw", "geoserver");
VERSION = getenv("gsmgr_version", "2.4");
// These tests will destroy data, so let's make sure we do want to run them
enabled = getenv("gsmgr_resttest", "false").equalsIgnoreCase("true");
@ -120,12 +125,16 @@ public abstract class GeoserverRESTTest extends Assert {
LOGGER.info("Using geoserver instance " + RESTUSER + ":" + RESTPW + " @ "
+ RESTURL);
}
}
if (!existgs) {
} else {
System.out.println("Failing tests : geoserver not found");
fail("GeoServer not found");
}
GSVersionDecoder v=reader.getGeoserverVersion();
if (!v.getVersion().equals(GSVersionDecoder.VERSION.getVersion(VERSION))){
System.out.println("Failing tests : geoserver version does not match.\nAccepted versions: "+GSVersionDecoder.VERSION.print());
fail("GeoServer version ("+v.getVersion()+") does not match the desired one (+VERSION+)");
}
} else {
System.out.println("Skipping tests ");
}

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,50 @@
package it.geosolutions.geoserver.rest.decoder;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import org.apache.commons.io.IOUtils;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
/**
*
* @author toben
*/
public class RESTFeatureTypeListTest {
public RESTFeatureTypeListTest() {
}
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
@Test
public void testBuild() throws IOException {
InputStream is = RESTFeatureTypeListTest.class.getResourceAsStream("/testdata/featureTypeListExample.xml");
String response = IOUtils.toString(is);
is.close();
RESTFeatureTypeList result = RESTFeatureTypeList.build(response);
List<String> list = result.getNames();
assertArrayEquals(new String[]{"states", "tasmania_cities", "tasmania_roads", "tasmania_state_boundaries", "tasmania_water_bodies"}
, list.toArray());
}
}

View File

@ -0,0 +1,137 @@
/*
* 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;
import java.util.List;
import it.geosolutions.geoserver.rest.encoder.authorityurl.AuthorityURLInfo;
import it.geosolutions.geoserver.rest.encoder.authorityurl.GSAuthorityURLInfoEncoder;
import it.geosolutions.geoserver.rest.encoder.identifier.GSIdentifierInfoEncoder;
import it.geosolutions.geoserver.rest.encoder.identifier.IdentifierInfo;
import junit.framework.Assert;
import org.jdom.Element;
import org.junit.Before;
import org.junit.Test;
/**
* GSLayerEncoder21Test
*
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com |
* emmanuel.blondel@fao.org
*/
public class GSLayerEncoder21Test {
GSLayerEncoder21 layerEncoder;
@Before
public void setup() {
layerEncoder = new GSLayerEncoder21();
layerEncoder.setAdvertised(true);
layerEncoder.addAuthorityURL(new GSAuthorityURLInfoEncoder(
"authority1", "http://www.authority1.org"));
layerEncoder.addIdentifier(new GSIdentifierInfoEncoder("authority1",
"identifier1"));
layerEncoder.addAuthorityURL(new GSAuthorityURLInfoEncoder(
"authority2", "http://www.authority2.org"));
layerEncoder.addIdentifier(new GSIdentifierInfoEncoder("authority2",
"identifier2"));
layerEncoder.addIdentifier(new GSIdentifierInfoEncoder("authority2",
"additionalId"));
}
@Test
public void testMetadata() {
List<Element> metaElements = layerEncoder.getRoot()
.getChild("metadata").getChildren();
for (Element el : metaElements) {
String key = el.getAttributeValue("key");
if (key.matches("advertised")) {
Assert.assertEquals(true, Boolean.parseBoolean(el.getValue()));
} else if (key.matches("authorityURLs")) {
String jsonStr = el.getValue();
jsonStr = jsonStr.substring(2);
jsonStr = jsonStr.substring(0, jsonStr.length() - 3);
String[] items = jsonStr.split("\\}(,)\\{");
String[] props1 = items[0].split(",");
String[] kvp1_1 = props1[0].split("\":");
String[] kvp1_2 = props1[1].split("\":");
Assert.assertEquals(AuthorityURLInfo.name.name(),
kvp1_1[0].replace("\"", ""));
Assert.assertEquals("authority1", kvp1_1[1].replace("\"", ""));
Assert.assertEquals(AuthorityURLInfo.href.name(),
kvp1_2[0].replace("\"", ""));
Assert.assertEquals("http://www.authority1.org",
kvp1_2[1].replace("\"", ""));
String[] props2 = items[1].split(",");
String[] kvp2_1 = props2[0].split("\":");
String[] kvp2_2 = props2[1].split("\":");
Assert.assertEquals(AuthorityURLInfo.name.name(),
kvp2_1[0].replace("\"", ""));
Assert.assertEquals("authority2", kvp2_1[1].replace("\"", ""));
Assert.assertEquals(AuthorityURLInfo.href.name(),
kvp2_2[0].replace("\"", ""));
Assert.assertEquals("http://www.authority2.org",
kvp2_2[1].replace("\"", ""));
} else if (key.matches("identifiers")) {
String jsonStr = el.getValue();
jsonStr = jsonStr.substring(2);
jsonStr = jsonStr.substring(0, jsonStr.length() - 3);
String[] items = jsonStr.split("\\}(,)\\{");
String[] props1 = items[0].split(",");
String[] kvp1_1 = props1[0].split("\":");
String[] kvp1_2 = props1[1].split("\":");
Assert.assertEquals(IdentifierInfo.authority.name(),
kvp1_1[0].replace("\"", ""));
Assert.assertEquals("authority2", kvp1_1[1].replace("\"", ""));
Assert.assertEquals(IdentifierInfo.identifier.name(),
kvp1_2[0].replace("\"", ""));
Assert.assertEquals("identifier2", kvp1_2[1].replace("\"", ""));
String[] props2 = items[1].split(",");
String[] kvp2_1 = props2[0].split("\":");
String[] kvp2_2 = props2[1].split("\":");
Assert.assertEquals(IdentifierInfo.authority.name(),
kvp2_1[0].replace("\"", ""));
Assert.assertEquals("authority2", kvp2_1[1].replace("\"", ""));
Assert.assertEquals(IdentifierInfo.identifier.name(),
kvp2_2[0].replace("\"", ""));
Assert.assertEquals("additionalId", kvp2_2[1].replace("\"", ""));
String[] props3 = items[2].split(",");
String[] kvp3_1 = props3[0].split("\":");
String[] kvp3_2 = props3[1].split("\":");
Assert.assertEquals(IdentifierInfo.authority.name(), kvp3_1[0].replace("\"", ""));
Assert.assertEquals("authority1", kvp3_1[1].replace("\"", ""));
Assert.assertEquals(IdentifierInfo.identifier.name(), kvp3_2[0].replace("\"", ""));
Assert.assertEquals("identifier1", kvp3_2[1].replace("\"", ""));
}
}
}
}

View File

@ -0,0 +1,116 @@
/*
* 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;
import it.geosolutions.geoserver.rest.encoder.authorityurl.GSAuthorityURLInfoEncoder;
import it.geosolutions.geoserver.rest.encoder.identifier.GSIdentifierInfoEncoder;
import junit.framework.Assert;
import org.jdom.Element;
import org.junit.Before;
import org.junit.Test;
/**
* GSLayerEncoderTest
*
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com |
* emmanuel.blondel@fao.org
*/
public class GSLayerEncoderTest {
GSLayerEncoder layerEncoder;
@Before
public void setup() {
layerEncoder = new GSLayerEncoder();
layerEncoder.setEnabled(true);
layerEncoder.setQueryable(true);
layerEncoder.setAdvertised(true);
layerEncoder.setDefaultStyle("point");
layerEncoder.addStyle("additional_style1");
layerEncoder.addStyle("additional_style2");
layerEncoder.addAuthorityURL(new GSAuthorityURLInfoEncoder(
"authority1", "http://www.authority1.org"));
layerEncoder.addIdentifier(new GSIdentifierInfoEncoder("authority1",
"identifier1"));
}
@Test
public void testProperties() {
Assert.assertEquals(
true,
Boolean.parseBoolean(layerEncoder.getRoot().getChild("enabled")
.getValue()));
Assert.assertEquals(
true,
Boolean.parseBoolean(layerEncoder.getRoot()
.getChild("queryable").getValue()));
Assert.assertEquals(
true,
Boolean.parseBoolean(layerEncoder.getRoot()
.getChild("advertised").getValue()));
}
@Test
public void testDefaultStyle() {
Assert.assertEquals("point",
layerEncoder.getRoot().getChild("defaultStyle").getValue());
}
@Test
public void testMultipleStyles() {
Assert.assertEquals(2, layerEncoder.getRoot().getChild("styles")
.getChildren().size());
Assert.assertEquals("additional_style1", ((Element) layerEncoder
.getRoot().getChild("styles").getChildren().get(0)).getText());
Assert.assertEquals("additional_style2", ((Element) layerEncoder
.getRoot().getChild("styles").getChildren().get(1)).getText());
}
@Test
public void testRemoveStyle() {
Assert.assertTrue(layerEncoder.delStyle("additional_style1"));
Assert.assertEquals(1, layerEncoder.getRoot().getChild("styles")
.getChildren().size());
Assert.assertEquals("additional_style2", ((Element) layerEncoder
.getRoot().getChild("styles").getChildren().get(0)).getText());
}
@Test
public void testAuthorityURL() {
Element el = (Element) layerEncoder.getRoot().getChild("authorityURLs")
.getChildren().get(0);
Assert.assertEquals("authority1", el.getChild("name").getValue());
Assert.assertEquals("http://www.authority1.org", el.getChild("href")
.getValue());
}
@Test
public void testIdentifier() {
Element el = (Element) layerEncoder.getRoot().getChild("identifiers")
.getChildren().get(0);
Assert.assertEquals("authority1", el.getChild("authority").getValue());
Assert.assertEquals("identifier1", el.getChild("identifier").getValue());
}
}

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

@ -0,0 +1,49 @@
/*
* 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.authorityurl;
import junit.framework.Assert;
import org.junit.Test;
/**
*
* @author eblondel
*
*/
public class GSAuthorityURLInfoEncoderTest {
@Test
public void authorityURLInfoTest() {
GSAuthorityURLInfoEncoder encoder = new GSAuthorityURLInfoEncoder();
encoder.setup("authority1", "http://www.authority1.org");
Assert.assertEquals("authority1", encoder.getName());
Assert.assertEquals("http://www.authority1.org", encoder.getHref());
Assert.assertTrue(encoder.delHref());
Assert.assertNull(encoder.getHref());
encoder.setName("authority2");
encoder.setHref("http://www.authority2.org");
Assert.assertEquals("authority2", encoder.getName());
Assert.assertEquals("http://www.authority2.org", encoder.getHref());
}
}

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

@ -22,12 +22,20 @@ package it.geosolutions.geoserver.rest.encoder.feature;
import it.geosolutions.geoserver.rest.GeoServerRESTPublisher;
import it.geosolutions.geoserver.rest.decoder.RESTLayer;
import it.geosolutions.geoserver.rest.decoder.RESTResource;
import it.geosolutions.geoserver.rest.decoder.about.GSVersionDecoder;
import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder;
import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder21;
import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder;
import it.geosolutions.geoserver.rest.encoder.authorityurl.GSAuthorityURLInfoEncoder;
import it.geosolutions.geoserver.rest.encoder.identifier.GSIdentifierInfoEncoder;
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;
@ -44,9 +52,14 @@ import org.slf4j.LoggerFactory;
import org.springframework.core.io.ClassPathResource;
/**
* Note on adding multiple available styles to the GSLayerEncoder: - to run the
* testIntegration(), 2 clones of the "point" style, named "point2" and "point3"
* have to be created.
*
* @author ETj (etj at geo-solutions.it)
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com |
* emmanuel.blondel@fao.org
*/
public class GSFeatureEncoderTest extends GeoserverRESTPublisherTest {
protected final static Logger LOGGER = LoggerFactory.getLogger(GSFeatureEncoderTest.class);
@ -64,19 +77,49 @@ public class GSFeatureEncoderTest extends GeoserverRESTPublisherTest {
String layerName = "cities";
GSFeatureTypeEncoder fte = new GSFeatureTypeEncoder();
fte.setNativeName(layerName);
fte.setName(layerName + "_NEW");
fte.setTitle("title");
// fte.addKeyword("TODO");
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();
GSLayerEncoder layerEncoder = null;
if (!GSVersionDecoder.VERSION.getVersion(VERSION).equals(
GSVersionDecoder.VERSION.UNRECOGNIZED)) {
layerEncoder = new GSLayerEncoder();
} else if (GSVersionDecoder.VERSION.getVersion(VERSION).equals(
GSVersionDecoder.VERSION.UNRECOGNIZED)) {
layerEncoder = new GSLayerEncoder21();
}
layerEncoder.setEnabled(true);
layerEncoder.setQueryable(true);
layerEncoder.setAdvertised(true);
layerEncoder.setDefaultStyle("point");
layerEncoder.addStyle("point2");
layerEncoder.addStyle("point3");
// authorityURL
GSAuthorityURLInfoEncoder authorityURL = new GSAuthorityURLInfoEncoder(
"authority1", "http://www.authority1.org");
layerEncoder.addAuthorityURL(authorityURL);
// identifier
GSIdentifierInfoEncoder identifier1 = new GSIdentifierInfoEncoder(
"authority1", "identifier1");
GSIdentifierInfoEncoder identifier2 = new GSIdentifierInfoEncoder(
"authority1", "another_identifier");
layerEncoder.addIdentifier(identifier1);
layerEncoder.addIdentifier(identifier2);
publisher.createWorkspace(DEFAULT_WS);
File zipFile = new ClassPathResource("testdata/resttestshp.zip").getFile();
@ -187,6 +230,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 +265,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,50 @@
/*
* 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.identifier;
import junit.framework.Assert;
import org.junit.Test;
/**
*
* @author eblondel
*
*/
public class GSIdentifierInfoEncoderTest {
@Test
public void identifierInfoTest() {
GSIdentifierInfoEncoder encoder = new GSIdentifierInfoEncoder();
encoder.setup("authority1", "identifier1");
Assert.assertEquals("authority1", encoder.getAuthority());
Assert.assertEquals("identifier1", encoder.getIdentifier());
Assert.assertTrue(encoder.delIdentifier());
Assert.assertNull(encoder.getIdentifier());
encoder.setAuthority("authority2");
encoder.setIdentifier("identifier2");
Assert.assertEquals("authority2", encoder.getAuthority());
Assert.assertEquals("identifier2", encoder.getIdentifier());
}
}

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

@ -2,11 +2,29 @@
<coverage>
<name>granuleTestMosaic</name>
<nativeName>granuleTestMosaic</nativeName>
<abstract>this is an abstract</abstract>
<namespace>
<name>topp</name>
<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>
<keywords>
<string>keyword1</string>
<string>keyword2</string>
<string>keyword3</string>
</keywords>
<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;

View File

@ -0,0 +1,22 @@
<featureTypes>
<featureType>
<name>states</name>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/workspaces/topp/featuretypes/states.xml" type="application/xml"/>
</featureType>
<featureType>
<name>tasmania_cities</name>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/workspaces/topp/featuretypes/tasmania_cities.xml" type="application/xml"/>
</featureType>
<featureType>
<name>tasmania_roads</name>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/workspaces/topp/featuretypes/tasmania_roads.xml" type="application/xml"/>
</featureType>
<featureType>
<name>tasmania_state_boundaries</name>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/workspaces/topp/featuretypes/tasmania_state_boundaries.xml" type="application/xml"/>
</featureType>
<featureType>
<name>tasmania_water_bodies</name>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/workspaces/topp/featuretypes/tasmania_water_bodies.xml" type="application/xml"/>
</featureType>
</featureTypes>

View File

@ -0,0 +1,44 @@
<layer>
<name>tasmania_cities</name>
<path>/</path>
<type>VECTOR</type>
<defaultStyle>
<name>capitals</name>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate"
href="http://localhost:8080/geoserver/rest/styles/capitals.xml" type="application/xml" />
</defaultStyle>
<resource class="featureType">
<name>tasmania_cities</name>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate"
href="http://localhost:8080/geoserver/rest/workspaces/topp/datastores/taz_shapes/featuretypes/tasmania_cities.xml"
type="application/xml" />
</resource>
<enabled>true</enabled>
<queryable>true</queryable>
<advertised>true</advertised>
<attribution>
<logoWidth>0</logoWidth>
<logoHeight>0</logoHeight>
</attribution>
<authorityURLs>
<AuthorityURL>
<name>authority1</name>
<href>http://www.authority1.org</href>
</AuthorityURL>
<AuthorityURL>
<name>authority2</name>
<href>http://www.authority2.org</href>
</AuthorityURL>
</authorityURLs>
<identifiers>
<Identifier>
<authority>authority1</authority>
<identifier>identifier1</identifier>
</Identifier>
<Identifier>
<authority>authority2</authority>
<identifier>identifier2</identifier>
</Identifier>
</identifiers>
</layer>

View File

@ -0,0 +1,29 @@
<layer>
<name>tasmania_cities</name>
<path>/</path>
<type>VECTOR</type>
<defaultStyle>
<name>capitals</name>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate"
href="http://localhost:8080/geoserver/rest/styles/capitals.xml" type="application/xml" />
</defaultStyle>
<resource class="featureType">
<name>tasmania_cities</name>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate"
href="http://localhost:8080/geoserver/rest/workspaces/topp/datastores/taz_shapes/featuretypes/tasmania_cities.xml"
type="application/xml" />
</resource>
<enabled>true</enabled>
<queryable>true</queryable>
<advertised>true</advertised>
<attribution>
<logoWidth>0</logoWidth>
<logoHeight>0</logoHeight>
</attribution>
<metadata>
<entry key="identifiers">[{"authority":"authority1","identifier":"identifier1"},{"authority":"authority2","identifier":"identifier2"},]</entry>
<entry key="authorityURLs">[{"name":"authority1","href":"http://www.authority1.org"},{"name":"authority2","href":"http://www.authority2.org"},]</entry>
<entry key="advertised">true</entry>
</metadata>
</layer>

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

Binary file not shown.