diff --git a/CHANGELOG.md b/CHANGELOG.md
index bab3e63099a..010b162e2f9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -28,6 +28,8 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- We changed the default keyboard shortcuts for moving between entries when the entry editor is active to ̀alt + up/down.
- Opening a new file now prompts the directory of the currently selected file, instead of the directory of the last opened file.
- Window state is saved on close and restored on start.
+- We made the MathSciNet fetcher more reliable.
+- We added the ISBN fetcher to the list of fetcher available under "Update with bibliographic information from the web" in the entry editor toolbar.
- Files without a defined external file type are now directly opened with the default application of the operating system
- We streamlined the process to rename and move files by removing the confirmation dialogs.
- We removed the redundant new lines of markings and wrapped the summary in the File annotation tab. [#3823](https://github.com/JabRef/jabref/issues/3823)
diff --git a/src/main/java/org/jabref/logic/importer/WebFetchers.java b/src/main/java/org/jabref/logic/importer/WebFetchers.java
index 3329a6215f2..c06849201f3 100644
--- a/src/main/java/org/jabref/logic/importer/WebFetchers.java
+++ b/src/main/java/org/jabref/logic/importer/WebFetchers.java
@@ -119,6 +119,7 @@ public static List getEntryBasedFetchers(ImportFormatPreferen
ArrayList list = new ArrayList<>();
list.add(new AstrophysicsDataSystem(importFormatPreferences));
list.add(new DoiFetcher(importFormatPreferences));
+ list.add(new IsbnFetcher(importFormatPreferences));
list.add(new MathSciNet(importFormatPreferences));
list.add(new CrossRef());
list.sort(Comparator.comparing(WebFetcher::getName));
diff --git a/src/main/java/org/jabref/logic/importer/fetcher/IsbnFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/IsbnFetcher.java
index 343d5e3e8cd..80612f0af83 100644
--- a/src/main/java/org/jabref/logic/importer/fetcher/IsbnFetcher.java
+++ b/src/main/java/org/jabref/logic/importer/fetcher/IsbnFetcher.java
@@ -1,23 +1,32 @@
package org.jabref.logic.importer.fetcher;
-import java.net.MalformedURLException;
-import java.net.URISyntaxException;
-import java.net.URL;
+import java.util.Collections;
+import java.util.List;
import java.util.Optional;
+import org.jabref.logic.help.HelpFile;
+import org.jabref.logic.importer.EntryBasedFetcher;
import org.jabref.logic.importer.FetcherException;
+import org.jabref.logic.importer.IdBasedFetcher;
import org.jabref.logic.importer.ImportFormatPreferences;
import org.jabref.model.entry.BibEntry;
+import org.jabref.model.entry.FieldName;
+import org.jabref.model.util.OptionalUtil;
import org.jsoup.helper.StringUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Fetcher for ISBN trying ebook.de first and then chimbori.com
*/
-public class IsbnFetcher extends AbstractIsbnFetcher {
+public class IsbnFetcher implements EntryBasedFetcher, IdBasedFetcher {
+
+ protected final ImportFormatPreferences importFormatPreferences;
+ Logger LOGGER = LoggerFactory.getLogger(IsbnFetcher.class);
public IsbnFetcher(ImportFormatPreferences importFormatPreferences) {
- super(importFormatPreferences);
+ this.importFormatPreferences = importFormatPreferences;
}
@Override
@@ -25,12 +34,9 @@ public String getName() {
return "ISBN";
}
- /**
- * Method never used
- */
@Override
- public URL getURLForID(String identifier) throws URISyntaxException, MalformedURLException, FetcherException {
- return null;
+ public Optional getHelpPage() {
+ return Optional.of(HelpFile.FETCHER_ISBN);
}
@Override
@@ -39,8 +45,6 @@ public Optional performSearchById(String identifier) throws FetcherExc
return Optional.empty();
}
- this.ensureThatIsbnIsValid(identifier);
-
IsbnViaEbookDeFetcher isbnViaEbookDeFetcher = new IsbnViaEbookDeFetcher(importFormatPreferences);
Optional bibEntry = isbnViaEbookDeFetcher.performSearchById(identifier);
// nothing found at ebook.de, try chimbori.com
@@ -55,8 +59,12 @@ public Optional performSearchById(String identifier) throws FetcherExc
}
@Override
- public void doPostCleanup(BibEntry entry) {
- // no action needed
+ public List performSearch(BibEntry entry) throws FetcherException {
+ Optional isbn = entry.getField(FieldName.ISBN);
+ if (isbn.isPresent()) {
+ return OptionalUtil.toList(performSearchById(isbn.get()));
+ } else {
+ return Collections.emptyList();
+ }
}
-
}
diff --git a/src/main/java/org/jabref/logic/importer/fetcher/MathSciNet.java b/src/main/java/org/jabref/logic/importer/fetcher/MathSciNet.java
index 603e84eac60..774d4155c00 100644
--- a/src/main/java/org/jabref/logic/importer/fetcher/MathSciNet.java
+++ b/src/main/java/org/jabref/logic/importer/fetcher/MathSciNet.java
@@ -8,6 +8,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
+import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@@ -52,6 +53,12 @@ public String getName() {
*/
@Override
public URL getURLForEntry(BibEntry entry) throws URISyntaxException, MalformedURLException, FetcherException {
+ Optional mrNumberInEntry = entry.getField(FieldName.MR_NUMBER);
+ if (mrNumberInEntry.isPresent()) {
+ // We are lucky and already know the id, so use it instead
+ return getURLForID(mrNumberInEntry.get());
+ }
+
URIBuilder uriBuilder = new URIBuilder("https://mathscinet.ams.org/mrlookup");
uriBuilder.addParameter("format", "bibtex");
diff --git a/src/test/java/org/jabref/logic/importer/fetcher/IsbnFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/IsbnFetcherTest.java
index ed140ff3dc8..bc39f08ebc1 100644
--- a/src/test/java/org/jabref/logic/importer/fetcher/IsbnFetcherTest.java
+++ b/src/test/java/org/jabref/logic/importer/fetcher/IsbnFetcherTest.java
@@ -1,5 +1,7 @@
package org.jabref.logic.importer.fetcher;
+import java.util.Collections;
+import java.util.List;
import java.util.Optional;
import org.jabref.logic.importer.FetcherException;
@@ -18,13 +20,13 @@
import static org.mockito.Mockito.mock;
@FetcherTest
-public class IsbnFetcherTest {
+class IsbnFetcherTest {
private IsbnFetcher fetcher;
private BibEntry bibEntry;
@BeforeEach
- public void setUp() {
+ void setUp() {
fetcher = new IsbnFetcher(mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS));
bibEntry = new BibEntry();
@@ -41,54 +43,61 @@ public void setUp() {
}
@Test
- public void testName() {
+ void testName() {
assertEquals("ISBN", fetcher.getName());
}
@Test
- public void testHelpPage() {
+ void testHelpPage() {
assertEquals("ISBNtoBibTeX", fetcher.getHelpPage().get().getPageName());
}
@Test
- public void searchByIdSuccessfulWithShortISBN() throws FetcherException {
+ void searchByIdSuccessfulWithShortISBN() throws FetcherException {
Optional fetchedEntry = fetcher.performSearchById("0134685997");
assertEquals(Optional.of(bibEntry), fetchedEntry);
}
@Test
- public void searchByIdSuccessfulWithLongISBN() throws FetcherException {
+ void searchByIdSuccessfulWithLongISBN() throws FetcherException {
Optional fetchedEntry = fetcher.performSearchById("9780134685991");
assertEquals(Optional.of(bibEntry), fetchedEntry);
}
@Test
- public void searchByIdReturnsEmptyWithEmptyISBN() throws FetcherException {
+ void searchByIdReturnsEmptyWithEmptyISBN() throws FetcherException {
Optional fetchedEntry = fetcher.performSearchById("");
assertEquals(Optional.empty(), fetchedEntry);
}
@Test
- public void searchByIdThrowsExceptionForShortInvalidISBN() {
+ void searchByIdThrowsExceptionForShortInvalidISBN() {
assertThrows(FetcherException.class, () -> fetcher.performSearchById("123456789"));
}
@Test
- public void searchByIdThrowsExceptionForLongInvalidISB() {
+ void searchByIdThrowsExceptionForLongInvalidISB() {
assertThrows(FetcherException.class, () -> fetcher.performSearchById("012345678910"));
}
@Test
- public void searchByIdThrowsExceptionForInvalidISBN() {
+ void searchByIdThrowsExceptionForInvalidISBN() {
assertThrows(FetcherException.class, () -> fetcher.performSearchById("jabref-4-ever"));
}
+ @Test
+ void searchByEntryWithISBNSuccessful() throws FetcherException {
+ BibEntry input = new BibEntry().withField("isbn", "0134685997");
+
+ List fetchedEntry = fetcher.performSearch(input);
+ assertEquals(Collections.singletonList(bibEntry), fetchedEntry);
+ }
/**
* This test searches for a valid ISBN. See https://www.amazon.de/dp/3728128155/?tag=jabref-21 However, this ISBN is
* not available on ebook.de. The fetcher should something as it falls back to Chimbori
*/
@Test
- public void searchForIsbnAvailableAtChimboriButNonOnEbookDe() throws FetcherException {
+ void searchForIsbnAvailableAtChimboriButNonOnEbookDe() throws FetcherException {
Optional fetchedEntry = fetcher.performSearchById("3728128155");
assertNotEquals(Optional.empty(), fetchedEntry);
}
diff --git a/src/test/java/org/jabref/logic/importer/fetcher/MathSciNetTest.java b/src/test/java/org/jabref/logic/importer/fetcher/MathSciNetTest.java
index e66d81f0948..cf938c036bb 100644
--- a/src/test/java/org/jabref/logic/importer/fetcher/MathSciNetTest.java
+++ b/src/test/java/org/jabref/logic/importer/fetcher/MathSciNetTest.java
@@ -1,5 +1,6 @@
package org.jabref.logic.importer.fetcher;
+import java.util.Collections;
import java.util.List;
import java.util.Optional;
@@ -55,8 +56,16 @@ void searchByEntryFindsEntry() throws Exception {
searchEntry.setField("journal", "fluid");
List fetchedEntries = fetcher.performSearch(searchEntry);
- assertFalse(fetchedEntries.isEmpty());
- assertEquals(ratiuEntry, fetchedEntries.get(0));
+ assertEquals(Collections.singletonList(ratiuEntry), fetchedEntries);
+ }
+
+ @Test
+ void searchByIdInEntryFindsEntry() throws Exception {
+ BibEntry searchEntry = new BibEntry();
+ searchEntry.setField("mrnumber", "3537908");
+
+ List fetchedEntries = fetcher.performSearch(searchEntry);
+ assertEquals(Collections.singletonList(ratiuEntry), fetchedEntries);
}
@Test