-
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.
Merge pull request #1193 from research-software-directory/citation-sc…
…raper-save-error-fix fix: only extract mention id if present when not able to update a men…
- Loading branch information
Showing
1 changed file
with
22 additions
and
19 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
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-License-Identifier: Apache-2.0 | ||
|
||
|
@@ -15,6 +15,8 @@ | |
import com.google.gson.JsonSerializer; | ||
import com.google.gson.reflect.TypeToken; | ||
import nl.esciencecenter.rsd.scraper.Utils; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.net.URI; | ||
import java.time.Instant; | ||
|
@@ -23,13 +25,10 @@ | |
import java.util.Objects; | ||
import java.util.UUID; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class PostgrestMentionRepository implements MentionRepository { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(PostgrestMentionRepository.class); | ||
|
||
private final String backendUrl; | ||
|
||
public PostgrestMentionRepository(String backendUrl) { | ||
|
@@ -92,15 +91,15 @@ public void save(Collection<MentionRecord> mentions) { | |
try { | ||
LOGGER.debug("Saving mention: {} / {} / {}", mention.doi, mention.externalId, mention.source); | ||
response = Utils.postAsAdmin(uri, scrapedMentionJson, "Prefer", "resolution=merge-duplicates,return=representation"); | ||
|
||
JsonArray responseAsArray = JsonParser.parseString(response).getAsJsonArray(); | ||
// Used in MainCitations, do not remove | ||
mention.id = UUID.fromString(responseAsArray.get(0).getAsJsonObject().getAsJsonPrimitive("id").getAsString()); | ||
|
||
} catch (RuntimeException e) { | ||
|
||
LOGGER.warn("Failed to save mention: {} / {} / {}", mention.doi, mention.externalId, mention.source, e); | ||
|
||
if (mention.doi == null) { | ||
Utils.saveExceptionInDatabase("Mention scraper", "mention", null, e); | ||
} else { | ||
|
@@ -109,16 +108,20 @@ public void save(Collection<MentionRecord> mentions) { | |
try { | ||
String existingMentionResponse = Utils.getAsAdmin("%s/mention?doi=eq.%s&select=id".formatted(backendUrl, mention.doi)); | ||
JsonArray array = JsonParser.parseString(existingMentionResponse).getAsJsonArray(); | ||
String id = array.get(0).getAsJsonObject().getAsJsonPrimitive("id").getAsString(); | ||
Utils.saveErrorMessageInDatabase(null, | ||
"mention", | ||
null, | ||
id, | ||
"id", | ||
ZonedDateTime.now(), | ||
"scraped_at"); | ||
|
||
Utils.saveExceptionInDatabase("Mention scraper", "mention", UUID.fromString(id), e); | ||
if (array.size() == 1) { | ||
String id = array.get(0).getAsJsonObject().getAsJsonPrimitive("id").getAsString(); | ||
Utils.saveErrorMessageInDatabase(null, | ||
"mention", | ||
null, | ||
id, | ||
"id", | ||
ZonedDateTime.now(), | ||
"scraped_at"); | ||
|
||
Utils.saveExceptionInDatabase("Mention scraper", "mention", UUID.fromString(id), e); | ||
} else { | ||
Utils.saveExceptionInDatabase("Mention scraper", "mention", null, e); | ||
} | ||
} catch (Exception e2) { | ||
LOGGER.warn("Failed to save exception in database", e2); | ||
} | ||
|