Search in sources :

Example 1 with DOIResolver

use of org.eol.globi.service.DOIResolver in project eol-globi-data by jhpoelen.

the class LinkerDOITest method addDOIToStudy.

@Test
public void addDOIToStudy() throws NodeFactoryException {
    DOIResolver doiResolver = new DOIResolver() {

        @Override
        public Map<String, String> resolveDoiFor(Collection<String> references) throws IOException {
            Map<String, String> doiMap = new HashMap<>();
            for (String reference : references) {
                doiMap.put(reference, resolveDoiFor(reference));
            }
            return doiMap;
        }

        @Override
        public String resolveDoiFor(String reference) throws IOException {
            return "doi:1234";
        }
    };
    StudyNode study = getNodeFactory().getOrCreateStudy(new StudyImpl("my title", "some source", null, ExternalIdUtil.toCitation("my contr", "some description", null)));
    new LinkerDOI(getGraphDb()).linkStudy(doiResolver, study);
    assertThat(study.getDOI(), is("doi:1234"));
    assertThat(study.getExternalId(), is("http://dx.doi.org/1234"));
    assertThat(study.getCitation(), is("my contr. some description"));
    study = getNodeFactory().getOrCreateStudy(new StudyImpl("my other title", "some source", null, ExternalIdUtil.toCitation("my contr", "some description", null)));
    new LinkerDOI(getGraphDb()).linkStudy(new DOIResolverThatExplodes(), study);
    assertThat(study.getDOI(), nullValue());
    assertThat(study.getExternalId(), nullValue());
    assertThat(study.getCitation(), is("my contr. some description"));
}
Also used : HashMap(java.util.HashMap) StudyImpl(org.eol.globi.domain.StudyImpl) Collection(java.util.Collection) DOIResolver(org.eol.globi.service.DOIResolver) StudyNode(org.eol.globi.domain.StudyNode) Test(org.junit.Test)

Aggregations

Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 StudyImpl (org.eol.globi.domain.StudyImpl)1 StudyNode (org.eol.globi.domain.StudyNode)1 DOIResolver (org.eol.globi.service.DOIResolver)1 Test (org.junit.Test)1