Browse Source

Layer creating porting to the new Gis Interface

master
lucio 2 years ago
parent
commit
5ec4aa8cb2
  1. 1
      .settings/org.eclipse.core.resources.prefs
  2. 8
      pom.xml
  3. 2
      src/main/java/org/gcube/data/spd/executor/jobs/layer/LayerCreatorJob.java
  4. 86
      src/main/java/org/gcube/data/spd/utils/MapUtils.java
  5. 8
      src/test/java/org/gcube/data/spd/MapTest.java

1
.settings/org.eclipse.core.resources.prefs

@ -2,5 +2,4 @@ eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8

8
pom.xml

@ -10,7 +10,7 @@
<groupId>org.gcube.data.spd</groupId>
<artifactId>species-products-discovery</artifactId>
<version>3.1.1-SNAPSHOT</version>
<version>3.1.0</version>
<packaging>war</packaging>
<name>species product discovery</name>
@ -65,7 +65,11 @@
<groupId>org.gcube.resources</groupId>
<artifactId>registry-publisher</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-encryption</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>

2
src/main/java/org/gcube/data/spd/executor/jobs/layer/LayerCreatorJob.java

@ -135,7 +135,7 @@ public class LayerCreatorJob extends URLJob{
org.gcube.data.spd.utils.MapUtils.Map map = MapUtils.publishLayerByCoords(this.metadata, points,false,true);
this.resultURL = map.getLayerUUID();
this.status = JobStatus.COMPLETED;
}catch (Exception e) {
}catch (Throwable e) {
logger.error("error executing Layer Job",e);
this.status = JobStatus.FAILED;
return;

86
src/main/java/org/gcube/data/spd/utils/MapUtils.java

@ -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.queryFor;
import java.io.File;
import java.net.URISyntaxException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Collection;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Set;
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.AccessPoint;
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.queries.api.SimpleQuery;
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.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.gis.GISInterface;
import org.gcube.spatial.data.gis.model.report.PublishResponse;
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.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.feature.GSFeatureTypeEncoder;
@ -110,11 +117,12 @@ public class MapUtils {
log.trace("Generating layer by points");
tableName=createPointTable(db, points);
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);
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)){
throw new Exception("Erors while publishing layer metadata. Messages are : "+resp.getMetaOperationMessages());
}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();
fte.setEnabled(true);
@ -222,44 +230,58 @@ public class MapUtils {
le.setEnabled(true);
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();
log.trace("Publishing layer from table {} with options {} in store {} ",tableName,layerOpt);
LoginLevel login= layerOpt.getAccessibleParentContexts()?LoginLevel.SCOPE:LoginLevel.PRIVATE;
return gis.publishDBTable(layerOpt.getWorkspace(),layerOpt.getStore(), fte, le,
meta, layerOpt.getLayerCategory(), "_none_", login,layerOpt.getPublishAsParentContext());
}
private static GcubeISOMetadata fillMeta(MetadataDetails metaDetails) throws Exception{
GcubeISOMetadata meta=new GcubeISOMetadata();
private static MetadataDescriptor fillMeta(MetadataDetails metaDetails, int pointsCount) throws Exception{
MetadataDescriptor meta=new MetadataDescriptor();
meta.setUUIDIdentifier(UUID.randomUUID().toString());
meta.setAbstractField(metaDetails.getAbstractField());
meta.setCreationDate(new Date(System.currentTimeMillis()));
meta.setExtent((DefaultExtent) DefaultExtent.WORLD);
meta.setGeometricObjectType(GeometricObjectType.SURFACE);
meta.setPresentationForm(PresentationForm.MAP_DIGITAL);
meta.setCreationTime(new GregorianCalendar().getTime());
meta.setPurpose(metaDetails.getPurpose());
meta.setResolution(0.5d);
meta.getExtent().addGeographicExtent(BoundingBox.WORLD_EXTENT);
//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.setTopologyLevel(TopologyLevel.GEOMETRY_ONLY);
meta.setUser(metaDetails.getAuthor());
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());
List<String> keywords=metaDetails.getKeywords();
if(keywords!=null&&!keywords.isEmpty()){
Thesaurus generalThesaurus=meta.getConfig().getThesauri().get("General");
for(String key:keywords)
meta.addKeyword(key, generalThesaurus);
Set<String> keyWordSet = keywords.stream().collect(Collectors.toSet());
KeywordSet set = new KeywordSet(keyWordSet);
meta.addKeywordSet(set);
}
meta.addTopicCategory(TopicCategory.BIOTA);
meta.addTopicCategory(org.gcube.spatial.data.geonetwork.iso.tpl.codelists.TopicCategory.BIOTA);
return meta;
}

8
src/test/java/org/gcube/data/spd/MapTest.java

@ -1,11 +1,16 @@
package org.gcube.data.spd;
import java.io.File;
import java.security.Key;
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.data.spd.model.PointInfo;
import org.gcube.data.spd.model.service.types.MetadataDetails;
import org.gcube.data.spd.utils.MapUtils;
import org.junit.Test;
public class MapTest {
@ -35,5 +40,6 @@ public class MapTest {
System.out.println("Result : "+MapUtils.publishLayerByCoords(details, points,false,true));
}
}

Loading…
Cancel
Save