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

Integrates fetching citation counts online (Google Scholar, Semantic Scholar and OpenCitations), integrates a general structure for fechting reference metadata and integrates a general websocket server for JabRef #5943

Closed
wants to merge 80 commits into from
Closed
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
75132ea
skeleton added for fetching citation counts online (Google Scholar)
systemoperator Feb 13, 2020
6d03ac8
extension
systemoperator Feb 13, 2020
0b7343c
correcting KeyBinding
systemoperator Feb 13, 2020
22145ee
Merge remote-tracking branch 'upstream/master' into citation-counts
systemoperator Feb 15, 2020
a6b2b1f
generalizing fetching citation counts to fetching citation metadata
systemoperator Feb 15, 2020
42b868d
refactoring fetching citation metadata to fetching reference metadata
systemoperator Feb 16, 2020
d57cea1
websocket server template added
systemoperator Feb 16, 2020
665d1b7
JabRefWebsocketServer: startup/shutdown registered; shutdown hook add…
systemoperator Feb 17, 2020
032a908
refactoring, extension
systemoperator Feb 17, 2020
d0c3d75
refactoring
systemoperator Feb 17, 2020
9a4d9ad
JabRefWebsocketServer: refactoring
systemoperator Feb 18, 2020
56c1e69
JabRefWebsocketServer: unification and extension
systemoperator Feb 18, 2020
575c5f2
JabRefWebsocketServer: extension, refactoring
systemoperator Feb 19, 2020
c397f45
testing fetching citation counts from Google Schloar, formattings, co…
systemoperator Feb 20, 2020
91b2adb
minor changes
systemoperator Feb 21, 2020
32d7400
Merge remote-tracking branch 'upstream/master' into citation-counts
systemoperator Feb 21, 2020
4325489
refactoring, extension
systemoperator Feb 24, 2020
9eb0e4f
minor changes
systemoperator Feb 24, 2020
057b13b
functional dump
systemoperator Feb 24, 2020
39362ec
current dump (already functional)
systemoperator Feb 25, 2020
1f324c9
cleanup
systemoperator Feb 25, 2020
99e5d77
extensions, LOGGERs added, improvements, formatting
systemoperator Feb 26, 2020
ac89007
extension
systemoperator Feb 26, 2020
4382482
ReferenceMetadataFetcherSemanticScholar added
systemoperator Feb 26, 2020
f1d10ad
extension in general; creating pipeline for fetching reference metadata
systemoperator Feb 26, 2020
395b99b
ReferenceMetadataFetcherOpenCitations added
systemoperator Feb 26, 2020
42b04d8
refactoring
systemoperator Feb 26, 2020
d949eb6
minor changes
systemoperator Feb 26, 2020
07a4016
Merge remote-tracking branch 'upstream/master' into citation-counts
systemoperator Feb 26, 2020
2dddb05
changelog updated
systemoperator Feb 26, 2020
c887fc0
changing field type
systemoperator Mar 1, 2020
b68a648
Merge remote-tracking branch 'upstream/master' into citation-counts
systemoperator Mar 1, 2020
17c8878
progress bar improved
systemoperator Mar 2, 2020
c8604f7
small fix
systemoperator Mar 2, 2020
dce8ce2
minor improvement of the progress bar for Google Scholar
systemoperator Mar 2, 2020
9f48fd2
resolve abbreviations; debug message added in case the given port for…
systemoperator Mar 7, 2020
511e503
code style updated
systemoperator Mar 7, 2020
eb68e09
refactoring
systemoperator Mar 7, 2020
10ae06b
Merge remote-tracking branch 'upstream/master' into citation-counts
systemoperator Mar 7, 2020
599741c
code quality
systemoperator Mar 7, 2020
dfdb9dc
localization
systemoperator Mar 9, 2020
e7b8773
translation en
systemoperator Mar 9, 2020
a5b1aaa
translations
systemoperator Mar 10, 2020
bdb3fb8
localization refactored
systemoperator Mar 10, 2020
df2118e
localization
systemoperator Mar 10, 2020
73ef19b
small improvement to remove latex code from specific fields to make i…
systemoperator Mar 15, 2020
0866a98
remove latex code from creators as well
systemoperator Mar 15, 2020
e7f217f
authors/editors: remove braces after parsing
systemoperator Mar 19, 2020
afbbe4e
duplicate changelog entry removed
systemoperator Mar 19, 2020
fa4be18
Merge remote-tracking branch 'upstream/master' into citation-counts
systemoperator Mar 19, 2020
6c69fca
IncompleteItem converted to private, inner class
systemoperator Mar 19, 2020
5a56a5a
convert use LOGGER.error() instead of printStackTrace()
systemoperator Mar 19, 2020
6a37291
degrading selected LOGGER.info() to LOGGER.debug()
systemoperator Mar 19, 2020
c9e61fd
integrate Optionals
systemoperator Mar 19, 2020
c19d22e
extract method prepareRequestObject()
systemoperator Mar 19, 2020
44041c2
remove preceding underscores of variables
systemoperator Mar 19, 2020
6c08a96
removing underscores in variable names
systemoperator Mar 19, 2020
9267a45
Merge branch 'local-tooltips' into citation-counts
systemoperator Mar 20, 2020
e0754b5
minor refactoring in terms of nesting
systemoperator Mar 25, 2020
dcf0e66
reduce nesting
systemoperator Mar 25, 2020
d684755
additional synchronized statements added
systemoperator Mar 25, 2020
4158caa
changelog: cleanup, move new features to "Added", split entry into tw…
systemoperator Mar 25, 2020
5a56bac
refactoring: reduce nesting
systemoperator Mar 25, 2020
24ce4d3
Merge remote-tracking branch 'upstream/master' into citation-counts
systemoperator Mar 26, 2020
5b76d3e
Merge remote-tracking branch 'upstream/master' into citation-counts
systemoperator Apr 3, 2020
967d134
Merge remote-tracking branch 'upstream/master' into citation-counts
systemoperator Apr 28, 2020
de6dbb4
Move "Fetch reference metadata" from menu "Tools" to menu "Lookup".
systemoperator Apr 28, 2020
2331754
Merge remote-tracking branch 'upstream/master' into citation-counts
systemoperator May 13, 2020
915227f
checkstyle
systemoperator May 15, 2020
b035310
Merge remote-tracking branch 'upstream/master' into citation-counts
systemoperator May 15, 2020
d3151ab
change showProgressDialogAndWait() to showProgressDialog()
systemoperator May 15, 2020
893324b
Merge remote-tracking branch 'upstream/master' into citation-counts
systemoperator May 29, 2020
8b46044
add field
systemoperator May 29, 2020
aebf2b6
Merge remote-tracking branch 'upstream/master' into citation-counts
systemoperator Sep 8, 2020
f5dc536
Merge remote-tracking branch 'upstream/master' into citation-counts
systemoperator Dec 19, 2020
70e2022
annotations added
systemoperator Dec 19, 2020
541bdb8
checkstyle
systemoperator Dec 19, 2020
8552691
refactoring
systemoperator Dec 21, 2020
29bf17a
refactoring
systemoperator Dec 21, 2020
756f342
Merge remote-tracking branch 'upstream/master' into citation-counts
systemoperator Jan 13, 2021
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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We reintroduced the index column. [#5844](https://github.com/JabRef/jabref/pull/5844)
- Filenames of external files can no longer contain curly braces. [#5926](https://github.com/JabRef/jabref/pull/5926)
- We made the filters more easily accessible in the integrity check dialog. [#5955](https://github.com/JabRef/jabref/pull/5955)
- We reimplemented and improved the dialog "Customize entry types" [#4719](https://github.com/JabRef/jabref/issues/4719)
systemoperator marked this conversation as resolved.
Show resolved Hide resolved
- We integrated fetching and updating citation counts online from Google Scholar, Semantic Scholar and OpenCitations. We integrated a general websocket server which currently allows bidirectional communication with the JabRef-Browser-Extension for fetching citation counts. The latest version of the JabRef-Browser-Extension (JabFox) is needed for that. [#5943](https://github.com/JabRef/jabref/pull/5943)
- We reimplemented and improved the dialog "Customize entry types". [#4719](https://github.com/JabRef/jabref/issues/4719)

### Fixed
Expand Down
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ dependencies {
exclude module: 'fastparse_2.12'
}

implementation group: 'org.java-websocket', name: 'Java-WebSocket', version: '1.4.0'

implementation group: 'com.microsoft.azure', name: 'applicationinsights-core', version: '2.4.1'
implementation (group: 'com.microsoft.azure', name: 'applicationinsights-logging-log4j2', version: '2.4.1') {
exclude module: "log4j-core"
Expand Down
1 change: 1 addition & 0 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,5 @@
requires org.antlr.antlr4.runtime;
requires flowless;
requires org.apache.tika.core;
requires Java.WebSocket;
}
4 changes: 4 additions & 0 deletions src/main/java/org/jabref/Globals.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.model.util.FileUpdateMonitor;
import org.jabref.preferences.JabRefPreferences;
import org.jabref.websocket.JabRefWebsocketServer;

import com.google.common.base.StandardSystemProperty;
import com.microsoft.applicationinsights.TelemetryClient;
Expand Down Expand Up @@ -98,6 +99,8 @@ public static void startBackgroundTasks() throws JabRefException {
if (Globals.prefs.shouldCollectTelemetry() && !GraphicsEnvironment.isHeadless()) {
startTelemetryClient();
}

JabRefWebsocketServer.getInstance().startServer();
}

private static void stopTelemetryClient() {
Expand Down Expand Up @@ -135,6 +138,7 @@ public static void shutdownThreadPools() {
public static void stopBackgroundTasks() {
stopTelemetryClient();
Unirest.shutDown();
JabRefWebsocketServer.getInstance().stopServer();
}

public static Optional<TelemetryClient> getTelemetryClient() {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
import org.jabref.gui.protectedterms.ManageProtectedTermsAction;
import org.jabref.gui.push.PushToApplicationAction;
import org.jabref.gui.push.PushToApplicationsManager;
import org.jabref.gui.referencemetadata.ReferenceMetadataFetcherAction;
import org.jabref.gui.search.GlobalSearchBar;
import org.jabref.gui.shared.ConnectToSharedDatabaseCommand;
import org.jabref.gui.shared.PullChangesFromSharedAction;
Expand Down Expand Up @@ -822,6 +823,8 @@ private MenuBar createMenu() {
lookupIdentifiers,
factory.createMenuItem(StandardActions.DOWNLOAD_FULL_TEXT, new DownloadFullTextAction(dialogService, stateManager, prefs)),

factory.createMenuItem(StandardActions.FETCH_REFERENCE_METADATA, new ReferenceMetadataFetcherAction(this, prefs, stateManager, undoManager, Globals.TASK_EXECUTOR)),
systemoperator marked this conversation as resolved.
Show resolved Hide resolved

new SeparatorMenuItem(),

factory.createMenuItem(StandardActions.SEND_AS_EMAIL, new SendAsEMailAction(dialogService, stateManager)),
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/jabref/gui/actions/StandardActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public enum StandardActions implements Action {
FIND_UNLINKED_FILES(Localization.lang("Search for unlinked local files"), IconTheme.JabRefIcons.SEARCH, KeyBinding.FIND_UNLINKED_FILES),
AUTO_LINK_FILES(Localization.lang("Automatically set file links"), IconTheme.JabRefIcons.AUTO_FILE_LINK, KeyBinding.AUTOMATICALLY_LINK_FILES),
LOOKUP_DOC_IDENTIFIER(Localization.lang("Search document identifier online")),
FETCH_REFERENCE_METADATA(Localization.lang("Fetch reference metadata online"), IconTheme.JabRefIcons.DOWNLOAD, KeyBinding.FETCH_REFERENCE_METADATA),
LOOKUP_FULLTEXT(Localization.lang("Search full text documents online"), IconTheme.JabRefIcons.FILE_SEARCH, KeyBinding.DOWNLOAD_FULL_TEXT),
GENERATE_CITE_KEY(Localization.lang("Generate BibTeX key"), IconTheme.JabRefIcons.MAKE_KEY, KeyBinding.AUTOGENERATE_BIBTEX_KEYS),
GENERATE_CITE_KEYS(Localization.lang("Generate BibTeX keys"), IconTheme.JabRefIcons.MAKE_KEY, KeyBinding.AUTOGENERATE_BIBTEX_KEYS),
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/jabref/gui/keyboard/KeyBinding.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public enum KeyBinding {
DELETE_ENTRY("Delete entry", Localization.lang("Delete entry"), "DELETE", KeyBindingCategory.BIBTEX),
DEFAULT_DIALOG_ACTION("Execute default action in dialog", Localization.lang("Execute default action in dialog"), "ctrl+ENTER", KeyBindingCategory.VIEW),
DOWNLOAD_FULL_TEXT("Download full text documents", Localization.lang("Download full text documents"), "alt+F7", KeyBindingCategory.QUALITY),
FETCH_REFERENCE_METADATA("Fetch reference metadata online", Localization.lang("Fetch reference metadata online"), "ctrl+alt+M", KeyBindingCategory.TOOLS),
EDIT_ENTRY("Edit entry", Localization.lang("Edit entry"), "ctrl+E", KeyBindingCategory.BIBTEX),
EXPORT("Export", Localization.lang("Export"), "ctrl+alt+e", KeyBindingCategory.FILE),
EXPORT_SELECTED("Export Selected", Localization.lang("Export selected entries"), "ctrl+shift+e", KeyBindingCategory.FILE),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public void setValues() {
new MainTableColumnModel(MainTableColumnModel.Type.NORMALFIELD, InternalField.OWNER.getName()),
new MainTableColumnModel(MainTableColumnModel.Type.NORMALFIELD, InternalField.GROUPS.getName()),
new MainTableColumnModel(MainTableColumnModel.Type.NORMALFIELD, InternalField.KEY_FIELD.getName()),
new MainTableColumnModel(MainTableColumnModel.Type.NORMALFIELD, InternalField.CITATION_COUNT.getName()),
new MainTableColumnModel(MainTableColumnModel.Type.NORMALFIELD, InternalField.TYPE_HEADER.getName())
);

Expand Down
31 changes: 31 additions & 0 deletions src/main/java/org/jabref/gui/referencemetadata/ExtendedTask.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.jabref.gui.referencemetadata;

import javafx.concurrent.Task;

public abstract class ExtendedTask<V> extends Task<V> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The purpose of this class is not clear to me (as it passes everything directly to its super class). Moreover, we have BackgroundTask which is usually used to for background tasks.

Copy link
Contributor Author

@systemoperator systemoperator Mar 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I needed this class, so that I can access the methods from outside, meaning the change is, that they are public.


@Override
public void updateProgress(long workDone, long max) {
super.updateProgress(workDone, max);
}

@Override
public void updateProgress(double workDone, double max) {
super.updateProgress(workDone, max);
}

@Override
public void updateMessage(String message) {
super.updateMessage(message);
}

@Override
public void updateTitle(String title) {
super.updateTitle(title);
}

@Override
public void updateValue(V value) {
super.updateValue(value);
}
}
39 changes: 39 additions & 0 deletions src/main/java/org/jabref/gui/referencemetadata/IncompleteItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.jabref.gui.referencemetadata;

import com.google.gson.JsonArray;

public class IncompleteItem {
systemoperator marked this conversation as resolved.
Show resolved Hide resolved
String key;
String title;
JsonArray authors;

public IncompleteItem(String key, String title, JsonArray authors) {
this.key = key;
this.title = title;
this.authors = authors;
}

public String getKey() {
return key;
}

public void setKey(String key) {
this.key = key;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public JsonArray getAuthors() {
return authors;
}

public void setAuthors(JsonArray authors) {
this.authors = authors;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package org.jabref.gui.referencemetadata;

import java.util.LinkedList;
import java.util.List;

import javax.swing.undo.UndoManager;

import javafx.collections.ObservableList;

import org.jabref.gui.DialogService;
import org.jabref.gui.JabRefFrame;
import org.jabref.gui.StateManager;
import org.jabref.gui.actions.SimpleCommand;
import org.jabref.gui.undo.NamedCompound;
import org.jabref.gui.util.BindingsHelper;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.preferences.JabRefPreferences;

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

import static org.jabref.gui.actions.ActionHelper.needsDatabase;
import static org.jabref.gui.actions.ActionHelper.needsEntriesSelected;

/**
* This class allows fetching the reference metadata (e.g. citation counts) from the web for the currently selected
* entries in a library.
*/
public class ReferenceMetadataFetcherAction extends SimpleCommand {

private static final Logger LOGGER = LoggerFactory.getLogger(ReferenceMetadataFetcherAction.class);

private static boolean USE_REFERENCE_METADATA_FETCHER_GOOGLE_SCHOLAR = true;
private static boolean USE_REFERENCE_METADATA_FETCHER_SEMANTIC_SCHOLAR = true;
private static boolean USE_REFERENCE_METADATA_FETCHER_OPEN_CITATIONS = true;

private final DialogService dialogService;
private final JabRefPreferences preferences;
private final StateManager stateManager;
private UndoManager undoManager;
private TaskExecutor taskExecutor;

public ReferenceMetadataFetcherAction(JabRefFrame frame, JabRefPreferences preferences, StateManager stateManager, UndoManager undoManager, TaskExecutor taskExecutor) {
this.dialogService = frame.getDialogService();
this.preferences = preferences;
this.stateManager = stateManager;
this.undoManager = undoManager;
this.taskExecutor = taskExecutor;

this.executable.bind(needsDatabase(this.stateManager).and(needsEntriesSelected(stateManager)));
this.statusMessage.bind(BindingsHelper.ifThenElse(executable, Localization.lang("This operation fetches " +
"reference metadata for the currently selected entries online."), Localization.lang("This " +
"operation requires one or more entries to be selected.")));
Comment on lines +51 to +53
Copy link
Member

@calixtus calixtus Mar 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the localization test is failing because of this statement. Please concatenate the strings inside the Localization:lang-expressions to single strings and add them to the l10n-resources.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only to the english resource file. Translations are handled by crowdin.

}

@Override
public void execute() {
systemoperator marked this conversation as resolved.
Show resolved Hide resolved
BibDatabaseContext database = stateManager.getActiveDatabase().orElseThrow(() -> new NullPointerException("Database null"));
tobiasdiez marked this conversation as resolved.
Show resolved Hide resolved
ObservableList<BibEntry> entries = stateManager.getSelectedEntries();

final NamedCompound nc = new NamedCompound(Localization.lang("Fetch reference metadata"));

ExtendedTask<List<BibEntry>> fetchReferenceMetadataTask = new ExtendedTask<List<BibEntry>>() {

@Override
protected List<BibEntry> call() {

boolean processCancelled = false;

ObservableList<BibEntry> entriesWithIncompleteMetadata = entries;

// run prioritized metadata fetcher pipeline

if (!processCancelled && USE_REFERENCE_METADATA_FETCHER_GOOGLE_SCHOLAR && entriesWithIncompleteMetadata.size() > 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add a method in WebFetchets which returns the three fetchers and then refactor the code to a foreach loop.

LOGGER.info("running " + ReferenceMetadataFetcherGoogleScholar.class.getSimpleName() + "...");
ReferenceMetadataFetcherGoogleScholar referenceMetadataFetcherGoogleScholar = new ReferenceMetadataFetcherGoogleScholar();
processCancelled = referenceMetadataFetcherGoogleScholar.fetchFor(database, entriesWithIncompleteMetadata, dialogService, this);
entriesWithIncompleteMetadata = referenceMetadataFetcherGoogleScholar.getEntriesWithIncompleteMetadata();
}

if (!processCancelled && USE_REFERENCE_METADATA_FETCHER_SEMANTIC_SCHOLAR && entriesWithIncompleteMetadata.size() > 0) {
LOGGER.info("running " + ReferenceMetadataFetcherSemanticScholar.class.getSimpleName() + "...");
ReferenceMetadataFetcherSemanticScholar referenceMetadataFetcherSemanticScholar = new ReferenceMetadataFetcherSemanticScholar();
processCancelled = referenceMetadataFetcherSemanticScholar.fetchFor(database, entriesWithIncompleteMetadata, dialogService, this);
entriesWithIncompleteMetadata = referenceMetadataFetcherSemanticScholar.getEntriesWithIncompleteMetadata();
}

if (!processCancelled && USE_REFERENCE_METADATA_FETCHER_OPEN_CITATIONS && entriesWithIncompleteMetadata.size() > 0) {
LOGGER.info("running " + ReferenceMetadataFetcherOpenCitations.class.getSimpleName() + "...");
ReferenceMetadataFetcherOpenCitations referenceMetadataFetcherOpenCitations = new ReferenceMetadataFetcherOpenCitations();
processCancelled = referenceMetadataFetcherOpenCitations.fetchFor(database, entriesWithIncompleteMetadata, dialogService, this);
entriesWithIncompleteMetadata = referenceMetadataFetcherOpenCitations.getEntriesWithIncompleteMetadata();
}

if (!processCancelled) {
return entries;
} else {
return new LinkedList<BibEntry>();
}
}

@Override
protected void succeeded() {
if (!getValue().isEmpty()) {
// reserved for future use
//if (nc.hasEdits()) {
// nc.end();
// undoManager.addEdit(nc);
//}
dialogService.notify(Localization.lang("Finished fetching reference metadata."));
} else {
dialogService.notify(Localization.lang("Cancelled fetching reference metadata."));
}
}
};

dialogService.showProgressDialogAndWait(
Localization.lang("Fetching reference metadata online"),
Localization.lang("Querying reference metadata:"),
fetchReferenceMetadataTask);
taskExecutor.execute(fetchReferenceMetadataTask);
}
}
Loading