Difference between revisions of "GeoNetwork library"
(→Changes in 3.0.0) |
m |
||
Line 1: | Line 1: | ||
<!-- CATEGORIES --> | <!-- CATEGORIES --> | ||
− | [[Category:Developer's Guide]] | + | [[Category:Developer's Guide]][[Category: gCube Spatial Data Infrastructure]] |
+ | <!-- CATEGORIES --> | ||
+ | |||
<!-- END CATEGORIES --> | <!-- END CATEGORIES --> | ||
A library to interact with GeoNetwork's REST Interface to publish/modify/delete and search for Metadata.The library is designed on top of [https://github.com/geosolutions-it/geoserver-manager/wiki geoserver-manager library], developed by [http://www.geo-solutions.it/ GeoSolutions]. Metadata objects managed by the library are compliant to standard specification [[ISO 19115:2003/19139]]. Default configuration of the library interacts exploits [[Featherweight Stack]] functionalities to discover geonetwork available in the infrastructure. | A library to interact with GeoNetwork's REST Interface to publish/modify/delete and search for Metadata.The library is designed on top of [https://github.com/geosolutions-it/geoserver-manager/wiki geoserver-manager library], developed by [http://www.geo-solutions.it/ GeoSolutions]. Metadata objects managed by the library are compliant to standard specification [[ISO 19115:2003/19139]]. Default configuration of the library interacts exploits [[Featherweight Stack]] functionalities to discover geonetwork available in the infrastructure. |
Revision as of 13:17, 6 July 2016
A library to interact with GeoNetwork's REST Interface to publish/modify/delete and search for Metadata.The library is designed on top of geoserver-manager library, developed by GeoSolutions. Metadata objects managed by the library are compliant to standard specification ISO 19115:2003/19139. Default configuration of the library interacts exploits Featherweight Stack functionalities to discover geonetwork available in the infrastructure.
Contents
Module overview
The library is distributed as the artifact
<dependency> <groupId>org.gcube.spatial.data</groupId> <artifactId>geonetwork</artifactId> <version>...</version> </dependency>
ISO 19115:2003 metadata compliance
Metadata objects used by the libraries implement GeoAPI interfaces, which are fully compliant to ISO 19115:2003/19139. Current implementation is based on GeoToolkit Metadata module.
Dependecies
The library declares these dependecies to external third parties artifacts
<dependency> <groupId>it.geosolutions</groupId> <artifactId>geonetwork-manager</artifactId> <version>1.1</version> </dependency> <dependency> <groupId>org.geotoolkit</groupId> <artifactId>geotk-metadata</artifactId> <version>3.20-geoapi-3.0</version> </dependency> <dependency> <groupId>org.w3c</groupId> <artifactId>dom</artifactId> <version>2.3.0-jaxb-1.0.6</version> </dependency> <dependency> <groupId>org.geotoolkit</groupId> <artifactId>geotk-referencing</artifactId> <version>3.20-geoapi-3.0</version> </dependency>
Using the library
The library acts as a wrapper to the functionalities exposed by the geonetwork-manager library. The methods offered by the library are splitted in three different interfaces :
- org.gcube.spatial.data.geonetwork.GeoNetworkReader : declares methods to access metadata stored in geonetwork
- org.gcube.spatial.data.geonetwork.GeoNetworkPublisher : extends GeoNetworkReader, and declares methods to publish/update/delete metadata in geonetwork
- org.gcube.spatial.data.geonetwork.GeoNetworkAdministration : extends GeoNetworkPublisher, and declares methods to manage users and groups on GeoNetwork (available from 3.0.0)
The class org.gcube.spatial.data.geonetwork.GeoNetwork offers two static members to obtain implementations of the above interfaces :
- public static GeoNetworkAdministration get() throws Exception : uses the current settings of ConfigurationManager to get a Configuration implementation.
- public static GeoNetworkAdministration get(Configuration config) : uses the passed Configuration implementation.
See #Configuration to get more information.
Security 2.0
From version 2.0.0 the library refers to the guidelines stated in GeoNetwork administration in particular :
- applications should publish their metadata in the current scope group
- applications should publish as <SCOPE_PUBLIC_USER> metadata with scope visibility
- applications should publish as <SCOPE_PRIVATE_USER> metadata with private (per user) visibility
Login
Unless the client calls the method public void login(LoginLevel level)throws AuthorizationException declared by GeoNetworkReader interface, all calls to geonetwork are sent without login thus :
- queries return only public metadata
- access to metadata with no public access will fail
- methods which change the current geonetwork state will fail
The following LoginLevels are defined :
- DEFAULT
- SCOPE
- PRIVATE
see #Configuration for details on how the related credentials are used.
Security 3.0
From version 3.0.0 the publication guidelines suggest that:
- metadata that should be visible only inside the current scope : use current scope's private group on GeoNetwork
- metadata that should be visible in the current scope and in parent ones : use current scope's public group on GeoNetwork
Login
Unless the client calls the method public void login(LoginLevel level)throws AuthorizationException declared by GeoNetworkReader interface, all calls to geonetwork are sent without login thus :
- queries return only public metadata
- access to metadata with no public access will fail
- methods which change the current geonetwork state will fail
Please note that by calling login method, the user specifies publishing behavior according to the current scope configuration involving the target group to use:
- DEFAULT : uses <SCOPE_USER> and publish into the default publishing group for the current scope;
- SCOPE : uses <SCOPE_USER> and publish into the <PUBLIC_GROUP> for the current scope;
- PRIVATE : uses <SCOPE_USER> and publish into the <PRIVATE_GROUP> for the current scope;
- ADMIN : uses administration privileges, thus no check/ constraint are performed;
- CKAN : uses read-only ckan user for that scope;
see #Configuration for details on how the related credentials are used.
Configuration
The geonetwork library relies on instances of org.gcube.spatial.data.geonetwork.configuration.Configuration interface in order to retrieve needed information to interact with geonetwork REST interface. The following snippets show how to set Configuration implementation to be used by the library :
Implicit Configuration
Using ConfigurationManager to set the class implementing Configuration. Every following instantiation of GeoNetworkReader will use a new object of the given Configuration implementing class.
//MyConfiguration must implement org.gcube.spatial.data.geonetwork.configuration.Configuration ConfigurationManager.setConfiguration(MyConfiguration.class); ... GeoNetworkReader reader1=GeoNetwork.get(); ... GeoNetworkReader reader2=GeoNetwork.get(); ... GeoNetworkPublisher publisher1=GeoNetwork.get();
Explicit Configuration
Explicit Configuration implementation declaration.
//MyConfiguration must implement org.gcube.spatial.data.geonetwork.configuration.Configuration GeoNetworkReader reader1=GeoNetwork.get(new MyConfiguration()); ... GeoNetworkReader reader2=GeoNetwork.get(new MyConfiguration()); ... GeoNetworkPublisher publisher1=GeoNetwork.get(new MyConfiguration());
Default Configuration
By default, the library uses implementation of the class org.gcube.spatial.data.geonetwork.configuration.DefaultConfiguration. This implementation is based on the ic-client, and relies on the gCube information system in order to get the needed parameters to interact with geonetwork REST interface. The convention used by this implementation are the one stated in GeoNetwork Runtime Resource Definition.
Changes in 3.0.0
From version 3.0.0 the interface org.gcube.spatial.data.geonetwork.configuration.Configuration has been completely changed in order to manage gcube4.0.0 SDI publishing policies as described in GeoNetwork Runtime Resource Definition.
Example Code
Querying for metadata
import it.geosolutions.geonetwork.util.GNSearchRequest; import it.geosolutions.geonetwork.util.GNSearchResponse; import org.opengis.metadata.Metadata; import org.gcube.spatial.data.geonetwork.GeoNetwork; import org.gcube.spatial.data.geonetwork.GeoNetworkReader; ... // Get the reader GeoNetworkReader reader=GeoNetwork.get(); ... //Configure search request GNSearchRequest req=new GNSearchRequest(); req.addParam(GNSearchRequest.Param.any,"....."); req.addConfig(GNSearchRequest.Config.similarity, "1"); ... //Get the result representation GNSearchResponse resp=gn.query(req); ... //Iterate through results and access found metadata for(GNSearchResponse.GNMetadata metadata:resp){ Metadata meta=reader.getById(metadata.getUUID()); ... }
Publishing metadata
import it.geosolutions.geonetwork.util.GNInsertConfiguration; import org.opengis.metadata.Metadata; import org.gcube.spatial.data.geonetwork.GeoNetwork; import org.gcube.spatial.data.geonetwork.GeoNetworkPublisher; import org.gcube.spatial.data.geonetwork.LoginLevel; ... //Get the publisher GeoNetworkPublisher publisher=GeoNetwork.get(); ... //Cannot publish without logging in publisher.login(...); ... //Configure publish request GNInsertConfiguration config=new GNInsertConfiguration("5", "datasets", "_none_", true); ... //Publish Metadata object Metadata toPublish=.... long publishedObjectId=publisher.insertMetadata(config, toPublish); ... //Publish Metadata file File myMetadataFile=... long publishedFileId=publisher.insertMetadata(config, myMetadataFile);
Publishing from 3.0.0
From 3.0.0 the library performs various checks on GNInsertConfiguration values. In order to publish with a valid configuration (compliant with gcube4.0.0 policies) users can and are encouraged to use the following snippet code instead of creating a new instance of the class GNInsertConfiguration.
... //Get the publisher GeoNetworkPublisher publisher=GeoNetwork.get(); ... //Cannot publish without logging in publisher.login(...); ... //Get publish configuration GNInsertConfiguration config=publisher.getCurrentUserConfiguration("datasets", "_none_"); ...
Change Metadata Privileges
import it.geosolutions.geonetwork.util.GNPriv; import it.geosolutions.geonetwork.util.GNPrivConfiguration; import org.gcube.spatial.data.geonetwork.GeoNetwork; import org.gcube.spatial.data.geonetwork.GeoNetworkPublisher; import org.gcube.spatial.data.geonetwork.LoginLevel; ... //Get the publisher GeoNetworkPublisher publisher=GeoNetwork.get(); ... //Cannot modify privileges without login publisher.login(...); ... //Configure privileges GNPrivConfiguration privConfig=new GNPrivConfiguration(); privConfig.addPrivileges(publisher.getConfiguration().getScopeGroup(),EnumSet.of(GNPriv.VIEW)); ... //Set the privileges long myMetadataId=... publisher.setPrivileges(myMetadataId, privConfig);
Changes in 3.0.0
Along with gcube 4.0, comes a new version of the library : 3.0.0. Basic usage of the library remains at most the same, even if some important feature have changed, thus some refactoring might be needed anyway. The following is a list of the main changes in the library, please refer to the rest of this page for more detailed information
- Introduced GeoNetworkAdministration interface to manage groups and users on GeoNetwork
- Configuration compliant with gcube 4.0.0 SDI publishing policies
- Automatic generation of scope configuration if none is present
- Improved publishing checks against current configuration
- Improved model and faults management