GeoServer integration

This commit is contained in:
Fabio Sinibaldi 2020-10-20 17:48:54 +02:00
parent 8b16d5f7b3
commit 2499bd7525
21 changed files with 336 additions and 94 deletions

42
pom.xml
View File

@ -13,8 +13,8 @@
<groupId>org.gcube.tools</groupId>
<version>1.1.0-SNAPSHOT</version>
</parent>
<scm>
<connection>scm:git:${gitBaseUrl}/${project.artifactId}.git</connection>
<developerConnection>scm:git:${gitBaseUrl}/${project.artifactId}.git</developerConnection>
@ -58,11 +58,11 @@
<!-- jackson java time -->
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.8.8</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.8.8</version>
</dependency>
<!-- read XLS -->
<dependency>
@ -94,8 +94,15 @@
<dependency>
<groupId>org.gcube.spatial.data</groupId>
<artifactId>sdi-library</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0)</version>
<version>[1.0.0,2.0.0)</version>
</dependency>
<dependency>
<groupId>org.gcube.data.transfer</groupId>
<artifactId>data-transfer-library</artifactId>
<version>[1.2.1,2.0.0]</version>
</dependency>
<dependency>
<groupId>org.gcube.spatial.data</groupId>
<artifactId>gis-interface</artifactId>
@ -115,6 +122,8 @@
</dependency>
<!-- TEST -->
<dependency>
<groupId>junit</groupId>
@ -122,13 +131,18 @@
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j18-impl</artifactId>
<version>2.13.3</version>
<scope>test</scope>
</dependency>
<!-- <dependency> -->
<!-- <groupId>commons-logging</groupId> -->
<!-- <artifactId>commons-logging</artifactId> -->
<!-- <version>1.2</version> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>commons-logging</groupId> -->
<!-- <artifactId>commons-logging</artifactId> -->
<!-- <version>1.2</version> -->
<!-- </dependency> -->
<dependency>

File diff suppressed because one or more lines are too long

View File

