-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
New fetcher #1929
Merged
Merged
New fetcher #1929
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
a90bc21
Refactor search based fetcher based on website and parser
tobiasdiez 4fc8551
Refactor BibtexParser
tobiasdiez 443f50f
Refactor cleanup preferences
tobiasdiez 1b57e28
Add search-based fetcher for the Astrophysics Data System
tobiasdiez d39fc73
Introduce EntryBasedFetcher
tobiasdiez adfe299
Add ADS as EntyBasedFetcher
tobiasdiez d3b62be
Add comment about new ADS API
tobiasdiez 9539d47
Add MathSciNet entry based fetcher
tobiasdiez 8d98ad9
Add MathSciNet search fetcher
tobiasdiez 9816aa7
Add zbMath fetcher
tobiasdiez 528b197
Add Changelog
tobiasdiez cde8b17
Remove header
tobiasdiez 0655709
Remove more headers
tobiasdiez f9c2ce6
Include feedback
tobiasdiez db93bbb
Rename GVKParser
tobiasdiez 3979146
Merge master
tobiasdiez e1002d3
Remove big
tobiasdiez 6737da0
Remove unused imports
tobiasdiez a1f98e8
Fix failing GVK tests
tobiasdiez 61579c3
Fix failing tests due to no subscription
tobiasdiez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
30 changes: 30 additions & 0 deletions
30
src/main/java/net/sf/jabref/logic/cleanup/CleanupPreferences.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,30 @@ | ||
package net.sf.jabref.logic.cleanup; | ||
|
||
import net.sf.jabref.FileDirectoryPreferences; | ||
import net.sf.jabref.logic.layout.LayoutFormatterPreferences; | ||
|
||
public class CleanupPreferences { | ||
|
||
private final String fileNamePattern; | ||
private final LayoutFormatterPreferences layoutFormatterPreferences; | ||
private final FileDirectoryPreferences fileDirectoryPreferences; | ||
|
||
public CleanupPreferences(String fileNamePattern, LayoutFormatterPreferences layoutFormatterPreferences, | ||
FileDirectoryPreferences fileDirectoryPreferences) { | ||
this.fileNamePattern = fileNamePattern; | ||
this.layoutFormatterPreferences = layoutFormatterPreferences; | ||
this.fileDirectoryPreferences = fileDirectoryPreferences; | ||
} | ||
|
||
public String getFileNamePattern() { | ||
return fileNamePattern; | ||
} | ||
|
||
public LayoutFormatterPreferences getLayoutFormatterPreferences() { | ||
return layoutFormatterPreferences; | ||
} | ||
|
||
public FileDirectoryPreferences getFileDirectoryPreferences() { | ||
return fileDirectoryPreferences; | ||
} | ||
} |
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
31 changes: 31 additions & 0 deletions
31
src/main/java/net/sf/jabref/logic/cleanup/MoveFieldCleanup.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,31 @@ | ||
package net.sf.jabref.logic.cleanup; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import net.sf.jabref.logic.util.OptionalUtil; | ||
import net.sf.jabref.model.FieldChange; | ||
import net.sf.jabref.model.entry.BibEntry; | ||
|
||
/** | ||
* Moves the content of one field to another field. | ||
*/ | ||
public class MoveFieldCleanup implements CleanupJob { | ||
|
||
private String sourceField; | ||
private String targetField; | ||
|
||
public MoveFieldCleanup(String sourceField, String targetField) { | ||
this.sourceField = sourceField; | ||
this.targetField = targetField; | ||
} | ||
|
||
@Override | ||
public List<FieldChange> cleanup(BibEntry entry) { | ||
|
||
Optional<FieldChange> setFieldChange = entry.getField(sourceField).flatMap( | ||
value -> entry.setField(targetField, value)); | ||
Optional<FieldChange> clearFieldChange = entry.clearField(sourceField); | ||
return OptionalUtil.toList(setFieldChange, clearFieldChange); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/net/sf/jabref/logic/importer/EntryBasedFetcher.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,21 @@ | ||
package net.sf.jabref.logic.importer; | ||
|
||
import java.util.List; | ||
|
||
import net.sf.jabref.model.entry.BibEntry; | ||
|
||
/** | ||
* Searches web resources for bibliographic information based on a {@link BibEntry}. | ||
* Useful to complete an existing entry with fetched information. | ||
* May return multiple search hits. | ||
*/ | ||
public interface EntryBasedFetcher extends WebFetcher { | ||
|
||
/** | ||
* Looks for hits which are matched by the given {@link BibEntry}. | ||
* | ||
* @param entry entry to search bibliographic information for | ||
* @return a list of {@link BibEntry}, which are matched by the query (may be empty) | ||
*/ | ||
List<BibEntry> performSearch(BibEntry entry) throws FetcherException; | ||
} |
71 changes: 71 additions & 0 deletions
71
src/main/java/net/sf/jabref/logic/importer/EntryBasedParserFetcher.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,71 @@ | ||
package net.sf.jabref.logic.importer; | ||
|
||
import java.io.BufferedInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.MalformedURLException; | ||
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import net.sf.jabref.logic.formatter.Formatter; | ||
import net.sf.jabref.model.entry.BibEntry; | ||
|
||
/** | ||
* Provides a convenient interface for entry-based fetcher, which follow the usual three-step procedure: | ||
* 1. Open a URL based on the entry | ||
* 2. Parse the response to get a list of {@link BibEntry} | ||
* 3. Post-process fetched entries | ||
*/ | ||
public interface EntryBasedParserFetcher extends EntryBasedFetcher { | ||
|
||
/** | ||
* Constructs a URL based on the {@link BibEntry}. | ||
* @param entry the entry to look information for | ||
*/ | ||
URL getURLForEntry(BibEntry entry) throws URISyntaxException, MalformedURLException, FetcherException; | ||
|
||
/** | ||
* Returns the parser used to convert the response to a list of {@link BibEntry}. | ||
*/ | ||
Parser getParser(); | ||
|
||
/** | ||
* Performs a cleanup of the fetched entry. | ||
* | ||
* Only systematic errors of the fetcher should be corrected here | ||
* (i.e. if information is consistently contained in the wrong field or the wrong format) | ||
* but not cosmetic issues which may depend on the user's taste (for example, LateX code vs HTML in the abstract). | ||
* | ||
* Try to reuse existing {@link Formatter} for the cleanup. For example, | ||
* {@code new FieldFormatterCleanup(FieldName.TITLE, new RemoveBracesFormatter()).cleanup(entry);} | ||
* | ||
* By default, no cleanup is done. | ||
* @param entry the entry to be cleaned-up | ||
*/ | ||
default void doPostCleanup(BibEntry entry) { | ||
// Do nothing by default | ||
} | ||
|
||
@Override | ||
default List<BibEntry> performSearch(BibEntry entry) throws FetcherException { | ||
Objects.requireNonNull(entry); | ||
|
||
try (InputStream stream = new BufferedInputStream(getURLForEntry(entry).openStream())) { | ||
List<BibEntry> fetchedEntries = getParser().parseEntries(stream); | ||
|
||
// Post-cleanup | ||
fetchedEntries.forEach(this::doPostCleanup); | ||
|
||
return fetchedEntries; | ||
} catch (URISyntaxException e) { | ||
throw new FetcherException("Search URI is malformed", e); | ||
} catch (IOException e) { | ||
// TODO: Catch HTTP Response 401 errors and report that user has no rights to access resource | ||
throw new FetcherException("An I/O exception occurred", e); | ||
} catch (ParserException e) { | ||
throw new FetcherException("An internal parser error occurred", e); | ||
} | ||
} | ||
} |
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,14 @@ | ||
package net.sf.jabref.logic.importer; | ||
|
||
import java.io.InputStream; | ||
import java.util.List; | ||
|
||
import net.sf.jabref.model.entry.BibEntry; | ||
|
||
/** | ||
* A parser converts an {@link InputStream} into a list of {@link BibEntry}. | ||
*/ | ||
public interface Parser { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add a JavaDoc comment here? |
||
|
||
List<BibEntry> parseEntries(InputStream inputStream) throws ParserException; | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/net/sf/jabref/logic/importer/ParserException.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,17 @@ | ||
package net.sf.jabref.logic.importer; | ||
|
||
public class ParserException extends Exception { | ||
|
||
|
||
public ParserException(String errorMessage, Exception cause) { | ||
super(errorMessage, cause); | ||
} | ||
|
||
public ParserException(String errorMessage) { | ||
super(errorMessage); | ||
} | ||
|
||
public ParserException(Exception cause) { | ||
super(cause); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar comment as at the other fetcher interface (#1929): Shouldn't we have a framework so that the not each implementer of a fetcher has to take care about the right calling, but just offer the cleanup method? -- Maybe, this is too much work and we have to stick with the current solution. Then, the method
doPostCleanup
is just an implementation recommendation without any outside use, isn't it?