Skip to content
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We fixed an issue where journal abbreviations chose the wrong abbreviation when fuzzy matching. [#14850](https://github.com/JabRef/jabref/pull/14850)
- We fixed an issue where JaRef would not correctly remember the opened side panels in the preferences [#14818](https://github.com/JabRef/jabref/issues/14818)
- Updates of the pre-selected fetchers are now followed at the Web fetchers. [#14768](https://github.com/JabRef/jabref/pull/14768)
- Restart search button in citation-relation panel now refreshes using external services. [#14757](https://github.com/JabRef/jabref/issues/14757)

### Removed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,9 @@ private SplitPane getPaneAndStartSearch(BibEntry entry) {
importCitedByButton,
citedByProgress);

refreshCitingButton.setOnMouseClicked(_ -> searchForRelations(citingComponents, citedByComponents));
refreshCitedByButton.setOnMouseClicked(_ -> searchForRelations(citedByComponents, citingComponents));
// click refresh button will trigger refresh from the remote
refreshCitingButton.setOnMouseClicked(_ -> searchForRelations(citingComponents, citedByComponents, true));
refreshCitedByButton.setOnMouseClicked(_ -> searchForRelations(citedByComponents, citingComponents, true));

fetcherCombo.getSelectionModel().selectedItemProperty().addListener((_, _, newValue) -> {
if (citingComponents.entry().getDOI().isEmpty()) {
Expand All @@ -464,16 +465,18 @@ private SplitPane getPaneAndStartSearch(BibEntry entry) {
citingTask.cancel();
}
entryEditorPreferences.setCitationFetcherType(newValue);
searchForRelations(citingComponents, citedByComponents);
// switch the fetcher will not trigger refresh from the remote
searchForRelations(citingComponents, citedByComponents, false);
});

// Create SplitPane to hold all nodes above
SplitPane container = new SplitPane(citingVBox, citedByVBox);
styleFetchedListView(citedByListView);
styleFetchedListView(citingListView);

searchForRelations(citingComponents, citedByComponents);
searchForRelations(citedByComponents, citingComponents);
// switch to the tab will not trigger refresh from the remote
searchForRelations(citingComponents, citedByComponents, false);
searchForRelations(citedByComponents, citingComponents, false);

return container;
}
Expand Down Expand Up @@ -660,12 +663,13 @@ protected void bindToEntry(BibEntry entry) {
}

private void searchForRelations(CitationComponents citationComponents,
CitationComponents otherCitationComponents) {
CitationComponents otherCitationComponents,
boolean bypassCache) {
if (citationComponents.entry().getDOI().isEmpty()) {
setUpEmptyPanel(citationComponents, otherCitationComponents);
return;
}
executeSearch(citationComponents);
executeSearch(citationComponents, bypassCache);
}

private void setUpEmptyPanel(CitationComponents citationComponents,
Expand All @@ -689,8 +693,9 @@ private void setUpEmptyPanel(CitationComponents citationComponents,
.onSuccess(identifier -> {
if (identifier.isPresent()) {
citationComponents.entry().setField(StandardField.DOI, identifier.get().asString());
executeSearch(citationComponents);
executeSearch(otherCitationComponents);
// if the DOI is successfully looked up (requested by the user), trigger refresh from the remote
executeSearch(citationComponents, true);
executeSearch(otherCitationComponents, true);
} else {
dialogService.notify(Localization.lang("No DOI found."));
setUpEmptyPanel(citationComponents, otherCitationComponents);
Expand Down Expand Up @@ -719,7 +724,7 @@ private static void setLabelOn(CheckListView<CitationRelationItem> listView, Str
listView.setPlaceholder(lookingUpDoiLabel);
}

private void executeSearch(CitationComponents citationComponents) {
private void executeSearch(CitationComponents citationComponents, boolean bypassCache) {
ObservableList<CitationRelationItem> observableList = FXCollections.observableArrayList();
citationComponents.listView().setItems(observableList);

Expand All @@ -730,7 +735,7 @@ private void executeSearch(CitationComponents citationComponents) {
citedByTask.cancel();
}

this.createBackgroundTask(citationComponents.entry(), citationComponents.searchType())
this.createBackgroundTask(citationComponents.entry(), citationComponents.searchType(), bypassCache)
.consumeOnRunning(task -> prepareToSearchForRelations(citationComponents, task))
.onSuccess(fetchedList -> onSearchForRelationsSucceed(citationComponents,
fetchedList,
Expand All @@ -756,18 +761,18 @@ private void executeSearch(CitationComponents citationComponents) {

/// TODO: Make the method return a callable and let the calling method create the background task.
private BackgroundTask<List<BibEntry>> createBackgroundTask(
BibEntry entry, CitationFetcher.SearchType searchType
BibEntry entry, CitationFetcher.SearchType searchType, boolean bypassCache
) {
return switch (searchType) {
case CitationFetcher.SearchType.CITES -> {
citingTask = BackgroundTask.wrap(
() -> this.searchCitationsRelationsService.searchCites(entry)
() -> this.searchCitationsRelationsService.searchCites(entry, bypassCache)
);
yield citingTask;
}
case CitationFetcher.SearchType.CITED_BY -> {
citedByTask = BackgroundTask.wrap(
() -> this.searchCitationsRelationsService.searchCitedBy(entry)
() -> this.searchCitationsRelationsService.searchCitedBy(entry, bypassCache)
);
yield citedByTask;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,11 @@ public SearchCitationsRelationsService(ImporterPreferences importerPreferences,
this.relationsRepository = repository;
}

public List<BibEntry> searchCites(BibEntry referencing) throws FetcherException {
public List<BibEntry> searchCites(BibEntry referencing, boolean bypassCache) throws FetcherException {
boolean isFetchingAllowed =
!relationsRepository.containsReferences(referencing) ||
relationsRepository.isReferencesUpdatable(referencing);
bypassCache
|| !relationsRepository.containsReferences(referencing)
|| relationsRepository.isReferencesUpdatable(referencing);
if (isFetchingAllowed) {
List<BibEntry> referencedBy = citationFetcher.getReferences(referencing);
relationsRepository.insertReferences(referencing, referencedBy);
Expand All @@ -89,10 +90,11 @@ public List<BibEntry> searchCites(BibEntry referencing) throws FetcherException
/// If the store was empty and nothing was fetch in any case (empty fetch, or error) then yes => empty list
/// If the store was not empty and nothing was fetched after a successful fetch => the store will be erased and the returned collection will be empty
/// If the store was not empty and an error occurs while fetching => will return the content of the store
public List<BibEntry> searchCitedBy(BibEntry cited) throws FetcherException {
public List<BibEntry> searchCitedBy(BibEntry cited, boolean bypassCache) throws FetcherException {
boolean isFetchingAllowed =
!relationsRepository.containsCitations(cited) ||
relationsRepository.isCitationsUpdatable(cited);
bypassCache
|| !relationsRepository.containsCitations(cited)
|| relationsRepository.isCitationsUpdatable(cited);
if (isFetchingAllowed) {
List<BibEntry> citedBy = citationFetcher.getCitations(cited);
relationsRepository.insertCitations(cited, citedBy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void serviceShouldSearchForCitations() throws FetcherException {
SearchCitationsRelationsService searchService = new SearchCitationsRelationsService(null, repository);

// WHEN
List<BibEntry> citations = searchService.searchCitedBy(cited);
List<BibEntry> citations = searchService.searchCitedBy(cited, false);

// THEN
assertEquals(citationsToReturn, citations);
Expand All @@ -92,7 +92,7 @@ void serviceShouldCallTheFetcherForCitationsWhenRepositoryIsUpdatable() throws F
SearchCitationsRelationsService searchService = new SearchCitationsRelationsService(fetcher, repository);

// WHEN
List<BibEntry> citations = searchService.searchCitedBy(cited);
List<BibEntry> citations = searchService.searchCitedBy(cited, false);

// THEN
assertTrue(citationsDatabase.containsKey(cited));
Expand All @@ -111,7 +111,7 @@ void serviceShouldFetchCitationsIfRepositoryIsEmpty() throws FetcherException {
SearchCitationsRelationsService searchService = new SearchCitationsRelationsService(fetcher, repository);

// WHEN
List<BibEntry> citations = searchService.searchCitedBy(cited);
List<BibEntry> citations = searchService.searchCitedBy(cited, false);

// THEN
assertTrue(citationsDatabase.containsKey(cited));
Expand All @@ -128,7 +128,7 @@ void insertingAnEmptyCitationsShouldBePossible() throws FetcherException {
SearchCitationsRelationsService searchService = new SearchCitationsRelationsService(fetcher, repository);

// WHEN
List<BibEntry> citations = searchService.searchCitedBy(cited);
List<BibEntry> citations = searchService.searchCitedBy(cited, false);

// THEN
assertTrue(citations.isEmpty());
Expand All @@ -150,7 +150,7 @@ void serviceShouldSearchForReferences() throws FetcherException {
SearchCitationsRelationsService searchService = new SearchCitationsRelationsService(null, repository);

// WHEN
List<BibEntry> references = searchService.searchCites(referencer);
List<BibEntry> references = searchService.searchCites(referencer, false);

// THEN
assertEquals(referencesToReturn, references);
Expand All @@ -176,7 +176,7 @@ void serviceShouldCallTheFetcherForReferencesWhenRepositoryIsUpdatable() throws
SearchCitationsRelationsService searchService = new SearchCitationsRelationsService(fetcher, repository);

// WHEN
List<BibEntry> references = searchService.searchCites(referencer);
List<BibEntry> references = searchService.searchCites(referencer, false);

// THEN
assertTrue(referencesDatabase.containsKey(referencer));
Expand All @@ -197,7 +197,7 @@ void serviceShouldFetchReferencesIfRepositoryIsEmpty() throws FetcherException {
SearchCitationsRelationsService searchService = new SearchCitationsRelationsService(fetcher, repository);

// WHEN
List<BibEntry> references = searchService.searchCites(reference);
List<BibEntry> references = searchService.searchCites(reference, false);

// THEN
assertTrue(referencesDatabase.containsKey(reference));
Expand All @@ -216,7 +216,7 @@ void insertingAnEmptyReferencesShouldBePossible() throws FetcherException {
SearchCitationsRelationsService searchService = new SearchCitationsRelationsService(fetcher, repository);

// WHEN
List<BibEntry> citations = searchService.searchCites(referencer);
List<BibEntry> citations = searchService.searchCites(referencer, false);

// THEN
assertTrue(citations.isEmpty());
Expand Down