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

Add "Look up DOIs" to Quality menu #2442

Merged
merged 5 commits into from
Mar 18, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
## [Unreleased]

### Changed
- Using "Look up DOIs" in the quality menu, it is possible to look up DOIs for multiple entries.

### Fixed
The formatter for normalizing pages now also can treat ACM pages such as `2:1--2:33`.
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/net/sf/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
import net.sf.jabref.gui.worker.AbstractWorker;
import net.sf.jabref.gui.worker.CallBack;
import net.sf.jabref.gui.worker.CitationStyleToClipboardWorker;
import net.sf.jabref.gui.worker.LookupDOIsWorker;
import net.sf.jabref.gui.worker.MarkEntriesAction;
import net.sf.jabref.gui.worker.SendAsEMailAction;
import net.sf.jabref.logic.autocompleter.AutoCompletePreferences;
Expand Down Expand Up @@ -702,6 +703,7 @@ public void update() {
actions.put(Actions.REMOVE_FROM_GROUP, new GroupAddRemoveDialog(this, false, false));
actions.put(Actions.MOVE_TO_GROUP, new GroupAddRemoveDialog(this, true, true));

actions.put(Actions.LOOKUP_DOIS, new LookupDOIsWorker(frame));
actions.put(Actions.DOWNLOAD_FULL_TEXT, new FindFullTextAction(this));
}

