simplify the publisher
This commit is contained in:
parent
a3a8715b03
commit
499924a527
@ -373,8 +373,7 @@ public class GeoServerRESTPublisher {
|
|||||||
sUrl += "?name=" + encode(name);
|
sUrl += "?name=" + encode(name);
|
||||||
}
|
}
|
||||||
LOGGER.debug("POSTing new style " + name + " to " + sUrl);
|
LOGGER.debug("POSTing new style " + name + " to " + sUrl);
|
||||||
String result = HTTPUtils
|
String result = HTTPUtils.post(sUrl, sldFile, Format.SLD.getContentType(), gsuser, gspass);
|
||||||
.post(sUrl, sldFile, Format.SLD.getContentType(), gsuser, gspass);
|
|
||||||
return result != null;
|
return result != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -515,7 +514,7 @@ public class GeoServerRESTPublisher {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static String getTypeName(StoreType type) {
|
public static String getTypeName(StoreType type) {
|
||||||
return StoreType.getTypeNameWithFormat(type,Format.XML);
|
return StoreType.getTypeNameWithFormat(type, Format.XML);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -554,7 +553,7 @@ public class GeoServerRESTPublisher {
|
|||||||
* @return "featureTypes.{xml|html|...}" for DATASTORES, "coverages.{xml|html|...}" otherwise.
|
* @return "featureTypes.{xml|html|...}" for DATASTORES, "coverages.{xml|html|...}" otherwise.
|
||||||
*/
|
*/
|
||||||
public static String getTypeNameWithFormat(StoreType type, Format format) {
|
public static String getTypeNameWithFormat(StoreType type, Format format) {
|
||||||
return getTypeName(type)+"."+format;
|
return getTypeName(type) + "." + format;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -565,7 +564,7 @@ public class GeoServerRESTPublisher {
|
|||||||
* @return "featuretypes.{xml|html|...}" for DATASTORES, "coverages.{xml|html|...}" otherwise.
|
* @return "featuretypes.{xml|html|...}" for DATASTORES, "coverages.{xml|html|...}" otherwise.
|
||||||
*/
|
*/
|
||||||
public String getTypeNameWithFormat(Format format) {
|
public String getTypeNameWithFormat(Format format) {
|
||||||
return getTypeName(this).toLowerCase()+"."+format;
|
return getTypeName(this).toLowerCase() + "." + format;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2010,32 +2009,7 @@ public class GeoServerRESTPublisher {
|
|||||||
*/
|
*/
|
||||||
public boolean removeDatastore(String workspace, String storename, final boolean recurse)
|
public boolean removeDatastore(String workspace, String storename, final boolean recurse)
|
||||||
throws IllegalArgumentException {
|
throws IllegalArgumentException {
|
||||||
try {
|
return removeStore(workspace, storename, StoreType.DATASTORES, recurse);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2047,13 +2021,7 @@ public class GeoServerRESTPublisher {
|
|||||||
* @deprecated use {@link #removeCoverageStore(String, String, boolean)}
|
* @deprecated use {@link #removeCoverageStore(String, String, boolean)}
|
||||||
*/
|
*/
|
||||||
public boolean removeCoverageStore(String workspace, String storename) {
|
public boolean removeCoverageStore(String workspace, String storename) {
|
||||||
try {
|
return removeCoverageStore(workspace, storename, true);
|
||||||
return removeCoverageStore(workspace, storename, true);
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
if (LOGGER.isErrorEnabled())
|
|
||||||
LOGGER.error("Arguments may not be null or empty!", e);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2066,6 +2034,21 @@ public class GeoServerRESTPublisher {
|
|||||||
*/
|
*/
|
||||||
public boolean removeCoverageStore(final String workspace, final String storename,
|
public boolean removeCoverageStore(final String workspace, final String storename,
|
||||||
final boolean recurse) throws IllegalArgumentException {
|
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 {
|
try {
|
||||||
if (workspace == null || storename == null)
|
if (workspace == null || storename == null)
|
||||||
throw new IllegalArgumentException("Arguments may not be null!");
|
throw new IllegalArgumentException("Arguments may not be null!");
|
||||||
@ -2073,7 +2056,7 @@ public class GeoServerRESTPublisher {
|
|||||||
throw new IllegalArgumentException("Arguments may not be empty!");
|
throw new IllegalArgumentException("Arguments may not be empty!");
|
||||||
|
|
||||||
final StringBuilder url = new StringBuilder(restURL);
|
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);
|
.append(storename);
|
||||||
if (recurse)
|
if (recurse)
|
||||||
url.append("?recurse=true");
|
url.append("?recurse=true");
|
||||||
@ -2081,12 +2064,12 @@ public class GeoServerRESTPublisher {
|
|||||||
|
|
||||||
boolean deleted = HTTPUtils.delete(deleteStore.toExternalForm(), gsuser, gspass);
|
boolean deleted = HTTPUtils.delete(deleteStore.toExternalForm(), gsuser, gspass);
|
||||||
if (!deleted) {
|
if (!deleted) {
|
||||||
LOGGER.warn("Could not delete CoverageStore " + workspace + ":" + storename);
|
LOGGER.warn("Could not delete store " + workspace + ":" + storename);
|
||||||
} else {
|
} else {
|
||||||
LOGGER.info("CoverageStore successfully deleted " + workspace + ":" + storename);
|
LOGGER.info("Store successfully deleted " + workspace + ":" + storename);
|
||||||
}
|
}
|
||||||
return deleted;
|
|
||||||
|
|
||||||
|
return deleted;
|
||||||
} catch (MalformedURLException ex) {
|
} catch (MalformedURLException ex) {
|
||||||
if (LOGGER.isErrorEnabled())
|
if (LOGGER.isErrorEnabled())
|
||||||
LOGGER.error(ex.getLocalizedMessage(), ex);
|
LOGGER.error(ex.getLocalizedMessage(), ex);
|
||||||
@ -2103,13 +2086,7 @@ public class GeoServerRESTPublisher {
|
|||||||
* @deprecated {@link #removeWorkspace(String, boolean)}
|
* @deprecated {@link #removeWorkspace(String, boolean)}
|
||||||
*/
|
*/
|
||||||
public boolean removeWorkspace(String workspace) {
|
public boolean removeWorkspace(String workspace) {
|
||||||
try {
|
return removeWorkspace(workspace, false);
|
||||||
return removeWorkspace(workspace, false);
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
if (LOGGER.isErrorEnabled())
|
|
||||||
LOGGER.error("Arguments may not be null or empty!", e);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2263,17 +2240,17 @@ public class GeoServerRESTPublisher {
|
|||||||
final String store = HTTPUtils.get(url, this.gsuser, this.gspass);
|
final String store = HTTPUtils.get(url, this.gsuser, this.gspass);
|
||||||
|
|
||||||
if (store != null) {
|
if (store != null) {
|
||||||
String storeTag=storeType.getTypeName();
|
String storeTag = storeType.getTypeName();
|
||||||
// switch (storeType) {
|
// switch (storeType) {
|
||||||
// case COVERAGESTORES:
|
// case COVERAGESTORES:
|
||||||
// storeTag = storeType.toString().replaceAll("store", "");
|
// storeTag = storeType.toString().replaceAll("store", "");
|
||||||
// break;
|
// break;
|
||||||
// case DATASTORES:
|
// case DATASTORES:
|
||||||
// storeTag = "featureTypes";
|
// storeTag = "featureTypes";
|
||||||
// break;
|
// break;
|
||||||
// default:
|
// default:
|
||||||
// throw new IllegalArgumentException("Unrecognized type");
|
// throw new IllegalArgumentException("Unrecognized type");
|
||||||
// }
|
// }
|
||||||
|
|
||||||
String startTag = "<" + storeTag + ">";
|
String startTag = "<" + storeTag + ">";
|
||||||
int start = store.indexOf(startTag);
|
int start = store.indexOf(startTag);
|
||||||
@ -2663,81 +2640,85 @@ public class GeoServerRESTPublisher {
|
|||||||
*
|
*
|
||||||
* @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.
|
||||||
*/
|
*/
|
||||||
public boolean createOrHarvestExternal(String workspace, String coverageStore, String format, String path) {
|
public boolean createOrHarvestExternal(String workspace, String coverageStore, String format,
|
||||||
|
String path) {
|
||||||
try {
|
try {
|
||||||
GeoServerRESTStructuredGridCoverageReaderManager manager =
|
GeoServerRESTStructuredGridCoverageReaderManager manager = new GeoServerRESTStructuredGridCoverageReaderManager(
|
||||||
new GeoServerRESTStructuredGridCoverageReaderManager(new URL(restURL), gsuser, gspass);
|
new URL(restURL), gsuser, gspass);
|
||||||
return manager.createOrHarvestExternal(workspace, coverageStore, format, path);
|
return manager.createOrHarvestExternal(workspace, coverageStore, format, path);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
if(LOGGER.isInfoEnabled()){
|
if (LOGGER.isInfoEnabled()) {
|
||||||
LOGGER.info(e.getLocalizedMessage(),e);
|
LOGGER.info(e.getLocalizedMessage(), e);
|
||||||
}
|
}
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
if(LOGGER.isInfoEnabled()){
|
if (LOGGER.isInfoEnabled()) {
|
||||||
LOGGER.info(e.getLocalizedMessage(),e);
|
LOGGER.info(e.getLocalizedMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove a granule from a structured coverage by id.
|
* Remove a granule from a structured coverage by id.
|
||||||
*
|
*
|
||||||
* @param workspace the GeoServer workspace
|
* @param workspace the GeoServer workspace
|
||||||
* @param coverageStore the GeoServer coverageStore
|
* @param coverageStore the GeoServer coverageStore
|
||||||
* @param coverage the name of the target coverage from which we are going to remove
|
* @param coverage the name of the target coverage from which we are going to remove
|
||||||
* @param filter the absolute path to the file to upload
|
* @param filter the absolute path to the file to upload
|
||||||
*
|
*
|
||||||
* @return <code>null</code> in case the call does not succeed, or an instance of {@link RESTStructuredCoverageGranulesList}.
|
* @return <code>null</code> in case the call does not succeed, or an instance of {@link RESTStructuredCoverageGranulesList}.
|
||||||
*
|
*
|
||||||
* @throws MalformedURLException
|
* @throws MalformedURLException
|
||||||
* @throws UnsupportedEncodingException
|
* @throws UnsupportedEncodingException
|
||||||
*/
|
*/
|
||||||
public boolean removeGranuleById(final String workspace, String coverageStore, String coverage, String granuleId) {
|
public boolean removeGranuleById(final String workspace, String coverageStore, String coverage,
|
||||||
try {
|
String granuleId) {
|
||||||
GeoServerRESTStructuredGridCoverageReaderManager manager =
|
try {
|
||||||
new GeoServerRESTStructuredGridCoverageReaderManager(new URL(restURL), gsuser, gspass);
|
GeoServerRESTStructuredGridCoverageReaderManager manager = new GeoServerRESTStructuredGridCoverageReaderManager(
|
||||||
return manager.removeGranuleById(workspace, coverageStore, coverage, granuleId);
|
new URL(restURL), gsuser, gspass);
|
||||||
} catch (IllegalArgumentException e) {
|
return manager.removeGranuleById(workspace, coverageStore, coverage, granuleId);
|
||||||
if(LOGGER.isInfoEnabled()){
|
} catch (IllegalArgumentException e) {
|
||||||
LOGGER.info(e.getLocalizedMessage(),e);
|
if (LOGGER.isInfoEnabled()) {
|
||||||
}
|
LOGGER.info(e.getLocalizedMessage(), e);
|
||||||
} catch (MalformedURLException e) {
|
}
|
||||||
if(LOGGER.isInfoEnabled()){
|
} catch (MalformedURLException e) {
|
||||||
LOGGER.info(e.getLocalizedMessage(),e);
|
if (LOGGER.isInfoEnabled()) {
|
||||||
}
|
LOGGER.info(e.getLocalizedMessage(), e);
|
||||||
}
|
}
|
||||||
return false;
|
}
|
||||||
}
|
return false;
|
||||||
/**
|
}
|
||||||
* Remove granules from a structured coverage, by providing a CQL filter.
|
|
||||||
*
|
|
||||||
* @param workspace the GeoServer workspace
|
|
||||||
* @param coverageStore the GeoServer coverageStore
|
|
||||||
* @param coverage the name of the target coverage from which we are going to remove
|
|
||||||
* @param filter the absolute path to the file to upload
|
|
||||||
*
|
|
||||||
* @return <code>null</code> in case the call does not succeed, or an instance of {@link RESTStructuredCoverageGranulesList}.
|
|
||||||
*
|
|
||||||
* @throws MalformedURLException
|
|
||||||
* @throws UnsupportedEncodingException
|
|
||||||
*/
|
|
||||||
public boolean removeGranulesByCQL(final String workspace, String coverageStore,String coverage, String filter) throws UnsupportedEncodingException{
|
|
||||||
try {
|
|
||||||
GeoServerRESTStructuredGridCoverageReaderManager manager =
|
|
||||||
new GeoServerRESTStructuredGridCoverageReaderManager(new URL(restURL), gsuser, gspass);
|
|
||||||
return manager.removeGranulesByCQL(workspace, coverageStore, coverage, filter);
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
if(LOGGER.isInfoEnabled()){
|
|
||||||
LOGGER.info(e.getLocalizedMessage(),e);
|
|
||||||
}
|
|
||||||
} catch (MalformedURLException e) {
|
|
||||||
if(LOGGER.isInfoEnabled()){
|
|
||||||
LOGGER.info(e.getLocalizedMessage(),e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
|
|
||||||
}
|
/**
|
||||||
|
* Remove granules from a structured coverage, by providing a CQL filter.
|
||||||
|
*
|
||||||
|
* @param workspace the GeoServer workspace
|
||||||
|
* @param coverageStore the GeoServer coverageStore
|
||||||
|
* @param coverage the name of the target coverage from which we are going to remove
|
||||||
|
* @param filter the absolute path to the file to upload
|
||||||
|
*
|
||||||
|
* @return <code>null</code> in case the call does not succeed, or an instance of {@link RESTStructuredCoverageGranulesList}.
|
||||||
|
*
|
||||||
|
* @throws MalformedURLException
|
||||||
|
* @throws UnsupportedEncodingException
|
||||||
|
*/
|
||||||
|
public boolean removeGranulesByCQL(final String workspace, String coverageStore,
|
||||||
|
String coverage, String filter) throws UnsupportedEncodingException {
|
||||||
|
try {
|
||||||
|
GeoServerRESTStructuredGridCoverageReaderManager manager = new GeoServerRESTStructuredGridCoverageReaderManager(
|
||||||
|
new URL(restURL), gsuser, gspass);
|
||||||
|
return manager.removeGranulesByCQL(workspace, coverageStore, coverage, filter);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
if (LOGGER.isInfoEnabled()) {
|
||||||
|
LOGGER.info(e.getLocalizedMessage(), e);
|
||||||
|
}
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
if (LOGGER.isInfoEnabled()) {
|
||||||
|
LOGGER.info(e.getLocalizedMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,6 +25,7 @@
|
|||||||
package it.geosolutions.geoserver.rest.manager;
|
package it.geosolutions.geoserver.rest.manager;
|
||||||
|
|
||||||
import it.geosolutions.geoserver.rest.GeoServerRESTPublisher.Format;
|
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.HTTPUtils;
|
||||||
import it.geosolutions.geoserver.rest.encoder.GSAbstractStoreEncoder;
|
import it.geosolutions.geoserver.rest.encoder.GSAbstractStoreEncoder;
|
||||||
import it.geosolutions.geoserver.rest.encoder.datastore.GSAbstractDatastoreEncoder;
|
import it.geosolutions.geoserver.rest.encoder.datastore.GSAbstractDatastoreEncoder;
|
||||||
@ -120,4 +121,6 @@ public class GeoServerRESTStoreManager extends GeoServerRESTAbstractManager {
|
|||||||
// }
|
// }
|
||||||
return deleted;
|
return deleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user