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;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manage GeoTools StructuredGridCoverageReader. It allows to create a store from a file or harvest
|
* Manage GeoTools StructuredGridCoverageReader. It allows to create a store from a file or harvest the coverages contained in a file, to delete
|
||||||
* the coverages contained in a file, to delete granules from an existing coverage and eventually
|
* granules from an existing coverage and eventually to get information about the granules inside a StructuredGridCoverageReader.
|
||||||
* to get information about the granules inside a StructuredGridCoverageReader.
|
|
||||||
*
|
*
|
||||||
* @author Simone Giannecchini, GeoSolutions
|
* @author Simone Giannecchini, GeoSolutions
|
||||||
*/
|
*/
|
||||||
@ -49,7 +48,8 @@ public class GeoServerRESTStructuredGridCoverageReaderManager extends GeoServerR
|
|||||||
/**
|
/**
|
||||||
* Default logger
|
* Default logger
|
||||||
*/
|
*/
|
||||||
private final static Logger LOGGER = LoggerFactory.getLogger(GeoServerRESTStructuredGridCoverageReaderManager.class);
|
private final static Logger LOGGER = LoggerFactory
|
||||||
|
.getLogger(GeoServerRESTStructuredGridCoverageReaderManager.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor.
|
* Default constructor.
|
||||||
@ -59,7 +59,8 @@ public class GeoServerRESTStructuredGridCoverageReaderManager extends GeoServerR
|
|||||||
* @param password GeoServer REST API password for the former username
|
* @param password GeoServer REST API password for the former username
|
||||||
* @throws IllegalArgumentException
|
* @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);
|
super(restURL, username, password);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,8 +73,10 @@ public class GeoServerRESTStructuredGridCoverageReaderManager extends GeoServerR
|
|||||||
* @param the absolut path to the file to upload
|
* @param the absolut path to the file to upload
|
||||||
*
|
*
|
||||||
* @return <code>true</code> if the call succeeds or <code>false</code> otherwise.
|
* @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
|
// checks
|
||||||
checkString(workspace);
|
checkString(workspace);
|
||||||
checkString(coverageStore);
|
checkString(coverageStore);
|
||||||
@ -81,7 +84,8 @@ public class GeoServerRESTStructuredGridCoverageReaderManager extends GeoServerR
|
|||||||
checkString(path);
|
checkString(path);
|
||||||
|
|
||||||
// create URL
|
// 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
|
// POST request
|
||||||
String result = HTTPUtils.post(sUrl, "file:/" + path, "text/plain", gsuser, gspass);
|
String result = HTTPUtils.post(sUrl, "file:/" + path, "text/plain", gsuser, gspass);
|
||||||
@ -118,8 +122,11 @@ public class GeoServerRESTStructuredGridCoverageReaderManager extends GeoServerR
|
|||||||
*
|
*
|
||||||
* @throws MalformedURLException
|
* @throws MalformedURLException
|
||||||
* @throws UnsupportedEncodingException
|
* @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
|
// checks
|
||||||
checkString(workspace);
|
checkString(workspace);
|
||||||
checkString(coverage);
|
checkString(coverage);
|
||||||
@ -141,13 +148,16 @@ public class GeoServerRESTStructuredGridCoverageReaderManager extends GeoServerR
|
|||||||
}
|
}
|
||||||
if (granulesList == null || granulesList.isEmpty()) {
|
if (granulesList == null || granulesList.isEmpty()) {
|
||||||
if (LOGGER.isTraceEnabled()) {
|
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
|
return true; // nothing to remove
|
||||||
}
|
}
|
||||||
|
|
||||||
// method
|
// 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)) {
|
if (!HTTPUtils.delete(sUrl, gsuser, gspass)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -183,8 +193,11 @@ public class GeoServerRESTStructuredGridCoverageReaderManager extends GeoServerR
|
|||||||
*
|
*
|
||||||
* @throws MalformedURLException
|
* @throws MalformedURLException
|
||||||
* @throws UnsupportedEncodingException
|
* @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
|
// checks
|
||||||
checkString(workspace);
|
checkString(workspace);
|
||||||
checkString(coverage);
|
checkString(coverage);
|
||||||
@ -206,7 +219,8 @@ public class GeoServerRESTStructuredGridCoverageReaderManager extends GeoServerR
|
|||||||
}
|
}
|
||||||
if (granule == null) {
|
if (granule == null) {
|
||||||
if (LOGGER.isTraceEnabled()) {
|
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
|
return true; // nothing to remove
|
||||||
}
|
}
|
||||||
@ -251,15 +265,19 @@ public class GeoServerRESTStructuredGridCoverageReaderManager extends GeoServerR
|
|||||||
*
|
*
|
||||||
* @throws MalformedURLException
|
* @throws MalformedURLException
|
||||||
* @throws UnsupportedEncodingException
|
* @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
|
// checks
|
||||||
checkString(workspace);
|
checkString(workspace);
|
||||||
checkString(coverage);
|
checkString(coverage);
|
||||||
checkString(coverageStore);
|
checkString(coverageStore);
|
||||||
|
|
||||||
// create URL and then call it
|
// 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);
|
String result = HTTPUtils.get(sUrl, gsuser, gspass);
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
return RESTStructuredCoverageIndexSchema.build(result);
|
return RESTStructuredCoverageIndexSchema.build(result);
|
||||||
@ -281,8 +299,11 @@ public class GeoServerRESTStructuredGridCoverageReaderManager extends GeoServerR
|
|||||||
*
|
*
|
||||||
* @throws MalformedURLException
|
* @throws MalformedURLException
|
||||||
* @throws UnsupportedEncodingException
|
* @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 {
|
throws MalformedURLException, UnsupportedEncodingException {
|
||||||
// checks
|
// checks
|
||||||
checkString(workspace);
|
checkString(workspace);
|
||||||
@ -291,17 +312,26 @@ public class GeoServerRESTStructuredGridCoverageReaderManager extends GeoServerR
|
|||||||
|
|
||||||
// method
|
// method
|
||||||
boolean append = false;
|
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()) {
|
if (filter != null && !filter.isEmpty()) {
|
||||||
append = true;
|
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) {
|
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;
|
append = true;
|
||||||
}
|
}
|
||||||
if (limit != null) {
|
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;
|
append = true;
|
||||||
}
|
}
|
||||||
String result = HTTPUtils.get(sUrl, gsuser, gspass);
|
String result = HTTPUtils.get(sUrl, gsuser, gspass);
|
||||||
@ -324,6 +354,8 @@ public class GeoServerRESTStructuredGridCoverageReaderManager extends GeoServerR
|
|||||||
*
|
*
|
||||||
* @throws MalformedURLException
|
* @throws MalformedURLException
|
||||||
* @throws UnsupportedEncodingException
|
* @throws UnsupportedEncodingException
|
||||||
|
*
|
||||||
|
* @since geoserver-2.4.0, geoserver-mng-1.6.0
|
||||||
*/
|
*/
|
||||||
public RESTStructuredCoverageGranulesList getGranuleById(final String workspace,
|
public RESTStructuredCoverageGranulesList getGranuleById(final String workspace,
|
||||||
String coverageStore, String coverage, String id) throws MalformedURLException,
|
String coverageStore, String coverage, String id) throws MalformedURLException,
|
||||||
@ -340,7 +372,8 @@ public class GeoServerRESTStructuredGridCoverageReaderManager extends GeoServerR
|
|||||||
}
|
}
|
||||||
|
|
||||||
// method
|
// 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);
|
String result = HTTPUtils.get(sUrl, gsuser, gspass);
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
return RESTStructuredCoverageGranulesList.build(result);
|
return RESTStructuredCoverageGranulesList.build(result);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user