Skip to content

Commit

Permalink
Replace throw new RuntimeException by LOGGER / other throws (JabRef#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
koppor authored Mar 5, 2024
1 parent 8374693 commit 967b651
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
import org.jabref.logic.importer.FetcherException;
import org.jabref.model.entry.BibEntry;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class BibEntryRelationsRepository {
private static final Logger LOGGER = LoggerFactory.getLogger(BibEntryRelationsRepository.class);

private final SemanticScholarFetcher fetcher;
private final BibEntryRelationsCache cache;

Expand All @@ -25,7 +30,13 @@ public List<BibEntry> getCitations(BibEntry entry) {

public List<BibEntry> getReferences(BibEntry entry) {
if (needToRefreshReferences(entry)) {
List<BibEntry> references = fetcher.searchCiting(entry);
List<BibEntry> references;
try {
references = fetcher.searchCiting(entry);
} catch (FetcherException e) {
LOGGER.error("Error while fetching references", e);
references = List.of();
}
cache.cacheOrMergeReferences(entry, references);
}

Expand All @@ -37,7 +48,7 @@ public void forceRefreshCitations(BibEntry entry) {
List<BibEntry> citations = fetcher.searchCitedBy(entry);
cache.cacheOrMergeCitations(entry, citations);
} catch (FetcherException e) {
throw new RuntimeException(e);
LOGGER.error("Error while fetching citations", e);
}
}

Expand All @@ -50,7 +61,13 @@ public boolean needToRefreshReferences(BibEntry entry) {
}

public void forceRefreshReferences(BibEntry entry) {
List<BibEntry> references = fetcher.searchCiting(entry);
List<BibEntry> references;
try {
references = fetcher.searchCiting(entry);
} catch (FetcherException e) {
LOGGER.error("Error while fetching references", e);
references = List.of();
}
cache.cacheOrMergeReferences(entry, references);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import org.jabref.logic.importer.FetcherException;
Expand Down Expand Up @@ -50,15 +49,14 @@ public List<BibEntry> searchCitedBy(BibEntry entry) throws FetcherException {
.stream().filter(citationDataItem -> citationDataItem.getCitingPaper() != null)
.map(citationDataItem -> citationDataItem.getCitingPaper().toBibEntry()).toList();
} catch (IOException e) {
throw new RuntimeException(e);
throw new FetcherException("Could not fetch", e);
}
}

return new ArrayList<>();
return List.of();
}

@Override
public List<BibEntry> searchCiting(BibEntry entry) {
public List<BibEntry> searchCiting(BibEntry entry) throws FetcherException {
if (entry.getDOI().isPresent()) {
StringBuilder urlBuilder = new StringBuilder(SEMANTIC_SCHOLAR_API)
.append("paper/")
Expand All @@ -82,11 +80,10 @@ public List<BibEntry> searchCiting(BibEntry entry) {
.filter(citationDataItem -> citationDataItem.getCitedPaper() != null)
.map(referenceDataItem -> referenceDataItem.getCitedPaper().toBibEntry()).toList();
} catch (IOException e) {
throw new RuntimeException(e);
throw new FetcherException("Could not fetch", e);
}
}

return new ArrayList<>();
return List.of();
}

@Override
Expand Down

0 comments on commit 967b651

Please sign in to comment.