Skip to content

Commit

Permalink
Do not trim or remove whitespace from the title based id fetcher (#4016)
Browse files Browse the repository at this point in the history
* Do not trim text for TitleBasedFetcher
Fixes #4014

* add changelog

* add trimming epxlicit to fetchers
add some tests

* move doi trim to parse
add test
  • Loading branch information
Siedlerchr committed May 11, 2018
1 parent b10f941 commit dae1c81
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 15 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- We added a fetcher based on RFC-IDs. [#3971](https://github.com/JabRef/jabref/issues/3971)

### Fixed
We fixed an issue where the export to clipboard functionality could not be invoked [#3994](https://github.com/JabRef/jabref/issues/3994)
We fixed an issue with the migration of invalid Look and Feels [#3995, comment](https://github.com/JabRef/jabref/issues/3995#issuecomment-385649448)
We fixed an issue where JabRef would no longer start, when the option "Override default font settings" was activated [#3986](https://github.com/JabRef/jabref/issues/3986)
We fixed an issue where the export to clipboard functionality could not be invoked. [#3994](https://github.com/JabRef/jabref/issues/3994)
We fixed an issue with the migration of invalid Look and Feels. [#3995, comment](https://github.com/JabRef/jabref/issues/3995#issuecomment-385649448)
We fixed an issue where JabRef would no longer start, when the option "Override default font settings" was activated. [#3986](https://github.com/JabRef/jabref/issues/3986)
We fixed an issue where JabRef removed whitespace from the Title-fetcher which resulting in no entries being found. [#4014](https://github.com/JabRef/jabref/issues/4014)
We fixed an issue where fetched entries from the ACM fetcher could not be imported. [#4018](https://github.com/JabRef/jabref/issues/4018)

### Removed
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/org/jabref/gui/EntryTypeDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public EntryTypeDialog(JabRefFrame frame) {
setTitle(Localization.lang("Select entry type"));

addWindowListener(new WindowAdapter() {

@Override
public void windowClosing(WindowEvent e) {
cancelAction.actionPerformed(null);
Expand Down Expand Up @@ -246,7 +247,6 @@ static class TypeButton extends JButton implements Comparable<TypeButton> {

private final EntryType type;


TypeButton(String label, EntryType type) {
super(label);
this.type = type;
Expand All @@ -263,6 +263,7 @@ public EntryType getType() {
}

class CancelAction extends AbstractAction {

public CancelAction() {
super("Cancel");
}
Expand All @@ -275,6 +276,7 @@ public void actionPerformed(ActionEvent e) {
}

private class FetcherWorker extends SwingWorker<Optional<BibEntry>, Void> {

private boolean fetcherException = false;
private String fetcherExceptionMessage = "";
private IdBasedFetcher fetcher = null;
Expand All @@ -288,10 +290,9 @@ protected Optional<BibEntry> doInBackground() throws Exception {
generateButton.setText(Localization.lang("Searching..."));
});

Globals.prefs.put(JabRefPreferences.ID_ENTRY_GENERATOR,String.valueOf(comboBox.getSelectedItem()));
searchID = idTextField.getText().trim();
searchID = searchID.replaceAll(" ", "");
Globals.prefs.put(JabRefPreferences.ID_ENTRY_GENERATOR, String.valueOf(comboBox.getSelectedItem()));
fetcher = WebFetchers.getIdBasedFetchers(Globals.prefs.getImportFormatPreferences()).get(comboBox.getSelectedIndex());
searchID = idTextField.getText();
if (!searchID.isEmpty()) {
try {
bibEntry = fetcher.performSearchById(searchID);
Expand All @@ -311,7 +312,7 @@ protected void done() {
if (result.isPresent()) {
final BibEntry bibEntry = result.get();
if ((DuplicateCheck.containsDuplicate(frame.getCurrentBasePanel().getDatabase(), bibEntry, frame.getCurrentBasePanel().getBibDatabaseContext().getMode()).isPresent())) {
//If there are duplicates starts ImportInspectionDialog
//If there are duplicates starts ImportInspectionDialog
final BasePanel panel = (BasePanel) frame.getTabbedPane().getSelectedComponent();

ImportInspectionDialog diag = new ImportInspectionDialog(frame, panel, Localization.lang("Import"), false);
Expand All @@ -321,7 +322,7 @@ protected void done() {
diag.setVisible(true);
diag.toFront();
} else {
// Regenerate CiteKey of imported BibEntry
// Regenerate CiteKey of imported BibEntry
new BibtexKeyGenerator(frame.getCurrentBasePanel().getBibDatabaseContext(), Globals.prefs.getBibtexKeyPatternPreferences()).generateAndSetKey(bibEntry);
// Update Timestamps
if (Globals.prefs.getTimestampPreferences().includeCreatedTimestamp()) {
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/org/jabref/logic/importer/fetcher/ArXiv.java
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,10 @@ public List<BibEntry> performSearch(String query) throws FetcherException {

@Override
public Optional<BibEntry> performSearchById(String identifier) throws FetcherException {
return searchForEntryById(identifier).map(
(arXivEntry) -> arXivEntry.toBibEntry(importFormatPreferences.getKeywordSeparator()));
String cleanedIdentifier = identifier.trim();
cleanedIdentifier = identifier.replaceAll(" ", "");

return searchForEntryById(cleanedIdentifier).map((arXivEntry) -> arXivEntry.toBibEntry(importFormatPreferences.getKeywordSeparator()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public HelpFile getHelpPage() {
@Override
public Optional<BibEntry> performSearchById(String identifier) throws FetcherException {
Optional<DOI> doi = DOI.parse(identifier);

try {
if (doi.isPresent()) {
URL doiURL = new URL(doi.get().getURIAsASCIIString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ public class IacrEprintFetcher implements IdBasedFetcher {

private static final Logger LOGGER = LoggerFactory.getLogger(IacrEprintFetcher.class);
private static final Pattern DATE_FROM_WEBSITE_AFTER_2000_PATTERN = Pattern.compile("[a-z ]+(\\d{1,2} [A-Za-z][a-z]{2} \\d{4})");
private static final DateTimeFormatter DATE_FORMAT_WEBSITE_AFTER_2000 = DateTimeFormatter.ofPattern("d MMM yyyy", Locale.US);
private static final Pattern DATE_FROM_WEBSITE_BEFORE_2000_PATTERN = Pattern.compile("[A-Za-z ]+? ([A-Za-z][a-z]{2,10} \\d{1,2}(th|st|nd|rd)?, \\d{4})\\.?");
private static final Pattern WITHOUT_LETTERS_SPACE = Pattern.compile("[^0-9/]");

private static final DateTimeFormatter DATE_FORMAT_WEBSITE_AFTER_2000 = DateTimeFormatter.ofPattern("d MMM yyyy", Locale.US);
private static final DateTimeFormatter DATE_FORMAT_WEBSITE_BEFORE_2000_LONG_MONTHS = DateTimeFormatter.ofPattern("MMMM d['th']['st']['nd']['rd'] yyyy", Locale.US);
private static final DateTimeFormatter DATE_FORMAT_WEBSITE_BEFORE_2000_SHORT_MONTHS = DateTimeFormatter.ofPattern("MMM d['th']['st']['nd']['rd'] yyyy", Locale.US);
private static final DateTimeFormatter DATE_FORMAT_BIBTEX = DateTimeFormatter.ISO_LOCAL_DATE;
Expand All @@ -55,7 +57,7 @@ public IacrEprintFetcher(ImportFormatPreferences prefs) {

@Override
public Optional<BibEntry> performSearchById(String identifier) throws FetcherException {
String identifierWithoutLettersAndSpaces = identifier.replaceAll("[^0-9/]", " ").trim();
String identifierWithoutLettersAndSpaces = WITHOUT_LETTERS_SPACE.matcher(identifier).replaceAll(" ").trim();

if (!IDENTIFIER_PREDICATE.test(identifierWithoutLettersAndSpaces)) {
throw new FetcherException(Localization.lang("Invalid identifier: '%0'.", identifier));
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/jabref/model/entry/identifier/DOI.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ public DOI(String doi) {
*/
public static Optional<DOI> parse(String doi) {
try {
return Optional.of(new DOI(doi));
String cleanedDOI = doi.trim();
cleanedDOI = doi.replaceAll(" ", "");
return Optional.of(new DOI(cleanedDOI));
} catch (IllegalArgumentException | NullPointerException e) {
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ public void searchEntryByIdWith4DigitsAndPrefix() throws Exception {
assertEquals(Optional.of(sliceTheoremPaper), finder.performSearchById("arXiv:1405.2249"));
}

@Test
public void searchEntryByIdWith4DigitsAndPrefixAndNotTrimmed() throws Exception {
assertEquals(Optional.of(sliceTheoremPaper), finder.performSearchById("arXiv : 1405. 2249"));
}

@Test
public void searchEntryByIdWith5Digits() throws Exception {
assertEquals(Optional.of(
Expand All @@ -186,4 +191,5 @@ public void searchIdentifierForSlicePaper() throws Exception {

assertEquals(ArXivIdentifier.parse("1405.2249v1"), finder.findIdentifier(sliceTheoremPaper));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public void setUp() {
bibEntryDecker2007.setField("doi", "10.1109/icws.2007.59");
}


@Test
public void testGetName() {
assertEquals("DOI", fetcher.getName());
Expand Down Expand Up @@ -80,4 +81,10 @@ public void testPerformSearchInvalidDOI() {
assertThrows(FetcherException.class, () -> fetcher.performSearchById("10.1002/9781118257517F"));

}

@Test
public void testPerformSearchNonTrimmedDOI() throws FetcherException {
Optional<BibEntry> fetchedEntry = fetcher.performSearchById("http s://doi.org/ 10.1109 /ICWS .2007.59 ");
assertEquals(Optional.of(bibEntryDecker2007), fetchedEntry);
}
}
8 changes: 8 additions & 0 deletions src/test/java/org/jabref/model/entry/identifier/DOITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,12 @@ public void findDoiInsideArbitraryText() {
public void noDOIFoundInsideArbitraryText() {
assertEquals(Optional.empty(), DOI.findInText("text without 28282 a doi"));
}

@Test
public void parseDOIWithWhiteSpace() {
String doiWithSpace = "https : / / doi.org / 10 .1109 /V LHCC.20 04.20";
assertEquals("https://doi.org/10.1109/VLHCC.2004.20", DOI.parse(doiWithSpace).get().getURIAsASCIIString());

}

}

0 comments on commit dae1c81

Please sign in to comment.