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

ISBN Fetcher using the new fetcher infrastructure #1654

Merged
merged 25 commits into from
Aug 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
badf5c3
implement isbnfetcher
zesaro Jul 30, 2016
a823022
create test
zesaro Aug 1, 2016
1afaf62
make fetcher usable and organise imports
zesaro Aug 1, 2016
281e853
fix codacy
zesaro Aug 1, 2016
a8c64d2
remove old isbn fetcher
zesaro Aug 1, 2016
42b882c
ignore tests needing needing online connection
zesaro Aug 1, 2016
40bc8e4
edit test and use wrapper for fetcher
zesaro Aug 4, 2016
7a321a5
add one more test to isbnfetcher
zesaro Aug 8, 2016
677af41
include feedback (1/2)
zesaro Aug 10, 2016
0a6b4f9
include feedback (2/2)
zesaro Aug 10, 2016
c9e0278
add logger to FetchAndMergeEntry
zesaro Aug 10, 2016
d7508be
remove obsolete keys
zesaro Aug 10, 2016
9b5b6f1
resolve conflicts
zesaro Aug 13, 2016
0d06ae3
Merge remote-tracking branch 'upstream/master' into isbnfetcher
zesaro Aug 16, 2016
53e8dee
include feedback and cleanup
zesaro Aug 18, 2016
f35a94b
include feedback (use Unirest and add more invalid tests)
zesaro Aug 19, 2016
a40ecae
Merge remote-tracking branch 'upstream/master' into isbnfetcher
zesaro Aug 19, 2016
78745ae
Merge remote-tracking branch 'upstream/master' into isbnfetcher
zesaro Aug 25, 2016
f2c1571
include feedback
zesaro Aug 25, 2016
7a1583c
Merge branch 'isbnfetcher' of github.com:zellerdev/jabref into isbnfe…
zesaro Aug 25, 2016
9615f10
refactor globals and fix logger
zesaro Aug 25, 2016
66b5dc8
refactor globals in isbnfetcher
zesaro Aug 29, 2016
c11e370
Merge remote-tracking branch 'upstream/master' into isbnfetcher
zesaro Aug 29, 2016
4887d8c
resolve merge issues
zesaro Aug 29, 2016
2ff9931
remove copyright
zesaro Aug 29, 2016
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
import java.util.LinkedList;
import java.util.List;

import net.sf.jabref.Globals;
import net.sf.jabref.logic.importer.fetcher.ArXiv;
import net.sf.jabref.logic.importer.fetcher.GvkFetcher;
import net.sf.jabref.logic.importer.fetcher.IsbnFetcher;
import net.sf.jabref.logic.journals.JournalAbbreviationLoader;

