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

Updates unirest and removes org.json dependency #5511

Merged
merged 35 commits into from
Oct 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
cd8a19d
Changed performSearch to default implementation
Oct 22, 2019
bbe2618
Added new ADS fetcher
Oct 22, 2019
167a617
Added new ADS fetcher
Oct 23, 2019
7279e1b
Added new ADS fetcher
Oct 23, 2019
329d1dd
added cleanup
Oct 23, 2019
605519d
support doi and ads bibcodes
Oct 23, 2019
cba7829
fixes wrong search syntax
Oct 23, 2019
bd6d845
fixed test cases to API response
Oct 23, 2019
27243ed
fixed bug where equals doesnt work with unknown field
Oct 23, 2019
8910676
changed array method parameters to Collections
Oct 24, 2019
b811c0b
removes json module dependency
Oct 24, 2019
638dd94
replace old fetcher with the new one
Oct 24, 2019
c9f46df
replace old fetcher with the new one
Oct 24, 2019
9319bb1
added Javadoc
Oct 24, 2019
6e81ed0
Add token
tobiasdiez Oct 24, 2019
c26612f
updated unirest version and removes org.json dependency
Oct 24, 2019
d5764fb
updated unirest version and removes org.json dependency
Oct 25, 2019
f4b164d
updated unirest version and removes org.json dependency
Oct 25, 2019
5405c53
Changed performSearch to default implementation
Oct 22, 2019
9d5b0b7
Added new ADS fetcher
Oct 22, 2019
0db18f9
Added new ADS fetcher
Oct 23, 2019
c82c4ff
Added new ADS fetcher
Oct 23, 2019
8435c6c
added cleanup
Oct 23, 2019
339df67
support doi and ads bibcodes
Oct 23, 2019
b6a8fea
fixes wrong search syntax
Oct 23, 2019
d2edeed
fixed test cases to API response
Oct 23, 2019
bbcac7b
fixed bug where equals doesnt work with unknown field
Oct 23, 2019
3871673
changed array method parameters to Collections
Oct 24, 2019
1298d0f
removes json module dependency
Oct 24, 2019
50be88b
replace old fetcher with the new one
Oct 24, 2019
972b025
replace old fetcher with the new one
Oct 24, 2019
6a94854
updated unirest version and removes org.json dependency
Oct 24, 2019
eecbb0e
updated unirest version and removes org.json dependency
Oct 25, 2019
0d9fa0a
updated unirest version and removes org.json dependency
Oct 25, 2019
ae9680c
Merge remote-tracking branch 'origin/fixjson' into fixjson
Oct 28, 2019
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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ dependencies {
compile 'org.controlsfx:controlsfx:11.0.0'

compile 'org.jsoup:jsoup:1.12.1'
compile 'com.mashape.unirest:unirest-java:1.4.9'
compile 'com.konghq:unirest-java:3.1.03'

compile 'org.slf4j:slf4j-api:2.0.0-alpha1'
compile group: 'org.apache.logging.log4j', name: 'log4j-jcl', version: '3.0.0-SNAPSHOT'
Expand Down
4 changes: 2 additions & 2 deletions external-libraries.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ Project: pgjdbc-ng
URL: http://impossibl.github.io/pgjdbc-ng
License: BSD-3-Clause

Id: com.mashape.unirest
Id: com.konghq.unirest
Project: Unirest for Java
URL: https://github.com/Mashape/unirest-java
URL: https://github.com/Kong/unirest-java
License: MIT

Id: com.microsoft.azure:applicationinsights-core
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
requires org.apache.pdfbox;
requires reactfx;
requires commons.cli;
requires httpclient;
requires com.github.tomtung.latex2unicode;
requires jbibtex;
requires citeproc.java;
Expand All @@ -65,4 +64,6 @@
requires de.saxsys.mvvmfx.validation;
requires richtextfx;
requires unirest.java;
requires org.apache.httpcomponents.httpclient;
requires org.jsoup;
}
7 changes: 2 additions & 5 deletions src/main/java/org/jabref/Globals.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.jabref;

import java.awt.GraphicsEnvironment;
import java.io.IOException;
import java.util.Optional;
import java.util.UUID;

Expand All @@ -26,11 +25,11 @@
import org.jabref.preferences.JabRefPreferences;

import com.google.common.base.StandardSystemProperty;
import com.mashape.unirest.http.Unirest;
import com.microsoft.applicationinsights.TelemetryClient;
import com.microsoft.applicationinsights.TelemetryConfiguration;
import com.microsoft.applicationinsights.internal.shutdown.SDKShutdownActivity;
import com.microsoft.applicationinsights.telemetry.SessionState;
import kong.unirest.Unirest;

