Fixed filename clash
This commit is contained in:
parent
52d8c884ec
commit
5af5b7f7d4
|
@ -2,6 +2,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||
|
||||
# Changelog for org.gcube.application.geoportal-logic
|
||||
|
||||
## [v1.0.13-SNAPSHOT] - 2020-12-11
|
||||
Geoserver filename clash
|
||||
|
||||
## [v1.0.12] - 2020-12-11
|
||||
Fixed missing centroid
|
||||
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -4,7 +4,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.gcube.application</groupId>
|
||||
<artifactId>geoportal-logic</artifactId>
|
||||
<version>1.0.12</version>
|
||||
<version>1.0.13-SNAPSHOT</version>
|
||||
<name>Geoportal Logic</name>
|
||||
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@ public class SDIManager {
|
|||
}
|
||||
|
||||
|
||||
// GEOSERVER-PERSISTENCE-ID / GNA / PROJECT-ID/ FILENAME
|
||||
// GEOSERVER-PERSISTENCE-ID / GNA / PROJECT-ID/ LAYER-ID /FILENAME(no extension)/...
|
||||
|
||||
public GeoServerContent pushShapeLayerFileSet(SDILayerDescriptor currentElement,String workspace) throws SDIInteractionException{
|
||||
try {
|
||||
|
@ -96,27 +96,34 @@ public class SDIManager {
|
|||
GeoServerContent content=new GeoServerContent();
|
||||
content.setGeoserverHostName(geoserverHostName);
|
||||
content.setWorkspace(workspace);
|
||||
|
||||
WorkspaceManager wsManager=new WorkspaceManager(currentElement.getRecord());
|
||||
|
||||
|
||||
currentElement.getActualContent().forEach((PersistedContent c)->{
|
||||
try {
|
||||
if(c instanceof WorkspaceContent) {
|
||||
WorkspaceContent wc=(WorkspaceContent) c;
|
||||
FileContainer fc=wsManager.getFileById(wc.getStorageID());
|
||||
|
||||
String filename=Files.fixFilename(fc.get().getName());
|
||||
String completeFilename=Files.fixFilename(fc.get().getName());
|
||||
String filename=completeFilename.contains(".")?completeFilename.substring(0, completeFilename.lastIndexOf(".")):completeFilename;
|
||||
|
||||
Destination destination=new Destination(filename);
|
||||
|
||||
Destination destination=new Destination(completeFilename);
|
||||
destination.setCreateSubfolders(true);
|
||||
destination.setOnExistingFileName(DestinationClashPolicy.REWRITE);
|
||||
destination.setOnExistingSubFolder(DestinationClashPolicy.ADD_SUFFIX);
|
||||
destination.setOnExistingSubFolder(DestinationClashPolicy.APPEND);
|
||||
|
||||
destination.setPersistenceId("geoserver");
|
||||
destination.setSubFolder("GNA/"+currentElement.getRecord().getId()+"/"+filename);
|
||||
destination.setSubFolder("GNA/"+currentElement.getRecord().getId()+"/"+
|
||||
currentElement.getId()+"/"+filename);
|
||||
|
||||
log.debug("Sending "+wc+" to "+destination);
|
||||
TransferResult result=dtGeoServer.httpSource(fc.getPublicLink(), destination);
|
||||
log.debug("Transferred "+result);
|
||||
content.getFileNames().add(filename);
|
||||
|
||||
|
||||
content.getFileNames().add(completeFilename);
|
||||
|
||||
content.setGeoserverPath(result.getRemotePath().substring(0,result.getRemotePath().lastIndexOf("/")));
|
||||
}
|
||||
|
@ -127,18 +134,24 @@ public class SDIManager {
|
|||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if(content.getFileNames().isEmpty())
|
||||
throw new SDIInteractionException("No Persisted content found in "+currentElement);
|
||||
|
||||
String fileName=content.getFileNames().get(0);
|
||||
String remoteFolder=content.getGeoserverPath().substring(0,content.getGeoserverPath().lastIndexOf("/"));
|
||||
String completeFileName=content.getFileNames().get(0);
|
||||
String filename=completeFileName.contains(".")?completeFileName.substring(0, completeFileName.lastIndexOf(".")):completeFileName;
|
||||
|
||||
String toSetLayerName=fileName.substring(0,fileName.lastIndexOf("."));
|
||||
String remoteFolder=content.getGeoserverPath();
|
||||
|
||||
String toSetLayerName=filename;
|
||||
int count=0;
|
||||
while(gis.getCurrentGeoServer().getReader().getLayer(workspace,toSetLayerName)!=null){
|
||||
count++;
|
||||
toSetLayerName=fileName.substring(0,fileName.lastIndexOf("."))+"_"+count;
|
||||
log.debug("layer for "+fileName+" already existing, trying "+toSetLayerName);
|
||||
toSetLayerName=filename+"_"+count;
|
||||
log.debug("layer for "+filename+" already existing, trying "+toSetLayerName);
|
||||
};
|
||||
|
||||
|
||||
|
@ -151,7 +164,7 @@ public class SDIManager {
|
|||
createWorkspace(workspace);
|
||||
log.debug("Publishing remote folder "+remoteFolder);
|
||||
|
||||
URL directoryPath=new URL("file:"+remoteFolder+"/"+toSetLayerName+".shp");
|
||||
URL directoryPath=new URL("file:"+remoteFolder+"/"+completeFileName);
|
||||
|
||||
|
||||
//TODO Evaluate SRS
|
||||
|
|
|
@ -92,7 +92,7 @@ public class TestModel {
|
|||
|
||||
// Piante fine scavo
|
||||
ArrayList<LayerConcessione> piante=new ArrayList<LayerConcessione>();
|
||||
for(int i=0;i<1;i++) {
|
||||
for(int i=0;i<2;i++) {
|
||||
LayerConcessione pianta=new LayerConcessione();
|
||||
pianta.setValutazioneQualita("Secondo me si");
|
||||
pianta.setMetodoRaccoltaDati("Fattobbene");
|
||||
|
|
|
@ -1,38 +1,21 @@
|
|||
package org.gcube.application.geoportal;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.application.geoportal.model.content.GeoServerContent;
|
||||
import org.gcube.application.geoportal.model.fault.SDIInteractionException;
|
||||
import org.gcube.application.geoportal.model.concessioni.Concessione;
|
||||
import org.gcube.application.geoportal.model.concessioni.LayerConcessione;
|
||||
import org.gcube.application.geoportal.model.gis.SDILayerDescriptor;
|
||||
import org.gcube.application.geoportal.storage.SDIManager;
|
||||
import org.gcube.application.geoportal.utils.Files;
|
||||
import org.gcube.application.geoportal.utils.Workspace;
|
||||
import org.gcube.common.storagehub.client.dsl.FileContainer;
|
||||
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||
import org.gcube.spatial.data.gis.GISInterface;
|
||||
import org.geotoolkit.storage.DataStoreException;
|
||||
|
||||
import it.geosolutions.geoserver.rest.GeoServerRESTReader;
|
||||
import it.geosolutions.geoserver.rest.decoder.RESTFeatureType;
|
||||
import it.geosolutions.geoserver.rest.decoder.RESTLayer;
|
||||
|
||||
public class TestSDI {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
TokenSetter.set("/gcube/devNext/NextNext");
|
||||
TokenSetter.set("/gcube/devsec/devVRE");
|
||||
|
||||
// String workspaceName="gna_conc_"+UUID.randomUUID().toString();
|
||||
//
|
||||
// FileContainer file=Workspace.getClient().getWSRoot().uploadFile(
|
||||
// new FileInputStream(Files.getFileFromResources("concessioni/pos.shp")), "posizionamento", "test layer");
|
||||
//
|
||||
// SDIManager sdiManager=new SDIManager();
|
||||
SDIManager sdiManager=new SDIManager();
|
||||
|
||||
// sdiManager.createWorkspace(workspaceName);
|
||||
// sdiManager.configureCentroidLayer("centroids_concessioni", "gna:test", "gna_test_postgis");
|
||||
|
@ -42,33 +25,38 @@ public class TestSDI {
|
|||
//
|
||||
// GeoServerContent content=sdiManager.pushLayerFile(Files.getFileFromResources("concessioni/pos.shp"), "pos.shp", 123, 1);
|
||||
// System.out.println("content is "+content);
|
||||
// sdiManager.publishShapeFileDirectory(workspaceName, content.getGeoserverPath());
|
||||
|
||||
// GeoServerContent content =
|
||||
//
|
||||
// SDILayerDescriptor desc=TestModel.prepareConcessione().getPosizionamentoScavo();
|
||||
//
|
||||
// sdiManager.pushShapeLayerFileSet(desc,new Workspace());
|
||||
|
||||
|
||||
GISInterface gis=GISInterface.get();
|
||||
String workspace="gna";
|
||||
String toSetLayerName="centroids_concessioni";
|
||||
String geoserverHostName=new URL(gis.getCurrentGeoServer().getUrl()).getHost();
|
||||
|
||||
GeoServerRESTReader reader=gis.getCurrentGeoServer().getReader();
|
||||
RESTLayer l=reader.getLayer(workspace, toSetLayerName);
|
||||
RESTFeatureType f= reader.getFeatureType(l);
|
||||
|
||||
System.out.println(String.format("http://%1$s/geoserver/%2$s/wms?"
|
||||
+"service=WMS&version=1.1.0&request=GetMap&layers=%2$s:%3$s&"
|
||||
+ "styles=&bbox=%4$f,%5$f,%6$f,%7$f&srs=%8$s&format=application/openlayers&width=%9$d&height=%10$d",
|
||||
geoserverHostName,
|
||||
workspace,
|
||||
toSetLayerName,
|
||||
f.getMinX(),
|
||||
f.getMinY(),
|
||||
f.getMaxX(),
|
||||
f.getMaxY(),
|
||||
"EPSG:4326",
|
||||
400,
|
||||
400)
|
||||
);
|
||||
|
||||
// GISInterface gis=GISInterface.get();
|
||||
// String workspace="gna";
|
||||
// String toSetLayerName="centroids_concessioni";
|
||||
// String geoserverHostName=new URL(gis.getCurrentGeoServer().getUrl()).getHost();
|
||||
//
|
||||
// GeoServerRESTReader reader=gis.getCurrentGeoServer().getReader();
|
||||
// RESTLayer l=reader.getLayer(workspace, toSetLayerName);
|
||||
// RESTFeatureType f= reader.getFeatureType(l);
|
||||
//
|
||||
// System.out.println(String.format("http://%1$s/geoserver/%2$s/wms?"
|
||||
// +"service=WMS&version=1.1.0&request=GetMap&layers=%2$s:%3$s&"
|
||||
// + "styles=&bbox=%4$f,%5$f,%6$f,%7$f&srs=%8$s&format=application/openlayers&width=%9$d&height=%10$d",
|
||||
// geoserverHostName,
|
||||
// workspace,
|
||||
// toSetLayerName,
|
||||
// f.getMinX(),
|
||||
// f.getMinY(),
|
||||
// f.getMaxX(),
|
||||
// f.getMaxY(),
|
||||
// "EPSG:4326",
|
||||
// 400,
|
||||
// 400)
|
||||
// );
|
||||
//
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue