From 481cb095249e237d5361de0f87553422f7b0d515 Mon Sep 17 00:00:00 2001 From: "Roc R. Currius" Date: Fri, 2 Feb 2024 15:35:12 +0000 Subject: [PATCH 01/10] Collect DOI and publication type from semantich scholar to be able to expand the information of the new entries later by search through DOI --- .../semanticscholar/PaperDetails.java | 53 +++++++++++++++++++ .../SemanticScholarFetcher.java | 5 +- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/semanticscholar/PaperDetails.java b/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/semanticscholar/PaperDetails.java index 48db00777cf..ad589be5fe0 100644 --- a/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/semanticscholar/PaperDetails.java +++ b/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/semanticscholar/PaperDetails.java @@ -1,10 +1,12 @@ package org.jabref.gui.entryeditor.citationrelationtab.semanticscholar; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.StandardField; +import org.jabref.model.entry.types.StandardEntryType; public class PaperDetails { private String paperId; @@ -13,6 +15,8 @@ public class PaperDetails { private int citationCount; private int referenceCount; private List authors; + private List publicationTypes; + private Map externalIds; public String getPaperId() { return paperId; @@ -58,6 +62,51 @@ public List getAuthors() { return authors; } + public String getPublicationType() { + if (publicationTypes == null || publicationTypes.isEmpty()) { + return "Misc"; + } + if (publicationTypes.contains("Conference")) { + return "InProceedings"; + } else if (publicationTypes.contains("JournalArticle")) { + return "Article"; + } else { + return switch (publicationTypes.getFirst()) { + case "Review" -> + "Misc"; + case "CaseReport" -> + "Report"; + case "ClinicalTrial" -> + "Report"; + case "Dataset" -> + "Dataset"; + case "Editorial" -> + "Misc"; + case "LettersAndComments" -> + "Misc"; + case "MetaAnalysis" -> + "Article"; + case "News" -> + "Misc"; + case "Study" -> + "Article"; + case "Book" -> + "Book"; + case "BookSection" -> + "InBook"; + default -> + "Misc"; + }; + } + } + + public String getDOI() { + if (externalIds != null && externalIds.containsKey("DOI")) { + return externalIds.get("DOI"); + } + return ""; + } + public BibEntry toBibEntry() { BibEntry bibEntry = new BibEntry(); bibEntry.setField(StandardField.TITLE, getTitle()); @@ -70,6 +119,10 @@ public BibEntry toBibEntry() { .collect(Collectors.joining(" and ")); bibEntry.setField(StandardField.AUTHOR, authors); + bibEntry.setType(StandardEntryType.valueOf(getPublicationType())); + + bibEntry.setField(StandardField.DOI, getDOI()); + return bibEntry; } diff --git a/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/semanticscholar/SemanticScholarFetcher.java b/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/semanticscholar/SemanticScholarFetcher.java index 0a5ca3b16a9..d24547a2eb2 100644 --- a/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/semanticscholar/SemanticScholarFetcher.java +++ b/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/semanticscholar/SemanticScholarFetcher.java @@ -33,7 +33,8 @@ public List searchCitedBy(BibEntry entry) throws FetcherException { .append("paper/") .append("DOI:").append(entry.getDOI().get().getDOI()) .append("/citations") - .append("?fields=").append("title,authors,year,citationCount,referenceCount") + .append("?fields=") + .append("title,authors,year,citationCount,referenceCount,externalIds,publicationTypes") .append("&limit=1000"); try { URL citationsUrl = URI.create(urlBuilder.toString()).toURL(); @@ -65,7 +66,7 @@ public List searchCiting(BibEntry entry) { .append("DOI:").append(entry.getDOI().get().getDOI()) .append("/references") .append("?fields=") - .append("title,authors,year,citationCount,referenceCount") + .append("title,authors,year,citationCount,referenceCount,externalIds,publicationTypes") .append("&limit=1000"); try { URL referencesUrl = URI.create(urlBuilder.toString()).toURL(); From 663542bf2d905051f1fc93b32ce15c173cf3282d Mon Sep 17 00:00:00 2001 From: "Roc R. Currius" Date: Wed, 13 Mar 2024 13:30:43 +0000 Subject: [PATCH 02/10] Include abstract in the request. This lets the GUI show the abstract since that was implemented already. Refactor api request string since most of it is shared --- .../semanticscholar/PaperDetails.java | 17 +++++++++++ .../SemanticScholarFetcher.java | 28 ++++++++----------- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/semanticscholar/PaperDetails.java b/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/semanticscholar/PaperDetails.java index ad589be5fe0..1bc86438cd2 100644 --- a/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/semanticscholar/PaperDetails.java +++ b/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/semanticscholar/PaperDetails.java @@ -8,10 +8,15 @@ import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.types.StandardEntryType; +import com.google.gson.annotations.SerializedName; + public class PaperDetails { private String paperId; private String title; private String year; + + @SerializedName("abstract") + private String abstr; private int citationCount; private int referenceCount; private List authors; @@ -42,6 +47,14 @@ public void setYear(String year) { this.year = year; } + public String getAbstract() { + return abstr; + } + + public void setAbstract(String abstr) { + this.abstr = abstr; + } + public int getCitationCount() { return citationCount; } @@ -123,6 +136,10 @@ public BibEntry toBibEntry() { bibEntry.setField(StandardField.DOI, getDOI()); + if (getAbstract() != null) { + bibEntry.setField(StandardField.ABSTRACT, getAbstract()); + } + return bibEntry; } diff --git a/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/semanticscholar/SemanticScholarFetcher.java b/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/semanticscholar/SemanticScholarFetcher.java index 694f75846cb..dd93167eae0 100644 --- a/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/semanticscholar/SemanticScholarFetcher.java +++ b/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/semanticscholar/SemanticScholarFetcher.java @@ -25,18 +25,21 @@ public SemanticScholarFetcher(ImporterPreferences importerPreferences) { this.importerPreferences = importerPreferences; } + public String getAPIUrl(String entry_point, BibEntry entry) { + return new StringBuilder(SEMANTIC_SCHOLAR_API) + .append("paper/") + .append("DOI:").append(entry.getDOI().orElseThrow().getDOI()) + .append("/").append(entry_point) + .append("?fields=") + .append("title,authors,year,citationCount,referenceCount,externalIds,publicationTypes,abstract") + .append("&limit=1000").toString(); + } + @Override public List searchCitedBy(BibEntry entry) throws FetcherException { if (entry.getDOI().isPresent()) { - StringBuilder urlBuilder = new StringBuilder(SEMANTIC_SCHOLAR_API) - .append("paper/") - .append("DOI:").append(entry.getDOI().get().getDOI()) - .append("/citations") - .append("?fields=") - .append("title,authors,year,citationCount,referenceCount,externalIds,publicationTypes") - .append("&limit=1000"); try { - URL citationsUrl = URI.create(urlBuilder.toString()).toURL(); + URL citationsUrl = URI.create(getAPIUrl("citations", entry)).toURL(); URLDownload urlDownload = new URLDownload(citationsUrl); String apiKey = getApiKey(); @@ -59,15 +62,8 @@ public List searchCitedBy(BibEntry entry) throws FetcherException { @Override public List searchCiting(BibEntry entry) throws FetcherException { if (entry.getDOI().isPresent()) { - StringBuilder urlBuilder = new StringBuilder(SEMANTIC_SCHOLAR_API) - .append("paper/") - .append("DOI:").append(entry.getDOI().get().getDOI()) - .append("/references") - .append("?fields=") - .append("title,authors,year,citationCount,referenceCount,externalIds,publicationTypes") - .append("&limit=1000"); try { - URL referencesUrl = URI.create(urlBuilder.toString()).toURL(); + URL referencesUrl = URI.create(getAPIUrl("references", entry)).toURL(); URLDownload urlDownload = new URLDownload(referencesUrl); String apiKey = getApiKey(); if (!apiKey.isEmpty()) { From 341567ca1206f5c4b1c7599f19a3b908f83dcb23 Mon Sep 17 00:00:00 2001 From: "Roc R. Currius" Date: Wed, 13 Mar 2024 13:33:57 +0000 Subject: [PATCH 03/10] Add button to open the relation paper's DOI URL. Fix DOI for some ArXiv entries. --- .../CitationRelationsTab.java | 33 +++++++++++++++++-- .../semanticscholar/PaperDetails.java | 9 +++-- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/CitationRelationsTab.java b/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/CitationRelationsTab.java index b3027a6f9b5..60121d67348 100644 --- a/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/CitationRelationsTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/CitationRelationsTab.java @@ -28,6 +28,7 @@ import org.jabref.gui.Globals; import org.jabref.gui.LibraryTab; import org.jabref.gui.StateManager; +import org.jabref.gui.desktop.JabRefDesktop; import org.jabref.gui.entryeditor.EntryEditorPreferences; import org.jabref.gui.entryeditor.EntryEditorTab; import org.jabref.gui.entryeditor.citationrelationtab.semanticscholar.CitationFetcher; @@ -40,6 +41,8 @@ import org.jabref.logic.l10n.Localization; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.field.StandardField; +import org.jabref.model.strings.StringUtil; import org.jabref.model.util.FileUpdateMonitor; import org.jabref.preferences.PreferencesService; @@ -201,6 +204,28 @@ private void styleFetchedListView(CheckListView listView) HBox hContainer = new HBox(); hContainer.prefWidthProperty().bind(listView.widthProperty().subtract(25)); + VBox vContainer = new VBox(); + + Button openWeb = IconTheme.JabRefIcons.OPEN_LINK.asButton(); + openWeb.setTooltip(new Tooltip(Localization.lang("Go to website"))); + openWeb.setOnMouseClicked(event -> { + String url = null; + if (entry.entry().getDOI().isPresent() && entry.entry().getDOI().get().getExternalURI().isPresent()) { + url = entry.entry().getDOI().get().getExternalURI().get().toString(); + } else if (entry.entry().getField(StandardField.URL).isPresent()) { + url = entry.entry().getField(StandardField.URL).get(); + } + if (StringUtil.isNullOrEmpty(url)) { + return; + } + + try { + JabRefDesktop.openBrowser(url, preferencesService.getFilePreferences()); + } catch (java.io.IOException ex) { + dialogService.notify(Localization.lang("Unable to open link.")); + } + }); + if (entry.isLocal()) { Button jumpTo = IconTheme.JabRefIcons.LINK.asButton(); jumpTo.setTooltip(new Tooltip(Localization.lang("Jump to entry in library"))); @@ -211,7 +236,7 @@ private void styleFetchedListView(CheckListView listView) citingTask.cancel(); citedByTask.cancel(); }); - hContainer.getChildren().addAll(entryNode, separator, jumpTo); + vContainer.getChildren().add(jumpTo); } else { ToggleButton addToggle = IconTheme.JabRefIcons.ADD.asToggleButton(); addToggle.setTooltip(new Tooltip(Localization.lang("Select entry"))); @@ -224,8 +249,12 @@ private void styleFetchedListView(CheckListView listView) }); addToggle.getStyleClass().add("addEntryButton"); addToggle.selectedProperty().bindBidirectional(listView.getItemBooleanProperty(entry)); - hContainer.getChildren().addAll(entryNode, separator, addToggle); + vContainer.getChildren().add(addToggle); } + + vContainer.getChildren().addLast(openWeb); + + hContainer.getChildren().addAll(entryNode, separator, vContainer); hContainer.getStyleClass().add("entry-container"); return hContainer; diff --git a/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/semanticscholar/PaperDetails.java b/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/semanticscholar/PaperDetails.java index 1bc86438cd2..f07af6add5e 100644 --- a/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/semanticscholar/PaperDetails.java +++ b/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/semanticscholar/PaperDetails.java @@ -114,8 +114,13 @@ public String getPublicationType() { } public String getDOI() { - if (externalIds != null && externalIds.containsKey("DOI")) { - return externalIds.get("DOI"); + if (externalIds != null) { + if (externalIds.containsKey("DOI")) { + return externalIds.get("DOI"); + } else if (externalIds.containsKey("ArXiv")) { + // Some ArXiv articles don't return the DOI, even though it's easy to obtain from the ArXiv ID + return "10.48550/arXiv." + externalIds.get("ArXiv"); + } } return ""; } From dc0a6bb302fa9dcda3f1da825be711643be1c037 Mon Sep 17 00:00:00 2001 From: "Roc R. Currius" Date: Wed, 13 Mar 2024 13:53:45 +0000 Subject: [PATCH 04/10] Don't show the open link button if there is no link to open. --- .../CitationRelationsTab.java | 44 ++++++++++--------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/CitationRelationsTab.java b/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/CitationRelationsTab.java index 60121d67348..94a34f38331 100644 --- a/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/CitationRelationsTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/CitationRelationsTab.java @@ -206,26 +206,6 @@ private void styleFetchedListView(CheckListView listView) VBox vContainer = new VBox(); - Button openWeb = IconTheme.JabRefIcons.OPEN_LINK.asButton(); - openWeb.setTooltip(new Tooltip(Localization.lang("Go to website"))); - openWeb.setOnMouseClicked(event -> { - String url = null; - if (entry.entry().getDOI().isPresent() && entry.entry().getDOI().get().getExternalURI().isPresent()) { - url = entry.entry().getDOI().get().getExternalURI().get().toString(); - } else if (entry.entry().getField(StandardField.URL).isPresent()) { - url = entry.entry().getField(StandardField.URL).get(); - } - if (StringUtil.isNullOrEmpty(url)) { - return; - } - - try { - JabRefDesktop.openBrowser(url, preferencesService.getFilePreferences()); - } catch (java.io.IOException ex) { - dialogService.notify(Localization.lang("Unable to open link.")); - } - }); - if (entry.isLocal()) { Button jumpTo = IconTheme.JabRefIcons.LINK.asButton(); jumpTo.setTooltip(new Tooltip(Localization.lang("Jump to entry in library"))); @@ -252,7 +232,29 @@ private void styleFetchedListView(CheckListView listView) vContainer.getChildren().add(addToggle); } - vContainer.getChildren().addLast(openWeb); + if (entry.entry().getDOI().isPresent() || entry.entry().getField(StandardField.URL).isPresent()) { + Button openWeb = IconTheme.JabRefIcons.OPEN_LINK.asButton(); + openWeb.setTooltip(new Tooltip(Localization.lang("Go to website"))); + openWeb.setOnMouseClicked(event -> { + String url = null; + if (entry.entry().getDOI().isPresent() && entry.entry().getDOI().get().getExternalURI().isPresent()) { + url = entry.entry().getDOI().get().getExternalURI().get().toString(); + } else if (entry.entry().getField(StandardField.URL).isPresent()) { + url = entry.entry().getField(StandardField.URL).get(); + } + if (StringUtil.isNullOrEmpty(url)) { + return; + } + + try { + JabRefDesktop.openBrowser(url, preferencesService.getFilePreferences()); + } catch ( + java.io.IOException ex) { + dialogService.notify(Localization.lang("Unable to open link.")); + } + }); + vContainer.getChildren().addLast(openWeb); + } hContainer.getChildren().addAll(entryNode, separator, vContainer); hContainer.getStyleClass().add("entry-container"); From 9e6dd3e07f2bced8287de8a5ec7ec5b5fab74633 Mon Sep 17 00:00:00 2001 From: "Roc R. Currius" Date: Wed, 13 Mar 2024 14:53:14 +0000 Subject: [PATCH 05/10] Make field value null error a bit more useful --- src/main/java/org/jabref/model/entry/BibEntry.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/model/entry/BibEntry.java b/src/main/java/org/jabref/model/entry/BibEntry.java index a8c940fb3bb..fda346e2302 100644 --- a/src/main/java/org/jabref/model/entry/BibEntry.java +++ b/src/main/java/org/jabref/model/entry/BibEntry.java @@ -602,7 +602,7 @@ public void setField(Map fields) { */ public Optional setField(Field field, String value, EntriesEventSource eventSource) { Objects.requireNonNull(field, "field name must not be null"); - Objects.requireNonNull(value, "field value must not be null"); + Objects.requireNonNull(value, "field value for field " + field.getName() + " must not be null"); Objects.requireNonNull(eventSource, "field eventSource must not be null"); if (value.isEmpty()) { From eb642064be8f78af62db31b8fc3356f8d53a70e1 Mon Sep 17 00:00:00 2001 From: "Roc R. Currius" Date: Wed, 13 Mar 2024 14:57:06 +0000 Subject: [PATCH 06/10] Include SemanticScholar url in the request and use it as the URL field. --- .../semanticscholar/PaperDetails.java | 17 ++++++++++++++++- .../semanticscholar/SemanticScholarFetcher.java | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/semanticscholar/PaperDetails.java b/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/semanticscholar/PaperDetails.java index f07af6add5e..58ba269616e 100644 --- a/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/semanticscholar/PaperDetails.java +++ b/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/semanticscholar/PaperDetails.java @@ -17,6 +17,7 @@ public class PaperDetails { @SerializedName("abstract") private String abstr; + private String url; private int citationCount; private int referenceCount; private List authors; @@ -55,6 +56,14 @@ public void setAbstract(String abstr) { this.abstr = abstr; } + public String getURL() { + return url; + } + + public void setURL(String url) { + this.url = url; + } + public int getCitationCount() { return citationCount; } @@ -139,7 +148,13 @@ public BibEntry toBibEntry() { bibEntry.setType(StandardEntryType.valueOf(getPublicationType())); - bibEntry.setField(StandardField.DOI, getDOI()); + if (getDOI() != null) { + bibEntry.setField(StandardField.DOI, getDOI()); + } + + if (getURL() != null) { + bibEntry.setField(StandardField.URL, getURL()); + } if (getAbstract() != null) { bibEntry.setField(StandardField.ABSTRACT, getAbstract()); diff --git a/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/semanticscholar/SemanticScholarFetcher.java b/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/semanticscholar/SemanticScholarFetcher.java index dd93167eae0..781376b5043 100644 --- a/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/semanticscholar/SemanticScholarFetcher.java +++ b/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/semanticscholar/SemanticScholarFetcher.java @@ -31,7 +31,7 @@ public String getAPIUrl(String entry_point, BibEntry entry) { .append("DOI:").append(entry.getDOI().orElseThrow().getDOI()) .append("/").append(entry_point) .append("?fields=") - .append("title,authors,year,citationCount,referenceCount,externalIds,publicationTypes,abstract") + .append("title,authors,year,citationCount,referenceCount,externalIds,publicationTypes,abstract,url") .append("&limit=1000").toString(); } From 753d5c699584f28c66ef272eedba0b09048c3197 Mon Sep 17 00:00:00 2001 From: "Roc R. Currius" Date: Wed, 13 Mar 2024 15:06:49 +0000 Subject: [PATCH 07/10] Add changes to changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 333e46dc805..4622b379815 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv - We enhanced the dialog for adding new fields in the content selector with a selection box containing a list of standard fields. [#10912](https://github.com/JabRef/jabref/pull/10912) - We store the citation relations in an LRU cache to avoid bloating the memory and out-of-memory exceptions. [#10958](https://github.com/JabRef/jabref/issues/10958) - Keywords filed are now displayed as tags. [#10910](https://github.com/JabRef/jabref/pull/10910) +- Citation relations now get more information, and have quick access to view the articles in a browser without adding them to the library [#10869](https://github.com/JabRef/jabref/issues/10869) ### Fixed From 52f6a33efb54102937646aab4a007937c969ca5a Mon Sep 17 00:00:00 2001 From: "Roc R. Currius" Date: Wed, 13 Mar 2024 15:21:00 +0000 Subject: [PATCH 08/10] Change tooltip text to an existing, more informative one --- .../entryeditor/citationrelationtab/CitationRelationsTab.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/CitationRelationsTab.java b/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/CitationRelationsTab.java index 94a34f38331..26984a3a50d 100644 --- a/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/CitationRelationsTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/CitationRelationsTab.java @@ -234,7 +234,7 @@ private void styleFetchedListView(CheckListView listView) if (entry.entry().getDOI().isPresent() || entry.entry().getField(StandardField.URL).isPresent()) { Button openWeb = IconTheme.JabRefIcons.OPEN_LINK.asButton(); - openWeb.setTooltip(new Tooltip(Localization.lang("Go to website"))); + openWeb.setTooltip(new Tooltip(Localization.lang("Open URL or DOI"))); openWeb.setOnMouseClicked(event -> { String url = null; if (entry.entry().getDOI().isPresent() && entry.entry().getDOI().get().getExternalURI().isPresent()) { From dca1e6580c2211b51cb28de4d508b2231a7e4754 Mon Sep 17 00:00:00 2001 From: "Roc R. Currius" Date: Wed, 13 Mar 2024 17:10:44 +0000 Subject: [PATCH 09/10] Run rewriter to fix pull request --- .../citationrelationtab/CitationRelationsTab.java | 5 ++--- .../semanticscholar/SemanticScholarFetcher.java | 10 +++------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/CitationRelationsTab.java b/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/CitationRelationsTab.java index 26984a3a50d..d7ebe81ca38 100644 --- a/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/CitationRelationsTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/CitationRelationsTab.java @@ -1,5 +1,6 @@ package org.jabref.gui.entryeditor.citationrelationtab; +import java.io.IOException; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; @@ -249,7 +250,7 @@ private void styleFetchedListView(CheckListView listView) try { JabRefDesktop.openBrowser(url, preferencesService.getFilePreferences()); } catch ( - java.io.IOException ex) { + IOException ex) { dialogService.notify(Localization.lang("Unable to open link.")); } }); @@ -423,8 +424,6 @@ private void showNodes(Node... nodes) { Arrays.stream(nodes).forEach(node -> node.setVisible(true)); } - // Absolute-phase phenomena in photoionization with few-cycle laser pulses - /** * Function to import selected entries to the database. Also writes the entries to import to the CITING/CITED field * diff --git a/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/semanticscholar/SemanticScholarFetcher.java b/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/semanticscholar/SemanticScholarFetcher.java index 781376b5043..1463d22aa9c 100644 --- a/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/semanticscholar/SemanticScholarFetcher.java +++ b/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/semanticscholar/SemanticScholarFetcher.java @@ -26,13 +26,9 @@ public SemanticScholarFetcher(ImporterPreferences importerPreferences) { } public String getAPIUrl(String entry_point, BibEntry entry) { - return new StringBuilder(SEMANTIC_SCHOLAR_API) - .append("paper/") - .append("DOI:").append(entry.getDOI().orElseThrow().getDOI()) - .append("/").append(entry_point) - .append("?fields=") - .append("title,authors,year,citationCount,referenceCount,externalIds,publicationTypes,abstract,url") - .append("&limit=1000").toString(); + return SEMANTIC_SCHOLAR_API + "paper/" + "DOI:" + entry.getDOI().orElseThrow().getDOI() + "/" + entry_point + + "?fields=" + "title,authors,year,citationCount,referenceCount,externalIds,publicationTypes,abstract,url" + + "&limit=1000"; } @Override From 75f6da69bf292d3c0af25a76aa8ce28e5609a5bc Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Mon, 18 Mar 2024 18:04:40 +0100 Subject: [PATCH 10/10] improve url optional handling --- .../citationrelationtab/CitationRelationsTab.java | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/CitationRelationsTab.java b/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/CitationRelationsTab.java index d7ebe81ca38..7f8fc40d15c 100644 --- a/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/CitationRelationsTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/citationrelationtab/CitationRelationsTab.java @@ -1,6 +1,7 @@ package org.jabref.gui.entryeditor.citationrelationtab; import java.io.IOException; +import java.net.URI; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; @@ -43,6 +44,7 @@ import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.StandardField; +import org.jabref.model.entry.identifier.DOI; import org.jabref.model.strings.StringUtil; import org.jabref.model.util.FileUpdateMonitor; import org.jabref.preferences.PreferencesService; @@ -237,20 +239,14 @@ private void styleFetchedListView(CheckListView listView) Button openWeb = IconTheme.JabRefIcons.OPEN_LINK.asButton(); openWeb.setTooltip(new Tooltip(Localization.lang("Open URL or DOI"))); openWeb.setOnMouseClicked(event -> { - String url = null; - if (entry.entry().getDOI().isPresent() && entry.entry().getDOI().get().getExternalURI().isPresent()) { - url = entry.entry().getDOI().get().getExternalURI().get().toString(); - } else if (entry.entry().getField(StandardField.URL).isPresent()) { - url = entry.entry().getField(StandardField.URL).get(); - } + String url = entry.entry().getDOI().flatMap(DOI::getExternalURI).map(URI::toString) + .or(() -> entry.entry().getField(StandardField.URL)).orElse(""); if (StringUtil.isNullOrEmpty(url)) { return; } - try { JabRefDesktop.openBrowser(url, preferencesService.getFilePreferences()); - } catch ( - IOException ex) { + } catch (IOException ex) { dialogService.notify(Localization.lang("Unable to open link.")); } });