-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: check if fields present in author before adding mention
- Loading branch information
1 parent
0f8b7e5
commit d4edece
Showing
2 changed files
with
26 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// SPDX-FileCopyrightText: 2022 - 2023 Ewan Cahen (Netherlands eScience Center) <[email protected]> | ||
// SPDX-FileCopyrightText: 2022 - 2023 Netherlands eScience Center | ||
// SPDX-FileCopyrightText: 2022 - 2024 Ewan Cahen (Netherlands eScience Center) <[email protected]> | ||
// 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); | ||
} | ||
|