GeoNetwork library

From Gcube Wiki
Jump to: navigation, search

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


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.


The library declares these dependecies to external third parties artifacts


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 :

  • : declares methods to access metadata stored in geonetwork
  • : extends GeoNetworkReader, and declares methods to publish/update/delete metadata in geonetwork
  • : extends GeoNetworkPublisher, and declares methods to manage users and groups on GeoNetwork (available from 3.0.0)

The class 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.

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

User management

Library version 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


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 :


see #Configuration for details on how the related credentials are used.

Library Version 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


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.

Geonetwork instances discovery

The geonetwork library relies on instances of 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
GeoNetworkReader    reader1=GeoNetwork.get();
GeoNetworkReader    reader2=GeoNetwork.get();
GeoNetworkPublisher publisher1=GeoNetwork.get();

Explicit Configuration

Explicit Configuration implementation declaration.

//MyConfiguration must implement
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 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 has been completely changed in order to manage gcube4.0.0 SDI publishing policies as described in GeoNetwork Runtime Resource Definition.

Metadata generation facilities

Instances of org.opengis.metadata.Metadata interface can be generated in very different ways. However, we identified a common set of information which every application should include in its published metadata. Providing a common way to generate these metadata entry aims to :

Metadata Descriptor is a Java class representing a simplified version of the ISO XML Model. The underlying logic will apply the model to XML templates in order to enforce the production of INSPIRE -compliant metadata throughout the infrastructure.


Following is an example snippet showing how to properly instantiate the class

MetadataDescriptor desc=new MetadataDescriptor();
//Setting Title
//Setting Identifier		
//Setting Purpose		
//Setting Abstract
//Setting Credits		
// Setting Responsible Parties
desc.addResponsibleParty(new ResponsibleParty("Author name","Author organization",
		ResponsiblePartyRole.AUTHOR,new Contact("","")));
//Setting Dataset Creation Time		
desc.setCreationTime(new GregorianCalendar().getTime());
//Setting Spatial Representation
VectorRepresentation representation=new VectorRepresentation(
		TopologyLevel.GEOMETRY_ONLY, 1000, GeometricObjectType.POINT);
