Difference between revisions of "Species Product Discovery: client library"

From Gcube Wiki
Jump to: navigation, search
m (Example)
m
 
(19 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
<!-- CATEGORIES -->
 +
[[Category:Developer's Guide]]
 +
<!-- END CATEGORIES -->
 
This client library allows user to contact the Species Product Discovery Service.
 
This client library allows user to contact the Species Product Discovery Service.
  
The '''spd-client-library''' is a client library for the '''Species Product Discovery''' Service. It helps clients interacting with the service and processing result. This library is part of the [https://gcube.wiki.gcube-system.org/gcube/index.php/Featherweight_Stack FeatherWeight Stack].
+
The '''spd-client-library''' is a client library for the '''Species Product Discovery''' Service. It helps clients interacting with the service and processing result. This library is part of the [[Featherweight_Stack|FeatherWeight Stack]].
  
 
== Download ==
 
== Download ==
Line 9: Line 12:
 
<source lang="xml">
 
<source lang="xml">
 
<dependency>
 
<dependency>
<groupId>org.gcube.data.spd</groupId>
+
<groupId>org.gcube.data.spd</groupId>
<artifactId>spd-client-library</artifactId>
+
<artifactId>spd-client-library</artifactId>
<version>${version}</version>
+
<version>${version}</version>
 
</dependency>
 
</dependency>
 
</source>
 
</source>
  
'''''the lastest released version is''''' : 2.0.0
+
'''''the latest released version is''''' : 3.0.0-2.15
 
+
'''''the lastest under development version is''''' : 2.1.0-SNAPSHOT
+
  
 +
'''''the latest under development version is''''' : 3.1.0-SNAPSHOT
  
 
== Architecture ==
 
== Architecture ==
Line 25: Line 27:
 
* ''QueryManager'': helps clients submitting queries to the service;
 
* ''QueryManager'': helps clients submitting queries to the service;
 
* ''OccurrencesManager'': helps clients retrieving occurrences and generating maps using retrieved occurrences;
 
* ''OccurrencesManager'': helps clients retrieving occurrences and generating maps using retrieved occurrences;
* ''TaxonManager'': help clients retrieving taxa and their ancestor by ids.
+
* ''ClassificationManager'': help clients retrieving taxa and their ancestor by ids.
 
* ''ExecutorManager'': helps clients submitting jobs to the system.
 
* ''ExecutorManager'': helps clients submitting jobs to the system.
  
 
=== QueryManager API ===
 
=== QueryManager API ===
  
* <source lang="java">
+
* <source lang="java">public Stream<ResultElement> search(String query) throws InvalidQueryException, UnsupportedPluginException;</source>
public Stream<ResultElement> search(String query) throws InvalidQueryException, UnsupportedPluginException;
+
</source>
+
 
This method is used to submit a query to the system.
 
This method is used to submit a query to the system.
The query '''MUST''' be defined following the [https://gcube.wiki.gcube-system.org/gcube/index.php/SPQL:_SPecies_Query_Language SPQL grammar].
+
The query '''MUST''' be written following the [[SPQL:_SPecies_Query_Language|SPQL grammar]].
  
* <source lang="java">
+
* <source lang="java">public List<PluginDescription> getPluginsDescription();</source>
public List<PluginDescription> getPluginsDescription();
+
</source>
+
 
This method is used to get the list of all external repositories available in the infrastructure and their capabilities.
 
This method is used to get the list of all external repositories available in the infrastructure and their capabilities.
  
  
 
==== Example ====
 
==== Example ====
 +
It's required to add following import :<code> import static org.gcube.data.spd.client.plugins.AbstractPlugin.*;</code>
 +
 +
 +
<source lang="java">
 +
ScopeProvider.instance.set(...);
 +
Manager manager = manager().withTimeout(3, TimeUnit.MINUTES).build();
 +
//returns all taxa points for  Melastomataceae found in CatalogueOfLife
 +
Stream<ResultElement> stream = manager.search(//SPQL query for taxa//);
 +
while (stream.hasNext()){
 +
    TaxonomyItem ti = (TaxonomyItem) stream.next();
 +
    ...
 +
}
 +
</source>
 +
 +
<source lang="java">
 +
ScopeProvider.instance.set(...);
 +
Manager manager = manager().withTimeout(3, TimeUnit.MINUTES).build();
 +
//returns all occurrence points for  Melastomataceae found in all external repositories
 +
Stream<ResultElement> stream = manager.search(//SPQL query for occurrences//);
 +
while (stream.hasNext()){
 +
    OccurrencePoint ti = (OccurrencePoint) stream.next();
 +
    ...
 +
}
 +
</source>
 +
 +
<source lang="java">
 +
ScopeProvider.instance.set(...);
 +
Manager manager = manager().withTimeout(3, TimeUnit.MINUTES).build();
 +
//returns all results (grouped by DataSet) for common name Shark with at least 1 occurrence found in Obis or GBIF
 +
Stream<ResultElement> stream = manager.search(//SPQL query for ResultItem//);
 +
while (stream.hasNext()){
 +
    ResultItem ti = (ResultItem) stream.next();
 +
    ...
 +
}
 +
</source>
 +
 
<source lang="java">
 
<source lang="java">
 
ScopeProvider.instance.set(...);
 
ScopeProvider.instance.set(...);
Line 51: Line 85:
 
     ...
 
     ...
 
}
 
}
 
 
</source>
 
</source>
 +
 +
=== OccurrenceManager API ===
 +
 +
* <source lang="java">public Stream<OccurrencePoint> getByIds(Stream<String> ids);</source>
 +
This method is used to get occurrence points object giving a stream of ids (every id represent only one occurrence point)
 +
 +
* <source lang="java">public String createLayer(Stream<PointInfo> coordinatesLocator);</source>
 +
This method is used to create a layer and publish it in GeoServer giniving a stream of Points
 +
 +
* <source lang="java">public Stream<OccurrencePoint> getByKeys(Stream<String> keys);</source>
 +
This method is used to get a stream of occurrence points object giving a stream of keys (a key represent a group of occurrence point)
 +
 +
 +
=== ClassificationManager API ===
 +
 +
* <source lang="java">public Stream<TaxonomyItem> getTaxonChildrenById(final String id) throws UnsupportedPluginException,UnsupportedCapabilityException, InvalidIdentifierException;</source>
 +
 +
* <source lang="java">public Stream<TaxonomyItem> getTaxaByIds(final Stream<String> ids);</source>
 +
 +
* <source lang="java">public Stream<TaxonomyItem> getTaxonTreeById(final String id) throws UnsupportedPluginException,UnsupportedCapabilityException, InvalidIdentifierException;</source>
 +
 +
* <source lang="java">public Stream<TaxonomyItem> getSynonymsById(String id) throws UnsupportedPluginException,UnsupportedCapabilityException, InvalidIdentifierException;</source>
 +
 +
 +
=== ExecutorManager API ===
 +
 +
* <source lang="java">public String createDwCAByChildren(String taxonKey) throws Exception;</source>
 +
 +
* <source lang="java">public String getResultLink(String jobId) throws InvalidIdentifierException;</source>
 +
 +
* <source lang="java">public Status getStatus(String jobId) throws InvalidIdentifierException;</source>
 +
 +
* <source lang="java">public void removeJob(String jobId) throws InvalidIdentifierException;</source>
 +
 +
* <source lang="java">public String createDwCAByIds(final Stream<String> ids) throws Exception;</source>
 +
 +
* <source lang="java">public String createCSV(final Stream<String> ids) throws Exception;</source>
 +
 +
* <source lang="java">public String createCSVforOM(final Stream<String> ids) throws Exception;</source>
 +
 +
* <source lang="java">public String createDarwincoreFromOccurrenceKeys(final Stream<String> ids) throws Exception;</source>

Latest revision as of 17:56, 11 July 2013

This client library allows user to contact the Species Product Discovery Service.

The spd-client-library is a client library for the Species Product Discovery Service. It helps clients interacting with the service and processing result. This library is part of the FeatherWeight Stack.

Download

The maven coordinates to get the spd-client-library is:

<dependency>
 <groupId>org.gcube.data.spd</groupId>
 <artifactId>spd-client-library</artifactId>
 <version>${version}</version>
</dependency>

the latest released version is : 3.0.0-2.15

the latest under development version is : 3.1.0-SNAPSHOT

Architecture

The spd-cl is divided into 4 parts:

  • QueryManager: helps clients submitting queries to the service;
  • OccurrencesManager: helps clients retrieving occurrences and generating maps using retrieved occurrences;
  • ClassificationManager: help clients retrieving taxa and their ancestor by ids.
  • ExecutorManager: helps clients submitting jobs to the system.

QueryManager API

  • public Stream<ResultElement> search(String query) throws InvalidQueryException, UnsupportedPluginException;

This method is used to submit a query to the system. The query MUST be written following the SPQL grammar.

  • public List<PluginDescription> getPluginsDescription();

This method is used to get the list of all external repositories available in the infrastructure and their capabilities.


Example

It's required to add following import : import static org.gcube.data.spd.client.plugins.AbstractPlugin.*;


ScopeProvider.instance.set(...);
Manager manager = manager().withTimeout(3, TimeUnit.MINUTES).build();
//returns all taxa points for  Melastomataceae found in CatalogueOfLife
Stream<ResultElement> stream = manager.search(//SPQL query for taxa//);
while (stream.hasNext()){
     TaxonomyItem ti = (TaxonomyItem) stream.next();
     ...
}
ScopeProvider.instance.set(...);
Manager manager = manager().withTimeout(3, TimeUnit.MINUTES).build();
//returns all occurrence points for  Melastomataceae found in all external repositories
Stream<ResultElement> stream = manager.search(//SPQL query for occurrences//);
while (stream.hasNext()){
     OccurrencePoint ti = (OccurrencePoint) stream.next();
     ...
}
ScopeProvider.instance.set(...);
Manager manager = manager().withTimeout(3, TimeUnit.MINUTES).build();
//returns all results (grouped by DataSet) for common name Shark with at least 1 occurrence found in Obis or GBIF
Stream<ResultElement> stream = manager.search(//SPQL query for ResultItem//);
while (stream.hasNext()){
     ResultItem ti = (ResultItem) stream.next();
     ...
}
ScopeProvider.instance.set(...);
Manager manager = manager().build();
List<PluginDescription> pluginDescriptions = manager.getPluginsDescription();
for (PluginDescription description : pluginDescriptions){
     System.out.println(description.getName());          
     ...
}

OccurrenceManager API

  • public Stream<OccurrencePoint> getByIds(Stream<String> ids);

This method is used to get occurrence points object giving a stream of ids (every id represent only one occurrence point)

  • public String createLayer(Stream<PointInfo> coordinatesLocator);

This method is used to create a layer and publish it in GeoServer giniving a stream of Points

  • public Stream<OccurrencePoint> getByKeys(Stream<String> keys);

This method is used to get a stream of occurrence points object giving a stream of keys (a key represent a group of occurrence point)


ClassificationManager API

  • public Stream<TaxonomyItem> getTaxonChildrenById(final String id) throws UnsupportedPluginException,UnsupportedCapabilityException, InvalidIdentifierException;
  • public Stream<TaxonomyItem> getTaxaByIds(final Stream<String> ids);
  • public Stream<TaxonomyItem> getTaxonTreeById(final String id) throws UnsupportedPluginException,UnsupportedCapabilityException, InvalidIdentifierException;
  • public Stream<TaxonomyItem> getSynonymsById(String id) throws UnsupportedPluginException,UnsupportedCapabilityException, InvalidIdentifierException;


ExecutorManager API

  • public String createDwCAByChildren(String taxonKey) throws Exception;
  • public String getResultLink(String jobId) throws InvalidIdentifierException;
  • public Status getStatus(String jobId) throws InvalidIdentifierException;
  • public void removeJob(String jobId) throws InvalidIdentifierException;
  • public String createDwCAByIds(final Stream<String> ids) throws Exception;
  • public String createCSV(final Stream<String> ids) throws Exception;
  • public String createCSVforOM(final Stream<String> ids) throws Exception;
  • public String createDarwincoreFromOccurrenceKeys(final Stream<String> ids) throws Exception;