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,10 +84,11 @@ 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);
|
||||||
return result != null;
|
return result != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,10 +101,10 @@ public class GeoServerRESTStructuredGridCoverageReaderManager extends GeoServerR
|
|||||||
* @param string the {@link String} to be checked
|
* @param string the {@link String} to be checked
|
||||||
*/
|
*/
|
||||||
private static void checkString(String string) {
|
private static void checkString(String string) {
|
||||||
if(string==null){
|
if (string == null) {
|
||||||
throw new NullPointerException("Provided string is is null!");
|
throw new NullPointerException("Provided string is is null!");
|
||||||
}
|
}
|
||||||
if(string.length()<=0){
|
if (string.length() <= 0) {
|
||||||
throw new IllegalArgumentException("Provided string is is empty!");
|
throw new IllegalArgumentException("Provided string is is empty!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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);
|
||||||
@ -127,45 +134,48 @@ public class GeoServerRESTStructuredGridCoverageReaderManager extends GeoServerR
|
|||||||
checkString(coverageStore);
|
checkString(coverageStore);
|
||||||
|
|
||||||
// does it exist?
|
// does it exist?
|
||||||
RESTStructuredCoverageGranulesList granulesList=null;
|
RESTStructuredCoverageGranulesList granulesList = null;
|
||||||
try {
|
try {
|
||||||
granulesList = getGranules(workspace, coverageStore, coverageStore, filter, null, 1);
|
granulesList = getGranules(workspace, coverageStore, coverageStore, filter, null, 1);
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
if(LOGGER.isTraceEnabled()){
|
if (LOGGER.isTraceEnabled()) {
|
||||||
LOGGER.trace(e.getMessage(), e);
|
LOGGER.trace(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
if(LOGGER.isTraceEnabled()){
|
if (LOGGER.isTraceEnabled()) {
|
||||||
LOGGER.trace(e.getMessage(), e);
|
LOGGER.trace(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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",
|
||||||
if(!HTTPUtils.delete(sUrl, gsuser, gspass)){
|
"/", coverageStore, "/coverages/", coverage, "/index/granules?filter=",
|
||||||
|
URLEncoder.encode(filter, "UTF-8")).toString();
|
||||||
|
if (!HTTPUtils.delete(sUrl, gsuser, gspass)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// does it exist?
|
// does it exist?
|
||||||
granulesList=null;
|
granulesList = null;
|
||||||
try {
|
try {
|
||||||
granulesList = getGranules(workspace, coverageStore, coverageStore, filter, null, 1);
|
granulesList = getGranules(workspace, coverageStore, coverageStore, filter, null, 1);
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
if(LOGGER.isTraceEnabled()){
|
if (LOGGER.isTraceEnabled()) {
|
||||||
LOGGER.trace(e.getMessage(), e);
|
LOGGER.trace(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
if(LOGGER.isTraceEnabled()){
|
if (LOGGER.isTraceEnabled()) {
|
||||||
LOGGER.trace(e.getMessage(), e);
|
LOGGER.trace(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (granulesList == null||granulesList.isEmpty()) {
|
if (granulesList == null || granulesList.isEmpty()) {
|
||||||
return true; // nothing to remove
|
return true; // nothing to remove
|
||||||
}
|
}
|
||||||
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);
|
||||||
@ -192,21 +205,22 @@ public class GeoServerRESTStructuredGridCoverageReaderManager extends GeoServerR
|
|||||||
checkString(coverageStore);
|
checkString(coverageStore);
|
||||||
|
|
||||||
// does it exist?
|
// does it exist?
|
||||||
RESTStructuredCoverageGranulesList granule=null;
|
RESTStructuredCoverageGranulesList granule = null;
|
||||||
try {
|
try {
|
||||||
granule = getGranuleById(workspace, coverageStore, coverage, granuleId);
|
granule = getGranuleById(workspace, coverageStore, coverage, granuleId);
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
if(LOGGER.isTraceEnabled()){
|
if (LOGGER.isTraceEnabled()) {
|
||||||
LOGGER.trace(e.getMessage(), e);
|
LOGGER.trace(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
if(LOGGER.isTraceEnabled()){
|
if (LOGGER.isTraceEnabled()) {
|
||||||
LOGGER.trace(e.getMessage(), e);
|
LOGGER.trace(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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
|
||||||
}
|
}
|
||||||
@ -215,21 +229,21 @@ public class GeoServerRESTStructuredGridCoverageReaderManager extends GeoServerR
|
|||||||
String sUrl = HTTPUtils.append(restURL, "/rest/workspaces/", workspace, "/coveragestores",
|
String sUrl = HTTPUtils.append(restURL, "/rest/workspaces/", workspace, "/coveragestores",
|
||||||
"/", coverageStore, "/coverages/", coverage, "/index/granules/", granuleId)
|
"/", coverageStore, "/coverages/", coverage, "/index/granules/", granuleId)
|
||||||
.toString();
|
.toString();
|
||||||
if(!HTTPUtils.delete(sUrl, gsuser, gspass)){
|
if (!HTTPUtils.delete(sUrl, gsuser, gspass)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// has it been canceled?
|
// has it been canceled?
|
||||||
// does it exist?
|
// does it exist?
|
||||||
granule=null;
|
granule = null;
|
||||||
try {
|
try {
|
||||||
granule = getGranuleById(workspace, coverageStore, coverage, granuleId);
|
granule = getGranuleById(workspace, coverageStore, coverage, granuleId);
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
if(LOGGER.isTraceEnabled()){
|
if (LOGGER.isTraceEnabled()) {
|
||||||
LOGGER.trace(e.getMessage(), e);
|
LOGGER.trace(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
if(LOGGER.isTraceEnabled()){
|
if (LOGGER.isTraceEnabled()) {
|
||||||
LOGGER.trace(e.getMessage(), e);
|
LOGGER.trace(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -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,
|
||||||
@ -333,14 +365,15 @@ public class GeoServerRESTStructuredGridCoverageReaderManager extends GeoServerR
|
|||||||
checkString(coverage);
|
checkString(coverage);
|
||||||
checkString(coverageStore);
|
checkString(coverageStore);
|
||||||
checkString(id);
|
checkString(id);
|
||||||
try{
|
try {
|
||||||
Integer.parseInt(id);
|
Integer.parseInt(id);
|
||||||
}catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
throw new IllegalArgumentException(e);
|
throw new IllegalArgumentException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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