Getting started

Adding the dependency

To use this library in a Maven project, add the following to your pom.xml:


<dependency>
    <groupId>nl.datastations</groupId>
    <artifactId>dans-dataverse-client-lib</artifactId>
    <version>4.3.1-SNAPSHOT</version>
</dependency>

Basic usage

A basic usage example follows:


public class Test {

    public static void main(String[] args) throws Exception {
        // Create a client object
        DataverseClientConfig config = new DataverseClientConfig(
            new URI("http://localhost:8080/"),
            "your-api-token-here");
        DataverseClient client = new DataverseClient(config);

        // Call an API end-point
        DataverseResponse<Dataverse> response = client.dataverse("root").view();

        // Retrieve response data as model object
        Dataverse dv = response.getData();

        // Query object
        System.out.println(dv.getDescription());
    }

}
  1. First, you need to create a client object. This object can be reused when calling the same Dataverse instance multiple times.
  2. The API end-points are grouped in roughly the same way as they appear in the Dataverse documentation: dataverse collection end-points, dataset end-points, etc.
  3. The result is a DataverseHttpResponse object, if successful, otherwise an exception.
  4. If Dataverse's response is a JSON document, this is converted to a model object, a simple value object. You can retrieve that from the response using the getData method.

Running the examples

More examples can be found in the examples submodule. To run an example:

  1. Copy the supplied dataverse.properties.template to dataverse.properties.
  2. Edit the properties to match your setup. For example, when running Dataverse on localhost, set the baseUrl=http://localhost:8080.
  3. Run one of the programs providing sensible command line parameters where required.
  4. To access admin end-points from outside a local development Vagrant box, follow the JVM-option setup and reset instructions in examples/dataverse.properties.template. Keep dataverse.api.blocked.endpoints=api/admin,api/builtin-users configured and temporarily switch dataverse.api.blocked.policy to unblock-key, with a matching dataverse.api.blocked.key. Set unblockKey in dataverse.properties to that key. Restart Payara after changing JVM options and restore localhost-only access when finished. Do not use this development setup on production systems.

Smoke tests

The "examples" submodule also contains a package "smoketest." The classes in this package can be used to run smoke tests against a running Dataverse instance. They are intended to verify that the library works as expected with the specific Dataverse version. So, they are more useful for library developers than for library users.