Search in sources :

Example 1 with DepositionPublication

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

the class DepositionPublicationServiceImpl method retrievePublication.

@Override
public DepositionPublication retrievePublication(String id) {
    log.info("Retrieving publication using id [{}]", id);
    DepositionPublication publication = null;
    Map<String, String> params = new HashMap<>();
    params.put("pmID", id);
    String url = depositionIngestUri + "/publications/{pmID}?pmid=true";
    try {
        String response = template.getForObject(url, String.class, params);
        publication = template.getForObject(url, DepositionPublication.class, params);
    } catch (HttpClientErrorException e) {
        System.out.println(e.getMessage());
    }
    return publication;
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) DepositionPublication(uk.ac.ebi.spot.goci.model.deposition.DepositionPublication) HashMap(java.util.HashMap)

Example 2 with DepositionPublication

use of uk.ac.ebi.spot.goci.model.deposition.DepositionPublication 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)

Example 3 with DepositionPublication

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

the class DepositionPublicationTest method testDepositionPublicationRead.

@Test
public void testDepositionPublicationRead() {
    try {
        Resource resource = new ClassPathResource("publication.json");
        assertTrue(resource.exists());
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.registerModule(new JodaModule());
        DepositionPublication publication = objectMapper.readValue(resource.getFile(), DepositionPublication.class);
        assertNotNull(publication);
        assertNotNull(publication.getStatus());
        assertNotNull(publication.getPublicationDate().year());
    } catch (IOException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : DepositionPublication(uk.ac.ebi.spot.goci.model.deposition.DepositionPublication) 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) Test(org.junit.Test)

Example 4 with DepositionPublication

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

the class DepositionPublicationTest method testDepositionPublicationWrite.

@Test
public void testDepositionPublicationWrite() {
    ObjectMapper objectMapper = new ObjectMapper();
    try {
        objectMapper.registerModule(new JodaModule());
        DepositionPublication publication = new DepositionPublication();
        publication.setPublicationDate(new LocalDate());
        String json = objectMapper.writeValueAsString(publication);
        assertNotNull(json);
    } catch (IOException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : DepositionPublication(uk.ac.ebi.spot.goci.model.deposition.DepositionPublication) JodaModule(com.fasterxml.jackson.datatype.joda.JodaModule) IOException(java.io.IOException) LocalDate(org.joda.time.LocalDate) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

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