Layer creating porting to the new Gis Interface
This commit is contained in:
parent
3cf1e7999f
commit
5ec4aa8cb2
|
@ -2,5 +2,4 @@ eclipse.preferences.version=1
|
||||||
encoding//src/main/java=UTF-8
|
encoding//src/main/java=UTF-8
|
||||||
encoding//src/main/resources=UTF-8
|
encoding//src/main/resources=UTF-8
|
||||||
encoding//src/test/java=UTF-8
|
encoding//src/test/java=UTF-8
|
||||||
encoding//src/test/resources=UTF-8
|
|
||||||
encoding/<project>=UTF-8
|
encoding/<project>=UTF-8
|
||||||
|
|
6
pom.xml
6
pom.xml
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
<groupId>org.gcube.data.spd</groupId>
|
<groupId>org.gcube.data.spd</groupId>
|
||||||
<artifactId>species-products-discovery</artifactId>
|
<artifactId>species-products-discovery</artifactId>
|
||||||
<version>3.1.1-SNAPSHOT</version>
|
<version>3.1.0</version>
|
||||||
<packaging>war</packaging>
|
<packaging>war</packaging>
|
||||||
<name>species product discovery</name>
|
<name>species product discovery</name>
|
||||||
|
|
||||||
|
@ -66,6 +66,10 @@
|
||||||
<artifactId>registry-publisher</artifactId>
|
<artifactId>registry-publisher</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.core</groupId>
|
||||||
|
<artifactId>common-encryption</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.servlet</groupId>
|
<groupId>javax.servlet</groupId>
|
||||||
|
|
|
@ -135,7 +135,7 @@ public class LayerCreatorJob extends URLJob{
|
||||||
org.gcube.data.spd.utils.MapUtils.Map map = MapUtils.publishLayerByCoords(this.metadata, points,false,true);
|
org.gcube.data.spd.utils.MapUtils.Map map = MapUtils.publishLayerByCoords(this.metadata, points,false,true);
|
||||||
this.resultURL = map.getLayerUUID();
|
this.resultURL = map.getLayerUUID();
|
||||||
this.status = JobStatus.COMPLETED;
|
this.status = JobStatus.COMPLETED;
|
||||||
}catch (Exception e) {
|
}catch (Throwable e) {
|
||||||
logger.error("error executing Layer Job",e);
|
logger.error("error executing Layer Job",e);
|
||||||
this.status = JobStatus.FAILED;
|
this.status = JobStatus.FAILED;
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -3,17 +3,20 @@ package org.gcube.data.spd.utils;
|
||||||
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
|
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
|
||||||
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
|
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Date;
|
import java.util.GregorianCalendar;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.gcube.common.encryption.StringEncrypter;
|
import org.gcube.common.encryption.encrypter.StringEncrypter;
|
||||||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||||
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
||||||
import org.gcube.common.resources.gcore.ServiceEndpoint.Property;
|
import org.gcube.common.resources.gcore.ServiceEndpoint.Property;
|
||||||
|
@ -22,19 +25,23 @@ import org.gcube.data.spd.model.service.types.MetadataDetails;
|
||||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||||
import org.gcube.spatial.data.geonetwork.LoginLevel;
|
import org.gcube.spatial.data.geonetwork.LoginLevel;
|
||||||
import org.gcube.spatial.data.geonetwork.iso.GcubeISOMetadata;
|
|
||||||
import org.gcube.spatial.data.geonetwork.iso.MissingInformationException;
|
import org.gcube.spatial.data.geonetwork.iso.MissingInformationException;
|
||||||
import org.gcube.spatial.data.geonetwork.iso.Thesaurus;
|
import org.gcube.spatial.data.geonetwork.iso.tpl.ISOMetadataByTemplate;
|
||||||
|
import org.gcube.spatial.data.geonetwork.iso.tpl.MetadataDescriptor;
|
||||||
|
import org.gcube.spatial.data.geonetwork.iso.tpl.codelists.ResponsiblePartyRole;
|
||||||
|
import org.gcube.spatial.data.geonetwork.iso.tpl.codelists.RestrictionCode;
|
||||||
|
import org.gcube.spatial.data.geonetwork.iso.tpl.constraints.LegalConstraints;
|
||||||
|
import org.gcube.spatial.data.geonetwork.iso.tpl.constraints.ResourceConstraints;
|
||||||
|
import org.gcube.spatial.data.geonetwork.iso.tpl.extent.BoundingBox;
|
||||||
|
import org.gcube.spatial.data.geonetwork.iso.tpl.keys.KeywordSet;
|
||||||
|
import org.gcube.spatial.data.geonetwork.iso.tpl.parties.ResponsibleParty;
|
||||||
|
import org.gcube.spatial.data.geonetwork.iso.tpl.spatial.VectorRepresentation;
|
||||||
import org.gcube.spatial.data.geonetwork.model.faults.EncryptionException;
|
import org.gcube.spatial.data.geonetwork.model.faults.EncryptionException;
|
||||||
import org.gcube.spatial.data.gis.GISInterface;
|
import org.gcube.spatial.data.gis.GISInterface;
|
||||||
import org.gcube.spatial.data.gis.model.report.PublishResponse;
|
import org.gcube.spatial.data.gis.model.report.PublishResponse;
|
||||||
import org.gcube.spatial.data.gis.model.report.Report.OperationState;
|
import org.gcube.spatial.data.gis.model.report.Report.OperationState;
|
||||||
import org.geotoolkit.metadata.iso.extent.DefaultExtent;
|
import org.geotoolkit.xml.XML;
|
||||||
import org.opengis.metadata.Metadata;
|
import org.opengis.metadata.Metadata;
|
||||||
import org.opengis.metadata.citation.PresentationForm;
|
|
||||||
import org.opengis.metadata.identification.TopicCategory;
|
|
||||||
import org.opengis.metadata.spatial.GeometricObjectType;
|
|
||||||
import org.opengis.metadata.spatial.TopologyLevel;
|
|
||||||
|
|
||||||
import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder;
|
import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder;
|
||||||
import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureTypeEncoder;
|
import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureTypeEncoder;
|
||||||
|
@ -110,11 +117,12 @@ public class MapUtils {
|
||||||
log.trace("Generating layer by points");
|
log.trace("Generating layer by points");
|
||||||
tableName=createPointTable(db, points);
|
tableName=createPointTable(db, points);
|
||||||
log.debug("Created table {} in {} ",tableName,db);
|
log.debug("Created table {} in {} ",tableName,db);
|
||||||
PublishResponse resp=createLayer(layerOptions, metadata, tableName);
|
PublishResponse resp=createLayer(layerOptions, metadata, tableName, points.size());
|
||||||
log.debug("Publish response output {} ",resp);
|
log.debug("Publish response output {} ",resp);
|
||||||
|
|
||||||
|
|
||||||
if(!resp.getDataOperationResult().equals(OperationState.COMPLETE)){
|
if(!resp.getDataOperationResult().equals(OperationState.COMPLETE)){
|
||||||
throw new Exception("Erors while publishing layer. Messages are : "+resp.getDataOperationMessages());
|
throw new Exception("Erors while publishing layer. Messages are : Operation errors "+resp.getDataOperationMessages()+" Metadata errors "+resp.getMetaOperationMessages() );
|
||||||
}else if(!resp.getMetaOperationResult().equals(OperationState.COMPLETE)){
|
}else if(!resp.getMetaOperationResult().equals(OperationState.COMPLETE)){
|
||||||
throw new Exception("Erors while publishing layer metadata. Messages are : "+resp.getMetaOperationMessages());
|
throw new Exception("Erors while publishing layer metadata. Messages are : "+resp.getMetaOperationMessages());
|
||||||
}else {
|
}else {
|
||||||
|
@ -206,7 +214,7 @@ public class MapUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static final PublishResponse createLayer(LayerCreationOptions layerOpt,MetadataDetails details,String tableName) throws URISyntaxException, MissingInformationException, Exception{
|
private static final PublishResponse createLayer(LayerCreationOptions layerOpt,MetadataDetails details,String tableName, int pointsCount) throws URISyntaxException, MissingInformationException, Exception{
|
||||||
|
|
||||||
GSFeatureTypeEncoder fte=new GSFeatureTypeEncoder();
|
GSFeatureTypeEncoder fte=new GSFeatureTypeEncoder();
|
||||||
fte.setEnabled(true);
|
fte.setEnabled(true);
|
||||||
|
@ -222,8 +230,11 @@ public class MapUtils {
|
||||||
le.setEnabled(true);
|
le.setEnabled(true);
|
||||||
|
|
||||||
log.debug("Generating meta for layer table {}. Meta parameters are {}",tableName,details);
|
log.debug("Generating meta for layer table {}. Meta parameters are {}",tableName,details);
|
||||||
Metadata meta=fillMeta(details).getMetadata();
|
MetadataDescriptor metaDescr=fillMeta(details, pointsCount);
|
||||||
|
|
||||||
|
File metaFile=ISOMetadataByTemplate.createXML(metaDescr);
|
||||||
|
|
||||||
|
Metadata meta = (Metadata) XML.unmarshal(metaFile);
|
||||||
|
|
||||||
GISInterface gis=GISInterface.get();
|
GISInterface gis=GISInterface.get();
|
||||||
|
|
||||||
|
@ -238,28 +249,39 @@ public class MapUtils {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private static GcubeISOMetadata fillMeta(MetadataDetails metaDetails) throws Exception{
|
private static MetadataDescriptor fillMeta(MetadataDetails metaDetails, int pointsCount) throws Exception{
|
||||||
GcubeISOMetadata meta=new GcubeISOMetadata();
|
MetadataDescriptor meta=new MetadataDescriptor();
|
||||||
|
meta.setUUIDIdentifier(UUID.randomUUID().toString());
|
||||||
meta.setAbstractField(metaDetails.getAbstractField());
|
meta.setAbstractField(metaDetails.getAbstractField());
|
||||||
meta.setCreationDate(new Date(System.currentTimeMillis()));
|
meta.setCreationTime(new GregorianCalendar().getTime());
|
||||||
meta.setExtent((DefaultExtent) DefaultExtent.WORLD);
|
|
||||||
meta.setGeometricObjectType(GeometricObjectType.SURFACE);
|
|
||||||
meta.setPresentationForm(PresentationForm.MAP_DIGITAL);
|
|
||||||
meta.setPurpose(metaDetails.getPurpose());
|
meta.setPurpose(metaDetails.getPurpose());
|
||||||
meta.setResolution(0.5d);
|
meta.getExtent().addGeographicExtent(BoundingBox.WORLD_EXTENT);
|
||||||
meta.setTitle(metaDetails.getTitle());
|
|
||||||
meta.setTopologyLevel(TopologyLevel.GEOMETRY_ONLY);
|
|
||||||
meta.setUser(metaDetails.getAuthor());
|
|
||||||
|
|
||||||
|
|
||||||
|
//Setting Spatial Representation
|
||||||
|
VectorRepresentation representation=new VectorRepresentation(
|
||||||
|
org.gcube.spatial.data.geonetwork.iso.tpl.codelists.TopologyLevel.GEOMETRY_ONLY, pointsCount , org.gcube.spatial.data.geonetwork.iso.tpl.codelists.GeometricObjectType.SURFACE);
|
||||||
|
meta.setSpatialRepresentation(representation);
|
||||||
|
|
||||||
|
meta.addResponsibleParty(new ResponsibleParty(metaDetails.getAuthor(),"D4Science",
|
||||||
|
ResponsiblePartyRole.AUTHOR));
|
||||||
|
|
||||||
|
//Setting the Lineage Statement
|
||||||
|
meta.setLineageStatement("this layer has been created using different occurrence sources via Species product Discovery service");
|
||||||
|
|
||||||
|
meta.setSpatialResolution(0.5d);
|
||||||
|
meta.setTitle(metaDetails.getTitle());
|
||||||
|
|
||||||
|
meta.setConstraints(new ResourceConstraints("This product has been generated by aggregating and harmonizing data that are freely accessible", new LegalConstraints(RestrictionCode.LICENSE,"CC-BY-SA"), new LegalConstraints(RestrictionCode.LICENSE,"CC-BY-SA")));
|
||||||
|
|
||||||
meta.addCredits(metaDetails.getCredits());
|
meta.addCredits(metaDetails.getCredits());
|
||||||
List<String> keywords=metaDetails.getKeywords();
|
List<String> keywords=metaDetails.getKeywords();
|
||||||
if(keywords!=null&&!keywords.isEmpty()){
|
if(keywords!=null&&!keywords.isEmpty()){
|
||||||
Thesaurus generalThesaurus=meta.getConfig().getThesauri().get("General");
|
Set<String> keyWordSet = keywords.stream().collect(Collectors.toSet());
|
||||||
for(String key:keywords)
|
KeywordSet set = new KeywordSet(keyWordSet);
|
||||||
meta.addKeyword(key, generalThesaurus);
|
meta.addKeywordSet(set);
|
||||||
}
|
}
|
||||||
meta.addTopicCategory(TopicCategory.BIOTA);
|
meta.addTopicCategory(org.gcube.spatial.data.geonetwork.iso.tpl.codelists.TopicCategory.BIOTA);
|
||||||
return meta;
|
return meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
package org.gcube.data.spd;
|
package org.gcube.data.spd;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.security.Key;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import org.gcube.common.encryption.SymmetricKey;
|
||||||
|
import org.gcube.common.encryption.encrypter.StringEncrypter;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
import org.gcube.data.spd.model.PointInfo;
|
import org.gcube.data.spd.model.PointInfo;
|
||||||
import org.gcube.data.spd.model.service.types.MetadataDetails;
|
import org.gcube.data.spd.model.service.types.MetadataDetails;
|
||||||
import org.gcube.data.spd.utils.MapUtils;
|
import org.gcube.data.spd.utils.MapUtils;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
public class MapTest {
|
public class MapTest {
|
||||||
|
|
||||||
|
@ -36,4 +41,5 @@ public class MapTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue