From d4edecefc96b675eb038cfa385a583720372942d Mon Sep 17 00:00:00 2001 From: Ewan Cahen Date: Mon, 27 May 2024 14:05:56 +0200 Subject: [PATCH] fix: check if fields present in author before adding mention --- frontend/utils/getCrossref.ts | 15 ++++++++++++-- .../rsd/scraper/doi/CrossrefMention.java | 20 ++++++++++++------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/frontend/utils/getCrossref.ts b/frontend/utils/getCrossref.ts index f0dc511bd..b5459cfa8 100644 --- a/frontend/utils/getCrossref.ts +++ b/frontend/utils/getCrossref.ts @@ -25,10 +25,21 @@ export function addPoliteEmail(url:string) { function extractAuthors(item: CrossrefSelectItem) { if (item.author) { return item.author.map(author => { - return `${author.given} ${author.family}` + if (author.given && author.family) { + return `${author.given} ${author.family}` + } + if (author.name) { + return author.name + } + if (author.given) { + return author.given + } + if (author.family) { + return author.family + } }).join(', ') } - return '' + return null } function extractYearPublished(item: CrossrefSelectItem) { diff --git a/scrapers/src/main/java/nl/esciencecenter/rsd/scraper/doi/CrossrefMention.java b/scrapers/src/main/java/nl/esciencecenter/rsd/scraper/doi/CrossrefMention.java index 2621d69de..5dc6fe905 100644 --- a/scrapers/src/main/java/nl/esciencecenter/rsd/scraper/doi/CrossrefMention.java +++ b/scrapers/src/main/java/nl/esciencecenter/rsd/scraper/doi/CrossrefMention.java @@ -1,5 +1,5 @@ -// SPDX-FileCopyrightText: 2022 - 2023 Ewan Cahen (Netherlands eScience Center) -// SPDX-FileCopyrightText: 2022 - 2023 Netherlands eScience Center +// SPDX-FileCopyrightText: 2022 - 2024 Ewan Cahen (Netherlands eScience Center) +// SPDX-FileCopyrightText: 2022 - 2024 Netherlands eScience Center // SPDX-FileCopyrightText: 2022 Dusan Mijatovic (dv4all) // SPDX-FileCopyrightText: 2022 dv4all // @@ -69,7 +69,7 @@ public CrossrefMention(String doi) { } @Override - public MentionRecord mentionData() throws IOException, InterruptedException, RsdResponseException{ + public MentionRecord mentionData() throws IOException, InterruptedException, RsdResponseException { StringBuilder url = new StringBuilder("https://api.crossref.org/works/" + Utils.urlEncode(doi)); Config.crossrefContactEmail().ifPresent(email -> url.append("?mailto=").append(email)); String responseJson = Utils.get(url.toString()); @@ -87,10 +87,16 @@ public MentionRecord mentionData() throws IOException, InterruptedException, Rsd for (JsonObject authorJson : authorsJson) { String givenName = Utils.stringOrNull(authorJson.get("given")); String familyName = Utils.stringOrNull(authorJson.get("family")); - if (givenName == null && familyName == null) continue; - if (givenName == null) authors.add(familyName); - else if (familyName == null) authors.add(givenName); - else authors.add(givenName + " " + familyName); + String name = Utils.stringOrNull(authorJson.get("name")); + if (givenName != null && familyName != null) { + authors.add(givenName + " " + familyName); + } else if (name != null) { + authors.add(name); + } else if (givenName != null) { + authors.add(givenName); + } else if (familyName != null) { + authors.add(familyName); + } } result.authors = String.join(", ", authors); }