add some javadoc and checks for arguments and apply geotools code refactoring to GeoServerRESTStructuredGridCoverageReaderManager
This commit is contained in:
parent
a81cf80f3f
commit
9e17fda833
@ -38,9 +38,8 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Manage GeoTools StructuredGridCoverageReader. It allows to create a store from a file or harvest
|
||||
* the coverages contained in a file, to delete granules from an existing coverage and eventually
|
||||
* to get information about the granules inside a StructuredGridCoverageReader.
|
||||
* Manage GeoTools StructuredGridCoverageReader. It allows to create a store from a file or harvest the coverages contained in a file, to delete
|
||||
* granules from an existing coverage and eventually to get information about the granules inside a StructuredGridCoverageReader.
|
||||
*
|
||||
* @author Simone Giannecchini, GeoSolutions
|
||||
*/
|
||||
@ -49,7 +48,8 @@ public class GeoServerRESTStructuredGridCoverageReaderManager extends GeoServerR
|
||||
/**
|
||||
* Default logger
|
||||
*/
|
||||
private final static Logger LOGGER = LoggerFactory.getLogger(GeoServerRESTStructuredGridCoverageReaderManager.class);
|
||||
private final static Logger LOGGER = LoggerFactory
|
||||
.getLogger(GeoServerRESTStructuredGridCoverageReaderManager.class);
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
@ -59,7 +59,8 @@ public class GeoServerRESTStructuredGridCoverageReaderManager extends GeoServerR
|
||||
* @param password GeoServer REST API password for the former username
|
||||
* @throws IllegalArgumentException
|
||||
*/
|
||||
public GeoServerRESTStructuredGridCoverageReaderManager(URL restURL, String username, String password) throws IllegalArgumentException, MalformedURLException{
|
||||
public GeoServerRESTStructuredGridCoverageReaderManager(URL restURL, String username,
|
||||
String password) throws IllegalArgumentException, MalformedURLException {
|
||||
super(restURL, username, password);
|
||||
}
|
||||
|
||||
@ -72,8 +73,10 @@ public class GeoServerRESTStructuredGridCoverageReaderManager extends GeoServerR
|
||||
* @param the absolut path to the file to upload
|
||||
*
|
||||
* @return <code>true</code> if the call succeeds or <code>false</code> otherwise.
|
||||
* @since geoserver-2.4.0, geoserver-mng-1.6.0
|
||||
*/
|
||||
public boolean createOrHarvestExternal(String workspace, String coverageStore, String format, String path) {
|
||||
public boolean createOrHarvestExternal(String workspace, String coverageStore, String format,
|
||||
String path) {
|
||||
// checks
|
||||
checkString(workspace);
|
||||
checkString(coverageStore);
|
||||
@ -81,7 +84,8 @@ public class GeoServerRESTStructuredGridCoverageReaderManager extends GeoServerR
|
||||
checkString(path);
|
||||
|
||||
// create URL
|
||||
String sUrl = HTTPUtils.append(restURL, "/rest/workspaces/", workspace, "/coveragestores/",coverageStore,"/",UploadMethod.EXTERNAL.toString(),".", format).toString();
|
||||
String sUrl = HTTPUtils.append(restURL, "/rest/workspaces/", workspace, "/coveragestores/",
|
||||
coverageStore, "/", UploadMethod.EXTERNAL.toString(), ".", format).toString();
|
||||
|
||||
// POST request
|
||||
String result = HTTPUtils.post(sUrl, "file:/" + path, "text/plain", gsuser, gspass);
|
||||
@ -118,8 +122,11 @@ public class GeoServerRESTStructuredGridCoverageReaderManager extends GeoServerR
|
||||
*
|
||||
* @throws MalformedURLException
|
||||
* @throws UnsupportedEncodingException
|
||||
*
|
||||
* @since geoserver-2.4.0, geoserver-mng-1.6.0
|
||||
*/
|
||||
public boolean removeGranulesByCQL(final String workspace, String coverageStore,String coverage, String filter) throws UnsupportedEncodingException{
|
||||
public boolean removeGranulesByCQL(final String workspace, String coverageStore,
|
||||
String coverage, String filter) throws UnsupportedEncodingException {
|
||||
// checks
|
||||
checkString(workspace);
|
||||
checkString(coverage);
|
||||
@ -141,13 +148,16 @@ public class GeoServerRESTStructuredGridCoverageReaderManager extends GeoServerR
|
||||
}
|
||||
if (granulesList == null || granulesList.isEmpty()) {
|
||||
if (LOGGER.isTraceEnabled()) {
|
||||
LOGGER.trace("Granules for filter: "+filter+ " does not exist for coverage "+coverage);
|
||||
LOGGER.trace("Granules for filter: " + filter + " does not exist for coverage "
|
||||
+ coverage);
|
||||
}
|
||||
return true; // nothing to remove
|
||||
}
|
||||
|
||||
// method
|
||||
String sUrl = HTTPUtils.append(restURL, "/rest/workspaces/", workspace, "/coveragestores", "/",coverageStore,"/coverages/",coverage,"/index/granules?filter=",URLEncoder.encode(filter, "UTF-8")).toString();
|
||||
String sUrl = HTTPUtils.append(restURL, "/rest/workspaces/", workspace, "/coveragestores",
|
||||
"/", coverageStore, "/coverages/", coverage, "/index/granules?filter=",
|
||||
URLEncoder.encode(filter, "UTF-8")).toString();
|
||||
if (!HTTPUtils.delete(sUrl, gsuser, gspass)) {
|
||||
return false;
|
||||
}
|
||||
@ -183,8 +193,11 @@ public class GeoServerRESTStructuredGridCoverageReaderManager extends GeoServerR
|
||||
*
|
||||
* @throws MalformedURLException
|
||||
* @throws UnsupportedEncodingException
|
||||
*
|
||||
* @since geoserver-2.4.0, geoserver-mng-1.6.0
|
||||
*/
|
||||
public boolean removeGranuleById(final String workspace, String coverageStore, String coverage, String granuleId) {
|
||||
public boolean removeGranuleById(final String workspace, String coverageStore, String coverage,
|
||||
String granuleId) {
|
||||
// checks
|
||||
checkString(workspace);
|
||||
checkString(coverage);
|
||||
@ -206,7 +219,8 @@ public class GeoServerRESTStructuredGridCoverageReaderManager extends GeoServerR
|
||||
}
|
||||
if (granule == null) {
|
||||
if (LOGGER.isTraceEnabled()) {
|
||||
LOGGER.trace("Granule for id: "+granuleId+ " does not exist for coverage "+coverage);
|
||||
LOGGER.trace("Granule for id: " + granuleId + " does not exist for coverage "
|
||||
+ coverage);
|
||||
}
|
||||
return true; // nothing to remove
|
||||
}
|
||||
@ -251,15 +265,19 @@ public class GeoServerRESTStructuredGridCoverageReaderManager extends GeoServerR
|
||||
*
|
||||
* @throws MalformedURLException
|
||||
* @throws UnsupportedEncodingException
|
||||
*
|
||||
* @since geoserver-2.4.0, geoserver-mng-1.6.0
|
||||
*/
|
||||
public RESTStructuredCoverageIndexSchema getGranuleIndexSchema(final String workspace, String coverageStore, String coverage) throws MalformedURLException {
|
||||
public RESTStructuredCoverageIndexSchema getGranuleIndexSchema(final String workspace,
|
||||
String coverageStore, String coverage) throws MalformedURLException {
|
||||
// checks
|
||||
checkString(workspace);
|
||||
checkString(coverage);
|
||||
checkString(coverageStore);
|
||||
|
||||
// create URL and then call it
|
||||
String sUrl = HTTPUtils.append(restURL, "/rest/workspaces/", workspace, "/coveragestores/", coverageStore, "/coverages/", coverage, "/index.xml").toString();
|
||||
String sUrl = HTTPUtils.append(restURL, "/rest/workspaces/", workspace, "/coveragestores/",
|
||||
coverageStore, "/coverages/", coverage, "/index.xml").toString();
|
||||
String result = HTTPUtils.get(sUrl, gsuser, gspass);
|
||||
if (result != null) {
|
||||
return RESTStructuredCoverageIndexSchema.build(result);
|
||||
@ -281,8 +299,11 @@ public class GeoServerRESTStructuredGridCoverageReaderManager extends GeoServerR
|
||||
*
|
||||
* @throws MalformedURLException
|
||||
* @throws UnsupportedEncodingException
|
||||
*
|
||||
* @since geoserver-2.4.0, geoserver-mng-1.6.0
|
||||
*/
|
||||
public RESTStructuredCoverageGranulesList getGranules(final String workspace, String coverageStore, String coverage, String filter, Integer offset, Integer limit)
|
||||
public RESTStructuredCoverageGranulesList getGranules(final String workspace,
|
||||
String coverageStore, String coverage, String filter, Integer offset, Integer limit)
|
||||
throws MalformedURLException, UnsupportedEncodingException {
|
||||
// checks
|
||||
checkString(workspace);
|
||||
@ -291,17 +312,26 @@ public class GeoServerRESTStructuredGridCoverageReaderManager extends GeoServerR
|
||||
|
||||
// method
|
||||
boolean append = false;
|
||||
String sUrl = HTTPUtils.append(restURL, "/rest/workspaces/", workspace, "/coveragestores/", coverageStore, "/coverages/", coverage, "/index/granules.xml").toString();
|
||||
String sUrl = HTTPUtils.append(restURL, "/rest/workspaces/", workspace, "/coveragestores/",
|
||||
coverageStore, "/coverages/", coverage, "/index/granules.xml").toString();
|
||||
if (filter != null && !filter.isEmpty()) {
|
||||
append = true;
|
||||
sUrl = HTTPUtils.append(sUrl, "?filter=", URLEncoder.encode(filter, "UTF-8")).toString();
|
||||
sUrl = HTTPUtils.append(sUrl, "?filter=", URLEncoder.encode(filter, "UTF-8"))
|
||||
.toString();
|
||||
}
|
||||
if (offset != null) {
|
||||
sUrl = HTTPUtils.append(sUrl, append ? "&offset=" : "?offset=", offset.toString()).toString();
|
||||
if (offset < 0)
|
||||
offset = 0;
|
||||
sUrl = HTTPUtils.append(sUrl, append ? "&offset=" : "?offset=", offset.toString())
|
||||
.toString();
|
||||
append = true;
|
||||
}
|
||||
if (limit != null) {
|
||||
sUrl = HTTPUtils.append(sUrl, append ? "&limit=" : "?limit=", limit.toString()).toString();
|
||||
if (limit < 1) {
|
||||
limit = 1;
|
||||
}
|
||||
sUrl = HTTPUtils.append(sUrl, append ? "&limit=" : "?limit=", limit.toString())
|
||||
.toString();
|
||||
append = true;
|
||||
}
|
||||
String result = HTTPUtils.get(sUrl, gsuser, gspass);
|
||||
@ -324,6 +354,8 @@ public class GeoServerRESTStructuredGridCoverageReaderManager extends GeoServerR
|
||||
*
|
||||
* @throws MalformedURLException
|
||||
* @throws UnsupportedEncodingException
|
||||
*
|
||||
* @since geoserver-2.4.0, geoserver-mng-1.6.0
|
||||
*/
|
||||
public RESTStructuredCoverageGranulesList getGranuleById(final String workspace,
|
||||
String coverageStore, String coverage, String id) throws MalformedURLException,
|
||||
@ -340,7 +372,8 @@ public class GeoServerRESTStructuredGridCoverageReaderManager extends GeoServerR
|
||||
}
|
||||
|
||||
// method
|
||||
String sUrl = HTTPUtils.append(restURL, "/rest/workspaces/", workspace, "/coveragestores/", coverageStore, "/coverages/", coverage, "/index/granules/", id, ".xml").toString();
|
||||
String sUrl = HTTPUtils.append(restURL, "/rest/workspaces/", workspace, "/coveragestores/",
|
||||
coverageStore, "/coverages/", coverage, "/index/granules/", id, ".xml").toString();
|
||||
String result = HTTPUtils.get(sUrl, gsuser, gspass);
|
||||
if (result != null) {
|
||||
return RESTStructuredCoverageGranulesList.build(result);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user