Commit 8a1eff92 authored by Matija Obreza's avatar Matija Obreza

Merge branch '23-updating-target-in-glis' into 'master'

Resolve "Updating target in GLIS"

Closes #23

See merge request genesys-pgr/glis-client!15
parents 5fa04f96 34c9710f
/*
* 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 static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.assertThat;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.genesys.glis.v1.model.PGRFA;
import org.genesys.glis.v1.model.UpdateTargets;
import org.genesys.glis.v1.model.UpdatedTarget;
import org.junit.Test;
/**
* API tests for QueryApi
*/
public class GenesysGlisTest extends TestEnvironmentAPITest {
private final QueryApi api = new QueryApi(defaultClient);
private final GenesysApi genesysApi = new GenesysApi(defaultClient);
@Test
public void insertTargets() {
// get some targets
int perPage = 10;
List<PGRFA> somePgrfa = api.search(0, perPage, null, null, null, null, null, null, "PER001", null, null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null);
if (somePgrfa.size() > 0) {
assertThat(somePgrfa, hasSize(perPage));
UpdateTargets targets = new UpdateTargets();
targets.addKwsItem("1");
for (PGRFA pgrfa : somePgrfa) {
targets.addDoisItem(pgrfa.getDoi());
}
List<UpdatedTarget> updatedTargets = genesysApi.registerGenesysAsTarget(targets);
assertThat(updatedTargets, hasSize(perPage));
// test that all OK targets have the link
for (UpdatedTarget updatedTarget : updatedTargets) {
List<PGRFA> lookups = api.search(0, 1, null, updatedTarget.getDoi(), null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null);
assertThat(lookups, hasSize(1));
PGRFA lookup = lookups.get(0);
assertThat(lookup.getDoi(), equalTo(updatedTarget.getDoi()));
assertThat(lookup.getR01(), hasSize(greaterThan(0)));
Set<String> targetUrls = lookup.getR01().stream().map(target -> target.getUrl()).collect(Collectors.toSet());
assertThat(targetUrls, hasItem("https://sandbox.genesys-pgr.org/" + updatedTarget.getDoi()));
}
} else {
// don't test
}
}
}
......@@ -16,12 +16,16 @@
package org.genesys.glis.v1.api;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.assertThat;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.genesys.glis.v1.model.DOIArray;
import org.genesys.glis.v1.model.DOIHolder;
......@@ -122,13 +126,39 @@ public class QueryApiTest extends ProductionEnvironmentAPITest {
*/
@Test
public void ownerTest() {
DOIArray dois=new DOIArray();
DOIArray dois = new DOIArray();
dois.addDoisItem(THE_DOI);
List<DOIHolder> holders = api.listHolders(dois);
assertThat(holders.size(), equalTo(1));
DOIHolder holder=holders.get(0);
DOIHolder holder = holders.get(0);
assertThat(holder.getDoi(), equalTo(THE_DOI));
assertThat(holder.getHoldwiews(), equalTo("PER001"));
}
@Test
public void testPagination() {
int perPage = 5;
List<PGRFA> somePgrfa = api.search(0, perPage, null, null, null, null, null, null, "PER001", null, null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null);
if (somePgrfa.size() > 0) {
assertThat(somePgrfa, hasSize(perPage));
List<PGRFA> somePgrfa2 = api.search(0, perPage, null, null, null, null, null, null, "PER001", null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null);
// we test that two calls return the same pagination results
Set<String> dois1 = somePgrfa.stream().map(pgrfa -> pgrfa.getDoi()).collect(Collectors.toSet());
Set<String> dois2 = somePgrfa2.stream().map(pgrfa -> pgrfa.getDoi()).collect(Collectors.toSet());
System.err.println("DOIs #1=" + dois1);
System.err.println("DOIs #2=" + dois2);
assertThat(dois1, contains(dois2.toArray()));
} else {
System.err.println("No records from PER001");
}
}
}
/*
* 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.test.TestEnvironmentTest;
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 GLIS Test environment at https://glistest.planttreaty.org/`
*
* @author Matija Obreza
*/
public abstract class TestEnvironmentAPITest extends TestEnvironmentTest {
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);
defaultClient.setDebugging(isDebugging());
defaultClient.setBasePath(getBasePath());
System.out.println("Using GLIS at " + defaultClient.getBasePath());
// Configure HTTP basic authorization: glis_auth
HttpBasicAuth easySmtaAuth = (HttpBasicAuth) defaultClient.getAuthentication("easySmta");
easySmtaAuth.setUsername(getUsername());
System.out.println("Using GLIS username " + easySmtaAuth.getUsername());
easySmtaAuth.setPassword(getPassword());
}
}
......@@ -72,11 +72,14 @@ tags:
externalDocs:
description: Find out more
url: 'https://glis.planttreaty.org'
- name: genesys
description: Genesys-specific interaction with GLIS
# - name: manager
# description: Manage PGRFA in GLIS
# externalDocs:
# description: Global Information System XML integration protocol
# url: 'https://glis.planttreaty.org'
paths:
# /glis/xml/register:
# post:
......@@ -141,6 +144,38 @@ paths:
# schema:
# $ref: '#/definitions/RegistrationResponse'
/glis/genesys/addtarget:
post:
tags:
- genesys
summary: Add Genesys as target URL to specified DOIs
description: >-
We'll have fun!
operationId: registerGenesysAsTarget
consumes:
- application/json
produces:
- application/json
parameters:
- in: body
name: targets
description: Registers Genesys as a target URL for specified DOIs
schema:
$ref: '#/definitions/UpdateTargets'
responses:
200:
description: Successful operation
schema:
type: array
items:
$ref: '#/definitions/UpdatedTarget'
examples:
application-json: >-
[
{"doi":"10.0155/WW", "result": "OK"},
{"doi":"10.222/Unknown", "result": "KO"}
]
/glisapi/v1/pgrfas:
get:
tags:
......@@ -977,6 +1012,34 @@ definitions:
type: string
example: 'PER001'
# Model for updating Genesys as target in GLIS
UpdateTargets:
type: object
properties:
kws:
type: array
items:
type: string
example:
- "1"
- "2"
dois:
type: array
items:
type: string
example:
- 10.0155/WW
- 10.222/Unknown
# GLIS response to updating targets
UpdatedTarget:
type: object
properties:
doi:
type: string
result:
type: string
# Model for PGRFA update
GLISUpdate:
type: object
......
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