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

Fix #2455: Add crossref as fetcher for everything (ID-, entry-, search-based) #2645

Merged
merged 11 commits into from
Mar 16, 2017
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- The MS Office XML export now exports the field `volumes` and `pubstate`.
- The integrity checker reports now if a journal is not found in the abbreviation list
- Comments in PDF files can now be displayed inside JabRef in a separate tab
- We are happy to welcome [CrossRef](https://www.crossref.org/) as a new member of our fetcher family. [#2455](https://github.com/JabRef/jabref/issues/2455)
- We improved the UI customization possibilities:
- It is now possible to customize the colors and the size of the icons (implements a [feature request in the forum](http://discourse.jabref.org/t/menu-and-buttons-with-a-dark-theme/405)).
- Resizing the menu and label sizes has been improved.
Expand Down Expand Up @@ -60,6 +61,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- We fixed an issue where the "find unlinked files" functionality threw an error when only one PDF was imported but not assigned to an entry [#2577](https://github.com/JabRef/jabref/issues/2577)
- We fixed issue where escaped braces were incorrectly counted when calculating brace balance in a field [#2561](https://github.com/JabRef/jabref/issues/2561)
- We fixed an issue introduced with Version 3.8.2 where executing the `Rename PDFs`-cleanup operation moved the files to the file directory. [#2526](https://github.com/JabRef/jabref/issues/2526)
- We improved the performance when opening a big database that still used the old groups format. Fixes an [issue raised in the forum](http://discourse.jabref.org/t/v3-8-2-x64-windows-problem-saving-large-bib-libraries/456).
- We fixed an issue where the `Move linked files to default file directory`- cleanup operation did not move the files to the location of the bib-file. [#2454](https://github.com/JabRef/jabref/issues/2454)
- We fixed an issue where executing `Move file` on a selected file in the `general`-tab could overwrite an existing file. [#2385](https://github.com/JabRef/jabref/issues/2358)
- We fixed an issue with importing groups and subgroups [#2600](https://github.com/JabRef/jabref/issues/2600)
Expand Down
36 changes: 23 additions & 13 deletions src/main/java/org/jabref/cli/CrossrefFetcherEvaluator.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
import java.util.concurrent.atomic.AtomicInteger;

import org.jabref.Globals;
import org.jabref.logic.identifier.DOI;
import org.jabref.logic.importer.FetcherException;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.importer.fetcher.CrossRef;
import org.jabref.logic.importer.fileformat.BibtexParser;
import org.jabref.model.database.BibDatabase;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.FieldName;
import org.jabref.model.entry.identifier.DOI;
import org.jabref.preferences.JabRefPreferences;

/**
Expand Down Expand Up @@ -52,22 +53,31 @@ public void run() {
Optional<DOI> origDOI = entry.getField(FieldName.DOI).flatMap(DOI::build);
if (origDOI.isPresent()) {
dois.incrementAndGet();
Optional<DOI> crossrefDOI = CrossRef.findDOI(entry);
if (crossrefDOI.isPresent()) {
doiFound.incrementAndGet();
if (origDOI.get().getDOI().equalsIgnoreCase(crossrefDOI.get().getDOI())) {
doiIdentical.incrementAndGet();
try {
Optional<DOI> crossrefDOI = new CrossRef().findIdentifier(entry);
if (crossrefDOI.isPresent()) {
doiFound.incrementAndGet();
if (origDOI.get().getDOI().equalsIgnoreCase(crossrefDOI.get().getDOI())) {
doiIdentical.incrementAndGet();
} else {
System.out.println("DOI not identical for : " + entry);
}
} else {
System.out.println("DOI not identical for : " + entry);
System.out.println("DOI not found for: " + entry);
}
} else {
System.out.println("DOI not found for: " + entry);
} catch (FetcherException e) {
e.printStackTrace();
}

} else {
Optional<DOI> crossrefDOI = CrossRef.findDOI(entry);
if (crossrefDOI.isPresent()) {
System.out.println("New DOI found for: " + entry);
doiNew.incrementAndGet();
try {
Optional<DOI> crossrefDOI = new CrossRef().findIdentifier(entry);
if (crossrefDOI.isPresent()) {
System.out.println("New DOI found for: " + entry);
doiNew.incrementAndGet();
}
} catch (FetcherException e) {
e.printStackTrace();
}
}
countDownLatch.countDown();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/ClipBoardManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
import java.util.Optional;

import org.jabref.Globals;
import org.jabref.logic.identifier.DOI;
import org.jabref.logic.importer.FetcherException;
import org.jabref.logic.importer.fetcher.DoiFetcher;
import org.jabref.logic.importer.fileformat.BibtexParser;
import org.jabref.model.database.BibDatabase;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.identifier.DOI;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Expand Down
53 changes: 25 additions & 28 deletions src/main/java/org/jabref/gui/EntryTypeDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
import javax.swing.SwingWorker;

import org.jabref.Globals;
import org.jabref.gui.importer.fetcher.EntryFetchers;
import org.jabref.gui.keyboard.KeyBinding;
import org.jabref.logic.importer.FetcherException;
import org.jabref.logic.importer.IdBasedFetcher;
import org.jabref.logic.importer.WebFetchers;
import org.jabref.logic.importer.fetcher.DoiFetcher;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.EntryTypes;
Expand All @@ -53,36 +53,14 @@
public class EntryTypeDialog extends JDialog implements ActionListener {

private static final Log LOGGER = LogFactory.getLog(EntryTypeDialog.class);

private static final int COLUMN = 3;
private final JabRefFrame frame;
private final CancelAction cancelAction = new CancelAction();
private EntryType type;
private SwingWorker<Optional<BibEntry>, Void> fetcherWorker = new FetcherWorker();
private JButton generateButton;
private JTextField idTextField;
private JComboBox<String> comboBox;
private final JabRefFrame frame;
private static final int COLUMN = 3;

private final CancelAction cancelAction = new CancelAction();

static class TypeButton extends JButton implements Comparable<TypeButton> {

private final EntryType type;


TypeButton(String label, EntryType type) {
super(label);
this.type = type;
}

@Override
public int compareTo(TypeButton o) {
return type.getName().compareTo(o.type.getName());
}

public EntryType getType() {
return type;
}
}

public EntryTypeDialog(JabRefFrame frame) {
// modal dialog
Expand Down Expand Up @@ -186,7 +164,7 @@ private JPanel createIdFetcherPanel() {
idTextField = new JTextField("");
comboBox = new JComboBox<>();

EntryFetchers.getIdFetchers(Globals.prefs.getImportFormatPreferences()).forEach(fetcher -> comboBox.addItem(fetcher.getName()));
WebFetchers.getIdBasedFetchers(Globals.prefs.getImportFormatPreferences()).forEach(fetcher -> comboBox.addItem(fetcher.getName()));
// set DOI as default
comboBox.setSelectedItem(DoiFetcher.name);

Expand Down Expand Up @@ -263,6 +241,25 @@ public EntryType getChoice() {
return type;
}

static class TypeButton extends JButton implements Comparable<TypeButton> {

private final EntryType type;


TypeButton(String label, EntryType type) {
super(label);
this.type = type;
}

@Override
public int compareTo(TypeButton o) {
return type.getName().compareTo(o.type.getName());
}

public EntryType getType() {
return type;
}
}

class CancelAction extends AbstractAction {
public CancelAction() {
Expand Down Expand Up @@ -290,7 +287,7 @@ protected Optional<BibEntry> doInBackground() throws Exception {
generateButton.setText(Localization.lang("Searching..."));
});
searchID = idTextField.getText().trim();
fetcher = EntryFetchers.getIdFetchers(Globals.prefs.getImportFormatPreferences()).get(comboBox.getSelectedIndex());
fetcher = WebFetchers.getIdBasedFetchers(Globals.prefs.getImportFormatPreferences()).get(comboBox.getSelectedIndex());
if (!searchID.isEmpty()) {
try {
bibEntry = fetcher.performSearchById(searchID);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/actions/CopyDoiUrlAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

import org.jabref.JabRefGUI;
import org.jabref.gui.ClipBoardManager;
import org.jabref.logic.identifier.DOI;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.entry.identifier.DOI;

/**
* Copies the doi url to the clipboard
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/gui/desktop/JabRefDesktop.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
import org.jabref.gui.filelist.FileListEntryEditor;
import org.jabref.gui.filelist.FileListTableModel;
import org.jabref.gui.undo.UndoableFieldChange;
import org.jabref.logic.identifier.DOI;
import org.jabref.logic.identifier.Eprint;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.OS;
import org.jabref.logic.util.io.FileUtil;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.FieldName;
import org.jabref.model.entry.identifier.DOI;
import org.jabref.model.entry.identifier.Eprint;
import org.jabref.preferences.JabRefPreferences;

import org.apache.commons.logging.Log;
Expand Down
Loading