@ -60,7 +60,6 @@ public class PostgisTableFactory {
log.debug("Creating table from CSV FILE "+csvFile);
parser=CSV.fromPath(csvFile);
// Getting type
GeometryType type=GeometryType.POINT;
if(csvFile.contains("linee"))

View File

@ -93,14 +93,12 @@ public abstract class AbstractRecordManager<T extends Record> {
// storeInfo(theRecord);
log.debug("Record is valid, storing changed content");
contentHandler.storeChanges();
contentHandler.storeChanges(publish);
storeInfo(theRecord);
if(publish) {
log.debug("Registering centroid of "+theRecord);
registerCentroid();
log.debug("Publishing changed content of "+theRecord);
publish();
storeInfo(theRecord);
}
@ -122,9 +120,10 @@ public abstract class AbstractRecordManager<T extends Record> {
log.debug("Inserting / updated centroid Row {} ",centroidRow);
PreparedStatement ps = db.prepareInsertStatement(centroidsTable, true, true);
centroidsTable.fillCSVPreparedStatament(centroidRow, ps, false);
ps.executeUpdate();
db.commit();
}catch(SQLException e) {
throw new PublishException("Unable to publish centroid.",e, null);
}

View File

@ -1,7 +1,6 @@
package org.gcube.application.geoportal.managers;
import java.io.IOException;
import java.time.temporal.ChronoField;
import java.util.HashMap;
import java.util.Map;
@ -100,8 +99,8 @@ public class ConcessioneManager extends AbstractRecordManager<Concessione> {
// CENTROID
Map<String,String> centroidsRow=new HashMap<String, String>();
// centroidsRow.put(DBConstants.Concessioni.UUID, toRegister.getId()+"");
centroidsRow.put(DBConstants.Concessioni.ANNO, record.getDataInizioProgetto().get(ChronoField.YEAR)+"");
centroidsRow.put(DBConstants.Concessioni.ID, record.getId()+"");
centroidsRow.put(DBConstants.Concessioni.ANNO, record.getDataInizioProgetto().getYear()+"");
centroidsRow.put(DBConstants.Concessioni.NOME, record.getNome());
centroidsRow.put(DBConstants.Concessioni.REGIONE, "");
centroidsRow.put(DBConstants.Defaults.XCOORD_FIELD, record.getCentroidLong()+"");
@ -123,7 +122,7 @@ public class ConcessioneManager extends AbstractRecordManager<Concessione> {
centroidsRow.put(DBConstants.Concessioni.VERSIONE,record.getVersion());
centroidsRow.put(DBConstants.Concessioni.LICENZA,record.getLicenzaID());
centroidsRow.put(DBConstants.Concessioni.TITOLARE_LICENZA,record.getTitolareLicenza());
//TODO centroidsRow.put(DBConstants.Concessioni.ACCESSO,r.get("accesso_dati"));
centroidsRow.put(DBConstants.Concessioni.ACCESSO,record.getAccesso().toString());
centroidsRow.put(DBConstants.Concessioni.PAROLE_CHIAVE,Serialization.asString(record.getParoleChiaveLibere()));
return centroidsRow;

View File

@ -0,0 +1,7 @@
package org.gcube.application.geoportal.model;
public enum AccessType {
OPEN_ACCESS,RESTRICTED,EMBARGOED
}

View File

@ -1,6 +1,6 @@
package org.gcube.application.geoportal.model;
import java.time.Instant;
import java.time.LocalDateTime;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.Entity;
@ -40,6 +40,7 @@ public abstract class Record {
protected RecordType recordType;
protected String version="1.0.0";
protected String licenzaID="CC-BY";
protected AccessType accesso=AccessType.OPEN_ACCESS;
//Nome del progetto
protected String nome;
@ -48,9 +49,9 @@ public abstract class Record {
protected String folderId;
//Accounting
protected Instant lastUpdateTime;
protected LocalDateTime lastUpdateTime;
protected String lastUpdateUser;
protected Instant creationTime;
protected LocalDateTime creationTime;
protected String creationUser;

View File

@ -1,6 +1,6 @@
package org.gcube.application.geoportal.model.concessioni;
import java.time.Instant;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
@ -57,8 +57,8 @@ public class Concessione extends Record{
private List<String> risorseCorrelate;
private Instant dataInizioProgetto;
private Instant dataFineProgetto;
private LocalDateTime dataInizioProgetto;
private LocalDateTime dataFineProgetto;
private String titolareLicenza;
private String titolareCopyright;

View File

@ -1,6 +1,6 @@
package org.gcube.application.geoportal.model.content;
import java.time.Instant;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
@ -42,7 +42,7 @@ public abstract class AssociatedContent {
private AccessPolicy policy;
private String licenseID;
private String titolo;
private Instant creationTime;
private LocalDateTime creationTime;
@ManyToOne
private Record record;

View File

@ -34,7 +34,7 @@ public class DBConstants {
*/
public static class Concessioni{
public static final String UUID="uuid";
public static final String ID="id";
public static final String NOME="nome";
public static final String ANNO="anno";
public static final String REGIONE="regione";
@ -67,7 +67,7 @@ public class DBConstants {
static {
CENTROIDS.getFields().add(new Field(Defaults.INTERNAL_ID,FieldType.AUTOINCREMENT));
CENTROIDS.getFields().add(new Field(UUID,FieldType.TEXT));
CENTROIDS.getFields().add(new Field(ID,FieldType.TEXT));
CENTROIDS.getFields().add(new Field(NOME,FieldType.TEXT));
CENTROIDS.getFields().add(new Field(ANNO,FieldType.INT));
CENTROIDS.getFields().add(new Field(REGIONE,FieldType.TEXT));

View File

@ -0,0 +1,39 @@
package org.gcube.application.geoportal.model.fault;
public class SDIInteractionException extends Exception {
/**
*
*/
private static final long serialVersionUID = 1L;
public SDIInteractionException() {
super();
// TODO Auto-generated constructor stub
}
public SDIInteractionException(String message, Throwable cause, boolean enableSuppression,
boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
// TODO Auto-generated constructor stub
}
public SDIInteractionException(String message, Throwable cause) {
super(message, cause);
// TODO Auto-generated constructor stub
}
public SDIInteractionException(String message) {
super(message);
// TODO Auto-generated constructor stub
}
public SDIInteractionException(Throwable cause) {
super(cause);
// TODO Auto-generated constructor stub
}
}

View File

@ -1,11 +1,7 @@
package org.gcube.application.geoportal.storage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
@ -19,15 +15,10 @@ import org.gcube.application.geoportal.model.content.AssociatedContent;
import org.gcube.application.geoportal.model.content.OtherContent;
import org.gcube.application.geoportal.model.content.PersistedContent;
import org.gcube.application.geoportal.model.content.UploadedImage;
import org.gcube.application.geoportal.model.content.WorkspaceContent;
import org.gcube.application.geoportal.model.fault.PersistenceException;
import org.gcube.application.geoportal.model.gis.SDILayerDescriptor;
import org.gcube.application.geoportal.utils.Files;
import org.gcube.application.geoportal.utils.Serialization;
import org.gcube.application.geoportal.utils.Workspace;
import org.gcube.common.storagehub.client.dsl.FileContainer;
import org.gcube.common.storagehub.client.dsl.FolderContainer;
import org.gcube.common.storagehub.client.dsl.StorageHubClient;
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
import lombok.Data;
@ -93,7 +84,7 @@ public class ContentHandler {
}
public void storeChanges() throws PersistenceException {
public void storeChanges(Boolean publish) throws PersistenceException {
//
@ -101,6 +92,10 @@ public class ContentHandler {
log.debug("Starting to persist "+uploadedResources.size()+" resources "+record.getNome());
WorkspaceManager wsManager=new WorkspaceManager(record);
SDIManager sdiManager=null;
if(publish)
sdiManager=new SDIManager();
for(Entry<AssociatedContent,ArrayList<TempFile>> entry:uploadedResources.entrySet()) {
AssociatedContent content=entry.getKey();
@ -121,8 +116,20 @@ public class ContentHandler {
if(content instanceof LayerConcessione) {
destination= wsManager.getSubFolder("layers/"+content.getTitolo());
description="Layer concessione : "+content.getTitolo();
if(publish) {
for(TempFile theFile : entry.getValue()) {
persisted.add(sdiManager.pushLayerFile(theFile.getTheFile(), theFile.getOriginalFileName(), record.getId(), content.getId()));
}
//TODO
//Layer registration
// GS + GN
}
}else throw new Exception("Invalid SDI Content "+content);
}else if (content instanceof OtherContent ) {
destination= wsManager.getSubFolder("other/"+content.getTitolo());
description= "Other content : "+content.getTitolo();
@ -146,29 +153,6 @@ public class ContentHandler {
}
// public void publishContent() {
// log.debug("Publishing updated content into SDI ");
// //TODO
// for(Entry<AssociatedContent,ArrayList<TempFile>> entry:uploadedResources.entrySet()) {
// AssociatedContent content=entry.getKey();
//
// if (content instanceof SDILayerDescriptor) {
// //SDI Section
// SDILayerDescriptor layer=(SDILayerDescriptor)content;
// log.debug("Publishing "+layer);
// if(content instanceof LayerConcessione) {
// // Upload Files to geoserver
//
//
// }else throw new Exception("Invalid SDI Content "+content);
//
// }
// }
//
//
//
// }
//
@Override
protected void finalize() throws Throwable {

View File

@ -1,9 +0,0 @@
package org.gcube.application.geoportal.storage;
public class GeoServerManager {
public GeoServerManager() {
// TODO Auto-generated constructor stub
}
}

View File

@ -0,0 +1,78 @@
package org.gcube.application.geoportal.storage;
import java.io.File;
import java.net.URL;
import org.gcube.application.geoportal.model.content.GeoServerContent;
import org.gcube.application.geoportal.model.fault.SDIInteractionException;
import org.gcube.data.transfer.library.DataTransferClient;
import org.gcube.data.transfer.library.TransferResult;
import org.gcube.data.transfer.library.faults.DestinationNotSetException;
import org.gcube.data.transfer.library.faults.FailedTransferException;
import org.gcube.data.transfer.library.faults.InitializationException;
import org.gcube.data.transfer.library.faults.InvalidDestinationException;
import org.gcube.data.transfer.library.faults.InvalidSourceException;
import org.gcube.data.transfer.library.faults.SourceNotSetException;
import org.gcube.data.transfer.model.Destination;
import org.gcube.data.transfer.model.DestinationClashPolicy;
import org.gcube.spatial.data.gis.GISInterface;
import org.gcube.spatial.data.gis.is.AbstractGeoServerDescriptor;
import lombok.extern.log4j.Log4j2;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class SDIManager {
private GISInterface gis;
private DataTransferClient dtGeoServer;
private String geoserverHostName;
public SDIManager() throws SDIInteractionException {
try{
log.debug("Initializing GIS Interface..");
gis=GISInterface.get();
AbstractGeoServerDescriptor geoserver=gis.getCurrentGeoServer();
if(geoserver==null)
throw new Exception("Unable to contact data transfer for geoserver ");
log.debug("Found geoserver descriptor "+geoserver);
geoserverHostName=new URL(gis.getCurrentGeoServer().getUrl()).getHost();
log.debug("Contacting Data Transfer from geoserver {} ",geoserverHostName);
dtGeoServer=DataTransferClient.getInstanceByEndpoint("http://"+geoserverHostName);
}catch(Exception e) {
throw new SDIInteractionException("Unable to initialize SDI Manager",e);
}
}
// GEOSERVER-PERSISTENCE-ID / GNA / PROJECT-ID /LAYER-ID/ FILENAME
public GeoServerContent pushLayerFile(File theFile, String filename, long projectID, long layerID) throws SDIInteractionException {
try {
Destination destination=new Destination(filename);
destination.setCreateSubfolders(true);
destination.setOnExistingFileName(DestinationClashPolicy.REWRITE);
destination.setPersistenceId("geoserver");
destination.setSubFolder("GNA/"+projectID+"/"+layerID);
TransferResult result=dtGeoServer.localFile(theFile, destination);
GeoServerContent content=new GeoServerContent();
content.setFilename(filename);
content.setGeoserverPath(result.getRemotePath());
content.setGeoserverHostName(geoserverHostName);
return content;
} catch (InvalidSourceException | SourceNotSetException | FailedTransferException | InitializationException
| InvalidDestinationException | DestinationNotSetException e) {
throw new SDIInteractionException("Unable to transfer file "+filename,e);
}
}
}

View File

@ -9,6 +9,7 @@ import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.gcube.spatial.data.geonetwork.model.ScopeConfiguration;
public class ISUtils {
@ -37,4 +38,5 @@ public class ISUtils {
throw new RuntimeException("Unable to decrypt : "+toDecrypt,e);
}
}
}

View File

@ -119,4 +119,21 @@ public class Layers {
// }
// }
public static void publishShapeFile() {
String DEFAULT_CRS="GEOGCS[\"WGS 84\", \n" +
" DATUM[\"World Geodetic System 1984\", \n" +
" SPHEROID[\"WGS 84\", 6378137.0, 298.257223563, AUTHORITY[\"EPSG\",\"7030\"]], \n" +
" AUTHORITY[\"EPSG\",\"6326\"]], \n" +
" PRIMEM[\"Greenwich\", 0.0, AUTHORITY[\"EPSG\",\"8901\"]], \n" +
" UNIT[\"degree\", 0.017453292519943295], \n" +
" AXIS[\"Geodetic longitude\", EAST], \n" +
" AXIS[\"Geodetic latitude\", NORTH], \n" +
" AUTHORITY[\"EPSG\",\"4326\"]]";
}
}

View File

@ -1,9 +1,8 @@
package org.gcube.application.geoportal;
import java.time.Instant;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import org.gcube.application.geoportal.model.AccessPolicy;
import org.gcube.application.geoportal.model.concessioni.Concessione;
@ -19,7 +18,7 @@ public class TestModel {
// Generic fields
concessione.setCreationTime(Instant.now());
concessione.setCreationTime(LocalDateTime.now());
concessione.setCreationUser("my author");
concessione.setLastUpdateTime(concessione.getCreationTime());
concessione.setVersion("1.0.0");
@ -46,8 +45,8 @@ public class TestModel {
concessione.setDataInizioProgetto(Instant.now());
concessione.setDataFineProgetto(Instant.now());
concessione.setDataInizioProgetto(LocalDateTime.now());
concessione.setDataFineProgetto(LocalDateTime.now());
concessione.setTitolareLicenza("Qualcun altro");
concessione.setTitolareCopyright("Chiedilo in giro");
@ -56,8 +55,8 @@ public class TestModel {
concessione.setParoleChiaveICCD(Arrays.asList(new String[] {"vattelapesca","somthing something"}));
concessione.setCentroidLat(180.0);
concessione.setCentroidLong(90.0);
concessione.setCentroidLat(-13.0);
concessione.setCentroidLong(45.0);
return concessione;
}
@ -88,7 +87,7 @@ public class TestModel {
img.setDidascalia("You can see my image number "+i);
img.setFormat("TIFF");
img.setSoggetto(concessione.getSoggetto());
img.setCreationTime(Instant.now());
img.setCreationTime(LocalDateTime.now());
img.setResponsabili(concessione.getAuthors());
img.setLicenseID("CC-BY");
imgs.add(img);

View File

@ -0,0 +1,18 @@
package org.gcube.application.geoportal;
import org.gcube.application.geoportal.model.fault.SDIInteractionException;
import org.gcube.application.geoportal.storage.SDIManager;
import org.gcube.application.geoportal.utils.Files;
public class TestSDI {
public static void main(String[] args) throws SDIInteractionException {
TokenSetter.set("/gcube/devNext/NextNext");
SDIManager sdiManager=new SDIManager();
sdiManager.pushLayerFile(Files.getFileFromResources("concessioni/pos.dbf"), "pos.dbf", 123, 1);
}
}

View File

@ -69,7 +69,7 @@ public class UseCases {
//If true -> data are published into the SDI
Boolean publish=false;
Boolean publish=true;
/*Chiedo al manager di salvare il progetto, causando :
*scrittura sul WS

View File

@ -0,0 +1,8 @@
log4j.rootLogger=DEBUG, stdout
#CONSOLE
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Threshold=INFO
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%t] %-5p %c %d{dd MMM yyyy ;HH:mm:ss.SSS} - %m%n

View File

@ -7,16 +7,6 @@
</encoder>
</appender>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>logFile.log</file>
<append>true</append>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss} | %-5p | [%thread] %logger{5}:%L - %msg%n</pattern>
</encoder>
</appender>
<root level="DEBUG">
<appender-ref ref="STDOUT" />