-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Add OpenCitations #14996
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add OpenCitations #14996
Changes from all commits
f572b32
4e5f01e
b31873f
4d7d56c
0c62740
312562b
d6545b1
6004e27
d3e6beb
345bac0
4e64795
5406e4f
b13ffec
f3867e1
057abaf
5f77b88
84fd50f
3538b3d
8a488ec
51bbae3
51dd141
b6a7cc9
3979fdc
2f811ee
3454654
343b6f5
15a1537
6bff9a9
8869a0b
dd3dabc
64e5d27
75e377e
dcd6c31
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -394,7 +394,7 @@ private SplitPane getPaneAndStartSearch(BibEntry entry) { | |
| .withText(CitationFetcherType::getName) | ||
| .install(fetcherCombo); | ||
| styleTopBarNode(fetcherCombo, 75.0); | ||
| fetcherCombo.setValue(entryEditorPreferences.getCitationFetcherType()); | ||
| fetcherCombo.valueProperty().bindBidirectional(entryEditorPreferences.citationFetcherTypeProperty()); | ||
|
|
||
| // Create abort buttons for both sides | ||
| Button abortCitingButton = IconTheme.JabRefIcons.CLOSE.asButton(); | ||
|
|
@@ -457,16 +457,9 @@ private SplitPane getPaneAndStartSearch(BibEntry entry) { | |
| return; | ||
| } | ||
|
|
||
| // Fetcher can only be changed for the citing search. | ||
| // Therefore, we handle this part only. | ||
|
|
||
| // Cancel any running searches so they don't continue with the old fetcher | ||
| if (citingTask != null && !citingTask.isCancelled()) { | ||
| citingTask.cancel(); | ||
| } | ||
| entryEditorPreferences.setCitationFetcherType(newValue); | ||
| // switch the fetcher will not trigger refresh from the remote | ||
| // switch the fetcher will not trigger refresh from the remote, therefore we trigger it explicitly. | ||
| searchForRelations(citingComponents, citedByComponents, false); | ||
| searchForRelations(citedByComponents, citingComponents, false); | ||
| }); | ||
|
|
||
| // Create SplitPane to hold all nodes above | ||
|
|
@@ -650,6 +643,16 @@ public boolean shouldShow(BibEntry entry) { | |
| protected void bindToEntry(BibEntry entry) { | ||
| citationsRelationsTabViewModel.bindToEntry(entry); | ||
|
|
||
| // TODO: All this should go to ViewModel | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will you do this or for follow-up
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe me, maybe someone else. This was in before - I created an issue for this. |
||
| if (citingTask != null && !citingTask.isCancelled()) { | ||
| citingTask.cancel(); | ||
| citingTask = null; | ||
| } | ||
| if (citedByTask != null && !citedByTask.isCancelled()) { | ||
| citedByTask.cancel(); | ||
| citedByTask = null; | ||
| } | ||
|
|
||
| SplitPane splitPane = getPaneAndStartSearch(entry); | ||
| splitPane.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE); | ||
| splitPane.setMinSize(0, 0); | ||
|
|
@@ -728,7 +731,6 @@ private void executeSearch(CitationComponents citationComponents, boolean bypass | |
| ObservableList<CitationRelationItem> observableList = FXCollections.observableArrayList(); | ||
| citationComponents.listView().setItems(observableList); | ||
|
|
||
| // TODO: It should not be possible to cancel a search task that is already running for same tab | ||
| if (citationComponents.searchType() == CitationFetcher.SearchType.CITES && citingTask != null && !citingTask.isCancelled()) { | ||
| citingTask.cancel(); | ||
| } else if (citationComponents.searchType() == CitationFetcher.SearchType.CITED_BY && citedByTask != null && !citedByTask.isCancelled()) { | ||
|
|
@@ -765,13 +767,13 @@ private BackgroundTask<List<BibEntry>> createBackgroundTask( | |
| ) { | ||
| return switch (searchType) { | ||
| case CitationFetcher.SearchType.CITES -> { | ||
| citingTask = BackgroundTask.wrap( | ||
| this.citingTask = BackgroundTask.wrap( | ||
| () -> this.searchCitationsRelationsService.searchCites(entry, bypassCache) | ||
| ); | ||
| yield citingTask; | ||
| } | ||
| case CitationFetcher.SearchType.CITED_BY -> { | ||
| citedByTask = BackgroundTask.wrap( | ||
| this.citedByTask = BackgroundTask.wrap( | ||
| () -> this.searchCitationsRelationsService.searchCitedBy(entry, bypassCache) | ||
| ); | ||
| yield citedByTask; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| package org.jabref.logic.importer.fetcher.citation.opencitations; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import org.jabref.model.entry.field.Field; | ||
| import org.jabref.model.entry.field.FieldFactory; | ||
| import org.jabref.model.entry.field.StandardField; | ||
|
|
||
| import com.google.gson.annotations.SerializedName; | ||
| import org.jspecify.annotations.NullMarked; | ||
| import org.jspecify.annotations.Nullable; | ||
|
|
||
| @NullMarked | ||
| class CitationItem { | ||
| @Nullable String oci; | ||
| @Nullable String citing; | ||
| @Nullable String cited; | ||
| @Nullable String creation; | ||
| @Nullable String timespan; | ||
|
|
||
| @SerializedName("journal_sc") | ||
| @Nullable String journalSelfCitation; | ||
|
|
||
| @SerializedName("author_sc") | ||
| @Nullable String authorSelfCitation; | ||
|
|
||
| record IdentifierWithField(Field field, String value) { | ||
| } | ||
|
|
||
| List<IdentifierWithField> extractIdentifiers(@Nullable String pidString) { | ||
| if (pidString == null || pidString.isEmpty()) { | ||
| return List.of(); | ||
| } | ||
|
|
||
| String[] pids = pidString.split("\\s+"); | ||
| List<IdentifierWithField> identifiers = new ArrayList<>(); | ||
| for (String pid : pids) { | ||
| int colonIndex = pid.indexOf(':'); | ||
| if (colonIndex > 0) { | ||
| String prefix = pid.substring(0, colonIndex); | ||
| String value = pid.substring(colonIndex + 1); | ||
| Field field = FieldFactory.parseField(prefix); | ||
| identifiers.add(new IdentifierWithField(field, value)); | ||
| } else { | ||
| identifiers.add(new IdentifierWithField(StandardField.NOTE, pid)); | ||
| } | ||
| } | ||
|
|
||
| return identifiers; | ||
| } | ||
|
|
||
| List<IdentifierWithField> citingIdentifiers() { | ||
| return extractIdentifiers(citing); | ||
| } | ||
|
|
||
| List<IdentifierWithField> citedIdentifiers() { | ||
| return extractIdentifiers(cited); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package org.jabref.logic.importer.fetcher.citation.opencitations; | ||
|
|
||
| import org.jspecify.annotations.NullMarked; | ||
| import org.jspecify.annotations.Nullable; | ||
|
|
||
| @NullMarked | ||
| class CountResponse { | ||
| @Nullable String count; | ||
|
|
||
| int countAsInt() { | ||
| if (count == null) { | ||
| return 0; | ||
| } | ||
| try { | ||
| return Integer.parseInt(count); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this class here really necessary?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DTO pattern. Better consistency in always using a DTO in this class than case-by-case --> CitatonItem is the other DTO. |
||
| } catch (NumberFormatException e) { | ||
| return 0; | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why bidirectional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
org.jabref.gui.fieldeditors.CitationCountEditor