//Setting INSPIRE THEME(s)
desc.addKeywordSet(new KeywordSet(
				Collections.singleton("Species distribution"),
//Setting arbitrary keywords
desc.addKeywordSet(new KeywordSet(Collections.singleton("...")));
//Setting Extent
//Utility method for setting GeoServer Distribution Info
		"ws","wmpa", "speciesProb", "EPSG:4326",BoundingBox.WORLD_EXTENT);
//Setting Spatial Resolution		
//Setting Usage and Access Constraints
desc.setConstraints(new ResourceConstraints("...", 
		new LegalConstraints(RestrictionCode.LICENSE,"CC-BY-SA"), 
		new LegalConstraints(RestrictionCode.LICENSE,"CC-BY-SA")));
//Setting Topic Category
//Setting the Lineage Statement
//Obtaining the metadata file		
File metaFile=ISOMetadataByTemplate.createXML(desc);

GcubeISOMetadata class

 Please note that this class is deprecated and won't be supported in upcoming versions. See the MetadataDescriptor section in this page.

The utility class lets developers to simply specify the metadata information strictly needed for the generation, relying on internal logic for generic behavior.


A GcubeISOMetadata instance should be generated for each publishing request, but this behavior depends on the caller application logic. At construction time, common information fetched from the gCube IS is loaded. Queries to IS are done via the ic-client, so be sure that a proper scope is setted via org.gcube.common.scope.api.ScopeProvider. Loaded configuration is represented by instances of the class see #EnvironmentConfiguration class.

import org.gcube.common.scope.api.ScopeProvider;
GcubeISOMetadata meta=new GcubeISOMetadata();
EnvironmentConfiguration configuration = meta.getConfig();
System.out.println("Current configuration is "+configuration);

Filling parameters

The GcubeISOMetadata class exposes setter/add methods to let users specify metadata information. The following is a list of attributes that can be set along with their cardinality. Attributes which cardinality can be more then 1 are setted via the related addXXX() method, while setXXX() methods are provided for the other ones.

Attribute Name Type Cardinality
User java.lang.String 1

Title java.lang.String 1
Date java.lang.Date 1
Presentation Form org.opengis.metadata.citation.PresentationForm 1
Abstract java.lang.String 1
Purpose java.lang.String 1
Credits java.lang.String 1..N
Descriptive Keyword java.lang.String 1..N
Topic Category org.opengis.metadata.identification.TopicCategory 1..N
Extent org.geotoolkit.metadata.iso.extent.DefaultExtent 1
Geometric Object Type org.opengis.metadata.spatial.GeometricObjectType 1
Geometry Count int 1
Topology Level org.opengis.metadata.spatial.TopologyLevel 1
Resolution double 1
Graphic Overview String 0..N

The following snippets shows how this parameters are set :

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;
GcubeISOMetadata meta=new GcubeISOMetadata();
//Setter methods
//Add methods
//Need to get keywords referred Thesaurus
Thesaurus generalThesaurus=meta.getConfig().getThesauri().get(...);		
meta.addKeyword(..., generalThesaurus);
meta.addKeyword(..., generalThesaurus);

Getting the metadata

Once the metadata information have been set to the GCubeISOMetadata instance, the caller can obtain the metadata to publish just by calling its public org.opengis.metadata.Metadata getMetadata() method. In case any mandatory value is missing a MissingInformationException is thrown.

GcubeISOMetadata meta=new GcubeISOMetadata();
// Set information
// Print out the metadata

Extending default behaviour

GCubeISOMetadata class can be extended in order to enhance its purpose and behaviour. In the following example we define our MyApplicationIsoMetadata class in order to :

  • Automatically set application default values when instatiating;
  • Add new mandatory fields to generate data quality information to our metadata, via :
    • Adding new member to our class
    • Override of protected method checkConstraints
    • Override of public method getMetadata()

import org.opengis.metadata.Metadata;
public class MyApplicationIsoMetadata extends GcubeISOMetadata {
	//We want this citation to be automatically added to credits
	private static final String applicationCitation="....";
	//Our mandatory field
	private String mandatoryField=null;
	public MyApplicationIsoMetadata() throws Exception {
		//Let the super class initialize itself
		//Let's add our citation to credits
	protected void checkConstraints() throws MissingInformationException {
		// We let the super class to perform its checks before continuing
		// Custom check against mandatoryField
		if(mandatoryField==null) throw new MissingInformationException();
	public Metadata getMetadata() throws URISyntaxException,MissingInformationException {
		Metadata toReturn=super.getMetadata();
		//We set our mandatory field to the metadata
		return toReturn;
	public String getMandatoryField() {
		return mandatoryField;
	public void setMandatoryField(String mandatoryField) {
		this.mandatoryField = mandatoryField;

EnvironmentConfiguration class

Common metadata values (i.e. project citation, project name etc.) are loaded from a gCube generic resource that must be accessible in the current scope. The given generic resource's body must contain an XML Serialization of class.

Configuration retrieval

The gcube generic resource is found submitting a query to the ic-client with the following parameters.

  • Secondary Type [default value = ISO]
  • Resource Name [default value = MetadataConstants]

The Generic resource is cached to avoid overhead in querying the IS. The cache TTL, along with the query parameters value can be configured by editing the #Properties file.

Configure environment

Geonetwork library allows administrator to easily configure their environment constants. The following snippets shows how :

import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.resources.gcore.GenericResource;
//Create the configuration
EnvironmentConfiguration config=new EnvironmentConfiguration();
//Set all the values in the configuration
//We set the scope where to Publish the configuration
//Let's actually publish the configuration
GenericResource res=config.publish();
//Just some output log here
System.out.println("Published configuration [res ID = "+id+"] under scope "+ScopeProvider.instance.get());

The method config.publish() creates and publishes a generic resource with the configured name and secondary type (see #Properties file).

Configuration parameters

Property Type Cardinality
Protocol declarations
WMS protocol java.lang.String 0..1
WFS protocol java.lang.String 0..1
WCS protocol java.lang.String 0..1
HTTP protocol java.lang.String 0..1
Project citation
Project Name java.lang.String 0..1
Project Citation java.lang.String 0..1

Distributor Role
Distributor individual name java.lang.String 0..1
Distributor e-mail java.lang.String 0..1
Distributor organization name java.lang.String 0..1
Distributor web site java.lang.String 0..1

Provider Role
Provider individual name java.lang.String 0..1
Provider e-mail java.lang.String 0..1
Provider organization name java.lang.String 0..1
Provider web site java.lang.String 0..1
License java.lang.String 0..1
Thesauri Map
Theaurus 0..N

Thesaurus class

Thesaurus class represents a thesaurus declaration for a given keyword set in ISO metadata (see ISO 19115:2003/19139).

The following is the list of its members.

Property Type Cardinality
Type org.opengis.metadata.identification.KeywordType 1
Title java.lang.String 1
Citation date java.util.Date 1
Citation description java.lang.String 0..1
Citation uri java.lang.String 0..1
Citation organization java.lang.String 0..1
Authored boolean 1

Example Code

Querying for metadata

import it.geosolutions.geonetwork.util.GNSearchRequest;
import it.geosolutions.geonetwork.util.GNSearchResponse;
import org.opengis.metadata.Metadata;
// Get the reader
GeoNetworkReader reader=GeoNetwork.get();
//Configure search request
GNSearchRequest req=new GNSearchRequest();
req.addConfig(GNSearchRequest.Config.similarity, "1");
//Get the result representation
GNSearchResponse resp=reader.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;
//Get the publisher
GeoNetworkPublisher publisher=GeoNetwork.get();
//Cannot publish without logging in
//Configure publish request
GNInsertConfiguration config=publisher..getCurrentUserConfiguration("dataset", "_none_");
//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
//Get publish configuration
GNInsertConfiguration config=publisher.getCurrentUserConfiguration("datasets", "_none_");

Change Metadata Privileges

import it.geosolutions.geonetwork.util.GNPriv;
import it.geosolutions.geonetwork.util.GNPrivConfiguration;
//Get the publisher
GeoNetworkPublisher publisher=GeoNetwork.get();
//Cannot modify privileges without login
//Configure privileges
GNPrivConfiguration privConfig=new GNPrivConfiguration();
//Set the privileges
long myMetadataId=...
publisher.setPrivileges(myMetadataId, privConfig);