diff --git a/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java b/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java index ce30f04..aace0ba 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java +++ b/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java @@ -51,7 +51,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Connect to a GeoServer instance to publish or modify data. + * Connect to a GeoServer instance to publish or modify its contents via REST + * API. *
* There are no modifiable instance fields, so all the calls are thread-safe. * @@ -60,23 +61,39 @@ import org.slf4j.LoggerFactory; */ public class GeoServerRESTPublisher { + /** The logger for this class */ private static final Logger LOGGER = LoggerFactory.getLogger(GeoServerRESTPublisher.class); + + /** + * GeoServer instance base URL. E.g.: + * http://localhost:8080/geoserver. + */ private final String restURL; + + /** + * GeoServer instance privileged username, with read & write permission on + * REST API + */ private final String gsuser; + + /** + * GeoServer instance password for privileged username with r&w permission + * on REST API + */ private final String gspass; - /** - * Creates a GeoServerRESTPublisher for a given GeoServer instance - * with the given auth credentials. - * - * @param restURL - * the base GeoServer URL (e.g.: - * http://localhost:8080/geoserver) - * @param username - * username auth credential - * @param password - * password auth credential - */ + /** + * Creates a GeoServerRESTPublisher to connect against a GeoServer + * instance with the given URL and user credentials. + * + * @param restURL + * the base GeoServer URL (e.g.: + * http://localhost:8080/geoserver) + * @param username + * auth credential + * @param password + * auth credential + */ public GeoServerRESTPublisher(String restURL, String username, String password) { this.restURL = HTTPUtils.decurtSlash(restURL); @@ -84,7 +101,6 @@ public class GeoServerRESTPublisher { this.gspass = password; } - // ========================================================================== // === BACKUP and RESTORE // ========================================================================== @@ -92,39 +108,33 @@ public class GeoServerRESTPublisher { /** * Issues a GeoServer BACKUP. *
- * This is the equivalent call with cUrl: - * - *
- * {@code curl -u admin:geoserver -XPOST \
- * -H 'Content-type: text/xml' \
- * --data "<task><path>${BACKUP_DATADIR}</path></task>" \
- * http://$GSIP:$GSPORT/$SERVLET/rest/bkprst/backup}
- *
- *
+ * Won't include data, cached tiles, or logs. Use
+ * {@link #backup(String, boolean, boolean, boolean)} to control these
+ * parameters.
+ *
* @param backupDir
* the target Backup Dir String.
- *
+ *
* @return id of the backup.
* @throws IllegalArgumentException
- * if the backup_dir is null or empty
+ * if the backupDir is null or empty
*/
public String backup(final String backupDir) throws IllegalArgumentException
{
+ /*
+ * This is the equivalent call with cUrl:
+ *
+ * {@code curl -u admin:geoserver -XPOST \
+ * -H 'Content-type: text/xml' \
+ * --data "<task><path>${BACKUP_DATADIR}</path></task>" \
+ * ${restURL}/rest/bkprst/backup}
+ */
return backup(backupDir, false, false, false);
}
/**
* Issues a GeoServer BACKUP.
- * - * This is the equivalent call with cUrl: - * - *
- * {@code curl -u admin:geoserver -XPOST \
- * -H 'Content-type: text/xml' \
- * --data "<task><path>${BACKUP_DATADIR}</path><includedata>${includedata}</includedata><includegwc>${includegwc}</includegwc><includelog>${includelog}</includelog></task>" \
- * http://$GSIP:$GSPORT/$SERVLET/rest/bkprst/backup}
- *
- *
+ *
* @param backupDir
* the target Backup Dir String.
* @param includedata
@@ -133,16 +143,23 @@ public class GeoServerRESTPublisher {
* whether or not include the geowebcache dir Boolean.
* @param includelog
* whether or not include the log dir Boolean.
- *
+ *
* @return id of the backup.
* @throws IllegalArgumentException
- * if the backup_dir is null or empty
+ * if the backupDir is null or empty.
*/
public String backup(final String backupDir,
final boolean includedata,
final boolean includegwc,
final boolean includelog) throws IllegalArgumentException
{
+ /* This is the equivalent call with cUrl:
+ *
+ * {@code curl -u admin:geoserver -XPOST \
+ * -H 'Content-type: text/xml' \
+ * --data "<task><path>${BACKUP_DATADIR}</path><includedata>${includedata}</includedata><includegwc>${includegwc}</includegwc><includelog>${includelog}</includelog></task>" \
+ * ${restURL}/rest/bkprst/backup}
+ */
if ((backupDir == null) || backupDir.isEmpty())
{
throw new IllegalArgumentException(
@@ -164,25 +181,24 @@ public class GeoServerRESTPublisher {
/**
* Issues a GeoServer RESTORE.
- * - * This is the equivalent call with cUrl: - * - *
- * {@code curl -u admin:geoserver -XPOST \
- * -H 'Content-type: text/xml' \
- * --data "<task><path>${BACKUP_DATADIR}</path></task>" \
- * http://$GSIP:$GSPORT/$SERVLET/rest/bkprst/restore}
- *
- *
+ *
* @param backupDir
- * the target Backup Dir String.
- *
+ * the source backup dir.
+ *
* @return id of the backup.
* @throws IllegalArgumentException
- * if the backup_dir is null or empty
+ * if the backupDir is null or empty
*/
public String restore(final String backupDir) throws IllegalArgumentException
{
+ /*
+ * This is the equivalent call with cUrl:
+ *
+ * {@code curl -u admin:geoserver -XPOST \
+ * -H 'Content-type: text/xml' \
+ * --data "<task><path>${BACKUP_DATADIR}</path></task>" \
+ * ${restURL}/rest/bkprst/restore}
+ */
if ((backupDir == null) || backupDir.isEmpty())
{
throw new IllegalArgumentException(
@@ -204,24 +220,27 @@ public class GeoServerRESTPublisher {
// === WORKSPACES
// ==========================================================================
- /**
- * Create a new Workspace
- *
- * @param workspace
- * The name of the new workspace.
- *
- * - * This is the equivalent call with cUrl: - * - *
- * {@code curl -u admin:geoserver -XPOST \
- * -H 'Content-type: text/xml' \
- * -d "$WORKSPACE " \
- * http://$GSIP:$GSPORT/$SERVLET/rest/workspaces
- * }
- *
- */
+ /**
+ * Create a new Workspace.
+ *
+ * GeoServer will automatically create an associated Namespace with the URI
+ * being "http://{workspaceName}". To specify a custom Namespace URI, use
+ * {@link #createWorkspace(String, URI)}.
+ *
+ * @param workspace
+ * The name of the new workspace.
+ *
+ * @return true if the workspace was created.
+ */
public boolean createWorkspace(final String workspace) {
+ /* This is the equivalent call with cUrl:
+ *
+ * {@code curl -u admin:geoserver -XPOST \
+ * -H 'Content-type: text/xml' \
+ * -d "
+ * Note that this method is equivalent to {@link #createNamespace}. + * + * @param name + * Name for the new workspace, which will be also its associated + * namespace prefix. + * @param uri + * Namespace URI. Cannot be empty. + * @return true if the Workspace and its associated namespace were + * successfully created. + */ public boolean createWorkspace(final String name, final URI uri) { // This is really an alias to createNamespace, as GeoServer - // will automatically create the workspace as well. + // will automatically create the associated workspace as well. return createNamespace(name, uri); } @@ -248,17 +271,23 @@ public class GeoServerRESTPublisher { // === NAMESPACES // ========================================================================== - /** - * Create a new namespace. GeoServer will automatically create the corresponding workspace. - * - * Prefix and uri are mandatory and cannot be empty. - * If a namespace with the given prefix already exists, it won't be created. - * - * @param prefix The name of the new namespace. - * @param uri The URI of the new namespace. - * @return true if the namespace was successfully created. - * @see GeoServer Documentation - */ + /** + * Create a new Namespace. GeoServer will automatically create the + * corresponding Workspace. + * + * Prefix and URI are mandatory and cannot be empty. If a Namespace with the + * given prefix already exists, it won't be created. + * + * @param prefix + * The name of the new Namespace. + * @param uri + * The URI of the new Namespace. + * + * @return true if the Namespace was successfully created. + * @see + * GeoServer Documentation + */ public boolean createNamespace(final String prefix, final URI uri) { final String sUrl = restURL + "/rest/namespaces"; final GSNamespaceEncoder nsenc = new GSNamespaceEncoder(prefix, uri); @@ -267,16 +296,19 @@ public class GeoServerRESTPublisher { return result != null; } - /** - * Update a namespace URI. - * - * Prefix and uri are mandatory and cannot be empty. - * A namespace with the given prefix should exist. - * - * @param prefix The prefix of an existing namespace. - * @param uri The new URI. - * @return true if the namespace was successfully updated. - */ + /** + * Update a Namespace URI. + * + * Prefix and URI are mandatory and cannot be empty. A Namespace with the + * given prefix should exist. + * + * @param prefix + * The prefix of an existing Namespace. + * @param uri + * The new URI. + * + * @return true if the Namespace was successfully updated. + */ public boolean updateNamespace(final String prefix, final URI uri) { final String sUrl = restURL + "/rest/namespaces/"+ encode(prefix); final GSNamespaceEncoder nsenc = new GSNamespaceEncoder(prefix, uri); @@ -285,20 +317,22 @@ public class GeoServerRESTPublisher { return result != null; } - /** - * Remove a given Namespace. It will remove the associated workspace as well. - * - * @param prefix - * The namespace prefix - * @param recurse - * The recurse parameter is used to recursively delete all - * resources contained in the workspace associated with this - * namespace. This includesdata stores, coverage stores, - * feature types, etc... Allowable values for this parameter - * are true or false. The default (safer) value - * is false. - * @return true if the namespace was successfully removed. - */ + /** + * Remove a given Namespace. It will remove the associated Workspace as + * well. + * + * @param prefix + * The Namespace prefix + * @param recurse + * The recurse parameter is used to recursively delete all + * resources contained in the workspace associated with this + * Namespace. This includes data stores, coverage stores, feature + * types, etc... Allowable values for this parameter are + * true or false. The default (safer) value is + * false. + * + * @return true if the Namespace was successfully removed. + */ public boolean removeNamespace(final String prefix, boolean recurse) { // Hack: We are instead calling removeWorkspace, as DELETE on // a namespace will leave associated workspace in an inconsistent @@ -311,24 +345,22 @@ public class GeoServerRESTPublisher { // === STYLES // ========================================================================== - /** - * Store and publish an SLD. - *
- * This is the equivalent call with cUrl: - * - *
- * {@code curl -u admin:geoserver -XPOST \
- * -H 'Content-type: application/vnd.ogc.sld+xml' \
- * -d @$FULLSLD \
- * http://$GSIP:$GSPORT/$SERVLET/rest/styles}
- *
- *
- * @param sldBody
- * the SLD document as an XML String.
- *
- * @return true if the operation completed successfully.
- */
+ /**
+ * Store and publish a Style.
+ *
+ * @param sldBody
+ * the full SLD document as a String.
+ *
+ * @return true if the operation completed successfully.
+ */
public boolean publishStyle(String sldBody) {
+ /* This is the equivalent call with cUrl:
+ *
+ * {@code curl -u admin:geoserver -XPOST \
+ * -H 'Content-type: application/vnd.ogc.sld+xml' \
+ * -d @$FULLSLD \
+ * http://$GSIP:$GSPORT/$SERVLET/rest/styles}
+ */
try {
return publishStyle(sldBody, null);
} catch (IllegalArgumentException e) {
@@ -339,29 +371,28 @@ public class GeoServerRESTPublisher {
return false;
}
- /**
- * Store and publish an SLD.
- * - * This is the equivalent call with cUrl: - * - *
- * {@code curl -u admin:geoserver -XPOST \
- * -H 'Content-type: application/vnd.ogc.sld+xml' \
- * -d @$FULLSLD \
- * http://$GSIP:$GSPORT/$SERVLET/rest/styles?name=name}
- *
- *
- * @param sldBody
- * the SLD document as an XML String.
- * @param name
- * the Style name (can be null).
- *
- * @return true if the operation completed successfully.
- * @throws IllegalArgumentException
- * if the style body is null or empty
- */
+ /**
+ * Store and publish a Style, assigning it a name.
+ *
+ * @param sldBody
+ * the full SLD document as a String.
+ * @param name
+ * the Style name.
+ *
+ * @return true if the operation completed successfully.
+ * @throws IllegalArgumentException
+ * if the style body is null or empty.
+ */
public boolean publishStyle(final String sldBody, final String name)
throws IllegalArgumentException {
+ /*
+ * This is the equivalent call with cUrl:
+ *
+ * {@code curl -u admin:geoserver -XPOST \
+ * -H 'Content-type: application/vnd.ogc.sld+xml' \
+ * -d @$FULLSLD \
+ * http://$GSIP:$GSPORT/$SERVLET/rest/styles?name=name}
+ */
if (sldBody == null || sldBody.isEmpty()) {
throw new IllegalArgumentException(
"The style body may not be null or empty");
@@ -377,10 +408,9 @@ public class GeoServerRESTPublisher {
}
/**
- * Store and publish an SLD.
+ * Store and publish a Style.
*
- * @param sldFile
- * the File containing the SLD document.
+ * @param sldFile the File containing the SLD document.
*
* @return true if the operation completed successfully.
*/
@@ -388,16 +418,16 @@ public class GeoServerRESTPublisher {
return publishStyle(sldFile, null);
}
- /**
- * Store and publish an SLD, assigning it a name.
- *
- * @param sldFile
- * the File containing the SLD document.
- * @param name
- * the Style name.
- *
- * @return true if the operation completed successfully.
- */
+ /**
+ * Store and publish a Style, assigning it a name.
+ *
+ * @param sldFile
+ * the File containing the SLD document.
+ * @param name
+ * the Style name.
+ *
+ * @return true if the operation completed successfully.
+ */
public boolean publishStyle(File sldFile, String name) {
String sUrl = restURL + "/rest/styles";
if (name != null && !name.isEmpty()) {
@@ -409,31 +439,28 @@ public class GeoServerRESTPublisher {
return result != null;
}
- /**
- * Update SLD called as 'name'.
- * - * This is the equivalent call with cUrl: - * - *
- * {@code curl -u admin:geoserver -XPUT \
- * -H 'Content-type: application/vnd.ogc.sld+xml' \
- * -d @$FULLSLD \
- * http://$GSIP:$GSPORT/$SERVLET/rest/styles/$NAME}
- *
- *
- * @param sldBody
- * the SLD document as an XML String.
- * @param name
- * the Style name to modify.
- *
- * @return true if the operation completed successfully.
- *
- * @throws IllegalArgumentException
- * if the style body or name are null or empty
- *
- */
+ /**
+ * Update a Style.
+ *
+ * @param sldBody
+ * the new SLD document as a String.
+ * @param name
+ * the Style name to update.
+ *
+ * @return true if the operation completed successfully.
+ * @throws IllegalArgumentException
+ * if the style body or name are null or empty.
+ */
public boolean updateStyle(final String sldBody, final String name)
throws IllegalArgumentException {
+ /*
+ * This is the equivalent call with cUrl:
+ *
+ * {@code curl -u admin:geoserver -XPUT \
+ * -H 'Content-type: application/vnd.ogc.sld+xml' \
+ * -d @$FULLSLD \
+ * http://$GSIP:$GSPORT/$SERVLET/rest/styles/$NAME}
+ */
if (sldBody == null || sldBody.isEmpty()) {
throw new IllegalArgumentException(
"The style body may not be null or empty");
@@ -450,20 +477,18 @@ public class GeoServerRESTPublisher {
return result != null;
}
- /**
- * Update an SLD called 'name'.
- *
- * @param sldFile
- * the File containing the SLD document.
- * @param name
- * the Style name.
- *
- * @return true if the operation completed successfully.
- *
- * @throws IllegalArgumentException
- * if the sldFile file or name are null or name is empty
- *
- */
+ /**
+ * Update a Style.
+ *
+ * @param sldFile
+ * the File containing the SLD document.
+ * @param name
+ * the Style name.
+ *
+ * @return true if the operation completed successfully.
+ * @throws IllegalArgumentException
+ * if the sldFile file or name are null or name is empty.
+ */
public boolean updateStyle(final File sldFile, final String name)
throws IllegalArgumentException {
@@ -484,21 +509,21 @@ public class GeoServerRESTPublisher {
}
- /**
- * Remove a Style.+ * The Style will be unpublished, and (optionally) the SLD file will be + * removed. + * + * @param styleName + * the name of the Style to remove. + * @param purge + * remove the related SLD file from disk. + * + * @return true if the operation completed successfully. + * @throws IllegalArgumentException + * if styleName is null or empty. + */ public boolean removeStyle(String styleName, final boolean purge) throws IllegalArgumentException { if (styleName == null || styleName.isEmpty()) @@ -542,38 +567,193 @@ public class GeoServerRESTPublisher { return false; } - private boolean createDataStore(String workspace, String storeName, - UploadMethod method, DataStoreExtension extension, String mimeType, - URI uri, ParameterConfigure configure, NameValuePair... params) - throws FileNotFoundException, IllegalArgumentException { - return createStore(workspace, DataStoreType.DATASTORES, storeName, - method, extension, mimeType, uri, configure, params); - } + // ========================================================================== + // === DATASTORE PUBLISHING + // ========================================================================== - private boolean createCoverageStore(String workspace, String storeName, - UploadMethod method, CoverageStoreExtension extension, - String mimeType, URI uri, ParameterConfigure configure, - NameValuePair... params) throws FileNotFoundException, - IllegalArgumentException { - return createStore(workspace, DataStoreType.COVERAGESTORES, storeName, - method, extension, mimeType, uri, configure, params); - } + /** + * DataStoreType definitions. + *
+ * The defaultCRS will be set to EPSG:4326.
+ *
+ * @see {@link #publishShp(String, String, NameValuePair[], String, UploadMethod, URI, String, ProjectionPolicy, String)}
+ *
+ * @param workspace
+ * The workspace name.
+ * @param storename
+ * The store name.
+ * @param layername
+ * The layer name.
+ * @param zipFile
+ * The zipped file to publish.
+ *
+ * @return {@code true} if the operation completed successfully.
+ * @throws FileNotFoundException
+ * , IllegalArgumentException
+ */
public boolean publishShp(String workspace, String storename,
String datasetname, File zipFile) throws FileNotFoundException, IllegalArgumentException {
return publishShp(workspace, storename, new NameValuePair[0], datasetname,UploadMethod.FILE, zipFile.toURI(), "EPSG:4326", ProjectionPolicy.NONE,null);
}
- /**
- *
- * Publish a shapefile.
- *
- * @param workspace
- * the name of the workspace to use
- * @param storename
- * the name of the store to create
- * @param storeParams
- * parameters to append to the url (can be null).
- * Accepted parameters are:
- *
- * These are the equivalent calls with cUrl: - * - *
- * {@code
- * curl -u admin:geoserver -XPUT -H 'Content-type: application/zip' \
- * --data-binary @$ZIPFILE \
- * http://$GSIP:$GSPORT/$SERVLET/rest/workspaces/$WORKSPACE/datastores/$STORENAME/file.shp
- *
- * curl -u admin:geoserver -XPOST -H 'Content-type: text/xml' \
- * -d "$BARE EPSG:4326 true " \
- * http://$GSIP:$GSPORT/$SERVLET/rest/workspaces/$WORKSPACE/datastores/$STORENAME/featuretypes/$LAYERNAME
- * }
- *
- *
- * @return true if the operation completed successfully.
- */
+ /**
+ * Publish a zipped shapefile.
+ *
+ * @see {@link #publishShp(String, String, NameValuePair[], String, UploadMethod, URI, String, ProjectionPolicy, String)}
+ *
+ * @param workspace
+ * the name of the workspace to use
+ * @param storename
+ * the name of the store to create
+ * @param layername
+ * the name of the layer to configure
+ * @param zipFile
+ * The zipped file to publish
+ * @param srs
+ * the native CRS
+ *
+ * @return {@code true} if the operation completed successfully.
+ * @throws FileNotFoundException
+ * if file to upload is not found
+ * @throws IllegalArgumentException
+ * if any of the mandatory arguments are {@code null}.
+ */
public boolean publishShp(String workspace, String storename,
String layername, File zipFile, String srs)
throws FileNotFoundException {
+ /*
+ * These are the equivalent calls with cUrl:
+ *
+ * {@code curl -u admin:geoserver -XPUT -H 'Content-type:
+ * application/zip' \ --data-binary @$ZIPFILE \
+ * http://$GSIP:$GSPORT/$SERVLET
+ * /rest/workspaces/$WORKSPACE/datastores/$STORENAME/file.shp
+ *
+ * curl -u admin:geoserver -XPOST -H 'Content-type: text/xml' \ -d
+ * "+ * Will automatically create the store and publish each shapefile as a + * layer. + * + * @param workspace + * the name of the workspace to use + * @param storeName + * the name of the store to create + * @param resource + * the shapefile collection. It can be: + *
- * This is the equivalent call with cUrl: - * - *
- * {@code curl -u admin:geoserver -XPOST -H 'Content-type: text/xml' \
- * -d "easia_gaul_1_aggr EPSG:4326 true " \
- * http://localhost:8080/geoserver/rest/workspaces/it.geosolutions/datastores/pg_kids/featuretypes
- * }
- *
- *
- * and a PUT to + * In a POST or PUT operation the format specifies 1) the representatin of + * the content being sent to the server, and 2) the representation of the + * response to be sent back. The former is specified with the Content-type + * header. To send a representation in XML, the content type "text/xml" or + * "application/xml" would be used. The latter is specified with the Accepts + * header as specified in the above paragraph describing a GET operation. + *
+ * The following table defines the Content-type values for each format: + *
- * This is an example with cUrl: - * - *
- * {@code
- * curl -u admin:geoserver -XPUT -H 'Content-type: application/zip' \
- *
- * --data-binary @$ZIPFILE \
- *
- * http://$GSIP:$GSPORT/$SERVLET/rest/workspaces/$WORKSPACE/coveragestores/$COVERAGESTORE/file.worldimage
- *
- *
- * @param workspace
- * Workspace to use
- * @param coveragestore
- * Name of the coveragestore
- * @param file
- * file to upload
- * @param configure
- * Configure parameter. It may be null.
- * @param params
- * parameters to append to the url (can be null).- * Here is an example call with cUrl: - * - *
- * {@code
- * curl -u admin:geoserver -XPUT -H 'Content-type: application/zip' \
- *
- * --data-binary @$ZIPFILE \
- *
- * http://$GSIP:$GSPORT/$SERVLET/rest/workspaces/$WORKSPACE/coveragestores/$COVERAGESTORE/file.worldimage
- *
- *
- * @param workspace
- * Workspace to use
- * @param coveragestore
- * Name of the coveragestore
- * @param file
- * file to upload
- * @param configure
- * Configure parameter. It may be null.
- * @param update
- * Accepted parameters are:
- * - * This is the equivalent call with cUrl: - * - *
- * {@code
- * curl -u admin:geoserver -XPUT -H 'Content-type: text' -d "file:$FULLPATH" \
- * http://$GSIP:$GSPORT/$SERVLET/rest/workspaces/$WORKSPACE/coveragestores/$STORENAME/external.geotiff
- * }
- *
- *
- * @param workspace
- * Workspace to use
- * @param storeName
- * Name of the coveragestore (if null the file name will be used)
- * @param coverageName
- * the name of the coverage (if null the file name will be used)
- * @param geotiff
- * file to upload
- * @return true if the operation completed successfully.
- * @throws FileNotFoundException
- * if file does not exists
- * @throws IllegalArgumentException
- * if workspace or geotiff are null
- */
+ /**
+ * Upload and publish a GeoTIFF image.
+ *
+ * @param workspace
+ * Workspace to use
+ * @param storeName
+ * Name of the coveragestore (if null the file name will be used)
+ * @param coverageName
+ * the name of the coverage (if null the file name will be used)
+ * @param geotiff
+ * file to upload
+ * @return true if the operation completed successfully.
+ * @throws FileNotFoundException
+ * if file does not exists
+ * @throws IllegalArgumentException
+ * if workspace or geotiff are null
+ */
public boolean publishGeoTIFF(final String workspace,
final String storeName, final String coverageName,
final File geotiff) throws FileNotFoundException,
@@ -1323,11 +1527,14 @@ public class GeoServerRESTPublisher {
: (NameValuePair[]) null);
}
- /**
- * Same as {@link publishGeoTIFF(String, String, String, File, String, ProjectionPolicy, String, double[])}
- * but without the last parameter (bbox). Kept here for backwards compatibility.
- * @deprecated
- */
+ /**
+ * Same as
+ * {@link #publishGeoTIFF(String, String, String, File, String, ProjectionPolicy, String, double[])}
+ * but without the last parameter (bbox). Kept here for backwards
+ * compatibility.
+ *
+ * @deprecated use the former method with bbox set to null.
+ */
public boolean publishGeoTIFF(String workspace, String storeName,
String resourceName, File geotiff, String srs,
ProjectionPolicy policy, String defaultStyle)
@@ -1336,26 +1543,39 @@ public class GeoServerRESTPublisher {
geotiff, srs, policy, defaultStyle, null);
}
- /**
- * @see {@link #publishExternalGeoTIFF(String, String, File, String, String, ProjectionPolicy, String)}
- * @param workspace
- * @param storeName
- * @param resourceName
- * @param geotiff
- * @param srs
- * @param policy
- * @param defaultStyle
- * @param bbox An array of 4 doubles indicating envelope in EPSG:4326. Order is [Xmin, Ymin, Xmax, Ymax]
- * @return
- * @throws FileNotFoundException
- * @throws IllegalArgumentException
- */
+ /**
+ * Upload and publish a GeoTIFF image.
+ *
+ * @param workspace
+ * Workspace to use
+ * @param storeName
+ * Name of the coveragestore (if null the file name will be used)
+ * @param coverageName
+ * the name of the coverage (if null the file name will be used)
+ * @param geotiff
+ * file to upload
+ * @param srs
+ * the native CRS
+ * @param policy
+ * projection policy. See {@link ProjectionPolicy}.
+ * @param defaultStyle
+ * the default style to apply.
+ * @param bbox
+ * An array of 4 doubles indicating envelope in EPSG:4326. Order
+ * is [Xmin, Ymin, Xmax, Ymax].
+ * @return true if the operation completed successfully.
+ * @throws FileNotFoundException
+ * if file does not exists
+ * @throws IllegalArgumentException
+ * if workspace or geotiff are null
+ *
+ */
public boolean publishGeoTIFF(String workspace, String storeName,
- String resourceName, File geotiff, String srs,
+ String coverageName, File geotiff, String srs,
ProjectionPolicy policy, String defaultStyle, double[] bbox)
throws FileNotFoundException, IllegalArgumentException {
if (workspace == null || storeName == null || geotiff == null
- || resourceName == null || srs == null || policy == null
+ || coverageName == null || srs == null || policy == null
|| defaultStyle == null)
throw new IllegalArgumentException("Unable to run: null parameter");
@@ -1371,7 +1591,7 @@ public class GeoServerRESTPublisher {
// config coverage props (srs)
final GSCoverageEncoder coverageEncoder = new GSCoverageEncoder();
- coverageEncoder.setName(resourceName);
+ coverageEncoder.setName(coverageName);
coverageEncoder.setSRS(srs);
coverageEncoder.setProjectionPolicy(policy);
if(bbox != null && bbox.length == 4) {
@@ -1388,25 +1608,31 @@ public class GeoServerRESTPublisher {
final GSLayerEncoder layerEncoder = new GSLayerEncoder();
layerEncoder.setDefaultStyle(defaultStyle);
- return configureLayer(workspace, resourceName, layerEncoder);
+ return configureLayer(workspace, coverageName, layerEncoder);
}
- /**
- *
- * Publish a GeoTiff already in a filesystem readable by GeoServer.
- *
- * @param workspace
- * an existing workspace
- * @param storeName
- * the coverageStore to be created
- * @param geotiff
- * the geoTiff to be published
- * @param srs
- * @param policy
- * @param defaultStyle
- * @return
- * @throws FileNotFoundException
- */
+ /**
+ * Publish a GeoTiff already in a filesystem readable by GeoServer.
+ *
+ * @param workspace
+ * an existing workspace
+ * @param storeName
+ * the coverageStore to be created
+ * @param geotiff
+ * the geoTiff to be published
+ * @param srs
+ * the native CRS
+ * @param policy
+ * projection policy. See {@link ProjectionPolicy}.
+ * @param defaultStyle
+ * the default style to apply.
+ *
+ * @return true if the operation completed successfully.
+ * @throws FileNotFoundException
+ * if file does not exists
+ * @throws IllegalArgumentException
+ * if any of the mandatory parameters are null.
+ */
public boolean publishExternalGeoTIFF(String workspace, String storeName,
File geotiff, String coverageName, String srs,
ProjectionPolicy policy, String defaultStyle)
@@ -1430,24 +1656,26 @@ public class GeoServerRESTPublisher {
coverageEncoder, layerEncoder) != null ? true : false;
}
- /**
- * Publish a GeoTiff already in a filesystem readable by GeoServer.
- *
- * @param workspace
- * an existing workspace
- * @param storeName
- * the coverageStore to be created
- * @param geotiff
- * the geoTiff to be published
- * @param coverageEncoder
- * @param layerEncoder
- * @return true if successfully configured
- *
- *
- * @throws FileNotFoundException
- * @throws IllegalArgumentException
- * if null parameter
- */
+ /**
+ * Publish a GeoTiff already in a filesystem readable by GeoServer.
+ *
+ * @param workspace
+ * an existing workspace
+ * @param storeName
+ * the coverageStore to be created
+ * @param geotiff
+ * the geoTiff to be published
+ * @param coverageEncoder
+ * coverage details. See {@link GSCoverageEncoder}.
+ * @param layerEncoder
+ * layer details, See {@link GSLayerEncoder}.
+ *
+ * @return true if the operation completed successfully.
+ * @throws FileNotFoundException
+ * if file does not exists
+ * @throws IllegalArgumentException
+ * if any of the mandatory parameters are null.
+ */
public RESTCoverageStore publishExternalGeoTIFF(final String workspace,
final String storeName, final File geotiff,
final GSCoverageEncoder coverageEncoder,
@@ -1498,50 +1726,48 @@ public class GeoServerRESTPublisher {
// === WORLDIMAGE
// ==========================================================================
- /**
- * {@link #publishWorldImage(String, String, File, ParameterConfigure, NameValuePair...)}
- */
+ /**
+ * Publish a zipped worldimage file. It is assumed that the the zip-file
+ * contain the *.prj to set the srs.
+ *
+ * @param workspace
+ * Workspace to use
+ * @param coveragestore
+ * Name of the coveragestore
+ * @param zipFile
+ * zip file to upload
+ *
+ * @return true if the operation completed successfully.
+ */
public boolean publishWorldImage(String workspace, String coveragestore,
File zipFile) throws FileNotFoundException {
return publishWorldImage(workspace, coveragestore, zipFile,
ParameterConfigure.FIRST, (NameValuePair) null);
}
- /**
- *
- * Publish a zipped worldimage file. It is assumed that the the zip-file
- * contain the *.prj to set the srs.
- * - * This is equivalent call with cUrl: - * - *
- * {@code
- * curl -u admin:geoserver -XPUT -H 'Content-type: application/zip' \
- *
- * --data-binary @$ZIPFILE \
- *
- * http://$GSIP:$GSPORT/$SERVLET/rest/workspaces/$WORKSPACE/coveragestores/$COVERAGESTORE/file.worldimage
- *
- *
- * @param workspace
- * Workspace to use
- * @param coveragestore
- * Name of the coveragestore
- * @param zipFile
- * zip file to upload
- * @param configure
- * Configure parameter. It may be null.
- * @param params
- * parameters to append to the url (can be null).
- * Sample cUrl usage:
- * <>
- * curl -u admin:geoserver -XPUT -H 'Content-type: text' -d "file:$ABSPORTDIR"
- * http://$GSIP:$GSPORT/$SERVLET/rest/workspaces/$WORKSPACE/coveragestores/$BAREDIR/external.imagemosaic
- *
- * @param workspace
- * an existing workspace
- * @param storeName
- * the name of the coverageStore to be created
- * @param mosaicDir
- * the directory where the raster images are located
- * @param configure
- * a specify if a coverage should be configured
- * @return true if the operation completed successfully.
- * @throws FileNotFoundException
- */
+ /**
+ * Publish a Mosaic from a filesystem currently readable by GeoServer.
+ *
+ * @param workspace
+ * an existing workspace
+ * @param storeName
+ * the name of the coverageStore to be created
+ * @param mosaicDir
+ * the directory where the raster images are located
+ * @param configure
+ * a specify if a coverage should be configured
+ *
+ * @return true if the operation completed successfully.
+ * @throws FileNotFoundException
+ */
public RESTCoverageStore createExternaMosaicDatastore(String workspace,
String storeName, File mosaicDir, ParameterConfigure configure,
ParameterUpdate update) throws FileNotFoundException {
@@ -1623,29 +1869,24 @@ public class GeoServerRESTPublisher {
return RESTCoverageStore.build(sendResult);
}
- /**
- * Publish a Mosaic already in a filesystem readable by GeoServer.
- *
- *
- * Sample cUrl usage:
- * curl -u admin:geoserver -XPUT -H 'Content-type: text' -d "file:$ABSPORTDIR"
- * http://$GSIP:$GSPORT/$SERVLET/rest/workspaces/$WORKSPACE/coveragestores/$BAREDIR/external.imagemosaic
- *
- * @param workspace
- * an existing workspace
- * @param storeName
- * the name of the coverageStore to be created
- * @param mosaicDir
- * the directory where the raster images are located
- * @param srs
- * the coverage declared SRS
- * @param defaultStyle
- * may be null
- *
- * @return true if the operation completed successfully.
- *
- * @throws FileNotFoundException
- */
+ /**
+ * Publish a Mosaic already in a filesystem readable by GeoServer.
+ *
+ * @param workspace
+ * an existing workspace
+ * @param storeName
+ * the name of the coverageStore to be created
+ * @param mosaicDir
+ * the directory where the raster images are located
+ * @param srs
+ * the coverage declared SRS
+ * @param defaultStyle
+ * may be null
+ *
+ * @return true if the operation completed successfully.
+ *
+ * @throws FileNotFoundException
+ */
public boolean publishExternalMosaic(String workspace, String storeName,
File mosaicDir, String srs, String defaultStyle)
throws FileNotFoundException {
@@ -1662,18 +1903,10 @@ public class GeoServerRESTPublisher {
coverageEncoder, layerEncoder);
}
- /**
- * @deprecated use {@link #publishExternalMosaic(String workspace, final
- * String storeName, File mosaicDir, GSCoverageEncoder
- * coverageEncoder, GSLayerEncoder layerEncoder)}
- * @param workspace
- * @param storeName
- * @param mosaicDir
- * @param coverageEncoder
- * @param layerEncoder
- * @return
- * @throws FileNotFoundException
- */
+ /**
+ * @deprecated use
+ * {@link #publishExternalMosaic(String, String, File, GSCoverageEncoder, GSLayerEncoder)}
+ */
public boolean createExternalMosaic(String workspace, String storeName,
File mosaicDir, GSCoverageEncoder coverageEncoder,
GSLayerEncoder layerEncoder) throws FileNotFoundException {
@@ -1681,30 +1914,25 @@ public class GeoServerRESTPublisher {
coverageEncoder, layerEncoder);
}
- /**
- * Publish a Mosaic already in a filesystem readable by GeoServer.
- *
- *
- * Sample cUrl usage:
- * curl -u admin:geoserver -XPUT -H 'Content-type: text' -d "file:$ABSPORTDIR"
- * http://$GSIP:$GSPORT/$SERVLET/rest/workspaces/$WORKSPACE/coveragestores/$BAREDIR/external.imagemosaic
- *
- * @param workspace
- * an existing workspace
- * @param storeName
- * the name of the coverageStore to be created
- * @param mosaicDir
- * the directory where the raster images are located
- * @param coverageEncoder
- * the set of parameters to be set to the coverage (bbox, srs,
- * ...)
- * @param layerEncoder
- * the set of parameters to be set to the layer (defaultstyle,
- * wmspath, ...)
- * @return true if the operation completed successfully.
- *
- * @throws FileNotFoundException
- */
+ /**
+ * Publish a Mosaic already in a filesystem readable by GeoServer.
+ *
+ * @param workspace
+ * an existing workspace
+ * @param storeName
+ * the name of the coverageStore to be created
+ * @param mosaicDir
+ * the directory where the raster images are located
+ * @param coverageEncoder
+ * the set of parameters to be set to the coverage (bbox, srs,
+ * ...)
+ * @param layerEncoder
+ * the set of parameters to be set to the layer (defaultstyle,
+ * wmspath, ...)
+ *
+ * @return true if the operation completed successfully.
+ * @throws FileNotFoundException
+ */
public boolean publishExternalMosaic(String workspace,
final String storeName, File mosaicDir,
GSCoverageEncoder coverageEncoder, GSLayerEncoder layerEncoder)
@@ -1744,23 +1972,20 @@ public class GeoServerRESTPublisher {
return true;
}
- // ==========================================================================
- // === COVERAGES
- // ==========================================================================
+ // ==========================================================================
+ // === REMOVING THINGS
+ // ==========================================================================
- /**
- * Remove the Coverage configuration from GeoServer.
- * First, the associated layer is removed, then the Coverage configuration
- * itself.
- *
- * CHECKME Maybe the coveragestore has to be removed as well. - * - *
- * REST URL: - * http://localhost:8080/geoserver/rest/workspaces/it.geosolutions/coveragestores/gbRESTtestStore/coverages/resttestdem.xml - * - * @return true if the operation completed successfully. - */ + /** + * Remove the Coverage configuration from GeoServer. + *
+ * First, the associated layer is removed, then the Coverage configuration + * itself. + *
+ * CHECKME Maybe the coveragestore has to be removed as well.
+ *
+ * @return true if the operation completed successfully.
+ */
public boolean unpublishCoverage(String workspace, String storename,
String layerName) {
try {
@@ -1822,17 +2047,14 @@ public class GeoServerRESTPublisher {
}
}
- // ==========================================================================
- // === FEATURETYPES
- // ==========================================================================
-
- /**
- * Removes the featuretype and the associated layer.
- * You may also want to {@link #removeDatastore(String, String) remove the
- * datastore}.
- *
- * @return true if the operation completed successfully.
- */
+ /**
+ * Removes the featuretype and the associated layer.
+ *
+ * You may also want to {@link #removeDatastore(String, String) remove the
+ * datastore}.
+ *
+ * @return true if the operation completed successfully.
+ */
public boolean unpublishFeatureType(String workspace, String storename,
String layerName) {
try {
@@ -2084,34 +2306,13 @@ public class GeoServerRESTPublisher {
}
}
- /**
- * reload the target geoserver configuration
- *
- * @return true if success
- *
- * @see http
- * ://docs.geoserver.org/stable/en/user/restconfig/rest-config-api.html
- */
- public boolean reload() {
- String sUrl = restURL + "/rest/reload";
- String result = HTTPUtils.post(sUrl, "", "text/plain", gsuser, gspass);
- return result != null;
- }
-
- /**
- * reset the target geoserver configuration
- *
- * @return true if success
- *
- * @see http
- * ://docs.geoserver.org/stable/en/user/restconfig/rest-config-api.html
- */
- public boolean reset() {
- String sUrl = restURL + "/rest/reset";
- String result = HTTPUtils.post(sUrl, "", "text/plain", gsuser, gspass);
- return result != null;
- }
-
+ /**
+ * Remove a layer group.
+ *
+ * @param name
+ * the layer group name.
+ * @return true if succeeded.
+ */
public boolean removeLayerGroup(String name) {
try {
URL deleteUrl = new URL(restURL + "/rest/layergroups/" + name);
@@ -2133,10 +2334,6 @@ public class GeoServerRESTPublisher {
}
}
- // ==========================================================================
- // ===
- // ==========================================================================
-
/**
* remove a generic given layer from a given workspace
*
@@ -2183,6 +2380,44 @@ public class GeoServerRESTPublisher {
return result;
}
+ // ==========================================================================
+ // === CATALOG REFRESHING
+ // ==========================================================================
+
+ /**
+ * Reload the target geoserver configuration
+ *
+ * @return true if success
+ *
+ * @see GeoServer
+ * REST Config API
+ */
+ public boolean reload() {
+ String sUrl = restURL + "/rest/reload";
+ String result = HTTPUtils.post(sUrl, "", "text/plain", gsuser, gspass);
+ return result != null;
+ }
+
+ /**
+ * Reset the target geoserver configuration
+ *
+ * @return true if success
+ *
+ * @see GeoServer
+ * REST Config API
+ */
+ public boolean reset() {
+ String sUrl = restURL + "/rest/reset";
+ String result = HTTPUtils.post(sUrl, "", "text/plain", gsuser, gspass);
+ return result != null;
+ }
+
+ // ==========================================================================
+ // === MISCELLANEA
+ // ==========================================================================
+
/**
* Allows to configure some layer attributes such and DefaultStyle
*
@@ -2306,10 +2541,6 @@ public class GeoServerRESTPublisher {
/**
* @deprecated use
* {@link #createCoverage(String, String, GSCoverageEncoder)}
- * @param ce
- * @param wsname
- * @param csname
- * @return
*/
public boolean createCoverage(final GSCoverageEncoder ce,
final String wsname, final String csname) {
@@ -2399,8 +2630,8 @@ public class GeoServerRESTPublisher {
return sendResult != null;
}
- /**
- *
+ /**
+ * Appends ".DUMMY" to any string containing a dot (sic).
*/
protected String sanitize(String s) {
if (s.indexOf(".") != -1) {
@@ -2409,17 +2640,17 @@ public class GeoServerRESTPublisher {
return s;
}
- /**
- * Append params generating a string in the form:
- *
- * NAME_0=VALUE_0&NAME_1=VALUE_1&....&NAME_n-1=VALUE_n-1 - *
- * - * - * @param params - * an array of NameValuePair - * @return the parameter string or empty an string - */ + /** + * Append params generating a string in the form: + *+ * NAME_0=VALUE_0&NAME_1=VALUE_1&....&NAME_n-1=VALUE_n-1 + *
+ * + * + * @param params + * an array of NameValuePair + * @return the parameter string or empty an string + */ private String appendParameters(NameValuePair... params) { StringBuilder sbUrl = new StringBuilder(); // append parameters @@ -2462,6 +2693,13 @@ public class GeoServerRESTPublisher { return sbUrl.toString(); } + /** + * URL-encodes a String. + * + * @param s + * The original string. + * @return The encoded string. + */ protected String encode(String s) { // try { // return URLEncoder.encode(s,"UTF-8"); diff --git a/src/main/java/it/geosolutions/geoserver/rest/encoder/GSResourceEncoder.java b/src/main/java/it/geosolutions/geoserver/rest/encoder/GSResourceEncoder.java index 44fbdda..df84b31 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/encoder/GSResourceEncoder.java +++ b/src/main/java/it/geosolutions/geoserver/rest/encoder/GSResourceEncoder.java @@ -135,11 +135,21 @@ public abstract class GSResourceEncoder })).size() == 0 ? false : true; } - /** - * NONE, REPROJECT_TO_DECLARED, FORCE_DECLARED - */ + /** + * Reprojection policy for a published layer. One of: + *