Skip to content
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

Adjust zbmath fetcher #7298

Merged
merged 7 commits into from
Jan 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve

### Added

- We added the possibility to add a new entry via its zbMath ID (zbMATH can be chosen as ID type in the "Select entry type" window). [#7202](https://github.com/JabRef/jabref/issues/7202)
- We added the extension support and the external application support (For Texshow, Texmaker and LyX) to the flatpak [#7248](https://github.com/JabRef/jabref/pull/7248)
- We added some symbols and keybindings to the context menu in the entry editor. [#7268](https://github.com/JabRef/jabref/pull/7268)

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 @@ -120,6 +120,7 @@ public static SortedSet<IdBasedFetcher> getIdBasedFetchers(ImportFormatPreferenc
set.add(new MedlineFetcher());
set.add(new TitleFetcher(importFormatPreferences));
set.add(new MathSciNet(importFormatPreferences));
set.add(new ZbMATH(importFormatPreferences));
set.add(new CrossRef());
set.add(new LibraryOfCongress(importFormatPreferences));
set.add(new IacrEprintFetcher(importFormatPreferences));
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/org/jabref/logic/importer/fetcher/ZbMATH.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.jabref.logic.cleanup.MoveFieldCleanup;
import org.jabref.logic.formatter.bibtexfields.RemoveBracesFormatter;
import org.jabref.logic.importer.FetcherException;
import org.jabref.logic.importer.IdBasedParserFetcher;
import org.jabref.logic.importer.ImportFormatPreferences;
import org.jabref.logic.importer.Parser;
import org.jabref.logic.importer.SearchBasedParserFetcher;
Expand All @@ -24,7 +25,7 @@
/**
* Fetches data from the Zentralblatt Math (https://www.zbmath.org/)
*/
public class ZbMATH implements SearchBasedParserFetcher {
public class ZbMATH implements SearchBasedParserFetcher, IdBasedParserFetcher {

private final ImportFormatPreferences preferences;

Expand Down Expand Up @@ -60,6 +61,19 @@ public URL getURLForQuery(String query) throws URISyntaxException, MalformedURLE
return uriBuilder.build().toURL();
}

@Override
public URL getUrlForIdentifier(String identifier) throws URISyntaxException, MalformedURLException, FetcherException {
URIBuilder uriBuilder = new URIBuilder("https://zbmath.org/bibtexoutput/");
String query = "an:".concat(identifier); // use an: to search for a zbMATH identifier
uriBuilder.addParameter("q", query);
uriBuilder.addParameter("start", "0"); // start index
uriBuilder.addParameter("count", "1"); // return exactly one item

URLDownload.bypassSSLVerification();

return uriBuilder.build().toURL();
}

@Override
public Parser getParser() {
return new BibtexParser(preferences, new DummyFileUpdateMonitor());
Expand Down
11 changes: 8 additions & 3 deletions src/test/java/org/jabref/logic/importer/fetcher/ZbMATHTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

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

import org.jabref.logic.bibtex.FieldContentFormatterPreferences;
import org.jabref.logic.importer.ImportFormatPreferences;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.StandardField;
import org.jabref.model.entry.field.UnknownField;
import org.jabref.model.entry.types.StandardEntryType;
import org.jabref.support.DisabledOnCIServer;
import org.jabref.testutils.category.FetcherTest;

import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -41,16 +41,21 @@ void setUp() throws Exception {
donaldsonEntry.setField(StandardField.KEYWORDS, "57N13 57R10 53C05 58J99 57R65");
donaldsonEntry.setField(StandardField.PAGES, "279--315");
donaldsonEntry.setField(StandardField.PUBLISHER, "International Press of Boston, Somerville, MA");
donaldsonEntry.setField(StandardField.TITLE, "An application of gauge theory to four dimensional topology.");
donaldsonEntry.setField(StandardField.TITLE, "An application of gauge theory to four dimensional topology");
donaldsonEntry.setField(StandardField.VOLUME, "18");
donaldsonEntry.setField(StandardField.YEAR, "1983");
donaldsonEntry.setField(new UnknownField("zbl"), "0507.57010");
}

@Test
@DisabledOnCIServer("CI server has no subscription to zbMath and thus gets 401 response")
void searchByQueryFindsEntry() throws Exception {
List<BibEntry> fetchedEntries = fetcher.performSearch("an:0507.57010");
assertEquals(Collections.singletonList(donaldsonEntry), fetchedEntries);
}

@Test
void searchByIdFindsEntry() throws Exception {
Optional<BibEntry> fetchedEntry = fetcher.performSearchById("0507.57010");
assertEquals(Optional.of(donaldsonEntry), fetchedEntry);
}
}