public class EntryFetchers {

private final List<EntryFetcher> entryFetchers = new LinkedList<>();


public EntryFetchers(JournalAbbreviationLoader abbreviationLoader) {
entryFetchers.add(new ADSFetcher());
entryFetchers.add(new CiteSeerXFetcher());
Expand All @@ -21,7 +22,6 @@ public EntryFetchers(JournalAbbreviationLoader abbreviationLoader) {
entryFetchers.add(new DOItoBibTeXFetcher());
entryFetchers.add(new IEEEXploreFetcher(abbreviationLoader));
entryFetchers.add(new INSPIREFetcher());
entryFetchers.add(new ISBNtoBibTeXFetcher());
entryFetchers.add(new MedlineFetcher());
// entryFetchers.add(new OAI2Fetcher()); - new arXiv fetcher in place, see below
// entryFetchers.add(new ScienceDirectFetcher()); currently not working - removed see #409
Expand All @@ -30,6 +30,7 @@ public EntryFetchers(JournalAbbreviationLoader abbreviationLoader) {
entryFetchers.add(new DOAJFetcher());
entryFetchers.add(new SpringerFetcher());

entryFetchers.add(new IdBasedEntryFetcher(new IsbnFetcher(Globals.prefs.getImportFormatPreferences ())));
entryFetchers.add(new SearchBasedEntryFetcher(new ArXiv()));
entryFetchers.add(new SearchBasedEntryFetcher(new GvkFetcher()));
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package net.sf.jabref.gui.importer.fetcher;

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

import javax.swing.JPanel;

import net.sf.jabref.logic.help.HelpFile;
import net.sf.jabref.logic.importer.FetcherException;
import net.sf.jabref.logic.importer.IdBasedFetcher;
import net.sf.jabref.logic.importer.ImportInspector;
import net.sf.jabref.logic.importer.OutputPrinter;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.model.entry.BibEntry;

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

public class IdBasedEntryFetcher implements EntryFetcher {

private static final Log LOGGER = LogFactory.getLog(IdBasedEntryFetcher.class);
private final IdBasedFetcher fetcher;

public IdBasedEntryFetcher(IdBasedFetcher fetcher) {
this.fetcher = Objects.requireNonNull(fetcher);
}

@Override
public boolean processQuery(String query, ImportInspector inspector, OutputPrinter status) {

status.setStatus(Localization.lang("Processing %0", query));
try {
Optional<BibEntry> match = fetcher.performSearchById(query);
match.ifPresent(inspector::addEntry);
return match.isPresent();
} catch (FetcherException e) {
status.setStatus(Localization.lang("Error while fetching from %0", fetcher.getName()));
LOGGER.error("Error while fetching from" + fetcher.getName(), e);
}

return false;
}

@Override
public String getTitle() {
return fetcher.getName();
}

@Override
public HelpFile getHelpPage() {
return fetcher.getHelpPage();
}

@Override
public JPanel getOptionsPanel() {
// not supported
return null;
}

@Override
public void stopFetching() {
// not supported
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,25 @@

import net.sf.jabref.Globals;
import net.sf.jabref.gui.BasePanel;
import net.sf.jabref.gui.importer.fetcher.ISBNtoBibTeXFetcher;
import net.sf.jabref.logic.importer.FetcherException;
import net.sf.jabref.logic.importer.fetcher.ArXiv;
import net.sf.jabref.logic.importer.fetcher.DOItoBibTeX;
import net.sf.jabref.logic.importer.fetcher.IsbnFetcher;
import net.sf.jabref.logic.l10n.Localization;
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;

/**
* Class for fetching and merging information based on a specific field
*
*/
public class FetchAndMergeEntry {

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

// A list of all field which are supported
public static List<String> SUPPORTED_FIELDS = Arrays.asList(FieldName.DOI, FieldName.EPRINT, FieldName.ISBN);

Expand Down Expand Up @@ -57,13 +62,21 @@ public FetchAndMergeEntry(BibEntry entry, BasePanel panel, List<String> fields)
fetchedEntry = new DOItoBibTeX().getEntryFromDOI(fieldContent.get(),
Globals.prefs.getImportFormatPreferences());
} else if (FieldName.ISBN.equals(field)) {
fetchedEntry = new ISBNtoBibTeXFetcher().getEntryFromISBN(fieldContent.get(), null);
try {
fetchedEntry = new IsbnFetcher(Globals.prefs.getImportFormatPreferences ()).performSearchById(fieldContent.get());
} catch (FetcherException e) {
LOGGER.error("Info cannot be found", e);
panel.frame().setStatus(
Localization.lang("Cannot get info based on given %0: %1", type, fieldContent.get()));
}

} else if (FieldName.EPRINT.equals(field)) {
try {
fetchedEntry = new ArXiv().performSearchById(fieldContent.get());
} catch (FetcherException e) {
LOGGER.error("Info cannot be found", e);
panel.frame().setStatus(
Localization.lang("Cannot get info based on given %0:_%1", type, fieldContent.get()));
Localization.lang("Cannot get info based on given %0: %1", type, fieldContent.get()));
}
}

Expand All @@ -73,7 +86,7 @@ public FetchAndMergeEntry(BibEntry entry, BasePanel panel, List<String> fields)
dialog.setVisible(true);
} else {
panel.frame()
.setStatus(Localization.lang("Cannot get info based on given %0:_%1", type,
.setStatus(Localization.lang("Cannot get info based on given %0: %1", type,
fieldContent.get()));
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public interface IdBasedFetcher extends WebFetcher {
*
* @param identifier a string which uniquely identifies the item
* @return a {@link BibEntry} containing the bibliographic information (or an empty optional if no data was found)
* @throws FetcherException
*/
Optional<BibEntry> performSearchById(String identifier) throws FetcherException;
}
Loading