From 83694b3d038fd3393a341e158afe9fd873da11a8 Mon Sep 17 00:00:00 2001 From: conorfos Date: Thu, 1 Nov 2018 15:59:43 +0000 Subject: [PATCH 01/14] Added more stats to be sent to MrDLib Added OS, OS version, Java Version, and Timezone to stats sent to MDL with each request. Updated API endpoint Updated JSON parsing --- .../org/jabref/logic/importer/fetcher/MrDLibFetcher.java | 9 +++++++-- .../jabref/logic/importer/fileformat/MrDLibImporter.java | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java index 2ae7db36e35..531d2de6dd3 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java @@ -4,6 +4,7 @@ import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; +import java.util.Calendar; import java.util.List; import java.util.Optional; @@ -104,11 +105,15 @@ private String constructQuery(String queryWithTitle) { URIBuilder builder = new URIBuilder(); builder.setScheme("http"); builder.setHost(getMdlUrl()); - builder.setPath("/v2/items/" + queryWithTitle + "/related_items"); - builder.addParameter("partner_id", "jabref"); + builder.setPath("/v2/documents/" + queryWithTitle + "/related_documents"); + builder.addParameter("partner_id", "1"); builder.addParameter("app_id", "jabref_desktop"); builder.addParameter("app_version", VERSION.getFullVersion()); builder.addParameter("app_lang", LANGUAGE); + builder.addParameter("os", System.getProperty("os.name")); + builder.addParameter("os_version", System.getProperty("os.version")); + builder.addParameter("java_version", System.getProperty("java.version")); + builder.addParameter("timezone", Calendar.getInstance().getTimeZone().getID()); try { URI uri = builder.build(); LOGGER.trace("Request: " + uri.toString()); diff --git a/src/main/java/org/jabref/logic/importer/fileformat/MrDLibImporter.java b/src/main/java/org/jabref/logic/importer/fileformat/MrDLibImporter.java index 6320b8d7483..5bc8af04b8c 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/MrDLibImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/MrDLibImporter.java @@ -146,10 +146,10 @@ private RankedBibEntry populateBibEntry(JSONObject recommendation) { // parse each of the relevant fields into variables String authors = isRecommendationFieldPresent(recommendation, "authors") ? getAuthorsString(recommendation) : ""; String title = isRecommendationFieldPresent(recommendation, "title") ? recommendation.getString("title") : ""; - String year = isRecommendationFieldPresent(recommendation, "year_published") ? Integer.toString(recommendation.getInt("year_published")) : ""; + String year = isRecommendationFieldPresent(recommendation, "published_year") ? Integer.toString(recommendation.getInt("published_year")) : ""; String journal = isRecommendationFieldPresent(recommendation, "published_in") ? recommendation.getString("published_in") : ""; String url = isRecommendationFieldPresent(recommendation, "url") ? recommendation.getString("url") : ""; - Integer rank = isRecommendationFieldPresent(recommendation, "url") ? recommendation.getInt("recommendation_id") : 100; + Integer rank = isRecommendationFieldPresent(recommendation, "recommendation_id") ? recommendation.getInt("recommendation_id") : 100; // Populate bib entry with relevant data current.setField(FieldName.AUTHOR, authors); From 96fd4ca72e38d3251d19f5d994d756508e7509fb Mon Sep 17 00:00:00 2001 From: conorfos Date: Thu, 1 Nov 2018 16:17:43 +0000 Subject: [PATCH 02/14] Updated url for Mr DLib production server --- .../java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java index 531d2de6dd3..a11709acbb9 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java @@ -125,6 +125,6 @@ private String constructQuery(String queryWithTitle) { } private String getMdlUrl() { - return VERSION.isDevelopmentVersion() ? "api-dev.darwingoliath.com" : "api.darwingoliath.com"; + return VERSION.isDevelopmentVersion() ? "api-dev.darwingoliath.com" : "api.mr-dlib.org"; } } From 6c76758317811d1357e1a503c05d8f29bb377bcf Mon Sep 17 00:00:00 2001 From: conorfos Date: Thu, 1 Nov 2018 16:28:27 +0000 Subject: [PATCH 03/14] Updated JabRef MDL Partner ID --- .../java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java index a11709acbb9..aae7cd0023d 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java @@ -28,6 +28,7 @@ public class MrDLibFetcher implements EntryBasedFetcher { private static final Logger LOGGER = LoggerFactory.getLogger(MrDLibFetcher.class); private static final String NAME = "MDL_FETCHER"; + private static final String MDL_JABREF_PARTNER_ID = "1"; private final String LANGUAGE; private final Version VERSION; @@ -106,7 +107,7 @@ private String constructQuery(String queryWithTitle) { builder.setScheme("http"); builder.setHost(getMdlUrl()); builder.setPath("/v2/documents/" + queryWithTitle + "/related_documents"); - builder.addParameter("partner_id", "1"); + builder.addParameter("partner_id", MDL_JABREF_PARTNER_ID); builder.addParameter("app_id", "jabref_desktop"); builder.addParameter("app_version", VERSION.getFullVersion()); builder.addParameter("app_lang", LANGUAGE); From fe278a2e4817811b561eb46656237789d9f95b4e Mon Sep 17 00:00:00 2001 From: conorfos Date: Fri, 2 Nov 2018 13:14:03 +0000 Subject: [PATCH 04/14] MrDLib Importer Test fix --- .../jabref/logic/importer/fileformat/MrDLibImporterTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/jabref/logic/importer/fileformat/MrDLibImporterTest.java b/src/test/java/org/jabref/logic/importer/fileformat/MrDLibImporterTest.java index 5af07b4dfa3..723afd1b6fc 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/MrDLibImporterTest.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/MrDLibImporterTest.java @@ -24,7 +24,7 @@ public class MrDLibImporterTest { @BeforeEach public void setUp() { importer = new MrDLibImporter(); - String testInput = "{ \"label\": { \"label-language\": \"en\", \"label-text\": \"Related Items\" }, \"recommendation-set-id\": \"1\", \"recommendations\": { \"74021358\": { \"abstract\": \"abstract\", \"authors\": [ \"Sajovic, Marija\" ], \"year_published\": \"2006\", \"item_id_original\": \"12088644\", \"keywords\": [ \"visoko\\u0161olski program Geodezija - smer Prostorska informatika\" ], \"language_provided\": \"sl\", \"recommendation_id\": \"1\", \"title\": \"The protection of rural lands with the spatial development strategy on the case of Hrastnik commune\", \"url\": \"http://drugg.fgg.uni-lj.si/701/1/GEV_0199_Sajovic.pdf\" }, \"82005804\": { \"abstract\": \"abstract\", \"year_published\": null, \"item_id_original\": \"30145702\", \"language_provided\": null, \"recommendation_id\": \"2\", \"title\": \"Engagement of the volunteers in the solution to the accidents in the South-Moravia region\" }, \"82149599\": { \"abstract\": \"abstract\", \"year_published\": null, \"item_id_original\": \"97690763\", \"language_provided\": null, \"recommendation_id\": \"3\", \"title\": \"\\\"The only Father's word\\\". The relationship of the Father and the Son in the documents of saint John of the Cross\", \"url\": \"http://www.nusl.cz/ntk/nusl-285711\" }, \"84863921\": { \"abstract\": \"abstract\", \"authors\": [ \"Kaffa, Elena\" ], \"year_published\": null, \"item_id_original\": \"19397104\", \"keywords\": [ \"BX\", \"D111\" ], \"language_provided\": \"en\", \"recommendation_id\": \"4\", \"title\": \"Greek Church of Cyprus, the Morea and Constantinople during the Frankish Era (1196-1303)\" }, \"88950992\": { \"abstract\": \"abstract\", \"authors\": [ \"Yasui, Kono\" ], \"year_published\": null, \"item_id_original\": \"38763657\", \"language_provided\": null, \"recommendation_id\": \"5\", \"title\": \"A Phylogenetic Consideration on the Vascular Plants, Cotyledonary Node Including Hypocotyl Being Taken as the Ancestral Form : A Preliminary Note\" } }}"; + String testInput = "{ \"label\": { \"label-language\": \"en\", \"label-text\": \"Related Items\" }, \"recommendation-set-id\": \"1\", \"recommendations\": { \"74021358\": { \"abstract\": \"abstract\", \"authors\": [ \"Sajovic, Marija\" ], \"published_year\": \"2006\", \"item_id_original\": \"12088644\", \"keywords\": [ \"visoko\\u0161olski program Geodezija - smer Prostorska informatika\" ], \"language_provided\": \"sl\", \"recommendation_id\": \"1\", \"title\": \"The protection of rural lands with the spatial development strategy on the case of Hrastnik commune\", \"url\": \"http://drugg.fgg.uni-lj.si/701/1/GEV_0199_Sajovic.pdf\" }, \"82005804\": { \"abstract\": \"abstract\", \"year_published\": null, \"item_id_original\": \"30145702\", \"language_provided\": null, \"recommendation_id\": \"2\", \"title\": \"Engagement of the volunteers in the solution to the accidents in the South-Moravia region\" }, \"82149599\": { \"abstract\": \"abstract\", \"year_published\": null, \"item_id_original\": \"97690763\", \"language_provided\": null, \"recommendation_id\": \"3\", \"title\": \"\\\"The only Father's word\\\". The relationship of the Father and the Son in the documents of saint John of the Cross\", \"url\": \"http://www.nusl.cz/ntk/nusl-285711\" }, \"84863921\": { \"abstract\": \"abstract\", \"authors\": [ \"Kaffa, Elena\" ], \"year_published\": null, \"item_id_original\": \"19397104\", \"keywords\": [ \"BX\", \"D111\" ], \"language_provided\": \"en\", \"recommendation_id\": \"4\", \"title\": \"Greek Church of Cyprus, the Morea and Constantinople during the Frankish Era (1196-1303)\" }, \"88950992\": { \"abstract\": \"abstract\", \"authors\": [ \"Yasui, Kono\" ], \"year_published\": null, \"item_id_original\": \"38763657\", \"language_provided\": null, \"recommendation_id\": \"5\", \"title\": \"A Phylogenetic Consideration on the Vascular Plants, Cotyledonary Node Including Hypocotyl Being Taken as the Ancestral Form : A Preliminary Note\" } }}"; input = new BufferedReader(new StringReader(testInput)); } From 2c0bd0d2764de7d4f37b720761562cf35d6636bf Mon Sep 17 00:00:00 2001 From: conorfos Date: Wed, 14 Nov 2018 11:15:18 +0000 Subject: [PATCH 05/14] Included support for heading and description Included support for heading and description on related articles tab. --- .../jabref/gui/entryeditor/EntryEditor.css | 13 +++++++++++++ .../gui/entryeditor/RelatedArticlesTab.java | 19 ++++++++++++++++--- .../jabref/logic/importer/ParserResult.java | 18 ++++++++++++++++++ .../logic/importer/fetcher/MrDLibFetcher.java | 14 +++++++++++++- .../importer/fileformat/MrDLibImporter.java | 4 ++++ 5 files changed, 64 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.css b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.css index 313583ed222..180477d2273 100644 --- a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.css +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.css @@ -88,4 +88,17 @@ -fx-padding: 20 20 20 20; } +.recommendation-heading { + -fx-font-size: 14pt; + -fx-font-weight: bold; +} + +.recommendation-description { + -fx-font-style: italic; +} + +.recommendation-item { + -fx-padding: 0 0 0 20; +} + diff --git a/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java b/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java index dbbe9ff096a..26cbc3ed969 100644 --- a/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java @@ -62,7 +62,7 @@ private StackPane getRelatedArticlesPane(BibEntry entry) { .onRunning(() -> progress.setVisible(true)) .onSuccess(relatedArticles -> { progress.setVisible(false); - root.getChildren().add(getRelatedArticleInfo(relatedArticles)); + root.getChildren().add(getRelatedArticleInfo(relatedArticles, fetcher)); }) .executeWith(Globals.TASK_EXECUTOR); @@ -76,13 +76,25 @@ private StackPane getRelatedArticlesPane(BibEntry entry) { * @param list List of BibEntries of related articles * @return VBox of related article descriptions to be displayed in the Related Articles tab */ - private VBox getRelatedArticleInfo(List list) { + private ScrollPane getRelatedArticleInfo(List list, MrDLibFetcher fetcher) { + ScrollPane scrollPane = new ScrollPane(); + VBox vBox = new VBox(); vBox.setSpacing(20.0); + String heading = fetcher.getHeading(); + Text headingText = new Text(heading); + headingText.getStyleClass().add("recommendation-heading"); + String description = fetcher.getDescription(); + Text descriptionText = new Text(description); + descriptionText.getStyleClass().add("recommendation-description"); + vBox.getChildren().add(headingText); + vBox.getChildren().add(descriptionText); + for (BibEntry entry : list) { HBox hBox = new HBox(); hBox.setSpacing(5.0); + hBox.getStyleClass().add("recommendation-item"); String title = entry.getTitle().orElse(""); String journal = entry.getField(FieldName.JOURNAL).orElse(""); @@ -108,7 +120,8 @@ private VBox getRelatedArticleInfo(List list) { hBox.getChildren().addAll(titleLink, journalText, authorsText, yearText); vBox.getChildren().add(hBox); } - return vBox; + scrollPane.setContent(vBox); + return scrollPane; } /** diff --git a/src/main/java/org/jabref/logic/importer/ParserResult.java b/src/main/java/org/jabref/logic/importer/ParserResult.java index c9163c75315..8c2b915e930 100644 --- a/src/main/java/org/jabref/logic/importer/ParserResult.java +++ b/src/main/java/org/jabref/logic/importer/ParserResult.java @@ -29,6 +29,8 @@ public class ParserResult { private boolean invalid; private boolean toOpenTab; private boolean changedOnMigration = false; + private String title; + private String description; public ParserResult() { this(Collections.emptyList()); @@ -102,6 +104,22 @@ public void setFile(File f) { file = f.toPath(); } + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + /** * Add a parser warning. * diff --git a/src/main/java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java index aae7cd0023d..b2563894671 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java @@ -31,6 +31,8 @@ public class MrDLibFetcher implements EntryBasedFetcher { private static final String MDL_JABREF_PARTNER_ID = "1"; private final String LANGUAGE; private final Version VERSION; + private String heading = ""; + private String description = ""; public MrDLibFetcher(String language, Version version) { @@ -53,6 +55,8 @@ public List performSearch(BibEntry entry) throws FetcherException { try { if (importer.isRecognizedFormat(response)) { parserResult = importer.importDatabase(response); + heading = parserResult.getTitle(); + description = parserResult.getDescription(); } else { // For displaying An ErrorMessage String error = importer.getResponseErrorMessage(response); @@ -73,6 +77,14 @@ public List performSearch(BibEntry entry) throws FetcherException { } } + public String getHeading() { + return heading; + } + + public String getDescription() { + return description; + } + /** * Contact the server with the title of the selected item * @@ -105,7 +117,7 @@ private String constructQuery(String queryWithTitle) { queryWithTitle = queryWithTitle.replaceAll("/", " "); URIBuilder builder = new URIBuilder(); builder.setScheme("http"); - builder.setHost(getMdlUrl()); + builder.setHost("localhost:5000"); builder.setPath("/v2/documents/" + queryWithTitle + "/related_documents"); builder.addParameter("partner_id", MDL_JABREF_PARTNER_ID); builder.addParameter("app_id", "jabref_desktop"); diff --git a/src/main/java/org/jabref/logic/importer/fileformat/MrDLibImporter.java b/src/main/java/org/jabref/logic/importer/fileformat/MrDLibImporter.java index 5bc8af04b8c..a30831dff72 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/MrDLibImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/MrDLibImporter.java @@ -133,6 +133,10 @@ private void parse(BufferedReader input) throws IOException { bibDatabase.insertEntry(bibentry); } parserResult = new ParserResult(bibDatabase); + + JSONObject label = new JSONObject(recommendations).getJSONObject("label"); + parserResult.setTitle(label.getString("label-text")); + parserResult.setDescription(label.getString("label-description")); } /** From 9c51b7c724a7dc8bd88cc3a2de8f7f2067d1f1a0 Mon Sep 17 00:00:00 2001 From: conorfos Date: Fri, 16 Nov 2018 11:04:02 +0000 Subject: [PATCH 06/14] Added error handling Handling non-status-200 responses from Mr. DLib and also status 200 responses that do not fit expected format. --- .../gui/entryeditor/RelatedArticlesTab.java | 23 +++++++++++++++++++ .../logic/importer/fetcher/MrDLibFetcher.java | 7 +++--- .../importer/fileformat/MrDLibImporter.java | 19 --------------- 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java b/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java index 26cbc3ed969..d837c1c8906 100644 --- a/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java @@ -64,6 +64,11 @@ private StackPane getRelatedArticlesPane(BibEntry entry) { progress.setVisible(false); root.getChildren().add(getRelatedArticleInfo(relatedArticles, fetcher)); }) + .onFailure(exception -> { + LOGGER.error("Error while fetching from Mr. DLib", exception); + progress.setVisible(false); + root.getChildren().add(getErrorInfo()); + }) .executeWith(Globals.TASK_EXECUTOR); root.getChildren().add(progress); @@ -124,6 +129,24 @@ private ScrollPane getRelatedArticleInfo(List list, MrDLibFetcher fetc return scrollPane; } + /** + * Gets a ScrollPane to display error info when recommendations fail. + * @return ScrollPane to display in place of recommendations + */ + private ScrollPane getErrorInfo() { + ScrollPane scrollPane = new ScrollPane(); + + VBox vBox = new VBox(); + vBox.setSpacing(20.0); + + Text descriptionText = new Text(Localization.lang("No recommendations received from Mr. DLib for this entry.")); + descriptionText.getStyleClass().add("recommendation-description"); + vBox.getChildren().add(descriptionText); + scrollPane.setContent(vBox); + + return scrollPane; + } + /** * Returns a consent dialog used to ask permission to send data to Mr. DLib. * @param entry Currently selected BibEntry. (required to allow reloading of pane if accepted) diff --git a/src/main/java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java index b2563894671..6caadeb7f45 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java @@ -12,6 +12,7 @@ import org.jabref.logic.importer.FetcherException; import org.jabref.logic.importer.ParserResult; import org.jabref.logic.importer.fileformat.MrDLibImporter; +import org.jabref.logic.l10n.Localization; import org.jabref.logic.net.URLDownload; import org.jabref.logic.util.Version; import org.jabref.model.database.BibDatabase; @@ -29,6 +30,7 @@ public class MrDLibFetcher implements EntryBasedFetcher { private static final Logger LOGGER = LoggerFactory.getLogger(MrDLibFetcher.class); private static final String NAME = "MDL_FETCHER"; private static final String MDL_JABREF_PARTNER_ID = "1"; + private static final String DEFAULT_MRDLIB_ERROR_MESSAGE = Localization.lang("Error while fetching recommendations from Mr.DLib."); private final String LANGUAGE; private final Version VERSION; private String heading = ""; @@ -59,11 +61,8 @@ public List performSearch(BibEntry entry) throws FetcherException { description = parserResult.getDescription(); } else { // For displaying An ErrorMessage - String error = importer.getResponseErrorMessage(response); - BibEntry errorBibEntry = new BibEntry(); - errorBibEntry.setField("html_representation", error); + description = DEFAULT_MRDLIB_ERROR_MESSAGE; BibDatabase errorBibDataBase = new BibDatabase(); - errorBibDataBase.insertEntry(errorBibEntry); parserResult = new ParserResult(errorBibDataBase); } } catch (IOException e) { diff --git a/src/main/java/org/jabref/logic/importer/fileformat/MrDLibImporter.java b/src/main/java/org/jabref/logic/importer/fileformat/MrDLibImporter.java index a30831dff72..56032b99814 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/MrDLibImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/MrDLibImporter.java @@ -12,7 +12,6 @@ import org.jabref.logic.importer.Importer; import org.jabref.logic.importer.ParserResult; -import org.jabref.logic.l10n.Localization; import org.jabref.logic.util.StandardFileType; import org.jabref.model.database.BibDatabase; import org.jabref.model.entry.BibEntry; @@ -29,7 +28,6 @@ */ public class MrDLibImporter extends Importer { - private static final String DEFAULT_MRDLIB_ERROR_MESSAGE = Localization.lang("Error while fetching from Mr.DLib."); private static final Logger LOGGER = LoggerFactory.getLogger(MrDLibImporter.class); public ParserResult parserResult; @@ -191,21 +189,4 @@ public ParserResult getParserResult() { return parserResult; } - /** - * Gets the error message to be returned if there has been an error in returning recommendations. - * Returns default error message if there is no message from Mr. DLib. - * @param response The response from the MDL server as a string. - * @return String error message to be shown to the user. - */ - public String getResponseErrorMessage(String response) { - try { - JSONObject jsonObject = new JSONObject(response); - if (!jsonObject.has("message")) { - return jsonObject.getString("message"); - } - } catch (JSONException ex) { - return DEFAULT_MRDLIB_ERROR_MESSAGE; - } - return DEFAULT_MRDLIB_ERROR_MESSAGE; - } } From e1442399a906c235e421b717912c5a0772f1c3f1 Mon Sep 17 00:00:00 2001 From: conorfos Date: Thu, 22 Nov 2018 13:54:36 +0000 Subject: [PATCH 07/14] Make confirmation posts to Mr. DLib for recommendations Post sent when they are received and when they are displayed. --- .../jabref/gui/entryeditor/EntryEditor.java | 2 +- .../gui/entryeditor/RelatedArticlesTab.java | 13 +++++++- .../jabref/logic/importer/ParserResult.java | 19 ----------- .../logic/importer/fetcher/MrDLibFetcher.java | 32 ++++++++++++++++--- .../importer/fileformat/MrDLibImporter.java | 28 +++++++++++++--- 5 files changed, 64 insertions(+), 30 deletions(-) diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java index c7961bff628..319d918fd2c 100644 --- a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java @@ -297,7 +297,7 @@ private List createTabs() { // Special tabs tabs.add(new MathSciNetTab()); tabs.add(new FileAnnotationTab(panel.getAnnotationCache())); - tabs.add(new RelatedArticlesTab(preferences, dialogService)); + tabs.add(new RelatedArticlesTab(this, preferences, dialogService)); // Source tab sourceTab = new SourceTab(databaseContext, undoManager, preferences.getLatexFieldFormatterPreferences(), preferences.getImportFormatPreferences(), fileMonitor); diff --git a/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java b/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java index d837c1c8906..048f80dfda4 100644 --- a/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java @@ -35,11 +35,13 @@ public class RelatedArticlesTab extends EntryEditorTab { private static final Logger LOGGER = LoggerFactory.getLogger(RelatedArticlesTab.class); private final EntryEditorPreferences preferences; + private final EntryEditor entryEditor; private final DialogService dialogService; - public RelatedArticlesTab(EntryEditorPreferences preferences, DialogService dialogService) { + public RelatedArticlesTab(EntryEditor entryEditor, EntryEditorPreferences preferences, DialogService dialogService) { setText(Localization.lang("Related articles")); setTooltip(new Tooltip(Localization.lang("Related articles"))); + this.entryEditor = entryEditor; this.preferences = preferences; this.dialogService = dialogService; } @@ -61,8 +63,17 @@ private StackPane getRelatedArticlesPane(BibEntry entry) { .wrap(() -> fetcher.performSearch(entry)) .onRunning(() -> progress.setVisible(true)) .onSuccess(relatedArticles -> { + BackgroundTask + .wrap(() -> fetcher.confirmRecommendations("received")) + .executeWith(Globals.TASK_EXECUTOR); progress.setVisible(false); root.getChildren().add(getRelatedArticleInfo(relatedArticles, fetcher)); + if (entry.getAuthorTitleYear(100) + .equals(entryEditor.getEntry().getAuthorTitleYear(100))) { + BackgroundTask + .wrap(() -> fetcher.confirmRecommendations("displayed")) + .executeWith(Globals.TASK_EXECUTOR); + } }) .onFailure(exception -> { LOGGER.error("Error while fetching from Mr. DLib", exception); diff --git a/src/main/java/org/jabref/logic/importer/ParserResult.java b/src/main/java/org/jabref/logic/importer/ParserResult.java index 8c2b915e930..e67e3e8b329 100644 --- a/src/main/java/org/jabref/logic/importer/ParserResult.java +++ b/src/main/java/org/jabref/logic/importer/ParserResult.java @@ -29,8 +29,6 @@ public class ParserResult { private boolean invalid; private boolean toOpenTab; private boolean changedOnMigration = false; - private String title; - private String description; public ParserResult() { this(Collections.emptyList()); @@ -103,23 +101,6 @@ public Optional getFile() { public void setFile(File f) { file = f.toPath(); } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - /** * Add a parser warning. * diff --git a/src/main/java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java index 6caadeb7f45..be8e75f4ea8 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java @@ -33,8 +33,9 @@ public class MrDLibFetcher implements EntryBasedFetcher { private static final String DEFAULT_MRDLIB_ERROR_MESSAGE = Localization.lang("Error while fetching recommendations from Mr.DLib."); private final String LANGUAGE; private final Version VERSION; - private String heading = ""; - private String description = ""; + private String heading; + private String description; + private String recommendationSetId; public MrDLibFetcher(String language, Version version) { @@ -57,8 +58,9 @@ public List performSearch(BibEntry entry) throws FetcherException { try { if (importer.isRecognizedFormat(response)) { parserResult = importer.importDatabase(response); - heading = parserResult.getTitle(); - description = parserResult.getDescription(); + heading = importer.getRecommendationsHeading(); + description = importer.getRecommendationsDescription(); + recommendationSetId = importer.getRecommendationSetId(); } else { // For displaying An ErrorMessage description = DEFAULT_MRDLIB_ERROR_MESSAGE; @@ -84,6 +86,28 @@ public String getDescription() { return description; } + public void confirmRecommendations(String status) { + try { + URIBuilder builder = new URIBuilder(); + builder.setScheme("http"); + builder.setHost("localhost:5000"); + builder.setPath("/v2/recommendations/" + recommendationSetId + "/status/" + status); + try { + URI uri = builder.build(); + URLDownload urlDownload = new URLDownload(uri.toString()); + URLDownload.bypassSSLVerification(); + urlDownload.setPostData(recommendationSetId); + urlDownload.asString(); + } + catch (URISyntaxException se) { + LOGGER.error("Problem connecting to Mr. DLib", se); + } + + } catch (IOException e) { + LOGGER.error("Problem connecting to Mr. DLib", e); + } + } + /** * Contact the server with the title of the selected item * diff --git a/src/main/java/org/jabref/logic/importer/fileformat/MrDLibImporter.java b/src/main/java/org/jabref/logic/importer/fileformat/MrDLibImporter.java index 56032b99814..3a70213b336 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/MrDLibImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/MrDLibImporter.java @@ -5,6 +5,7 @@ import java.io.BufferedReader; import java.io.IOException; +import java.math.BigInteger; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -29,6 +30,9 @@ public class MrDLibImporter extends Importer { private static final Logger LOGGER = LoggerFactory.getLogger(MrDLibImporter.class); + private String recommendationsHeading; + private String recommendationsDescription; + private String recommendationSetId; public ParserResult parserResult; @SuppressWarnings("unused") @@ -109,12 +113,13 @@ private void parse(BufferedReader input) throws IOException { // The Bibdatabase that gets returned in the ParserResult. BibDatabase bibDatabase = new BibDatabase(); // The document to parse - String recommendations = convertToString(input); + String recommendationSet = convertToString(input); + JSONObject recommendationSetJson = new JSONObject(recommendationSet); // The sorted BibEntries gets stored here later List rankedBibEntries = new ArrayList<>(); // Get recommendations from response and populate bib entries - JSONObject recommendationsJson = new JSONObject(recommendations).getJSONObject("recommendations"); + JSONObject recommendationsJson = recommendationSetJson.getJSONObject("recommendations"); Iterator keys = recommendationsJson.keys(); while (keys.hasNext()) { String key = keys.next(); @@ -132,9 +137,10 @@ private void parse(BufferedReader input) throws IOException { } parserResult = new ParserResult(bibDatabase); - JSONObject label = new JSONObject(recommendations).getJSONObject("label"); - parserResult.setTitle(label.getString("label-text")); - parserResult.setDescription(label.getString("label-description")); + JSONObject label = recommendationSetJson.getJSONObject("label"); + recommendationsHeading = label.getString("label-text"); + recommendationsDescription = label.getString("label-description"); + recommendationSetId = recommendationSetJson.getBigInteger("recommendation_set_id").toString(); } /** @@ -189,4 +195,16 @@ public ParserResult getParserResult() { return parserResult; } + public String getRecommendationsHeading() { + return recommendationsHeading; + } + + public String getRecommendationsDescription() { + return recommendationsDescription; + } + + public String getRecommendationSetId() { + return recommendationSetId; + } + } From dbec2c86bcb3160383fecf3463ea339be6bb8e8b Mon Sep 17 00:00:00 2001 From: conorfos Date: Thu, 22 Nov 2018 14:50:14 +0000 Subject: [PATCH 08/14] Fixed checkstyle and test issues --- .../java/org/jabref/gui/entryeditor/RelatedArticlesTab.java | 6 ++++-- src/main/java/org/jabref/logic/importer/ParserResult.java | 1 + .../jabref/logic/importer/fileformat/MrDLibImporter.java | 3 +-- src/main/resources/l10n/JabRef_en.properties | 5 +++-- .../logic/importer/fileformat/MrDLibImporterTest.java | 4 ++-- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java b/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java index 048f80dfda4..7918cdba3cc 100644 --- a/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java @@ -34,6 +34,8 @@ public class RelatedArticlesTab extends EntryEditorTab { private static final Logger LOGGER = LoggerFactory.getLogger(RelatedArticlesTab.class); + private static final String MDL_STATUS_RECEIVED = "received"; + private static final String MDL_STATUS_DISPLAYED = "displayed"; private final EntryEditorPreferences preferences; private final EntryEditor entryEditor; private final DialogService dialogService; @@ -64,14 +66,14 @@ private StackPane getRelatedArticlesPane(BibEntry entry) { .onRunning(() -> progress.setVisible(true)) .onSuccess(relatedArticles -> { BackgroundTask - .wrap(() -> fetcher.confirmRecommendations("received")) + .wrap(() -> fetcher.confirmRecommendations(MDL_STATUS_RECEIVED)) .executeWith(Globals.TASK_EXECUTOR); progress.setVisible(false); root.getChildren().add(getRelatedArticleInfo(relatedArticles, fetcher)); if (entry.getAuthorTitleYear(100) .equals(entryEditor.getEntry().getAuthorTitleYear(100))) { BackgroundTask - .wrap(() -> fetcher.confirmRecommendations("displayed")) + .wrap(() -> fetcher.confirmRecommendations(MDL_STATUS_DISPLAYED)) .executeWith(Globals.TASK_EXECUTOR); } }) diff --git a/src/main/java/org/jabref/logic/importer/ParserResult.java b/src/main/java/org/jabref/logic/importer/ParserResult.java index e67e3e8b329..c9163c75315 100644 --- a/src/main/java/org/jabref/logic/importer/ParserResult.java +++ b/src/main/java/org/jabref/logic/importer/ParserResult.java @@ -101,6 +101,7 @@ public Optional getFile() { public void setFile(File f) { file = f.toPath(); } + /** * Add a parser warning. * diff --git a/src/main/java/org/jabref/logic/importer/fileformat/MrDLibImporter.java b/src/main/java/org/jabref/logic/importer/fileformat/MrDLibImporter.java index 3a70213b336..e3f0ab7f1a6 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/MrDLibImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/MrDLibImporter.java @@ -5,7 +5,6 @@ import java.io.BufferedReader; import java.io.IOException; -import java.math.BigInteger; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -30,10 +29,10 @@ public class MrDLibImporter extends Importer { private static final Logger LOGGER = LoggerFactory.getLogger(MrDLibImporter.class); + public ParserResult parserResult; private String recommendationsHeading; private String recommendationsDescription; private String recommendationSetId; - public ParserResult parserResult; @SuppressWarnings("unused") @Override diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index e4bd843bed0..44e1e2eaf2f 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -379,8 +379,6 @@ Error\ occurred\ when\ parsing\ entry=Error occurred when parsing entry Error\ opening\ file=Error opening file -Error\ while\ fetching\ from\ Mr.DLib.=Error while fetching from Mr.DLib. - Error\ while\ writing=Error while writing '%0'\ exists.\ Overwrite\ file?='%0' exists. Overwrite file? @@ -664,6 +662,9 @@ Moved\ group\ "%0".=Moved group "%0". Mr.\ DLib\ is\ an\ external\ service\ which\ provides\ article\ recommendations\ based\ on\ the\ currently\ selected\ entry.\ Data\ about\ the\ selected\ entry\ must\ be\ sent\ to\ Mr.\ DLib\ in\ order\ to\ provide\ these\ recommendations.\ Do\ you\ agree\ that\ this\ data\ may\ be\ sent?=Mr. DLib is an external service which provides article recommendations based on the currently selected entry. Data about the selected entry must be sent to Mr. DLib in order to provide these recommendations. Do you agree that this data may be sent? +No\ recommendations\ received\ from\ Mr.\ DLib\ for\ this\ entry.=No recommendations received from Mr. DLib for this entry. + +Error\ while\ fetching\ recommendations\ from\ Mr.DLib.=Error while fetching recommendations from Mr.DLib. Name=Name Name\ formatter=Name formatter diff --git a/src/test/java/org/jabref/logic/importer/fileformat/MrDLibImporterTest.java b/src/test/java/org/jabref/logic/importer/fileformat/MrDLibImporterTest.java index 723afd1b6fc..1b5f8ffa5a2 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/MrDLibImporterTest.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/MrDLibImporterTest.java @@ -24,9 +24,9 @@ public class MrDLibImporterTest { @BeforeEach public void setUp() { importer = new MrDLibImporter(); - String testInput = "{ \"label\": { \"label-language\": \"en\", \"label-text\": \"Related Items\" }, \"recommendation-set-id\": \"1\", \"recommendations\": { \"74021358\": { \"abstract\": \"abstract\", \"authors\": [ \"Sajovic, Marija\" ], \"published_year\": \"2006\", \"item_id_original\": \"12088644\", \"keywords\": [ \"visoko\\u0161olski program Geodezija - smer Prostorska informatika\" ], \"language_provided\": \"sl\", \"recommendation_id\": \"1\", \"title\": \"The protection of rural lands with the spatial development strategy on the case of Hrastnik commune\", \"url\": \"http://drugg.fgg.uni-lj.si/701/1/GEV_0199_Sajovic.pdf\" }, \"82005804\": { \"abstract\": \"abstract\", \"year_published\": null, \"item_id_original\": \"30145702\", \"language_provided\": null, \"recommendation_id\": \"2\", \"title\": \"Engagement of the volunteers in the solution to the accidents in the South-Moravia region\" }, \"82149599\": { \"abstract\": \"abstract\", \"year_published\": null, \"item_id_original\": \"97690763\", \"language_provided\": null, \"recommendation_id\": \"3\", \"title\": \"\\\"The only Father's word\\\". The relationship of the Father and the Son in the documents of saint John of the Cross\", \"url\": \"http://www.nusl.cz/ntk/nusl-285711\" }, \"84863921\": { \"abstract\": \"abstract\", \"authors\": [ \"Kaffa, Elena\" ], \"year_published\": null, \"item_id_original\": \"19397104\", \"keywords\": [ \"BX\", \"D111\" ], \"language_provided\": \"en\", \"recommendation_id\": \"4\", \"title\": \"Greek Church of Cyprus, the Morea and Constantinople during the Frankish Era (1196-1303)\" }, \"88950992\": { \"abstract\": \"abstract\", \"authors\": [ \"Yasui, Kono\" ], \"year_published\": null, \"item_id_original\": \"38763657\", \"language_provided\": null, \"recommendation_id\": \"5\", \"title\": \"A Phylogenetic Consideration on the Vascular Plants, Cotyledonary Node Including Hypocotyl Being Taken as the Ancestral Form : A Preliminary Note\" } }}"; + String testInput = "{\"label\": {\"label-description\": \"The following articles are similar to the document have currently selected.\", \"label-language\": \"en\", \"label-text\": \"Related Articles\"}, \"recommendation_set_id\": \"1\", \"recommendations\": { \"74021358\": { \"abstract\": \"abstract\", \"authors\": [ \"Sajovic, Marija\" ], \"published_year\": \"2006\", \"item_id_original\": \"12088644\", \"keywords\": [ \"visoko\\u0161olski program Geodezija - smer Prostorska informatika\" ], \"language_provided\": \"sl\", \"recommendation_id\": \"1\", \"title\": \"The protection of rural lands with the spatial development strategy on the case of Hrastnik commune\", \"url\": \"http://drugg.fgg.uni-lj.si/701/1/GEV_0199_Sajovic.pdf\" }, \"82005804\": { \"abstract\": \"abstract\", \"year_published\": null, \"item_id_original\": \"30145702\", \"language_provided\": null, \"recommendation_id\": \"2\", \"title\": \"Engagement of the volunteers in the solution to the accidents in the South-Moravia region\" }, \"82149599\": { \"abstract\": \"abstract\", \"year_published\": null, \"item_id_original\": \"97690763\", \"language_provided\": null, \"recommendation_id\": \"3\", \"title\": \"\\\"The only Father's word\\\". The relationship of the Father and the Son in the documents of saint John of the Cross\", \"url\": \"http://www.nusl.cz/ntk/nusl-285711\" }, \"84863921\": { \"abstract\": \"abstract\", \"authors\": [ \"Kaffa, Elena\" ], \"year_published\": null, \"item_id_original\": \"19397104\", \"keywords\": [ \"BX\", \"D111\" ], \"language_provided\": \"en\", \"recommendation_id\": \"4\", \"title\": \"Greek Church of Cyprus, the Morea and Constantinople during the Frankish Era (1196-1303)\" }, \"88950992\": { \"abstract\": \"abstract\", \"authors\": [ \"Yasui, Kono\" ], \"year_published\": null, \"item_id_original\": \"38763657\", \"language_provided\": null, \"recommendation_id\": \"5\", \"title\": \"A Phylogenetic Consideration on the Vascular Plants, Cotyledonary Node Including Hypocotyl Being Taken as the Ancestral Form : A Preliminary Note\" } }}"; input = new BufferedReader(new StringReader(testInput)); - } + } @Test public void testGetDescription() { From e4256760e0f613085c81457ce19f632f5c35e24a Mon Sep 17 00:00:00 2001 From: conorfos Date: Thu, 17 Jan 2019 11:45:10 +0000 Subject: [PATCH 09/14] Set Mr. DLib URL Set JabRef to always point to the Mr. DLib production URL --- .../org/jabref/logic/importer/fetcher/MrDLibFetcher.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/main/java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java index be8e75f4ea8..a1f4742c952 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java @@ -140,7 +140,7 @@ private String constructQuery(String queryWithTitle) { queryWithTitle = queryWithTitle.replaceAll("/", " "); URIBuilder builder = new URIBuilder(); builder.setScheme("http"); - builder.setHost("localhost:5000"); + builder.setHost("api.mr-dlib.org"); builder.setPath("/v2/documents/" + queryWithTitle + "/related_documents"); builder.addParameter("partner_id", MDL_JABREF_PARTNER_ID); builder.addParameter("app_id", "jabref_desktop"); @@ -159,8 +159,4 @@ private String constructQuery(String queryWithTitle) { } return ""; } - - private String getMdlUrl() { - return VERSION.isDevelopmentVersion() ? "api-dev.darwingoliath.com" : "api.mr-dlib.org"; - } } From c66e474aa3086f05ce5d620971e4069387779575 Mon Sep 17 00:00:00 2001 From: conorfos Date: Mon, 21 Jan 2019 15:56:42 +0000 Subject: [PATCH 10/14] Added line to CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce2410787c6..869f3ac2f5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# - We added the ability to have an export preference where previously "File"-->"Export"/"Export selected entries" would not save the user's preference[#4495](https://github.com/JabRef/jabref/issues/4495) - We added the ability to add field names from the Preferences Dialog [#4546](https://github.com/JabRef/jabref/issues/4546) - We added the ability change the column widths directly in the main table. [#4546](https://github.com/JabRef/jabref/issues/4546) +- We added description of how recommendations where chosen and better error handling to Related Articles tab From d9c4bdd9083545688d1d32c96612c9e8d905c2d2 Mon Sep 17 00:00:00 2001 From: conorfos Date: Thu, 4 Jul 2019 10:01:48 +0100 Subject: [PATCH 11/14] Removed 'displayed' and 'received' confirmations Fixed author parser to support new format --- .../gui/entryeditor/RelatedArticlesTab.java | 9 -------- .../importer/fileformat/MrDLibImporter.java | 21 +------------------ 2 files changed, 1 insertion(+), 29 deletions(-) diff --git a/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java b/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java index 3b70d68cc22..1ed2a97ee84 100644 --- a/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java @@ -66,17 +66,8 @@ private StackPane getRelatedArticlesPane(BibEntry entry) { .wrap(() -> fetcher.performSearch(entry)) .onRunning(() -> progress.setVisible(true)) .onSuccess(relatedArticles -> { - BackgroundTask - .wrap(() -> fetcher.confirmRecommendations(MDL_STATUS_RECEIVED)) - .executeWith(Globals.TASK_EXECUTOR); progress.setVisible(false); root.getChildren().add(getRelatedArticleInfo(relatedArticles, fetcher)); - if (entry.getAuthorTitleYear(100) - .equals(entryEditor.getEntry().getAuthorTitleYear(100))) { - BackgroundTask - .wrap(() -> fetcher.confirmRecommendations(MDL_STATUS_DISPLAYED)) - .executeWith(Globals.TASK_EXECUTOR); - } }) .onFailure(exception -> { LOGGER.error("Error while fetching from Mr. DLib", exception); diff --git a/src/main/java/org/jabref/logic/importer/fileformat/MrDLibImporter.java b/src/main/java/org/jabref/logic/importer/fileformat/MrDLibImporter.java index e3f0ab7f1a6..b71f5eabf2c 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/MrDLibImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/MrDLibImporter.java @@ -17,7 +17,6 @@ import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.FieldName; -import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.slf4j.Logger; @@ -151,7 +150,7 @@ private RankedBibEntry populateBibEntry(JSONObject recommendation) { BibEntry current = new BibEntry(); // parse each of the relevant fields into variables - String authors = isRecommendationFieldPresent(recommendation, "authors") ? getAuthorsString(recommendation) : ""; + String authors = isRecommendationFieldPresent(recommendation, "authors") ? recommendation.getString("authors") : ""; String title = isRecommendationFieldPresent(recommendation, "title") ? recommendation.getString("title") : ""; String year = isRecommendationFieldPresent(recommendation, "published_year") ? Integer.toString(recommendation.getInt("published_year")) : ""; String journal = isRecommendationFieldPresent(recommendation, "published_in") ? recommendation.getString("published_in") : ""; @@ -172,24 +171,6 @@ private Boolean isRecommendationFieldPresent(JSONObject recommendation, String f return recommendation.has(field) && !recommendation.isNull(field); } - /** - * Creates an authors string from a JSON recommendation - * @param recommendation JSON Object recommendation from Mr. DLib - * @return A string of all authors, separated by commas and finished with a full stop. - */ - private String getAuthorsString(JSONObject recommendation) { - String authorsString = ""; - JSONArray array = recommendation.getJSONArray("authors"); - for (int i = 0; i < array.length(); ++i) { - authorsString += array.getString(i) + "; "; - } - int stringLength = authorsString.length(); - if (stringLength > 2) { - authorsString = authorsString.substring(0, stringLength - 2) + "."; - } - return authorsString; - } - public ParserResult getParserResult() { return parserResult; } From 96d0b07bac27a808b0edbcd61bbec8f76f5f6abc Mon Sep 17 00:00:00 2001 From: conorfos Date: Thu, 4 Jul 2019 10:30:30 +0100 Subject: [PATCH 12/14] Removed unnecessary spaces and variables --- CHANGELOG.md | 2 -- .../java/org/jabref/gui/entryeditor/RelatedArticlesTab.java | 2 -- 2 files changed, 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 15950981435..c461952c966 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,8 +54,6 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# - We added the ability to add field names from the Preferences Dialog [#4546](https://github.com/JabRef/jabref/issues/4546) - We added the ability change the column widths directly in the main table. [#4546](https://github.com/JabRef/jabref/issues/4546) - We added description of how recommendations where chosen and better error handling to Related Articles tab - - - We added the ability to execute default action in dialog by using with Ctrl + Enter combination [#4496](https://github.com/JabRef/jabref/issues/4496) - We grouped and reordered the Main Menu (File, Edit, Library, Quality, Tools, and View tabs & icons). [#4666](https://github.com/JabRef/jabref/issues/4666) [#4667](https://github.com/JabRef/jabref/issues/4667) [#4668](https://github.com/JabRef/jabref/issues/4668) [#4669](https://github.com/JabRef/jabref/issues/4669) [#4670](https://github.com/JabRef/jabref/issues/4670) [#4671](https://github.com/JabRef/jabref/issues/4671) [#4672](https://github.com/JabRef/jabref/issues/4672) [#4673](https://github.com/JabRef/jabref/issues/4673) - We added additional modifiers (capitalize, titlecase and sentencecase) to the Bibtex key generator. [#1506](https://github.com/JabRef/jabref/issues/1506) diff --git a/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java b/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java index 1ed2a97ee84..0fbb3d2e08d 100644 --- a/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java @@ -35,8 +35,6 @@ public class RelatedArticlesTab extends EntryEditorTab { private static final Logger LOGGER = LoggerFactory.getLogger(RelatedArticlesTab.class); - private static final String MDL_STATUS_RECEIVED = "received"; - private static final String MDL_STATUS_DISPLAYED = "displayed"; private final EntryEditorPreferences preferences; private final EntryEditor entryEditor; private final DialogService dialogService; From fd19e5b03ee1bad01aa15a072f0fce5195ff8b28 Mon Sep 17 00:00:00 2001 From: conorfos Date: Thu, 4 Jul 2019 10:47:57 +0100 Subject: [PATCH 13/14] Fixed MrDLibImporterTest with new authors format --- .../jabref/logic/importer/fileformat/MrDLibImporterTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/jabref/logic/importer/fileformat/MrDLibImporterTest.java b/src/test/java/org/jabref/logic/importer/fileformat/MrDLibImporterTest.java index 39ae1ffe39f..246bee9e3cf 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/MrDLibImporterTest.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/MrDLibImporterTest.java @@ -24,7 +24,7 @@ public class MrDLibImporterTest { @BeforeEach public void setUp() { importer = new MrDLibImporter(); - String testInput = "{\"label\": {\"label-description\": \"The following articles are similar to the document have currently selected.\", \"label-language\": \"en\", \"label-text\": \"Related Articles\"}, \"recommendation_set_id\": \"1\", \"recommendations\": { \"74021358\": { \"abstract\": \"abstract\", \"authors\": [ \"Sajovic, Marija\" ], \"published_year\": \"2006\", \"item_id_original\": \"12088644\", \"keywords\": [ \"visoko\\u0161olski program Geodezija - smer Prostorska informatika\" ], \"language_provided\": \"sl\", \"recommendation_id\": \"1\", \"title\": \"The protection of rural lands with the spatial development strategy on the case of Hrastnik commune\", \"url\": \"http://drugg.fgg.uni-lj.si/701/1/GEV_0199_Sajovic.pdf\" }, \"82005804\": { \"abstract\": \"abstract\", \"year_published\": null, \"item_id_original\": \"30145702\", \"language_provided\": null, \"recommendation_id\": \"2\", \"title\": \"Engagement of the volunteers in the solution to the accidents in the South-Moravia region\" }, \"82149599\": { \"abstract\": \"abstract\", \"year_published\": null, \"item_id_original\": \"97690763\", \"language_provided\": null, \"recommendation_id\": \"3\", \"title\": \"\\\"The only Father's word\\\". The relationship of the Father and the Son in the documents of saint John of the Cross\", \"url\": \"http://www.nusl.cz/ntk/nusl-285711\" }, \"84863921\": { \"abstract\": \"abstract\", \"authors\": [ \"Kaffa, Elena\" ], \"year_published\": null, \"item_id_original\": \"19397104\", \"keywords\": [ \"BX\", \"D111\" ], \"language_provided\": \"en\", \"recommendation_id\": \"4\", \"title\": \"Greek Church of Cyprus, the Morea and Constantinople during the Frankish Era (1196-1303)\" }, \"88950992\": { \"abstract\": \"abstract\", \"authors\": [ \"Yasui, Kono\" ], \"year_published\": null, \"item_id_original\": \"38763657\", \"language_provided\": null, \"recommendation_id\": \"5\", \"title\": \"A Phylogenetic Consideration on the Vascular Plants, Cotyledonary Node Including Hypocotyl Being Taken as the Ancestral Form : A Preliminary Note\" } }}"; + String testInput = "{\"label\": {\"label-description\": \"The following articles are similar to the document have currently selected.\", \"label-language\": \"en\", \"label-text\": \"Related Articles\"}, \"recommendation_set_id\": \"1\", \"recommendations\": { \"74021358\": { \"abstract\": \"abstract\", \"authors\":\"Sajovic, Marija\", \"published_year\": \"2006\", \"item_id_original\": \"12088644\", \"keywords\": [ \"visoko\\u0161olski program Geodezija - smer Prostorska informatika\" ], \"language_provided\": \"sl\", \"recommendation_id\": \"1\", \"title\": \"The protection of rural lands with the spatial development strategy on the case of Hrastnik commune\", \"url\": \"http://drugg.fgg.uni-lj.si/701/1/GEV_0199_Sajovic.pdf\" }, \"82005804\": { \"abstract\": \"abstract\", \"year_published\": null, \"item_id_original\": \"30145702\", \"language_provided\": null, \"recommendation_id\": \"2\", \"title\": \"Engagement of the volunteers in the solution to the accidents in the South-Moravia region\" }, \"82149599\": { \"abstract\": \"abstract\", \"year_published\": null, \"item_id_original\": \"97690763\", \"language_provided\": null, \"recommendation_id\": \"3\", \"title\": \"\\\"The only Father's word\\\". The relationship of the Father and the Son in the documents of saint John of the Cross\", \"url\": \"http://www.nusl.cz/ntk/nusl-285711\" }, \"84863921\": { \"abstract\": \"abstract\", \"authors\":\"Kaffa, Elena\", \"year_published\": null, \"item_id_original\": \"19397104\", \"keywords\": [ \"BX\", \"D111\" ], \"language_provided\": \"en\", \"recommendation_id\": \"4\", \"title\": \"Greek Church of Cyprus, the Morea and Constantinople during the Frankish Era (1196-1303)\" }, \"88950992\": { \"abstract\": \"abstract\", \"authors\":\"Yasui, Kono\", \"year_published\": null, \"item_id_original\": \"38763657\", \"language_provided\": null, \"recommendation_id\": \"5\", \"title\": \"A Phylogenetic Consideration on the Vascular Plants, Cotyledonary Node Including Hypocotyl Being Taken as the Ancestral Form : A Preliminary Note\" } }}"; input = new BufferedReader(new StringReader(testInput)); } From 76d5399118987f72352162b9716af20f5333fdbc Mon Sep 17 00:00:00 2001 From: Andrew Collins Date: Tue, 9 Jul 2019 14:26:04 +0100 Subject: [PATCH 14/14] Removed unused method ConfirmRecommendations() --- .../logic/importer/fetcher/MrDLibFetcher.java | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/src/main/java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java index 6556efbc31f..f09f032cfbb 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/MrDLibFetcher.java @@ -88,27 +88,6 @@ public String getDescription() { return description; } - public void confirmRecommendations(String status) { - try { - URIBuilder builder = new URIBuilder(); - builder.setScheme("http"); - builder.setHost(MDL_URL); - builder.setPath("/v2/recommendations/" + recommendationSetId + "/status/" + status); - try { - URI uri = builder.build(); - URLDownload urlDownload = new URLDownload(uri.toString()); - URLDownload.bypassSSLVerification(); - urlDownload.asString(); - } - catch (URISyntaxException se) { - LOGGER.error("Problem connecting to Mr. DLib", se); - } - - } catch (IOException e) { - LOGGER.error("Problem connecting to Mr. DLib", e); - } - } - /** * Contact the server with the title of the selected item *