public class Globals {

Expand Down Expand Up @@ -127,9 +126,7 @@ public static void shutdownThreadPools() {

public static void stopBackgroundTasks() {
stopTelemetryClient();
try {
Unirest.shutdown();
} catch (IOException ignore) { }
Unirest.shutDown();
}

public static Optional<TelemetryClient> getTelemetryClient() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
import org.jabref.model.strings.StringUtil;
import org.jabref.model.util.DummyFileUpdateMonitor;

import kong.unirest.json.JSONArray;
import kong.unirest.json.JSONException;
import kong.unirest.json.JSONObject;
import org.apache.http.client.utils.URIBuilder;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
* Fetches data from the SAO/NASA Astrophysics Data System (https://ui.adsabs.harvard.edu/)
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/jabref/logic/importer/fetcher/CrossRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
import org.jabref.model.entry.types.StandardEntryType;
import org.jabref.model.util.OptionalUtil;

import kong.unirest.json.JSONArray;
import kong.unirest.json.JSONException;
import kong.unirest.json.JSONObject;
import org.apache.http.client.utils.URIBuilder;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
* A class for fetching DOIs from CrossRef
Expand Down
42 changes: 21 additions & 21 deletions src/main/java/org/jabref/logic/importer/fetcher/DOAJFetcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import org.jabref.model.entry.types.StandardEntryType;
import org.jabref.model.strings.StringUtil;

import kong.unirest.json.JSONArray;
import kong.unirest.json.JSONObject;
import org.apache.http.client.utils.URIBuilder;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -153,25 +153,6 @@ public static BibEntry parseBibJSONtoBibtex(JSONObject bibJsonEntry, Character k
return entry;
}

@Override
public String getName() {
return "DOAJ";
}

@Override
public Optional<HelpFile> getHelpPage() {
return Optional.of(HelpFile.FETCHER_DOAJ);
}

@Override
public URL getURLForQuery(String query) throws URISyntaxException, MalformedURLException, FetcherException {
URIBuilder uriBuilder = new URIBuilder(SEARCH_URL);
DOAJFetcher.addPath(uriBuilder, query);
uriBuilder.addParameter("pageSize", "30"); // Number of results
//uriBuilder.addParameter("page", "1"); // Page (not needed so far)
return uriBuilder.build().toURL();
}

/**
* @implNote slightly altered version based on https://gist.github.com/enginer/230e2dc2f1d213a825d5
*/
Expand All @@ -196,6 +177,25 @@ private static String appendSegmentToPath(String path, String segment) {
return path + "/" + segment;
}

@Override
public String getName() {
return "DOAJ";
}

@Override
public Optional<HelpFile> getHelpPage() {
return Optional.of(HelpFile.FETCHER_DOAJ);
}

@Override
public URL getURLForQuery(String query) throws URISyntaxException, MalformedURLException, FetcherException {
URIBuilder uriBuilder = new URIBuilder(SEARCH_URL);
DOAJFetcher.addPath(uriBuilder, query);
uriBuilder.addParameter("pageSize", "30"); // Number of results
//uriBuilder.addParameter("page", "1"); // Page (not needed so far)
return uriBuilder.build().toURL();
}

@Override
public Parser getParser() {
return inputStream -> {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/logic/importer/fetcher/IEEE.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
import org.jabref.model.entry.identifier.DOI;
import org.jabref.model.entry.types.StandardEntryType;

import kong.unirest.json.JSONArray;
import kong.unirest.json.JSONObject;
import org.apache.http.client.utils.URIBuilder;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
import org.jabref.model.entry.field.StandardField;
import org.jabref.model.strings.StringUtil;

import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
import kong.unirest.RawResponse;
import kong.unirest.Unirest;
import kong.unirest.UnirestException;

/**
* Fetcher for ISBN using https://bibtex.chimbori.com/, which in turn uses Amazon's API.
*/
public class IsbnViaChimboriFetcher extends AbstractIsbnFetcher {
private RawResponse postResponse;

public IsbnViaChimboriFetcher(ImportFormatPreferences importFormatPreferences) {
super(importFormatPreferences);
Expand All @@ -47,21 +48,21 @@ public Optional<BibEntry> performSearchById(String identifier) throws FetcherExc

this.ensureThatIsbnIsValid(identifier);

HttpResponse<String> postResponse;
postResponse = null;
try {
postResponse = Unirest.post("https://bibtex.chimbori.com/isbn-bibtex")
.field("isbn", identifier)
.asString();
Unirest.post("https://bibtex.chimbori.com/isbn-bibtex")
.field("isbn", identifier)
.thenConsume(rawResponse -> postResponse = rawResponse);
} catch (UnirestException e) {
throw new FetcherException("Could not retrieve data from chimbori.com", e);
}
if (postResponse.getStatus() != 200) {
throw new FetcherException("Error while retrieving data from chimbori.com: " + postResponse.getBody());
throw new FetcherException("Error while retrieving data from chimbori.com: " + postResponse.getContentAsString());
}

List<BibEntry> fetchedEntries;
try {
fetchedEntries = getParser().parseEntries(postResponse.getRawBody());
fetchedEntries = getParser().parseEntries(postResponse.getContent());
} catch (ParseException e) {
throw new FetcherException("An internal parser error occurred", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
import org.jabref.model.entry.field.StandardField;
import org.jabref.model.entry.identifier.DOI;

import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
import org.json.JSONObject;
import kong.unirest.HttpResponse;
import kong.unirest.JsonNode;
import kong.unirest.Unirest;
import kong.unirest.UnirestException;
import kong.unirest.json.JSONObject;

/**
* A fulltext fetcher that uses <a href="https://oadoi.org/">oaDOI</a>.
Expand Down Expand Up @@ -49,8 +49,8 @@ public TrustLevel getTrustLevel() {

public Optional<URL> findFullText(DOI doi) throws UnirestException, MalformedURLException {
HttpResponse<JsonNode> jsonResponse = Unirest.get(API_URL + doi.getDOI() + "?email=developers@jabref.org")
.header("accept", "application/json")
.asJson();
.header("accept", "application/json")
.asJson();
JSONObject root = jsonResponse.getBody().getObject();
Optional<String> url = Optional.ofNullable(root.optJSONObject("best_oa_location"))
.map(location -> location.optString("url"));
Expand Down
28 changes: 14 additions & 14 deletions src/main/java/org/jabref/logic/importer/fetcher/ScienceDirect.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
import org.jabref.model.entry.field.StandardField;
import org.jabref.model.entry.identifier.DOI;

import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import kong.unirest.HttpResponse;
import kong.unirest.JsonNode;
import kong.unirest.Unirest;
import kong.unirest.UnirestException;
import kong.unirest.json.JSONArray;
import kong.unirest.json.JSONException;
import kong.unirest.json.JSONObject;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
Expand All @@ -28,7 +28,7 @@
/**
* FulltextFetcher implementation that attempts to find a PDF URL at ScienceDirect.
*
* @see http://dev.elsevier.com/
* @see 'https://dev.elsevier.com/'
*/
public class ScienceDirect implements FulltextFetcher {
private static final Logger LOGGER = LoggerFactory.getLogger(ScienceDirect.class);
Expand All @@ -50,9 +50,9 @@ public Optional<URL> findFullText(BibEntry entry) throws IOException {
// scrape the web page not as mobile client!
if (!sciLink.isEmpty()) {
Document html = Jsoup.connect(sciLink)
.userAgent(URLDownload.USER_AGENT)
.referrer("http://www.google.com")
.ignoreHttpErrors(true).get();
.userAgent(URLDownload.USER_AGENT)
.referrer("http://www.google.com")
.ignoreHttpErrors(true).get();

// Retrieve PDF link from meta data (most recent)
Elements metaLinks = html.getElementsByAttributeValue("name", "citation_pdf_url");
Expand Down Expand Up @@ -98,9 +98,9 @@ private String getUrlByDoi(String doi) throws UnirestException {
try {
String request = API_URL + doi;
HttpResponse<JsonNode> jsonResponse = Unirest.get(request)
.header("X-ELS-APIKey", API_KEY)
.queryString("httpAccept", "application/json")
.asJson();
.header("X-ELS-APIKey", API_KEY)
.queryString("httpAccept", "application/json")
.asJson();

JSONObject json = jsonResponse.getBody().getObject();
JSONArray links = json.getJSONObject("full-text-retrieval-response").getJSONObject("coredata").getJSONArray("link");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import org.jabref.model.entry.field.StandardField;
import org.jabref.model.entry.types.StandardEntryType;

import kong.unirest.json.JSONArray;
import kong.unirest.json.JSONObject;
import org.apache.http.client.utils.URIBuilder;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
import org.jabref.model.entry.field.StandardField;
import org.jabref.model.entry.identifier.DOI;

import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
import org.json.JSONObject;
import kong.unirest.HttpResponse;
import kong.unirest.JsonNode;
import kong.unirest.Unirest;
import kong.unirest.UnirestException;
import kong.unirest.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -42,9 +42,9 @@ public Optional<URL> findFullText(BibEntry entry) throws IOException {
// Available in catalog?
try {
HttpResponse<JsonNode> jsonResponse = Unirest.get(API_URL)
.queryString("api_key", API_KEY)
.queryString("q", String.format("doi:%s", doi.get().getDOI()))
.asJson();
.queryString("api_key", API_KEY)
.queryString("q", String.format("doi:%s", doi.get().getDOI()))
.asJson();

JSONObject json = jsonResponse.getBody().getObject();
int results = json.getJSONArray("result").getJSONObject(0).getInt("total");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.StandardField;

import org.json.JSONException;
import org.json.JSONObject;
import kong.unirest.json.JSONException;
import kong.unirest.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import org.jabref.logic.importer.ParseException;

import org.json.JSONObject;
import kong.unirest.json.JSONObject;

/**
* Converts an {@link InputStream} into a {@link JSONObject}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
import org.jabref.logic.net.URLDownload;
import org.jabref.model.entry.identifier.DOI;

import kong.unirest.json.JSONException;
import kong.unirest.json.JSONObject;
import org.apache.http.client.utils.URIBuilder;
import org.json.JSONException;
import org.json.JSONObject;

/**
* Class for obtaining shortened DOI names.
*
* @see http://shortdoi.org
* @see 'https://shortdoi.org'
*/
public class ShortDOIService {

Expand Down
Loading