-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2442 from JabRef/lookupdoi
Add "Look up DOIs" to Quality menu
- Loading branch information
Showing
50 changed files
with
289 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/org/jabref/gui/actions/LookupIdentifierAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.jabref.gui.actions; | ||
|
||
import java.awt.event.ActionEvent; | ||
|
||
import javax.swing.Action; | ||
|
||
import org.jabref.gui.BasePanel; | ||
import org.jabref.gui.JabRefFrame; | ||
import org.jabref.gui.worker.LookupIdentifiersWorker; | ||
import org.jabref.logic.importer.IdFetcher; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
|
||
public class LookupIdentifierAction extends MnemonicAwareAction { | ||
|
||
private static final Log LOGGER = LogFactory.getLog(LookupIdentifierAction.class); | ||
|
||
private final JabRefFrame frame; | ||
private final IdFetcher fetcher; | ||
|
||
@Override | ||
public void actionPerformed(ActionEvent actionEvent) { | ||
try { | ||
BasePanel.runWorker(new LookupIdentifiersWorker(frame, fetcher)); | ||
} catch (Exception e) { | ||
LOGGER.error(e); | ||
} | ||
} | ||
|
||
public LookupIdentifierAction(JabRefFrame frame, IdFetcher fetcher) { | ||
super(); | ||
this.frame = frame; | ||
this.fetcher = fetcher; | ||
|
||
putValue(Action.NAME, fetcher.getIdentifierName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/main/java/org/jabref/gui/worker/LookupIdentifiersWorker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package org.jabref.gui.worker; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
import org.jabref.gui.BasePanel; | ||
import org.jabref.gui.JabRefFrame; | ||
import org.jabref.gui.undo.NamedCompound; | ||
import org.jabref.gui.undo.UndoableFieldChange; | ||
import org.jabref.logic.importer.FetcherException; | ||
import org.jabref.logic.importer.IdFetcher; | ||
import org.jabref.logic.l10n.Localization; | ||
import org.jabref.model.FieldChange; | ||
import org.jabref.model.entry.BibEntry; | ||
import org.jabref.model.entry.identifier.Identifier; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
|
||
public class LookupIdentifiersWorker<T extends Identifier> extends AbstractWorker { | ||
|
||
private final JabRefFrame frame; | ||
private final IdFetcher<T> fetcher; | ||
private String message; | ||
|
||
private static final Log LOGGER = LogFactory.getLog(LookupIdentifiersWorker.class); | ||
|
||
public LookupIdentifiersWorker(JabRefFrame frame, IdFetcher<T> fetcher) { | ||
this.frame = Objects.requireNonNull(frame); | ||
this.fetcher = Objects.requireNonNull(fetcher); | ||
} | ||
|
||
@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 %0", fetcher.getIdentifierName())); | ||
int count = 0; | ||
int foundCount = 0; | ||
for (BibEntry bibEntry : bibEntries) { | ||
count++; | ||
frame.output(Localization.lang("Looking up %0... - entry %1 out of %2 - found %3", | ||
fetcher.getIdentifierName(), Integer.toString(count), totalCount, Integer.toString(foundCount))); | ||
Optional<T> identifier = Optional.empty(); | ||
try { | ||
identifier = fetcher.findIdentifier(bibEntry); | ||
} catch (FetcherException e) { | ||
LOGGER.error("Could not fetch " + fetcher.getIdentifierName(), e); | ||
} | ||
if (identifier.isPresent() && !bibEntry.hasField(identifier.get().getDefaultField())) { | ||
Optional<FieldChange> fieldChange = bibEntry.setField(identifier.get().getDefaultField(), identifier.get().getNormalized()); | ||
if (fieldChange.isPresent()) { | ||
namedCompound.addEdit(new UndoableFieldChange(fieldChange.get())); | ||
foundCount++; | ||
frame.output(Localization.lang("Looking up %0... - entry %1 out of %2 - found %3", | ||
Integer.toString(count), totalCount, Integer.toString(foundCount))); | ||
} | ||
} | ||
} | ||
namedCompound.end(); | ||
if (foundCount > 0) { | ||
basePanel.getUndoManager().addEdit(namedCompound); | ||
basePanel.markBaseChanged(); | ||
} | ||
message = Localization.lang("Determined %0 for %1 entries", fetcher.getIdentifierName(), Integer.toString(foundCount)); | ||
} | ||
} | ||
|
||
@Override | ||
public void update() { | ||
frame.output(message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.