Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add accept header
Browse files Browse the repository at this point in the history
Siedlerchr committed Nov 4, 2023
1 parent 5c09c36 commit cd6d630
Showing 3 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -19,11 +19,13 @@
import org.jabref.logic.importer.PagedSearchBasedParserFetcher;
import org.jabref.logic.importer.Parser;
import org.jabref.logic.importer.fetcher.transformers.ISIDOREQueryTransformer;
import org.jabref.logic.net.URLDownload;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.StandardField;
import org.jabref.model.entry.types.EntryType;
import org.jabref.model.entry.types.StandardEntryType;

import jakarta.ws.rs.core.MediaType;
import org.apache.http.client.utils.URIBuilder;
import org.apache.lucene.queryparser.flexible.core.nodes.QueryNode;
import org.jooq.lambda.Unchecked;
@@ -46,8 +48,6 @@ public class ISIDOREFetcher implements PagedSearchBasedParserFetcher {

private static final String SOURCE_WEB_SEARCH = "https://api.isidore.science/resource/search";

private String URL;

private final DocumentBuilderFactory factory;

public ISIDOREFetcher() {
@@ -57,7 +57,6 @@ public ISIDOREFetcher() {
@Override
public Parser getParser() {
return xmlData -> {

try {
DocumentBuilder builder = this.factory.newDocumentBuilder();
Document document = builder.parse(xmlData);
@@ -80,13 +79,20 @@ public Parser getParser() {
};
}

@Override
public URLDownload getUrlDownload(URL url) {
URLDownload download = new URLDownload(url);
download.addHeader("Accept", MediaType.APPLICATION_XML);
return download;
}

@Override
public URL getURLForQuery(QueryNode luceneQuery, int pageNumber) throws URISyntaxException, MalformedURLException, FetcherException {
ISIDOREQueryTransformer queryTransformer = new ISIDOREQueryTransformer();
String transformedQuery = queryTransformer.transformLuceneQuery(luceneQuery).orElse("");
URIBuilder uriBuilder = new URIBuilder(SOURCE_WEB_SEARCH);
uriBuilder.addParameter("q", transformedQuery);
// uriBuilder.addParameter("page", String.valueOf(pageNumber));
// uriBuilder.addParameter("page", String.valueOf(pageNumber));
uriBuilder.addParameter("replies", String.valueOf(getPageSize()));
//uriBuilder.addParameter("lang", "en");
uriBuilder.addParameter("output", "xml");
@@ -115,8 +121,7 @@ private BibEntry xmlItemToBibEntry(Element itemElement) {
.withField(StandardField.YEAR, itemElement.getElementsByTagName("date").item(0).getChildNodes().item(1).getTextContent().substring(0, 4))
.withField(StandardField.JOURNAL, getJournal(itemElement.getElementsByTagName("dc:source")))
.withField(StandardField.PUBLISHER, getPublishers(itemElement.getElementsByTagName("publishers").item(0)))
.withField(StandardField.DOI, getDOI(itemElement.getElementsByTagName("ore").item(0).getChildNodes()))
.withField(StandardField.URL, this.URL);
.withField(StandardField.DOI, getDOI(itemElement.getElementsByTagName("ore").item(0).getChildNodes()));
}

private String getDOI(NodeList list) {
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.jabref.logic.importer.fetcher.transformers;

import org.jabref.model.strings.StringUtil;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@@ -28,7 +30,7 @@ protected String handleAuthor(String author) {

@Override
protected String handleTitle(String title) {
return createKeyValuePair("title", title);
return createKeyValuePair("title", StringUtil.quoteStringIfSpaceIsContained(title));
}

@Override
Original file line number Diff line number Diff line change
@@ -23,7 +23,6 @@ public void setup() {
this.fetcher = new ISIDOREFetcher();
}


@Test
public void checkArticleTest() throws FetcherException {
BibEntry expected = new BibEntry(StandardEntryType.Article)
@@ -35,7 +34,7 @@ public void checkArticleTest() throws FetcherException {
.withField(StandardField.DOI, "10.1016/j.tbs.2019.12.003")
.withField(StandardField.URL, "https://isidore.science/document/10670/1.hrzlqd");

List<BibEntry> actual = fetcher.performSearch("cnqrs");
List<BibEntry> actual = fetcher.performSearch("Investigating day-to-day variability of transit usage on a multimonth scale with smart card data. A case study in Lyon");

assertEquals(List.of(expected), actual);
}
@@ -59,7 +58,7 @@ public void checkArticle() throws FetcherException {
@Test
public void checkArticle2() throws FetcherException {
BibEntry expected = new BibEntry(StandardEntryType.Article)
.withField(StandardField.TITLE, " Anthony B. Atkinson, Inequality – What Can Be Done ? Cambridge (Mass.) Harvard University Press, 2015, XI-384 p. ")
.withField(StandardField.TITLE, "Inequality – What Can Be Done ? Cambridge (Mass.) Harvard University Press, 2015, XI-384 p. ")
.withField(StandardField.AUTHOR, "Benoît Rapoport")
.withField(StandardField.YEAR, "2016")
.withField(StandardField.JOURNAL, "Population (édition française)")
@@ -77,8 +76,7 @@ public void checkThesis() throws FetcherException {
BibEntry expected = new BibEntry(StandardEntryType.Thesis)
.withField(StandardField.TITLE, "Mapping English L2 errors : an integrated system and textual approach")
.withField(StandardField.AUTHOR, "Clive Hamilton")
.withField(StandardField.YEAR, "2015")
.withField(StandardField.URL, "https://isidore.science/document/10670/1.m05oth");
.withField(StandardField.YEAR, "2015");

List<BibEntry> actual = fetcher.performSearch("Mapping English L2 errors : an integrated system and textual approach");

0 comments on commit cd6d630

Please sign in to comment.