Using new publishGeoTIFF method (not deprecated)
This commit is contained in:
parent
2dd01c0c82
commit
faa01e40da
|
@ -44,304 +44,295 @@ import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureTypeEncoder;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class SDIManagerWrapper extends SDIManager{
|
public class SDIManagerWrapper extends SDIManager {
|
||||||
|
|
||||||
public SDIManagerWrapper() throws SDIInteractionException {
|
public SDIManagerWrapper() throws SDIInteractionException {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Expected paramters :
|
* Expected paramters : - "workspace" - "layerTitle" - "documentID" -
|
||||||
* - "workspace"
|
* "basePersistencePath" (useCaseDescriptor specific, e.g. "GNA")
|
||||||
* - "layerTitle"
|
*
|
||||||
* - "documentID"
|
* @param fileSet
|
||||||
* - "basePersistencePath" (useCaseDescriptor specific, e.g. "GNA")
|
* @param params
|
||||||
*
|
* @return
|
||||||
* @param fileSet
|
* @throws SDIInteractionException
|
||||||
* @param params
|
*/
|
||||||
* @return
|
public RegisteredFileSet materializeLayer(RegisteredFileSet fileSet, Document params)
|
||||||
* @throws SDIInteractionException
|
throws SDIInteractionException {
|
||||||
*/
|
try {
|
||||||
public RegisteredFileSet materializeLayer(RegisteredFileSet fileSet, Document params) throws SDIInteractionException{
|
log.debug("Materializing FS {} on {} ", fileSet, getGeoserverHostName());
|
||||||
try {
|
|
||||||
log.debug("Materializing FS {} on {} ", fileSet, getGeoserverHostName());
|
|
||||||
|
|
||||||
// validate parameters
|
// validate parameters
|
||||||
String workspace = BaseExecutionRequest.getMandatory("workspace", params);
|
String workspace = BaseExecutionRequest.getMandatory("workspace", params);
|
||||||
String documentID = BaseExecutionRequest.getMandatory("documentID", params);
|
String documentID = BaseExecutionRequest.getMandatory("documentID", params);
|
||||||
String basePersistencePAth = BaseExecutionRequest.getMandatory("basePersistencePath", params);
|
String basePersistencePAth = BaseExecutionRequest.getMandatory("basePersistencePath", params);
|
||||||
|
|
||||||
|
// check if empty
|
||||||
|
if (fileSet.getPayloads().isEmpty())
|
||||||
|
throw new SDIInteractionException("No payload to materialize");
|
||||||
|
|
||||||
// check if empty
|
// Document geoserverInfo = new Document();
|
||||||
if (fileSet.getPayloads().isEmpty()) throw new SDIInteractionException("No payload to materialize");
|
GCubeSDILayerBuilder layerBuilder = new GCubeSDILayerBuilder();
|
||||||
|
layerBuilder.setWorkspace(workspace);
|
||||||
|
layerBuilder.setHost(getGeoserverHostName());
|
||||||
|
|
||||||
|
// Evaluate layer data in filesets
|
||||||
|
// TODO optimize cicles
|
||||||
|
List<SupportedFormat> toCheckFormats = SupportedFormat.getByExtension(".tif", ".shp");
|
||||||
|
SupportedFormat selectedFormat = null;
|
||||||
|
String baseName = null;
|
||||||
|
for (SupportedFormat format : toCheckFormats) {
|
||||||
|
log.debug("Checking for {}", format);
|
||||||
|
for (Object o : fileSet.getPayloads()) {
|
||||||
|
RegisteredFile file = Serialization.convert(o, RegisteredFile.class);
|
||||||
|
format.consider(file);
|
||||||
|
}
|
||||||
|
if (format.getIsProposedFilesetValid()) {
|
||||||
|
log.debug("Selected format is {}. Fileset is {}", format, format.getToUseFileSet());
|
||||||
|
selectedFormat = format;
|
||||||
|
// get basename for layer
|
||||||
|
baseName = format.getToUseFileSet().get(0).getName();
|
||||||
|
baseName = Files.fixFilename(baseName).substring(0, baseName.lastIndexOf('.'));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Document geoserverInfo = new Document();
|
if (selectedFormat == null)
|
||||||
GCubeSDILayerBuilder layerBuilder=new GCubeSDILayerBuilder();
|
throw new SDIInteractionException(
|
||||||
layerBuilder.setWorkspace(workspace);
|
"Unable to identify layer format. Configured formats are " + toCheckFormats);
|
||||||
layerBuilder.setHost(getGeoserverHostName());
|
|
||||||
|
|
||||||
|
// Evaluate Layer Name
|
||||||
|
log.debug("Base layer name is {}, checking conflicts.. ", baseName);
|
||||||
|
String toSetLayerName = baseName;
|
||||||
|
|
||||||
|
// Checking if layer already exists
|
||||||
|
int count = 0;
|
||||||
|
GeoServerRESTReader gsReader = getCurrentGeoserver().getReader();
|
||||||
|
while (gsReader.getLayer(workspace, toSetLayerName) != null) {
|
||||||
|
count++;
|
||||||
|
toSetLayerName = baseName + "_" + count;
|
||||||
|
log.debug("layer for " + baseName + " already existing, trying " + toSetLayerName);
|
||||||
|
}
|
||||||
|
log.debug("Layer name will be {}", toSetLayerName);
|
||||||
|
layerBuilder.setLayerName(toSetLayerName);
|
||||||
|
|
||||||
// Evaluate layer data in filesets
|
// Publishing layer in GS
|
||||||
// TODO optimize cicles
|
String storeName = toSetLayerName + "_store";
|
||||||
List<SupportedFormat> toCheckFormats=SupportedFormat.getByExtension(".tif",".shp");
|
layerBuilder.setStoreName(storeName);
|
||||||
SupportedFormat selectedFormat = null;
|
|
||||||
String baseName=null;
|
|
||||||
for(SupportedFormat format: toCheckFormats){
|
|
||||||
log.debug("Checking for {}",format);
|
|
||||||
for (Object o : fileSet.getPayloads()) {
|
|
||||||
RegisteredFile file = Serialization.convert(o, RegisteredFile.class);
|
|
||||||
format.consider(file);
|
|
||||||
}
|
|
||||||
if(format.getIsProposedFilesetValid()){
|
|
||||||
log.debug("Selected format is {}. Fileset is {}",format,format.getToUseFileSet());
|
|
||||||
selectedFormat = format;
|
|
||||||
// get basename for layer
|
|
||||||
baseName = format.getToUseFileSet().get(0).getName();
|
|
||||||
baseName= Files.fixFilename(baseName).substring(0,baseName.lastIndexOf('.'));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(selectedFormat==null)
|
GeoServerRESTPublisher publisher = getCurrentGeoserver().getPublisher();
|
||||||
throw new SDIInteractionException("Unable to identify layer format. Configured formats are "+toCheckFormats);
|
log.debug("Trying to create remote workspace : " + workspace);
|
||||||
|
createWorkspace(workspace);
|
||||||
|
|
||||||
|
// Actually publishing files into GS
|
||||||
|
|
||||||
// Evaluate Layer Name
|
Boolean published = null;
|
||||||
log.debug("Base layer name is {}, checking conflicts.. ",baseName);
|
|
||||||
String toSetLayerName = baseName;
|
|
||||||
|
|
||||||
//Checking if layer already exists
|
switch (selectedFormat.getFileExtension()) {
|
||||||
int count = 0;
|
case ".tif": {
|
||||||
GeoServerRESTReader gsReader = getCurrentGeoserver().getReader();
|
RegisteredFile f = selectedFormat.getToUseFileSet().get(0);
|
||||||
while (gsReader.getLayer(workspace, toSetLayerName) != null) {
|
File temp = null;
|
||||||
count++;
|
try {
|
||||||
toSetLayerName = baseName + "_" + count;
|
temp = Files.downloadFromUrl(f.getName(), f.getLink());
|
||||||
log.debug("layer for " + baseName + " already existing, trying " + toSetLayerName);
|
//Added by Francesco M.
|
||||||
}
|
published = publisher.publishGeoTIFF(workspace, storeName, toSetLayerName, temp, EPSG_4326,
|
||||||
log.debug("Layer name will be {}", toSetLayerName);
|
REPROJECT_TO_DECLARED, "raster", null);
|
||||||
layerBuilder.setLayerName(toSetLayerName);
|
// published = publisher.publishGeoTIFF(workspace, storeName,
|
||||||
|
// toSetLayerName,temp,EPSG_4326,REPROJECT_TO_DECLARED,"raster");
|
||||||
|
} finally {
|
||||||
|
if (temp != null)
|
||||||
|
java.nio.file.Files.deleteIfExists(temp.toPath());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ".shp": {
|
||||||
|
// TODO Evaluate SRS
|
||||||
|
String absolutePath = transferFilesetToGS(basePersistencePAth, documentID,
|
||||||
|
selectedFormat.getToUseFileSet(), fileSet.getUUID(), toSetLayerName, baseName, layerBuilder);
|
||||||
|
URL directoryPath = new URL("file:" + absolutePath + "/" + toSetLayerName + ".shp");
|
||||||
|
published = publisher.publishShp(workspace, storeName, null, toSetLayerName,
|
||||||
|
// UploadMethod.FILE, // neeeds zip
|
||||||
|
GeoServerRESTPublisher.UploadMethod.EXTERNAL, // needs shp
|
||||||
|
directoryPath.toURI(), EPSG_4326, // SRS
|
||||||
|
"");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
throw new SDIInteractionException("Unsupported data format");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if success
|
||||||
|
if (!published) {
|
||||||
|
throw new SDIInteractionException("Unable to publish layer " + toSetLayerName + " under " + workspace
|
||||||
|
+ ". Unknown Geoserver fault.");
|
||||||
|
}
|
||||||
|
|
||||||
|
RESTLayer l = gsReader.getLayer(workspace, toSetLayerName);
|
||||||
|
RESTFeatureType f = gsReader.getFeatureType(l);
|
||||||
|
|
||||||
|
layerBuilder.setBBOX(f.getMaxX(), f.getMinX(), f.getMaxY(), f.getMinY(), 0d, 0d);
|
||||||
|
|
||||||
// Publishing layer in GS
|
GCubeSDILayer materialization = layerBuilder.getLayer();
|
||||||
String storeName = toSetLayerName + "_store";
|
log.info("Generated Materialization {}", materialization);
|
||||||
layerBuilder.setStoreName(storeName);
|
|
||||||
|
|
||||||
GeoServerRESTPublisher publisher = getCurrentGeoserver().getPublisher();
|
// Add Materialization to registered file set
|
||||||
log.debug("Trying to create remote workspace : " + workspace);
|
List materializations = fileSet.getMaterializations();
|
||||||
createWorkspace(workspace);
|
if (materializations == null)
|
||||||
|
materializations = new ArrayList();
|
||||||
|
materializations.add(materialization);
|
||||||
|
fileSet.put(RegisteredFileSet.MATERIALIZATIONS, materializations);
|
||||||
|
|
||||||
|
return fileSet;
|
||||||
|
} catch (SDIInteractionException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (Throwable t) {
|
||||||
|
throw new SDIInteractionException(
|
||||||
|
"Unexpected exception while trying to materialize File Set " + t.getMessage(), t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String transferFilesetToGS(String basePersistencePAth, String documentID, List<RegisteredFile> fileSet,
|
||||||
|
String fileSetUUID, String toSetLayerName, String baseName, GCubeSDILayerBuilder layerBuilder)
|
||||||
|
throws MalformedURLException, InvalidSourceException, SourceNotSetException, InvalidDestinationException,
|
||||||
|
DestinationNotSetException, InitializationException, FailedTransferException {
|
||||||
|
String folderRelativePath = basePersistencePAth + "/" + documentID + "/" + fileSetUUID + "/" + toSetLayerName;
|
||||||
|
log.debug("GS Relative destination path is {}", folderRelativePath);
|
||||||
|
layerBuilder.setPersistencePath(folderRelativePath);
|
||||||
|
|
||||||
|
List<String> filenames = new ArrayList<>();
|
||||||
|
|
||||||
// Actually publishing files into GS
|
String absolutePath = null;
|
||||||
|
|
||||||
Boolean published = null;
|
for (RegisteredFile file : fileSet) {
|
||||||
|
log.info("Sending {} to GS {} at {} ", file, getGeoserverHostName(), folderRelativePath);
|
||||||
|
String completeFilename = Files.fixFilename(file.getName());
|
||||||
|
completeFilename = completeFilename.replaceAll(baseName, toSetLayerName);
|
||||||
|
|
||||||
switch(selectedFormat.getFileExtension()){
|
Destination destination = new Destination(completeFilename);
|
||||||
case ".tif" : {
|
destination.setCreateSubfolders(true);
|
||||||
RegisteredFile f = selectedFormat.getToUseFileSet().get(0);
|
destination.setOnExistingFileName(DestinationClashPolicy.REWRITE);
|
||||||
File temp= null;
|
destination.setOnExistingSubFolder(DestinationClashPolicy.APPEND);
|
||||||
try {
|
|
||||||
temp = Files.downloadFromUrl(f.getName(),f.getLink());
|
|
||||||
published = publisher.publishGeoTIFF(workspace, storeName, toSetLayerName,temp,EPSG_4326,REPROJECT_TO_DECLARED,"raster");
|
|
||||||
}finally{ if (temp!=null) java.nio.file.Files.deleteIfExists(temp.toPath());}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case ".shp" :{
|
|
||||||
//TODO Evaluate SRS
|
|
||||||
String absolutePath = transferFilesetToGS(basePersistencePAth,documentID,selectedFormat.getToUseFileSet(),
|
|
||||||
fileSet.getUUID(),toSetLayerName,baseName,layerBuilder);
|
|
||||||
URL directoryPath = new URL("file:" + absolutePath + "/" + toSetLayerName + ".shp");
|
|
||||||
published = publisher.publishShp(
|
|
||||||
workspace,
|
|
||||||
storeName,
|
|
||||||
null,
|
|
||||||
toSetLayerName,
|
|
||||||
// UploadMethod.FILE, // neeeds zip
|
|
||||||
GeoServerRESTPublisher.UploadMethod.EXTERNAL, // needs shp
|
|
||||||
directoryPath.toURI(),
|
|
||||||
EPSG_4326, //SRS
|
|
||||||
"");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
throw new SDIInteractionException("Unsupported data format");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if success
|
destination.setPersistenceId("geoserver");
|
||||||
if (!published) {
|
destination.setSubFolder(folderRelativePath);
|
||||||
throw new SDIInteractionException("Unable to publish layer " + toSetLayerName + " under " + workspace + ". Unknown Geoserver fault.");
|
|
||||||
}
|
|
||||||
|
|
||||||
RESTLayer l = gsReader.getLayer(workspace, toSetLayerName);
|
log.debug("Sending {} to {}", file, destination);
|
||||||
RESTFeatureType f = gsReader.getFeatureType(l);
|
TransferResult result = getDtGeoServer().httpSource(new URL(file.getLink()), destination);
|
||||||
|
log.debug("Transferred " + result);
|
||||||
|
|
||||||
|
filenames.add(completeFilename);
|
||||||
|
// NB Clash con subfolder is APPEND, thus FOLDER is expected to be the one
|
||||||
|
// specified by caller
|
||||||
|
// geoserverInfo.put(""result.getRemotePath().substring(0,
|
||||||
|
// result.getRemotePath().lastIndexOf("/")));
|
||||||
|
absolutePath = result.getRemotePath().substring(0, result.getRemotePath().lastIndexOf("/"));
|
||||||
|
}
|
||||||
|
layerBuilder.setFiles(filenames);
|
||||||
|
return absolutePath;
|
||||||
|
}
|
||||||
|
|
||||||
layerBuilder.setBBOX(f.getMaxX(),f.getMinX(),f.getMaxY(),f.getMinY(),0d,0d);
|
public void deleteLayer(GCubeSDILayer toDelete) throws SDIInteractionException {
|
||||||
|
log.trace("Deleting {}", toDelete);
|
||||||
|
try {
|
||||||
|
AbstractGeoServerDescriptor gs = getCurrentGeoserver();
|
||||||
|
GeoServerRESTPublisher publisher = gs.getPublisher();
|
||||||
|
for (Object platformObj : toDelete.getPlatformInfo()) {
|
||||||
|
PlatformInfo info = Serialization.convert(platformObj, PlatformInfo.class);
|
||||||
|
switch (info.getType()) {
|
||||||
|
case GeoServerPlatform.GS_PLATFORM: {
|
||||||
|
GeoServerPlatform gsInfo = Serialization.convert(info, GeoServerPlatform.class);
|
||||||
|
log.trace("Deleting {} ", gsInfo);
|
||||||
|
// remove store (recursion deletes related layers)
|
||||||
|
log.trace("Removing datastore {}:{}", gsInfo.getWorkspace(), gsInfo.getStoreName());
|
||||||
|
if (!publisher.removeDatastore(gsInfo.getWorkspace(), gsInfo.getStoreName(), true))
|
||||||
|
throw new SDIInteractionException(
|
||||||
|
"Unable to remove store " + gsInfo.getWorkspace() + ":" + gsInfo.getStoreName());
|
||||||
|
// remove ws if empty
|
||||||
|
log.trace("Checking if empty WS {}", gsInfo.getWorkspace());
|
||||||
|
if (gs.getReader().getDatastores(gsInfo.getWorkspace()).isEmpty())
|
||||||
|
if (!publisher.removeWorkspace(gsInfo.getWorkspace(), true))
|
||||||
|
throw new SDIInteractionException("Unable to remove WS " + gsInfo.getWorkspace());
|
||||||
|
|
||||||
|
// remove actual files data
|
||||||
GCubeSDILayer materialization = layerBuilder.getLayer();
|
// TODO REMOVE HARDCODED PATCH
|
||||||
log.info("Generated Materialization {}", materialization);
|
String path = "geoserver/" + gsInfo.getPersistencePath();
|
||||||
|
log.info("Deleting files at {}@{}", path, getGeoserverHostName());
|
||||||
//Add Materialization to registered file set
|
try {
|
||||||
List materializations = fileSet.getMaterializations();
|
Client dtClient = new Client("https://" + getGeoserverHostName());
|
||||||
if (materializations == null) materializations = new ArrayList();
|
dtClient.delete(path);
|
||||||
materializations.add(materialization);
|
|
||||||
fileSet.put(RegisteredFileSet.MATERIALIZATIONS, materializations);
|
|
||||||
|
|
||||||
return fileSet;
|
|
||||||
}catch(SDIInteractionException e){
|
|
||||||
throw e;
|
|
||||||
}catch (Throwable t){
|
|
||||||
throw new SDIInteractionException("Unexpected exception while trying to materialize File Set "+t.getMessage(),t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String transferFilesetToGS(String basePersistencePAth,String documentID,List<RegisteredFile> fileSet,
|
|
||||||
String fileSetUUID,
|
|
||||||
String toSetLayerName, String baseName, GCubeSDILayerBuilder layerBuilder)
|
|
||||||
throws MalformedURLException, InvalidSourceException, SourceNotSetException, InvalidDestinationException,
|
|
||||||
DestinationNotSetException, InitializationException, FailedTransferException {
|
|
||||||
String folderRelativePath = basePersistencePAth + "/" + documentID + "/" + fileSetUUID + "/" + toSetLayerName;
|
|
||||||
log.debug("GS Relative destination path is {}", folderRelativePath);
|
|
||||||
layerBuilder.setPersistencePath(folderRelativePath);
|
|
||||||
|
|
||||||
List<String> filenames = new ArrayList<>();
|
|
||||||
|
|
||||||
String absolutePath = null;
|
|
||||||
|
|
||||||
for (RegisteredFile file : fileSet) {
|
|
||||||
log.info("Sending {} to GS {} at {} ", file, getGeoserverHostName(), folderRelativePath);
|
|
||||||
String completeFilename = Files.fixFilename(file.getName());
|
|
||||||
completeFilename = completeFilename.replaceAll(baseName, toSetLayerName);
|
|
||||||
|
|
||||||
|
|
||||||
Destination destination = new Destination(completeFilename);
|
|
||||||
destination.setCreateSubfolders(true);
|
|
||||||
destination.setOnExistingFileName(DestinationClashPolicy.REWRITE);
|
|
||||||
destination.setOnExistingSubFolder(DestinationClashPolicy.APPEND);
|
|
||||||
|
|
||||||
destination.setPersistenceId("geoserver");
|
|
||||||
destination.setSubFolder(folderRelativePath);
|
|
||||||
|
|
||||||
log.debug("Sending {} to {}", file, destination);
|
|
||||||
TransferResult result = getDtGeoServer().httpSource(new URL(file.getLink()), destination);
|
|
||||||
log.debug("Transferred " + result);
|
|
||||||
|
|
||||||
|
|
||||||
filenames.add(completeFilename);
|
|
||||||
// NB Clash con subfolder is APPEND, thus FOLDER is expected to be the one specified by caller
|
|
||||||
//geoserverInfo.put(""result.getRemotePath().substring(0, result.getRemotePath().lastIndexOf("/")));
|
|
||||||
absolutePath = result.getRemotePath().substring(0, result.getRemotePath().lastIndexOf("/"));
|
|
||||||
}
|
|
||||||
layerBuilder.setFiles(filenames);
|
|
||||||
return absolutePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deleteLayer(GCubeSDILayer toDelete) throws SDIInteractionException {
|
|
||||||
log.trace("Deleting {}",toDelete);
|
|
||||||
try{
|
|
||||||
AbstractGeoServerDescriptor gs=getCurrentGeoserver();
|
|
||||||
GeoServerRESTPublisher publisher = gs.getPublisher();
|
|
||||||
for(Object platformObj : toDelete.getPlatformInfo()){
|
|
||||||
PlatformInfo info =Serialization.convert(platformObj, PlatformInfo.class);
|
|
||||||
switch(info.getType()){
|
|
||||||
case GeoServerPlatform.GS_PLATFORM:{
|
|
||||||
GeoServerPlatform gsInfo = Serialization.convert(info,GeoServerPlatform.class);
|
|
||||||
log.trace("Deleting {} ",gsInfo);
|
|
||||||
// remove store (recursion deletes related layers)
|
|
||||||
log.trace("Removing datastore {}:{}",gsInfo.getWorkspace(),gsInfo.getStoreName());
|
|
||||||
if(!publisher.removeDatastore(gsInfo.getWorkspace(),gsInfo.getStoreName(),true))
|
|
||||||
throw new SDIInteractionException("Unable to remove store "+gsInfo.getWorkspace()+":"+gsInfo.getStoreName());
|
|
||||||
// remove ws if empty
|
|
||||||
log.trace("Checking if empty WS {}",gsInfo.getWorkspace());
|
|
||||||
if(gs.getReader().getDatastores(gsInfo.getWorkspace()).isEmpty())
|
|
||||||
if(!publisher.removeWorkspace(gsInfo.getWorkspace(),true))
|
|
||||||
throw new SDIInteractionException("Unable to remove WS "+gsInfo.getWorkspace());
|
|
||||||
|
|
||||||
// remove actual files data
|
|
||||||
// TODO REMOVE HARDCODED PATCH
|
|
||||||
String path="geoserver/"+gsInfo.getPersistencePath();
|
|
||||||
log.info("Deleting files at {}@{}",path,getGeoserverHostName());
|
|
||||||
try{
|
|
||||||
Client dtClient = new Client("https://"+getGeoserverHostName());
|
|
||||||
dtClient.delete(path);
|
|
||||||
// getDtGeoServer().getWebClient().delete("geoserver/"+path);
|
// getDtGeoServer().getWebClient().delete("geoserver/"+path);
|
||||||
}catch(Exception e){
|
} catch (Exception e) {
|
||||||
throw new Exception("Data Transfer ERROR. Unable to delete files at "+getGeoserverHostName()+" PATH "+path,e);
|
throw new Exception("Data Transfer ERROR. Unable to delete files at " + getGeoserverHostName()
|
||||||
}
|
+ " PATH " + path, e);
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default : {
|
default: {
|
||||||
throw new SDIInteractionException("Unable to manage platform "+info);
|
throw new SDIInteractionException("Unable to manage platform " + info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}catch(SDIInteractionException e){
|
} catch (SDIInteractionException e) {
|
||||||
throw e;
|
throw e;
|
||||||
}catch (Throwable t){
|
} catch (Throwable t) {
|
||||||
throw new SDIInteractionException("Unexpected exception while trying to delete Layer : "+t.getMessage(),t);
|
throw new SDIInteractionException("Unexpected exception while trying to delete Layer : " + t.getMessage(),
|
||||||
}
|
t);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class CQL_GS_Feature extends GSFeatureTypeEncoder{
|
private static class CQL_GS_Feature extends GSFeatureTypeEncoder {
|
||||||
private static final String CQL = "cqlFilter";
|
private static final String CQL = "cqlFilter";
|
||||||
public void setCQL(String cql){this.set(CQL,cql);}
|
|
||||||
|
|
||||||
}
|
public void setCQL(String cql) {
|
||||||
|
this.set(CQL, cql);
|
||||||
|
}
|
||||||
|
|
||||||
public GCubeSDILayer configureCentroidLayer(String name, String workspace, String storeName, PostgisTable table, DatabaseConnection connection) throws SDIInteractionException {
|
}
|
||||||
|
|
||||||
GCubeSDILayerBuilder builder = new GCubeSDILayerBuilder()
|
public GCubeSDILayer configureCentroidLayer(String name, String workspace, String storeName, PostgisTable table,
|
||||||
.setWorkspace(workspace)
|
DatabaseConnection connection) throws SDIInteractionException {
|
||||||
.setStoreName(storeName)
|
|
||||||
.setHost(getGeoserverHostName())
|
|
||||||
.setLayerName(name);
|
|
||||||
|
|
||||||
CQL_GS_Feature fte=new CQL_GS_Feature();
|
GCubeSDILayerBuilder builder = new GCubeSDILayerBuilder().setWorkspace(workspace).setStoreName(storeName)
|
||||||
fte.setAbstract("Centroid layer for "+name);
|
.setHost(getGeoserverHostName()).setLayerName(name);
|
||||||
fte.setEnabled(true);
|
|
||||||
fte.setNativeCRS(WGS84_FULL);
|
|
||||||
fte.setTitle(name);
|
|
||||||
fte.setName(name);
|
|
||||||
fte.setCQL(DBConstants.Defaults.DISPLAYED+" = true");
|
|
||||||
|
|
||||||
|
CQL_GS_Feature fte = new CQL_GS_Feature();
|
||||||
|
fte.setAbstract("Centroid layer for " + name);
|
||||||
|
fte.setEnabled(true);
|
||||||
|
fte.setNativeCRS(WGS84_FULL);
|
||||||
|
fte.setTitle(name);
|
||||||
|
fte.setName(name);
|
||||||
|
fte.setCQL(DBConstants.Defaults.DISPLAYED + " = true");
|
||||||
|
|
||||||
|
fte.setLatLonBoundingBox(-180.0, -90.0, 180.0, 90.0, WGS84_FULL);
|
||||||
|
|
||||||
fte.setLatLonBoundingBox(-180.0, -90.0, 180.0, 90.0, WGS84_FULL);
|
String style = "clustered_centroids";
|
||||||
|
|
||||||
String style="clustered_centroids";
|
GSLayerEncoder layerEncoder = new GSLayerEncoder();
|
||||||
|
layerEncoder.setDefaultStyle(style);
|
||||||
|
layerEncoder.setEnabled(true);
|
||||||
|
layerEncoder.setQueryable(true);
|
||||||
|
|
||||||
GSLayerEncoder layerEncoder=new GSLayerEncoder();
|
try {
|
||||||
layerEncoder.setDefaultStyle(style);
|
// Checking workspace
|
||||||
layerEncoder.setEnabled(true);
|
createWorkspace(workspace);
|
||||||
layerEncoder.setQueryable(true);
|
// Checking store
|
||||||
|
createStoreFromPostgisDB(workspace, storeName, connection);
|
||||||
|
// Checking layer
|
||||||
|
publishStyle(Files.getFileFromResources("styles/clustered_points.sld"), style);
|
||||||
|
|
||||||
|
log.info("Creating layer in {} : {} with FTE {} , LE {}", workspace, storeName, fte, layerEncoder);
|
||||||
|
if (getCurrentGeoserver().getReader().getLayer(workspace, name) == null)
|
||||||
|
if (!getCurrentGeoserver().getPublisher().publishDBLayer(workspace, storeName, fte, layerEncoder))
|
||||||
|
throw new SDIInteractionException("Unable to create layer " + name);
|
||||||
|
log.debug("layer " + name + " already exists");
|
||||||
|
|
||||||
try {
|
return builder.getLayer();
|
||||||
//Checking workspace
|
} catch (IllegalArgumentException | MalformedURLException e) {
|
||||||
createWorkspace(workspace);
|
throw new SDIInteractionException("Unable to create layer " + name, e);
|
||||||
//Checking store
|
}
|
||||||
createStoreFromPostgisDB(workspace, storeName,connection);
|
}
|
||||||
//Checking layer
|
|
||||||
publishStyle(Files.getFileFromResources("styles/clustered_points.sld"),style);
|
|
||||||
|
|
||||||
log.info("Creating layer in {} : {} with FTE {} , LE {}",workspace,storeName,fte,layerEncoder);
|
|
||||||
if(getCurrentGeoserver().getReader().getLayer(workspace, name)==null)
|
|
||||||
if(!getCurrentGeoserver().getPublisher().publishDBLayer(workspace, storeName, fte, layerEncoder))
|
|
||||||
throw new SDIInteractionException("Unable to create layer "+name);
|
|
||||||
log.debug("layer "+name+" already exists");
|
|
||||||
|
|
||||||
|
|
||||||
return builder.getLayer();
|
|
||||||
} catch (IllegalArgumentException | MalformedURLException e) {
|
|
||||||
throw new SDIInteractionException("Unable to create layer "+name,e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue