Skip to content

Commit

Permalink
Improve MathSciNet fetcher and add ISBN fetcher to entry editor toolbar
Browse files Browse the repository at this point in the history
Makes the MathSciNet fetcher more reliable in the case the entry already contains a mrnumber.
Moreover, adds the ISBN fetcher to the list of fetcher available under "Update with bibliographic information from the web" in the entry editor toolbar.
  • Loading branch information
tobiasdiez committed Oct 31, 2018
1 parent 274fed4 commit e843eb2
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 28 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ̀<kbd>alt</kbd> + <kbd>up/down</kbd>.
- 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)
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/jabref/logic/importer/WebFetchers.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public static List<EntryBasedFetcher> getEntryBasedFetchers(ImportFormatPreferen
ArrayList<EntryBasedFetcher> 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));
Expand Down
38 changes: 23 additions & 15 deletions src/main/java/org/jabref/logic/importer/fetcher/IsbnFetcher.java
Original file line number Diff line number Diff line change
@@ -1,36 +1,42 @@
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
public String getName() {
return "ISBN";
}

/**
* Method never used
*/
@Override
public URL getURLForID(String identifier) throws URISyntaxException, MalformedURLException, FetcherException {
return null;
public Optional<HelpFile> getHelpPage() {
return Optional.of(HelpFile.FETCHER_ISBN);
}

@Override
Expand All @@ -39,8 +45,6 @@ public Optional<BibEntry> performSearchById(String identifier) throws FetcherExc
return Optional.empty();
}

this.ensureThatIsbnIsValid(identifier);

IsbnViaEbookDeFetcher isbnViaEbookDeFetcher = new IsbnViaEbookDeFetcher(importFormatPreferences);
Optional<BibEntry> bibEntry = isbnViaEbookDeFetcher.performSearchById(identifier);
// nothing found at ebook.de, try chimbori.com
Expand All @@ -55,8 +59,12 @@ public Optional<BibEntry> performSearchById(String identifier) throws FetcherExc
}

@Override
public void doPostCleanup(BibEntry entry) {
// no action needed
public List<BibEntry> performSearch(BibEntry entry) throws FetcherException {
Optional<String> isbn = entry.getField(FieldName.ISBN);
if (isbn.isPresent()) {
return OptionalUtil.toList(performSearchById(isbn.get()));
} else {
return Collections.emptyList();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -52,6 +53,12 @@ public String getName() {
*/
@Override
public URL getURLForEntry(BibEntry entry) throws URISyntaxException, MalformedURLException, FetcherException {
Optional<String> 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");

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
Expand All @@ -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<BibEntry> fetchedEntry = fetcher.performSearchById("0134685997");
assertEquals(Optional.of(bibEntry), fetchedEntry);
}

@Test
public void searchByIdSuccessfulWithLongISBN() throws FetcherException {
void searchByIdSuccessfulWithLongISBN() throws FetcherException {
Optional<BibEntry> fetchedEntry = fetcher.performSearchById("9780134685991");
assertEquals(Optional.of(bibEntry), fetchedEntry);
}

@Test
public void searchByIdReturnsEmptyWithEmptyISBN() throws FetcherException {
void searchByIdReturnsEmptyWithEmptyISBN() throws FetcherException {
Optional<BibEntry> 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<BibEntry> 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<BibEntry> fetchedEntry = fetcher.performSearchById("3728128155");
assertNotEquals(Optional.empty(), fetchedEntry);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jabref.logic.importer.fetcher;

import java.util.Collections;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -55,8 +56,16 @@ void searchByEntryFindsEntry() throws Exception {
searchEntry.setField("journal", "fluid");

List<BibEntry> 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<BibEntry> fetchedEntries = fetcher.performSearch(searchEntry);
assertEquals(Collections.singletonList(ratiuEntry), fetchedEntries);
}

@Test
Expand Down

0 comments on commit e843eb2

Please sign in to comment.