Difference between revisions of "GeoNetwork library"

From Gcube Wiki
Jump to: navigation, search
(Configuration)
(Example Code)
Line 203: Line 203:
 
long publishedFileId=publisher.insertMetadata(config, myMetadataFile);
 
long publishedFileId=publisher.insertMetadata(config, myMetadataFile);
 
</source>
 
</source>
 +
 +
====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''.
 +
<source land="Java">
 +
...
 +
//Get the publisher
 +
GeoNetworkPublisher publisher=GeoNetwork.get();
 +
...
 +
//Cannot publish without logging in
 +
publisher.login(...);
 +
...
 +
//Get publish configuration
 +
GNInsertConfiguration config=publisher.getCurrentUserConfiguration("datasets", "_none_");
 +
...
 +
</source>
 +
 
====Change Metadata Privileges====
 
====Change Metadata Privileges====
 
<source lang="Java">
 
<source lang="Java">

Revision as of 14:43, 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 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.

Invalid language.

You need to specify a language like this: <source lang="html4strict">...</source>

Supported languages for syntax highlighting:

4cs, 6502acme, 6502kickass, 6502tasm, 68000devpac, abap, actionscript, actionscript3, ada, aimms, algol68, apache, applescript, arm, asm, asp, asymptote, autoconf, autohotkey, autoit, avisynth, awk, bascomavr, bash, basic4gl, bf, bibtex, blitzbasic, bnf, boo, c, caddcl, cadlisp, cfdg, cfm, chaiscript, chapel, cil, clojure, cmake, cobol, coffeescript, cpp, csharp, css, cuesheet, d, dart, dcl, dcpu16, dcs, delphi, diff, div, dos, dot, e, ecmascript, eiffel, email, epc, erlang, euphoria, ezt, f1, falcon, fo, fortran, freebasic, freeswitch, fsharp, gambas, gdb, genero, genie, gettext, glsl, gml, gnuplot, go, groovy, gwbasic, haskell, haxe, hicest, hq9plus, html4strict, html5, icon, idl, ini, inno, intercal, io, ispfpanel, j, java, java5, javascript, jcl, jquery, kixtart, klonec, klonecpp, latex, lb, ldif, lisp, llvm, locobasic, logtalk, lolcode, lotusformulas, lotusscript, lscript, lsl2, lua, m68k, magiksf, make, mapbasic, matlab, mirc, mmix, modula2, modula3, mpasm, mxml, mysql, nagios, netrexx, newlisp, nginx, nimrod, nsis, oberon2, objc, objeck, ocaml, octave, oobas, oorexx, oracle11, oracle8, oxygene, oz, parasail, parigp, pascal, pcre, per, perl, perl6, pf, php, pic16, pike, pixelbender, pli, plsql, postgresql, postscript, povray, powerbuilder, powershell, proftpd, progress, prolog, properties, providex, purebasic, pycon, pys60, python, q, qbasic, qml, racket, rails, rbs, rebol, reg, rexx, robots, rpmspec, rsplus, ruby, rust, sas, scala, scheme, scilab, scl, sdlbasic, smalltalk, smarty, spark, sparql, sql, standardml, stonescript, systemverilog, tcl, teraterm, text, thinbasic, tsql, typoscript, unicon, upc, urbi, uscript, vala, vb, vbnet, vbscript, vedit, verilog, vhdl, vim, visualfoxpro, visualprolog, whitespace, whois, winbatch, xbasic, xml, xpp, yaml, z80, zxbasic


...
//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