-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Citations Relations Service Layer (#11189)
* Move logic from repository to service * Refactor repositories * Update tab configuration
- Loading branch information
1 parent
f603c78
commit 9fe8522
Showing
11 changed files
with
499 additions
and
330 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
35 changes: 26 additions & 9 deletions
35
src/main/java/org/jabref/logic/citation/repository/LRUBibEntryRelationsCache.java
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,38 +1,55 @@ | ||
package org.jabref.logic.citation.repository; | ||
|
||
import java.util.Collections; | ||
import java.util.LinkedHashSet; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import org.eclipse.jgit.util.LRUMap; | ||
import org.jabref.model.entry.BibEntry; | ||
import org.jabref.model.entry.identifier.DOI; | ||
|
||
public class LRUBibEntryRelationsCache { | ||
private static final Integer MAX_CACHED_ENTRIES = 100; | ||
private static final Map<String, List<BibEntry>> CITATIONS_MAP = new LRUMap<>(MAX_CACHED_ENTRIES, MAX_CACHED_ENTRIES); | ||
private static final Map<String, List<BibEntry>> REFERENCES_MAP = new LRUMap<>(MAX_CACHED_ENTRIES, MAX_CACHED_ENTRIES); | ||
private static final Map<DOI, Set<BibEntry>> CITATIONS_MAP = new LRUMap<>(MAX_CACHED_ENTRIES, MAX_CACHED_ENTRIES); | ||
private static final Map<DOI, Set<BibEntry>> REFERENCES_MAP = new LRUMap<>(MAX_CACHED_ENTRIES, MAX_CACHED_ENTRIES); | ||
|
||
public List<BibEntry> getCitations(BibEntry entry) { | ||
return CITATIONS_MAP.getOrDefault(entry.getDOI().map(DOI::getDOI).orElse(""), Collections.emptyList()); | ||
return entry | ||
.getDOI() | ||
.stream() | ||
.flatMap(doi -> CITATIONS_MAP.getOrDefault(doi, Set.of()).stream()) | ||
.toList(); | ||
} | ||
|
||
public List<BibEntry> getReferences(BibEntry entry) { | ||
return REFERENCES_MAP.getOrDefault(entry.getDOI().map(DOI::getDOI).orElse(""), Collections.emptyList()); | ||
return entry | ||
.getDOI() | ||
.stream() | ||
.flatMap(doi -> REFERENCES_MAP.getOrDefault(doi, Set.of()).stream()) | ||
.toList(); | ||
} | ||
|
||
public void cacheOrMergeCitations(BibEntry entry, List<BibEntry> citations) { | ||
entry.getDOI().ifPresent(doi -> CITATIONS_MAP.put(doi.getDOI(), citations)); | ||
entry.getDOI().ifPresent(doi -> { | ||
var cachedRelations = CITATIONS_MAP.getOrDefault(doi, new LinkedHashSet<>()); | ||
cachedRelations.addAll(citations); | ||
CITATIONS_MAP.put(doi, cachedRelations); | ||
}); | ||
} | ||
|
||
public void cacheOrMergeReferences(BibEntry entry, List<BibEntry> references) { | ||
entry.getDOI().ifPresent(doi -> REFERENCES_MAP.putIfAbsent(doi.getDOI(), references)); | ||
entry.getDOI().ifPresent(doi -> { | ||
var cachedRelations = REFERENCES_MAP.getOrDefault(doi, new LinkedHashSet<>()); | ||
cachedRelations.addAll(references); | ||
REFERENCES_MAP.put(doi, cachedRelations); | ||
}); | ||
} | ||
|
||
public boolean citationsCached(BibEntry entry) { | ||
return CITATIONS_MAP.containsKey(entry.getDOI().map(DOI::getDOI).orElse("")); | ||
return entry.getDOI().map(CITATIONS_MAP::containsKey).orElse(false); | ||
} | ||
|
||
public boolean referencesCached(BibEntry entry) { | ||
return REFERENCES_MAP.containsKey(entry.getDOI().map(DOI::getDOI).orElse("")); | ||
return entry.getDOI().map(REFERENCES_MAP::containsKey).orElse(false); | ||
} | ||
} |
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
Oops, something went wrong.