Search in sources :

Example 1 with DepositionPublicationListWrapper

use of uk.ac.ebi.spot.goci.model.deposition.util.DepositionPublicationListWrapper in project goci by EBISPOT.

the class DepositionPublicationTest method testReadAllPublications.

@Test
public void testReadAllPublications() {
    try {
        Resource resource = new ClassPathResource("publications.json");
        assertTrue(resource.exists());
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.registerModule(new JodaModule());
        DepositionPublicationListWrapper publication = objectMapper.readValue(resource.getFile(), DepositionPublicationListWrapper.class);
        assertNotNull(publication);
        assertNotNull(publication.getPublications().getPublications().get(0).getPublicationDate().year());
        assertNotNull(publication.getPublications().getPublications().get(0).getStatus());
    } catch (IOException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : JodaModule(com.fasterxml.jackson.datatype.joda.JodaModule) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) IOException(java.io.IOException) ClassPathResource(org.springframework.core.io.ClassPathResource) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DepositionPublicationListWrapper(uk.ac.ebi.spot.goci.model.deposition.util.DepositionPublicationListWrapper) Test(org.junit.Test)

Example 2 with DepositionPublicationListWrapper

use of uk.ac.ebi.spot.goci.model.deposition.util.DepositionPublicationListWrapper in project goci by EBISPOT.

the class DepositionPublicationServiceImpl method getAllBackendPublications.

@Override
public Map<String, DepositionPublication> getAllBackendPublications() {
    log.info("Retrieving publications");
    String url = depositionBackendUri + "/publications?page={page}&size=100";
    Map<String, DepositionPublication> publicationMap = new HashMap<>();
    try {
        int i = 0;
        Map<String, Integer> params = new HashMap<>();
        params.put("page", i);
        String response = template.getForObject(url, String.class, params);
        DepositionPublicationListWrapper publications = template.getForObject(url, DepositionPublicationListWrapper.class, params);
        while (i < publications.getPage().getTotalPages()) {
            addPublications(publicationMap, publications);
            params.put("page", ++i);
            publications = template.getForObject(url, DepositionPublicationListWrapper.class, params);
        }
    } catch (HttpClientErrorException e) {
        System.out.println(e.getMessage());
    }
    return publicationMap;
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) DepositionPublication(uk.ac.ebi.spot.goci.model.deposition.DepositionPublication) HashMap(java.util.HashMap) DepositionPublicationListWrapper(uk.ac.ebi.spot.goci.model.deposition.util.DepositionPublicationListWrapper)

Aggregations

DepositionPublicationListWrapper (uk.ac.ebi.spot.goci.model.deposition.util.DepositionPublicationListWrapper)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 JodaModule (com.fasterxml.jackson.datatype.joda.JodaModule)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1 Resource (org.springframework.core.io.Resource)1 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)1 DepositionPublication (uk.ac.ebi.spot.goci.model.deposition.DepositionPublication)1