Expand Down
9 changes: 7 additions & 2 deletions src/main/java/net/sf/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,10 @@ public void actionPerformed(ActionEvent e) {
private final MassSetFieldAction massSetField = new MassSetFieldAction(this);
private final ManageKeywordsAction manageKeywords = new ManageKeywordsAction(this);

private final AbstractAction lookupDOIs = new GeneralAction(Actions.LOOKUP_DOIS,
Localization.menuTitle("Look up DOIs"),
Localization.lang("Look up DOIs"));

private final GeneralAction findUnlinkedFiles = new GeneralAction(
FindUnlinkedFilesDialog.ACTION_COMMAND,
FindUnlinkedFilesDialog.ACTION_MENU_TITLE, FindUnlinkedFilesDialog.ACTION_SHORT_DESCRIPTION,
Expand Down Expand Up @@ -1304,6 +1308,7 @@ private void fillMenu() {
quality.add(autoSetFile);
quality.add(findUnlinkedFiles);
quality.add(autoLinkFile);
quality.add(lookupDOIs);
quality.add(downloadFullText);
mb.add(quality);

Expand Down Expand Up @@ -1501,7 +1506,7 @@ private void initActions() {
saveAs, saveSelectedAs, saveSelectedAsPlain, editModeAction, undo, redo, cut, deleteEntry, copy, paste, mark, markSpecific, unmark,
unmarkAll, rankSubMenu, editEntry, selectAll, copyKey, copyCiteKey, copyKeyAndTitle, copyKeyAndLink, editPreamble, editStrings,
groupSelector.getToggleAction(), makeKeyAction, normalSearch, generalFetcher.getToggleAction(), mergeEntries, cleanupEntries, exportToClipboard, replaceAll,
sendAsEmail, downloadFullText, writeXmpAction, openOfficePanel.getToggleAction(), findUnlinkedFiles, addToGroup, removeFromGroup,
sendAsEmail, downloadFullText, lookupDOIs, writeXmpAction, openOfficePanel.getToggleAction(), findUnlinkedFiles, addToGroup, removeFromGroup,
moveToGroup, autoLinkFile, resolveDuplicateKeys, openUrl, openFolder, openFile, togglePreview,
dupliCheck, autoSetFile, newEntryAction, newSpec, customizeAction, plainTextImport, getMassSetField(), getManageKeywords(),
pushExternalButton.getMenuAction(), closeDatabaseAction, getNextPreviewStyleAction(), getPreviousPreviewStyleAction(), checkIntegrity,
Expand Down Expand Up @@ -1534,7 +1539,7 @@ dupliCheck, autoSetFile, newEntryAction, newSpec, customizeAction, plainTextImpo
twoEntriesOnlyActions.addAll(Arrays.asList(mergeEntries));

atLeastOneEntryActions.clear();
atLeastOneEntryActions.addAll(Arrays.asList(downloadFullText));
atLeastOneEntryActions.addAll(Arrays.asList(downloadFullText, lookupDOIs));

tabbedPane.addChangeListener(event -> updateEnabledState());

Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/sf/jabref/gui/actions/Actions.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class Actions {
public static final String EXPORT_TO_CLIPBOARD = "exportToClipboard";
public static final String FOCUS_TABLE = "focusTable";
public static final String FORWARD = "forward";
public static final String LOOKUP_DOIS = "lookupDOIs";
public static final String MAKE_KEY = "makeKey";
public static final String MANAGE_SELECTORS = "manageSelectors";
public static final String MARK_ENTRIES = "markEntries";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public static Optional<JComponent> getDoiExtraComponent(BasePanel panel, EntryEd
}
});
// lookup doi
JButton doiButton = new JButton(Localization.lang("Lookup DOI"));
JButton doiButton = new JButton(Localization.lang("Look up DOI"));
doiButton.addActionListener(actionEvent -> {
Optional<DOI> doi = DOI.fromBibEntry(entryEditor.getEntry());
if (doi.isPresent()) {
Expand Down
69 changes: 69 additions & 0 deletions src/main/java/net/sf/jabref/gui/worker/LookupDOIsWorker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package net.sf.jabref.gui.worker;

import java.util.List;
import java.util.Objects;
import java.util.Optional;

import net.sf.jabref.gui.BasePanel;
import net.sf.jabref.gui.JabRefFrame;
import net.sf.jabref.gui.undo.NamedCompound;
import net.sf.jabref.gui.undo.UndoableFieldChange;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.util.DOI;
import net.sf.jabref.model.FieldChange;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.model.entry.FieldName;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class LookupDOIsWorker extends AbstractWorker {

private final JabRefFrame frame;
private String message;

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

public LookupDOIsWorker(JabRefFrame frame) {
Copy link
Member

Choose a reason for hiding this comment

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

For maximal reusability, could you please make this class independent on DOI. There are many other identifier for which such an automatic look-up makes sense.

Copy link
Member Author

@koppor koppor Jan 20, 2017

Choose a reason for hiding this comment

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

  • Language: Either ID or let the caller set the DOI name
  • lines 43 to 46 somehow extract. Interface: CanCompleteEntry

Copy link
Member

Choose a reason for hiding this comment

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

@koppor can you please rebase and I will implement then the rest. Deal?

this.frame = Objects.requireNonNull(frame);
}

@Override
public void run() {
BasePanel basePanel = Objects.requireNonNull(frame.getCurrentBasePanel());
List<BibEntry> bibEntries = basePanel.getSelectedEntries();
if (!bibEntries.isEmpty()) {
String totalCount = Integer.toString(bibEntries.size());
NamedCompound namedCompound = new NamedCompound(Localization.lang("Look up DOIs"));
int count = 0;
int foundCount = 0;
for (BibEntry bibEntry : bibEntries) {
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't it make sense to directly filter out the bibtex fields which have a DOI here with a stream?
e.g bibentries.stream().filter(x->hasField(FielName.DOI).....

Copy link
Member Author

Choose a reason for hiding this comment

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

I have no idea how to create a progress bar there.

I found http://stackoverflow.com/a/26814087/873282, but that code looks much more complicated than the current code. Should I change it?

Copy link
Member

Choose a reason for hiding this comment

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

Na then go for it now.,

count++;
frame.output(Localization.lang("Looking up DOIs... - entry %0 out of %1 - found %2", Integer.toString(count), totalCount, Integer.toString(foundCount)));
if (!bibEntry.hasField(FieldName.DOI)) {
Optional<DOI> doi = DOI.fromBibEntry(bibEntry);
if (doi.isPresent()) {
Copy link
Member

Choose a reason for hiding this comment

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

You could chain the optionals with flatmap, avoid the ifPresent cascading...

http://www.nurkiewicz.com/2013/08/optional-in-java-8-cheat-sheet.html

Copy link
Member Author

Choose a reason for hiding this comment

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

No clue how I can do that with progress...

Copy link
Member

Choose a reason for hiding this comment

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

Okay, was just an idea. If it does not make it easier forget about it

Optional<FieldChange> fieldChange = bibEntry.setField(FieldName.DOI, doi.get().getDOI());
if (fieldChange.isPresent()) {
namedCompound.addEdit(new UndoableFieldChange(fieldChange.get()));
foundCount++;
frame.output(Localization.lang("Looking up DOIs... - entry %0 out of %1 - found %2", Integer.toString(count), totalCount, Integer.toString(foundCount)));
}
}
}
}
namedCompound.end();
if (foundCount > 0) {
basePanel.getUndoManager().addEdit(namedCompound);
basePanel.markBaseChanged();
}
message = Localization.lang("Determined_DOIs_for_%0_entries", Integer.toString(foundCount));
}
}

@Override
public void update() {
frame.output(message);
}

}
3 changes: 0 additions & 3 deletions src/main/java/net/sf/jabref/gui/worker/MarkEntriesAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
*
*/
public class MarkEntriesAction extends AbstractWorker implements ActionListener {

private final JabRefFrame frame;
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/l10n/JabRef_da.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2085,7 +2085,10 @@ Mixed_names=
Neuter_name=
Neuter_names=

Lookup_DOI=
Look_up_DOI=
Look_up_DOIs=
Looking_up_DOIs..._-_entry_%0_out_of_%1_-_found_%2=
Determined_DOIs_for_%0_entries=

Audio_CD=
British_patent=
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/l10n/JabRef_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2085,7 +2085,10 @@ Mixed_names=gemischte_Namen
Neuter_name=neutraler_Name
Neuter_names=neutrale_Namen

Lookup_DOI=Suche_DOI
Look_up_DOI=Suche_DOI
Look_up_DOIs=
Looking_up_DOIs..._-_entry_%0_out_of_%1_-_found_%2=
Determined_DOIs_for_%0_entries=

Audio_CD=Audio_CD
British_patent=Britisches_Patent
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2085,7 +2085,10 @@ Mixed_names=Mixed_names
Neuter_name=Neuter_name
Neuter_names=Neuter_names

Lookup_DOI=Lookup_DOI
Look_up_DOI=Look_up_DOI
Look_up_DOIs=Look_up_DOIs
Looking_up_DOIs..._-_entry_%0_out_of_%1_-_found_%2=Looking_up_DOIs..._-_entry_%0_out_of_%1_-_found_%2
Determined_DOIs_for_%0_entries=Determined_DOIs_for_%0_entries

Audio_CD=Audio_CD
British_patent=British_patent
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/l10n/JabRef_es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2085,7 +2085,10 @@ Mixed_names=Nombres_mixtos
Neuter_name=Nombre_neutro
Neuter_names=Nombres_neutros

Lookup_DOI=Buscar_DOI
Look_up_DOI=Buscar_DOI
Look_up_DOIs=
Looking_up_DOIs..._-_entry_%0_out_of_%1_-_found_%2=
Determined_DOIs_for_%0_entries=

Audio_CD=Audio_CD
British_patent=Patente_británica
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/l10n/JabRef_fa.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2085,7 +2085,10 @@ Mixed_names=
Neuter_name=
Neuter_names=

Lookup_DOI=
Look_up_DOI=
Look_up_DOIs=
Looking_up_DOIs..._-_entry_%0_out_of_%1_-_found_%2=
Determined_DOIs_for_%0_entries=

Audio_CD=
British_patent=
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/l10n/JabRef_fr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2085,7 +2085,10 @@ Mixed_names=Noms_mixtes
Neuter_name=Nom_neutre
Neuter_names=Noms_neutres

Lookup_DOI=Chercher_le_DOI
Look_up_DOI=Chercher_le_DOI
Look_up_DOIs=
Looking_up_DOIs..._-_entry_%0_out_of_%1_-_found_%2=
Determined_DOIs_for_%0_entries=

Audio_CD=CD_audio
British_patent=Brevet_britannique
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/l10n/JabRef_in.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2085,7 +2085,10 @@ Mixed_names=
Neuter_name=
Neuter_names=

Lookup_DOI=
Look_up_DOI=
Look_up_DOIs=
Looking_up_DOIs..._-_entry_%0_out_of_%1_-_found_%2=
Determined_DOIs_for_%0_entries=

Audio_CD=
British_patent=
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/l10n/JabRef_it.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2085,7 +2085,10 @@ Mixed_names=Nomi_misti
Neuter_name=Nome_neutro
Neuter_names=Nomi_neutri

Lookup_DOI=Cerca_DOI
Look_up_DOI=Cerca_DOI
Look_up_DOIs=
Looking_up_DOIs..._-_entry_%0_out_of_%1_-_found_%2=
Determined_DOIs_for_%0_entries=

Audio_CD=CD_Audio
British_patent=Brevetto_britannico
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/l10n/JabRef_ja.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2085,7 +2085,10 @@ Mixed_names=男女名
Neuter_name=中性名
Neuter_names=中性名

Lookup_DOI=DOIを検索
Look_up_DOI=DOIを検索
Look_up_DOIs=
Looking_up_DOIs..._-_entry_%0_out_of_%1_-_found_%2=
Determined_DOIs_for_%0_entries=

Audio_CD=オーディオCD
British_patent=イギリス特許
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/l10n/JabRef_nl.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2085,7 +2085,10 @@ Mixed_names=
Neuter_name=
Neuter_names=

Lookup_DOI=
Look_up_DOI=
Look_up_DOIs=
Looking_up_DOIs..._-_entry_%0_out_of_%1_-_found_%2=
Determined_DOIs_for_%0_entries=

Audio_CD=
British_patent=
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/l10n/JabRef_no.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2085,7 +2085,10 @@ Mixed_names=
Neuter_name=
Neuter_names=

Lookup_DOI=
Look_up_DOI=
Look_up_DOIs=
Looking_up_DOIs..._-_entry_%0_out_of_%1_-_found_%2=
Determined_DOIs_for_%0_entries=

Audio_CD=
British_patent=
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/l10n/JabRef_pt_BR.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2085,7 +2085,10 @@ Mixed_names=
Neuter_name=
Neuter_names=

Lookup_DOI=
Look_up_DOI=
Look_up_DOIs=
Looking_up_DOIs..._-_entry_%0_out_of_%1_-_found_%2=
Determined_DOIs_for_%0_entries=

Audio_CD=
British_patent=
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/l10n/JabRef_ru.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2085,7 +2085,10 @@ Mixed_names=Смешанные_имена
Neuter_name=Имя_среднего_рода
Neuter_names=Имена_среднего_рода

Lookup_DOI=DOI_для_поиска
Look_up_DOI=DOI_для_поиска
Look_up_DOIs=
Looking_up_DOIs..._-_entry_%0_out_of_%1_-_found_%2=
Determined_DOIs_for_%0_entries=

Audio_CD=Аудио_CD
British_patent=Патент_(Британия)
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/l10n/JabRef_sv.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2085,7 +2085,10 @@ Mixed_names=_Blandade_namn
Neuter_name=Ett_neutrumnamn
Neuter_names=Flera_neutrumnamn

Lookup_DOI=Leta_efter_DOI
Look_up_DOI=Leta_efter_DOI
Look_up_DOIs=
Looking_up_DOIs..._-_entry_%0_out_of_%1_-_found_%2=
Determined_DOIs_for_%0_entries=

Audio_CD=Ljud-CD
British_patent=Brittiskt_patent
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/l10n/JabRef_tr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2085,7 +2085,10 @@ Mixed_names=Karışık_adlar
Neuter_name=Cinsiyetsiz_ad
Neuter_names=Cinsiyetsiz_adlar

Lookup_DOI=DOI_bul
Look_up_DOI=DOI_bul
Look_up_DOIs=
Looking_up_DOIs..._-_entry_%0_out_of_%1_-_found_%2=
Determined_DOIs_for_%0_entries=

Audio_CD=Müzik_CDsi
British_patent=İngiliz_patenti
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/l10n/JabRef_vi.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2085,7 +2085,10 @@ Mixed_names=
Neuter_name=
Neuter_names=

Lookup_DOI=Tra_từ_DOI
Look_up_DOI=Tra_từ_DOI
Look_up_DOIs=
Looking_up_DOIs..._-_entry_%0_out_of_%1_-_found_%2=
Determined_DOIs_for_%0_entries=

Audio_CD=Đĩa_âm_thanh
British_patent=Sáng_chế_của_Anh
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/l10n/JabRef_zh.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2085,7 +2085,10 @@ Mixed_names=
Neuter_name=
Neuter_names=

Lookup_DOI=
Look_up_DOI=
Look_up_DOIs=
Looking_up_DOIs..._-_entry_%0_out_of_%1_-_found_%2=
Determined_DOIs_for_%0_entries=

Audio_CD=
British_patent=
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/l10n/Menu_da.properties
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ Decrease_table_font_size=For&mindsk_fontstørrelse_i_hovedtabel
Forward=Frem
Back=Tilbage

Look_up_DOIs=
Look_up_full_text_documents=
Set/clear/rename_fields=Udfyld/ryd/omdøb_felter

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/l10n/Menu_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ Decrease_table_font_size=Schriftgröße_in_der_Tabelle_verkleinern
Forward=Vor
Back=Zurück

Look_up_DOIs=
Look_up_full_text_documents=Volltext-Dokumente_suchen
Set/clear/rename_fields=Felder_setzen/löschen/umbenennen

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/l10n/Menu_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ Decrease_table_font_size=&Decrease_table_font_size
Forward=Forward
Back=Back

Look_up_DOIs=Look_up_DOIs
Look_up_full_text_documents=Look_up_full_text_documents
Set/clear/rename_fields=Set/clear/rename_fields

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/l10n/Menu_es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ Decrease_table_font_size=&Disminuir_tama\u00f1o_de_fuente_en_tabla
Forward=Avanzar
Back=Retroceder

Look_up_DOIs=
Look_up_full_text_documents=
Set/clear/rename_fields=Establecer/limpiar/renombrar_campos

Expand Down
Loading