From 97055d17bdadf292579fa432d7b051195d78d551 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Thu, 22 Dec 2016 14:35:00 +0100 Subject: [PATCH 1/2] Fix #2417: DOI no longer contains URL --- CHANGELOG.md | 1 + .../logic/importer/fetcher/DoiFetcher.java | 16 +++++++++++----- .../logic/importer/fetcher/DoiFetcherTest.java | 2 -- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 844c4ea3e51..7bd96e4b5d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# - When using "Copy citation (HTML)" and pasting into a text editor, plain text is always pasted. - When using the "Download from URL" functionality, one is not limited to http(s) URLs, but can, for instance, enter ftp URLs. - When using the "Look up full text documents" functionality, JabRef warns more explicitly about multiple requests. +- The entry received from DOI does no longer contain the DOI as URL. Implements [#2417](https://github.com/JabRef/jabref/issues/2417). ### Fixed - Fixed [#2391](https://github.com/JabRef/jabref/issues/2391): Clicking on "Get Fulltext" button sets links correctly for the entry being edited. diff --git a/src/main/java/net/sf/jabref/logic/importer/fetcher/DoiFetcher.java b/src/main/java/net/sf/jabref/logic/importer/fetcher/DoiFetcher.java index d6b84c06a63..d4dcd7b4409 100644 --- a/src/main/java/net/sf/jabref/logic/importer/fetcher/DoiFetcher.java +++ b/src/main/java/net/sf/jabref/logic/importer/fetcher/DoiFetcher.java @@ -5,6 +5,7 @@ import java.nio.charset.StandardCharsets; import java.util.Optional; +import net.sf.jabref.logic.formatter.bibtexfields.ClearFormatter; import net.sf.jabref.logic.formatter.bibtexfields.NormalizePagesFormatter; import net.sf.jabref.logic.help.HelpFile; import net.sf.jabref.logic.importer.FetcherException; @@ -15,7 +16,9 @@ import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.logic.net.URLDownload; import net.sf.jabref.logic.util.DOI; +import net.sf.jabref.model.cleanup.FieldFormatterCleanup; import net.sf.jabref.model.entry.BibEntry; +import net.sf.jabref.model.entry.FieldName; public class DoiFetcher implements IdBasedFetcher { @@ -25,10 +28,6 @@ public DoiFetcher(ImportFormatPreferences preferences) { this.preferences = preferences; } - private String cleanupEncoding(String bibtex) { - return new NormalizePagesFormatter().format(bibtex); - } - @Override public String getName() { return "DOI"; @@ -53,7 +52,9 @@ public Optional performSearchById(String identifier) throws FetcherExc String bibtexString = download.downloadToString(StandardCharsets.UTF_8); // BibTeX entry - return BibtexParser.singleFromString(cleanupEncoding(bibtexString), preferences); + Optional fetchedEntry = BibtexParser.singleFromString(bibtexString, preferences); + fetchedEntry.ifPresent(this::doPostCleanup); + return fetchedEntry; } else { throw new FetcherException(Localization.lang("Invalid_DOI:_'%0'.", identifier)); } @@ -63,4 +64,9 @@ public Optional performSearchById(String identifier) throws FetcherExc throw new FetcherException("Could not parse BibTeX entry", e); } } + + private void doPostCleanup(BibEntry entry) { + new FieldFormatterCleanup(FieldName.PAGES, new NormalizePagesFormatter()).cleanup(entry); + new FieldFormatterCleanup(FieldName.URL, new ClearFormatter()).cleanup(entry); + } } diff --git a/src/test/java/net/sf/jabref/logic/importer/fetcher/DoiFetcherTest.java b/src/test/java/net/sf/jabref/logic/importer/fetcher/DoiFetcherTest.java index 1eb3d200ab1..5dc08dc7a70 100644 --- a/src/test/java/net/sf/jabref/logic/importer/fetcher/DoiFetcherTest.java +++ b/src/test/java/net/sf/jabref/logic/importer/fetcher/DoiFetcherTest.java @@ -34,7 +34,6 @@ public void setUp() { bibEntryBurd2011.setField("author", "Barry Burd"); bibEntryBurd2011.setField("month", "jul"); bibEntryBurd2011.setField("doi", "10.1002/9781118257517"); - bibEntryBurd2011.setField("url", "http://dx.doi.org/10.1002/9781118257517"); bibEntryDecker2007 = new BibEntry(); bibEntryDecker2007.setType(BibLatexEntryTypes.INPROCEEDINGS); @@ -44,7 +43,6 @@ public void setUp() { bibEntryDecker2007.setField("month", "jul"); bibEntryDecker2007.setField("publisher", "Institute of Electrical and Electronics Engineers ({IEEE})"); bibEntryDecker2007.setField("title", "{BPEL}4Chor: Extending {BPEL} for Modeling Choreographies"); - bibEntryDecker2007.setField("url", "http://dx.doi.org/10.1109/ICWS.2007.59"); bibEntryDecker2007.setField("year", "2007"); bibEntryDecker2007.setField("doi", "10.1109/icws.2007.59"); } From 011dbea68aeee8a6f6a5cd97489f8277e1f090fd Mon Sep 17 00:00:00 2001 From: Simon Harrer Date: Thu, 22 Dec 2016 14:31:43 +0100 Subject: [PATCH 2/2] Fixes tests again. --- .../net/sf/jabref/logic/importer/fetcher/TitleFetcherTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/net/sf/jabref/logic/importer/fetcher/TitleFetcherTest.java b/src/test/java/net/sf/jabref/logic/importer/fetcher/TitleFetcherTest.java index a8009f7e35a..08ed4fb6587 100644 --- a/src/test/java/net/sf/jabref/logic/importer/fetcher/TitleFetcherTest.java +++ b/src/test/java/net/sf/jabref/logic/importer/fetcher/TitleFetcherTest.java @@ -31,7 +31,6 @@ public void setUp() { bibEntryBischof2009.setField("booktitle", "2009 35th Euromicro Conference on Software Engineering and Advanced Applications"); bibEntryBischof2009.setField("publisher", "Institute of Electrical and Electronics Engineers ({IEEE})"); bibEntryBischof2009.setField("title", "{BPELscript}: A Simplified Script Syntax for {WS}-{BPEL} 2.0"); - bibEntryBischof2009.setField("url", "http://dx.doi.org/10.1109/seaa.2009.21"); bibEntryBischof2009.setField("year", "2009"); bibEntryBischof2009.setField("doi", "10.1109/seaa.2009.21"); }