Commit 0e0d1a80 authored by Matija Obreza's avatar Matija Obreza

GLIS Query API, JSON only (fixes #24)

parent 913f2bb6
......@@ -35,6 +35,11 @@ public abstract class BaseApiTest {
if ("true".equals(System.getenv("GLIS_DEBUG"))) {
defaultClient.setDebugging(true);
}
if (System.getenv("GLIS_URL") != null) {
defaultClient.setBasePath(System.getenv("GLIS_URL"));
}
System.out.println("Using GLIS at " + defaultClient.getBasePath());
// Configure HTTP basic authorization: glis_auth
HttpBasicAuth easySmtaAuth = (HttpBasicAuth) defaultClient.getAuthentication("easySmta");
easySmtaAuth.setUsername(GLIS_USERNAME);
......
......@@ -56,15 +56,10 @@
<version>${jackson-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>${jackson-version}</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>${jodatime-version}</version>
</dependency>
<!-- XML processing: Jackson -->
<dependency>
......
/*
* Copyright 2017 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.genesys.glis.v1.api;
import java.util.ArrayList;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator;
import org.genesys.glis.v1.invoker.ApiClient;
import org.genesys.glis.v1.invoker.auth.HttpBasicAuth;
import org.junit.BeforeClass;
import org.springframework.http.client.BufferingClientHttpRequestFactory;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter;
import org.springframework.web.client.RestTemplate;
/**
* Tests against the production GLIS API at https://ssl.fao.org
*
* @author Matija Obreza
*/
public abstract class ProductionApiTest {
public static final String GLIS_DOI_PATTERN = "^(doi:)?10\\.[0-9]+\\/[0123456789ABCDEFGHJKMNPQRSTVWXYZ]+[0123456789ABCDEFGHJKMNPQRSTVWXYZ~\\*\\$=U]$";
/**
* This test DOI is a sweet potato accession at CIP, Lima, Peru.
*/
public static final String THE_DOI = "10.18730/583E";
private static final String GLIS_PRODUCTION_URL = "https://ssl.fao.org";
protected static String GLIS_USERNAME = System.getenv("GLIS_USERNAME");
protected static String GLIS_PASSWORD = System.getenv("GLIS_PASSWORD");
protected static ApiClient defaultClient;
protected static XmlMapper xmlMapper;
@BeforeClass
public static void config() {
List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
messageConverters.add(new MappingJackson2HttpMessageConverter());
xmlMapper = new XmlMapper();
xmlMapper.configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true);
xmlMapper.setSerializationInclusion(Include.NON_NULL);
messageConverters.add(new MappingJackson2XmlHttpMessageConverter(xmlMapper));
RestTemplate restTemplate = new RestTemplate(messageConverters);
restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(restTemplate.getRequestFactory()));
defaultClient = new ApiClient(restTemplate);
if ("true".equals(System.getenv("GLIS_DEBUG"))) {
defaultClient.setDebugging(true);
}
defaultClient.setBasePath(GLIS_PRODUCTION_URL);
System.out.println("Using GLIS at " + defaultClient.getBasePath());
// Configure HTTP basic authorization: glis_auth
HttpBasicAuth easySmtaAuth = (HttpBasicAuth) defaultClient.getAuthentication("easySmta");
easySmtaAuth.setUsername(GLIS_USERNAME);
System.out.println("Using GLIS username " + easySmtaAuth.getUsername());
easySmtaAuth.setPassword(GLIS_PASSWORD);
}
}
......@@ -16,12 +16,15 @@
package org.genesys.glis.v1.api;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import java.util.Arrays;
import java.util.List;
import org.genesys.glis.v1.model.DOIArray;
import org.genesys.glis.v1.model.DOIHolder;
import org.genesys.glis.v1.model.PGRFA;
import org.genesys.glis.v1.model.Relationship;
import org.genesys.glis.v1.model.Term;
......@@ -30,7 +33,7 @@ import org.junit.Test;
/**
* API tests for QueryApi
*/
public class QueryApiTest extends BaseApiTest {
public class QueryApiTest extends ProductionApiTest {
private final QueryApi api = new QueryApi(defaultClient);
......@@ -47,15 +50,14 @@ public class QueryApiTest extends BaseApiTest {
String oper = null;
List<Relationship> response = api.listRelationships(THE_DOI, role, oper);
// GLIS test environment is occasionally cleaned
// assertThat(response.size(), greaterThan(0));
assertThat(response.size(), is(0));
}
/**
* GLIS vocabularies
*
* To describe the kind of information that will be found in the targets, GLIS adopts a simple controlled
* vocabulary.
* To describe the kind of information that will be found in the targets, GLIS
* adopts a simple controlled vocabulary.
*
* @throws ApiException if the Api call fails
*/
......@@ -103,10 +105,30 @@ public class QueryApiTest extends BaseApiTest {
String biostatus = null;
String mlsstatus = null;
String targetkw = null;
List<PGRFA> response = api.search(page, perPage, lang, THE_DOI, identifier, genus, species, name, holdwiews, holdpid, holdname, holdcountry, methodcode, provwiews, provpid, provname,
provcountry, provenance, collwiews, collpid, collname, collcountry, bredwiews, bredpid, bredname, bredcountry, biostatus, mlsstatus, targetkw);
// assertThat(response.size(), greaterThan(0));
List<PGRFA> response = api.search(page, perPage, lang, THE_DOI, identifier, genus, species, name, holdwiews, holdpid, holdname, holdcountry, methodcode, provwiews, provpid,
provname, provcountry, provenance, collwiews, collpid, collname, collcountry, bredwiews, bredpid, bredname, bredcountry, biostatus, mlsstatus, targetkw);
assertThat(response.size(), is(1));
PGRFA pgrfa = response.get(0);
assertThat(pgrfa.getDoi(), is(THE_DOI));
assertThat(pgrfa.getUrl(), is("https://ssl.fao.org/glis/doi/" + THE_DOI));
assertThat(pgrfa.getM01().getWiews(), is("PER001"));
assertThat(pgrfa.getM01().getCountry(), is("PER"));
}
/**
* Assert that PER001 is the holder of {@link TestApiTest#THE_DOI}
*/
@Test
public void ownerTest() {
DOIArray dois=new DOIArray();
dois.addDoisItem(THE_DOI);
List<DOIHolder> holders = api.listHolders(dois);
assertThat(holders.size(), is(1));
DOIHolder holder=holders.get(0);
assertThat(holder.getDoi(), is(THE_DOI));
assertThat(holder.getHoldwiews(), is("PER001"));
}
}
......@@ -32,10 +32,19 @@ import org.springframework.http.converter.json.MappingJackson2HttpMessageConvert
import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter;
import org.springframework.web.client.RestTemplate;
public abstract class BaseApiTest {
/**
* Tests against GLIS Test environment at https://glistest.planttreaty.org/`
*
* @author Matija Obreza
*/
public abstract class TestApiTest {
public static final String GLIS_DOI_PATTERN = "^(doi:)?10\\.[0-9]+\\/[0123456789ABCDEFGHJKMNPQRSTVWXYZ]+[0123456789ABCDEFGHJKMNPQRSTVWXYZ~\\*\\$=U]$";
public static final String THE_DOI = "10.0155/11";
/**
* This test DOI is a sweet potato accession at CIP, Lima, Peru.
*/
public static final String THE_DOI = "10.18730/583E";
protected static String GLIS_USERNAME = System.getenv("GLIS_USERNAME");
protected static String GLIS_PASSWORD = System.getenv("GLIS_PASSWORD");
......@@ -56,11 +65,16 @@ public abstract class BaseApiTest {
RestTemplate restTemplate = new RestTemplate(messageConverters);
restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(restTemplate.getRequestFactory()));
defaultClient = new ApiClient(restTemplate);
if ("true".equals(System.getenv("GLIS_DEBUG"))) {
defaultClient.setDebugging(true);
}
if (System.getenv("GLIS_URL") != null) {
defaultClient.setBasePath(System.getenv("GLIS_URL"));
}
System.out.println("Using GLIS at " + defaultClient.getBasePath());
// Configure HTTP basic authorization: glis_auth
HttpBasicAuth easySmtaAuth = (HttpBasicAuth) defaultClient.getAuthentication("easySmta");
easySmtaAuth.setUsername(GLIS_USERNAME);
......
......@@ -724,7 +724,9 @@ definitions:
title: Physical existence
description: >-
Describes whether the PGRFA is still available or permanently lost after being registered.
type: boolean
Contains "y" or "n" string value.
type: string
A01:
title: Provider's location
description: >-
......@@ -970,10 +972,10 @@ definitions:
properties:
doi:
type: string
example: '10.0155/WW'
holderwiews:
example: '10.18730/583E'
holdwiews:
type: string
example: 'PHL001'
example: 'PER001'
# Model for PGRFA update
GLISUpdate:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment