Difference between revisions of "GeoNetwork library"

From Gcube Wiki
Jump to: navigation, search
m
(Using the library)
Line 49: Line 49:
  
 
The library acts as a wrapper to the functionalities exposed by the ''geonetwork-manager'' 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 two different interfaces :  
+
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.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.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 :
 
The class ''org.gcube.spatial.data.geonetwork.GeoNetwork'' offers two static members to obtain implementations of the above interfaces :
  
* ''public static GeoNetworkPublisher get() throws Exception'' : uses the current settings of ''ConfigurationManager'' to get a ''Configuration'' implementation.
+
* ''public static GeoNetworkAdministration get() throws Exception'' : uses the current settings of ''ConfigurationManager'' to get a ''Configuration'' implementation.
* ''public static GeoNetworkPublisher get(Configuration config)'' : uses the passed ''Configuration'' implementation.
+
* ''public static GeoNetworkAdministration get(Configuration config)'' : uses the passed ''Configuration'' implementation.
  
 
See [[#Configuration]] to get more information.
 
See [[#Configuration]] to get more information.

Revision as of 12:03, 23 May 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.

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

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.

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.

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);

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);