Difference between revisions of "Motu Client Java"

From Gcube Wiki
Jump to: navigation, search
(Retrieving the product catalogue)
(Usage)
Line 42: Line 42:
  
 
<source lang="java5" highlight="4">
 
<source lang="java5" highlight="4">
   // retrieve the catalogue
+
   // retrieve the catalogue (it might take some time)
 
   MotuCatalogue catalogue = client.getCatalogue();
 
   MotuCatalogue catalogue = client.getCatalogue();
  
Line 88: Line 88:
 
   Collection<Axis> axes = product.getDataGeospatialCoverage();
 
   Collection<Axis> axes = product.getDataGeospatialCoverage();
  
 +
</source>
 +
 +
== Getting the list of services ==
 +
 +
Instead of retrieving the full catalogue (it might be slow), you might want to get the list of available services, without any nested product information:
 +
 +
<source lang="java5" highlight="4">
 +
  // get a shallow list of available services
 +
  Collection<ServiceMetadata> services = client.listServices();
 +
</source>
 +
 +
== Getting product metadata ==
 +
 +
Similarly, once you know the service and product name, you can retrieve product metadata directly:
 +
 +
<source lang="java5" highlight="4">
 +
  // get product metadata by service and product name
 +
  ProductMetadataInfo product = describeProduct(String serviceName, String productName);
 
</source>
 
</source>
  

Revision as of 18:12, 29 November 2017

Overview

Usage

Configure your project

Maven coordinates:

  <dependency>
    <groupId>org.gcube.dataanalysis</groupId>
    <artifactId>motu-client</artifactId>
    <version>[1.0.0, 2.0.0)</version>
  </dependency>

Create a client

As a first step, you need to create a MotuClient object providing enough information to connect to the corresponding server:

  MotuClient client = new MotuClient("server endpoint");
  client.setUsername("username");
  client.setPassword("password");

Setting the preferred download size

You can optionally specify the size of chunks to be downloaded. If not provided, the client will use the maximum size allowed by the server (currently most servers allow between 1 and 2 GB).

  client.setPreferredDownloadSize(20*SizeUtils.MB);

Retrieving the product catalogue

A full catalogue containing all services published by the Motu server can be obtained with the code below.

Note: this might take some time to process as it recursively goes into nested server resources. If you only need some specific information, query for the specifically, as described in the following sections.

  // retrieve the catalogue (it might take some time)
  MotuCatalogue catalogue = client.getCatalogue();
 
  // get available services  Collection<ServiceMetadata> services = catalogue.getServices();

A service usually contain different products (datasets). Typically there are products for different time resolution and/or different variables.

  // get the list of products for a service
  Collection<ProductMetadataInfo> products = service.getProducts();

Product metadata can be obtained with:

  ProductMetadataInfo product = ...;
 
  // get timestamps for which there are data available
  List<Calendar> times = product.getAvailableTimeCodes(); 
  // the oldest timestamp in the dataset
  Calendar start = product.getFirstAvailableTimeCode();
 
  // the most recent timestamp in the dataset
  Calendar end = product.getLastAvailableTimeCode();
 
  // get the time resolution of the dataset (in hours)
  Long hours = product.getTimeResolution();
 
  // get a list of depths for which there are data available
  List<Double> depths = product.getAvailableDepths();
 
  // get the lowest depth value (i.e. closer to the surface)
  Double depth = product.getFirstAvailableDepth();
 
  // get the highest depth value (i.e. the deeper level)
  Double depth = product.getLastAvailableDepth();
 
  // get the set of variables in the dataset
  Collection<Variable> variables = product.getVariables();
 
  // get the dimensions of the dataset (e.g. lat, lon, depth)
  Collection<Axis> axes = product.getDataGeospatialCoverage();

Getting the list of services

Instead of retrieving the full catalogue (it might be slow), you might want to get the list of available services, without any nested product information:

  // get a shallow list of available services
  Collection<ServiceMetadata> services = client.listServices();

Getting product metadata

Similarly, once you know the service and product name, you can retrieve product metadata directly:

  // get product metadata by service and product name
  ProductMetadataInfo product = describeProduct(String serviceName, String productName);

Under the hood

TODO

References