From c12f911ac2c1d6716f71c7d7a40059404ec5e388 Mon Sep 17 00:00:00 2001 From: Pasquale Lisena Date: Fri, 22 Jun 2018 18:47:24 +0200 Subject: [PATCH] fix source vs sources --- build.gradle | 2 +- .../org/doremus/isnimatcher/ISNIRecord.java | 23 ++++++++++++++++--- .../java/org/doremus/isnimatcher/Source.java | 5 ++++ src/test/java/ISNITest.java | 6 +++++ 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index 3f2a643..ab3452b 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ plugins { } group 'org.doremus' -version '1.1.2' +version '1.2.0' sourceCompatibility = 1.8 diff --git a/src/main/java/org/doremus/isnimatcher/ISNIRecord.java b/src/main/java/org/doremus/isnimatcher/ISNIRecord.java index df98fd9..9abf0ea 100644 --- a/src/main/java/org/doremus/isnimatcher/ISNIRecord.java +++ b/src/main/java/org/doremus/isnimatcher/ISNIRecord.java @@ -32,10 +32,23 @@ public class ISNIRecord { public List externalInformations; @XmlElement(name = "source") - public List sources; + private List sources1; + + @XmlElement(name = "sources") + private List sources2; + + private List source = null; private String body; + public List getSources(){ + if (source == null) { + source = sources1; + if(sources1 ==null) source = sources2; + else source.addAll(sources2); + } + return source; + } private void setBody(String body) { this.body = body; @@ -84,6 +97,10 @@ record = record.replaceAll("", ""); public String getViafURI() { for (ExternalInformation ex : externalInformations) if (ex.isType("viaf")) return ex.URI; + + for (Source s : getSources()) + if ("VIAF".equals(s.codeOfSource)) return s.asViafURI(); + return null; } @@ -130,7 +147,7 @@ public String getDBpediaUri() { } public String getMusicBrainzUri() { - for (Source s : sources) { + for (Source s : getSources()) { if ("MUBZ".equals(s.codeOfSource)) return s.asMusicBrainzURI(); } @@ -138,7 +155,7 @@ public String getMusicBrainzUri() { } public String getBNFUri() { - for (Source s : sources) { + for (Source s : getSources()) { if ("BNF".equals(s.codeOfSource)) return s.asBNFUri(); } diff --git a/src/main/java/org/doremus/isnimatcher/Source.java b/src/main/java/org/doremus/isnimatcher/Source.java index 4a04b13..b5aa542 100644 --- a/src/main/java/org/doremus/isnimatcher/Source.java +++ b/src/main/java/org/doremus/isnimatcher/Source.java @@ -10,6 +10,7 @@ public class Source { private static final String MUSICBRAINZ_BASE = "https://musicbrainz.org/artist/"; private static final String BNF_BASE = "http://catalogue.bnf.fr/ark:/12148/cb"; + private static final String VIAF_BASE = "https://viaf.org/viaf/"; @XmlElement(name = "codeOfSource") public String codeOfSource; @@ -24,4 +25,8 @@ public String asMusicBrainzURI() { public String asBNFUri() { return BNF_BASE + sourceIdentifier + "b"; } + + public String asViafURI() { + return VIAF_BASE + sourceIdentifier; + } } diff --git a/src/test/java/ISNITest.java b/src/test/java/ISNITest.java index cbe288d..2665c76 100644 --- a/src/test/java/ISNITest.java +++ b/src/test/java/ISNITest.java @@ -35,6 +35,12 @@ public void getByISNICode() throws IOException { assertEquals("Beethoven", r.personalNames.get(0).surname); } + @Test + public void getViaf() throws IOException { + ISNIRecord r = ISNI.get("000000007368351X"); + assertEquals("https://viaf.org/viaf/19620875", r.getViafURI()); + } + @Test public void searchWithNameAndDate() throws IOException { String str = "Beethoven, Ludwig van";