2013-11-18 19:25:01 +01:00
package org.gcube.dataanalysis.geo.meta ;
2016-07-28 17:27:41 +02:00
import it.geosolutions.geonetwork.util.GNPriv ;
import it.geosolutions.geonetwork.util.GNPrivConfiguration ;
2013-11-18 19:25:01 +01:00
import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder ;
import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureTypeEncoder ;
import java.util.Date ;
2016-07-28 17:27:41 +02:00
import java.util.EnumSet ;
import java.util.Set ;
2013-11-18 19:25:01 +01:00
import org.gcube.common.scope.api.ScopeProvider ;
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger ;
2016-07-28 17:27:41 +02:00
import org.gcube.spatial.data.geonetwork.GeoNetwork ;
import org.gcube.spatial.data.geonetwork.GeoNetworkPublisher ;
2013-11-18 19:25:01 +01:00
import org.gcube.spatial.data.geonetwork.LoginLevel ;
import org.gcube.spatial.data.geonetwork.configuration.Configuration ;
import org.gcube.spatial.data.geonetwork.iso.GcubeISOMetadata ;
import org.gcube.spatial.data.geonetwork.iso.Thesaurus ;
2016-07-28 17:27:41 +02:00
import org.gcube.spatial.data.geonetwork.model.ScopeConfiguration ;
2013-11-18 19:25:01 +01:00
import org.gcube.spatial.data.gis.GISInterface ;
import org.gcube.spatial.data.gis.model.report.PublishResponse ;
import org.geotoolkit.metadata.iso.extent.DefaultExtent ;
import org.opengis.metadata.citation.PresentationForm ;
import org.opengis.metadata.identification.TopicCategory ;
import org.opengis.metadata.spatial.GeometricObjectType ;
import org.opengis.metadata.spatial.TopologyLevel ;
public class PolyMapMetadata {
2016-07-28 17:27:41 +02:00
2013-11-18 19:25:01 +01:00
private static final String crs = " GEOGCS[ \" WGS 84 \" , DATUM[ \" World Geodetic System 1984 \" , SPHEROID[ \" WGS 84 \" , 6378137.0, 298.257223563, AUTHORITY[ \" EPSG \" , \" 7030 \" ]], " + " AUTHORITY[ \" EPSG \" , \" 6326 \" ]], PRIMEM[ \" Greenwich \" , 0.0, AUTHORITY[ \" EPSG \" , \" 8901 \" ]], UNIT[ \" degree \" , 0.017453292519943295], " + " AXIS[ \" Geodetic longitude \" , EAST], AXIS[ \" Geodetic latitude \" , NORTH], AUTHORITY[ \" EPSG \" , \" 4326 \" ]] " ;
2016-07-28 17:27:41 +02:00
2016-06-14 12:47:46 +02:00
public static PublishResponse publishTable ( String scope , String tableName , double resolution , String username , String layerName , String defaultStyle , String workspace , String datastore , String purpose , String credits , String keyword , boolean isprivate ) throws Exception {
2016-07-28 17:27:41 +02:00
2013-11-18 19:25:01 +01:00
GSFeatureTypeEncoder fte = new GSFeatureTypeEncoder ( ) ;
fte . setEnabled ( true ) ;
fte . setLatLonBoundingBox ( - 180 . 0 , - 90 . 0 , 180 . 0 , 90 . 0 , crs ) ;
fte . setName ( tableName ) ;
fte . setNativeCRS ( crs ) ;
GSLayerEncoder le = new GSLayerEncoder ( ) ;
le . setDefaultStyle ( defaultStyle ) ;
le . setEnabled ( true ) ;
2013-11-19 12:32:56 +01:00
AnalysisLogger . getLogger ( ) . debug ( " Filling Metadata " ) ;
2016-07-28 17:27:41 +02:00
GcubeISOMetadata meta = fillMeta ( resolution , username , layerName , scope , tableName , purpose , credits , keyword ) ;
AnalysisLogger . getLogger ( ) . debug ( " Getting GIS from scope " + scope ) ;
2013-11-18 19:25:01 +01:00
GISInterface gis = GISInterface . get ( ) ;
Configuration gnConfig = gis . getGeoNetworkReader ( ) . getConfiguration ( ) ;
AnalysisLogger . getLogger ( ) . debug ( " Using the following GNetwork: " + gnConfig . getGeoNetworkEndpoint ( ) ) ;
2016-06-14 12:47:46 +02:00
LoginLevel level = LoginLevel . SCOPE ;
if ( isprivate )
level = LoginLevel . PRIVATE ;
2016-07-28 17:27:41 +02:00
// PublishResponse resp = gis.publishDBTable(workspace, datastore, fte, le, meta.getMetadata(), new GNInsertConfiguration(gnConfig.getScopeGroup() + "", "datasets", "_none_", true), LoginLevel.DEFAULT);
2016-09-27 18:00:11 +02:00
PublishResponse resp = gis . publishDBTable ( workspace , datastore , fte , le , meta . getMetadata ( ) , " datasets " , " _none_ " , level , ! isprivate ) ;
2016-06-14 12:47:46 +02:00
2013-11-18 19:25:01 +01:00
AnalysisLogger . getLogger ( ) . debug ( resp ) ;
AnalysisLogger . getLogger ( ) . debug ( " ID: " + resp . getReturnedMetaId ( ) ) ;
AnalysisLogger . getLogger ( ) . debug ( " Result: " + resp . getMetaOperationResult ( ) ) ;
2016-07-28 17:27:41 +02:00
if ( resp . getReturnedMetaId ( ) = = 0 )
2013-11-18 19:25:01 +01:00
return null ;
else
return resp ;
}
2016-07-28 17:27:41 +02:00
private static GcubeISOMetadata fillMeta ( double resolution , String username , String title , String scope , String tableName , String purpose , String credits , String keyword ) throws Exception {
2013-11-18 19:25:01 +01:00
2016-09-27 18:00:11 +02:00
/ *
2013-11-18 19:25:01 +01:00
if ( scope = = null )
scope = ScopeProvider . instance . get ( ) ;
2016-09-27 18:00:11 +02:00
* /
2013-11-19 12:32:56 +01:00
AnalysisLogger . getLogger ( ) . debug ( " Setting scope for filling Meta " ) ;
2016-09-27 18:00:11 +02:00
// ScopeProvider.instance.set(scope);
2016-07-28 17:27:41 +02:00
2013-11-19 12:32:56 +01:00
AnalysisLogger . getLogger ( ) . debug ( " Fulfilling metadata " ) ;
2013-11-18 19:25:01 +01:00
GcubeISOMetadata meta = new GcubeISOMetadata ( ) ;
2013-11-19 12:32:56 +01:00
AnalysisLogger . getLogger ( ) . debug ( " Fulfilling metadata Begin " ) ;
2016-07-28 17:27:41 +02:00
meta . setAbstractField ( " This metadata has been automatically generated from the Statistical Manager on the basis of a distribution of points and according the resolution of " + resolution + " degrees. " ) ;
2013-11-18 19:25:01 +01:00
meta . setCreationDate ( new Date ( System . currentTimeMillis ( ) ) ) ;
meta . setExtent ( ( DefaultExtent ) DefaultExtent . WORLD ) ;
meta . setGeometricObjectType ( GeometricObjectType . SURFACE ) ;
meta . setPresentationForm ( PresentationForm . MAP_DIGITAL ) ;
meta . setPurpose ( purpose ) ;
meta . setResolution ( resolution ) ;
if ( title = = null | | title . length ( ) = = 0 )
meta . setTitle ( " Distribution " ) ;
else
meta . setTitle ( title ) ;
meta . setTopologyLevel ( TopologyLevel . GEOMETRY_ONLY ) ;
meta . setUser ( username ) ;
meta . addGraphicOverview ( " http://www.d4science.org/D4ScienceOrg-Social-theme/images/custom/D4ScienceInfrastructure.png " ) ;
meta . addCredits ( credits ) ;
Thesaurus generalThesaurus = meta . getConfig ( ) . getThesauri ( ) . get ( " General " ) ;
meta . addKeyword ( title , generalThesaurus ) ;
meta . addKeyword ( username , generalThesaurus ) ;
2016-09-30 10:39:46 +02:00
meta . addKeyword ( " DataMiner " , generalThesaurus ) ;
2013-11-18 19:25:01 +01:00
meta . addKeyword ( keyword , generalThesaurus ) ;
2016-07-28 17:27:41 +02:00
meta . addKeyword ( tableName , generalThesaurus ) ;
2013-11-18 19:25:01 +01:00
meta . addTopicCategory ( TopicCategory . BIOTA ) ;
2013-11-19 12:32:56 +01:00
AnalysisLogger . getLogger ( ) . debug ( " Fulfilling done " ) ;
2013-11-18 19:25:01 +01:00
return meta ;
}
2016-07-28 17:27:41 +02:00
2013-11-18 19:25:01 +01:00
}