Skip to content

Commit

Permalink
Resolve File Creation Issue With Medline/PubMed (#8552)
Browse files Browse the repository at this point in the history
* #8455 : Ensure Fetcher Name is converted to a legal file name

* #8455 : Modify Test Case

* #8455 : Add changelog entry and fix failing tests

* #8455 : Fix another failing test

* #8455 : Implement test suggestions

* #8455 : Format issues

* Fixed checkstyle

Co-authored-by: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com>
  • Loading branch information
addak and calixtus authored Mar 16, 2022
1 parent 6406619 commit 5b27522
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed an issue where someone could add a duplicate field in the customize entry type dialog. [#8194](https://github.com/JabRef/jabref/issues/8194)
- We fixed a typo in the library properties tab: "String constants". There, one can configure [BibTeX string constants](https://docs.jabref.org/advanced/strings).
- We fixed an issue when writing a non-UTF-8 encoded file: The header is written again. [#8417](https://github.com/JabRef/jabref/issues/8417)
- We fixed an issue where folder creation during systemic literature review failed due to an illegal fetcher name. [#8552](https://github.com/JabRef/jabref/pull/8552)

## [5.4] - 2021-12-20

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/jabref/logic/crawler/StudyRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.jabref.logic.importer.SearchBasedFetcher;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.OS;
import org.jabref.logic.util.io.FileNameCleaner;
import org.jabref.model.database.BibDatabase;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntryTypesManager;
Expand Down Expand Up @@ -428,7 +429,7 @@ private void writeResultToFile(Path pathToFile, BibDatabase entries) throws IOEx
}

private Path getPathToFetcherResultFile(String query, String fetcherName) {
return Path.of(repositoryPath.toString(), trimNameAndAddID(query), fetcherName + ".bib");
return Path.of(repositoryPath.toString(), trimNameAndAddID(query), FileNameCleaner.cleanFileName(fetcherName) + ".bib");
}

private Path getPathToQueryResultFile(String query) {
Expand Down
15 changes: 7 additions & 8 deletions src/test/java/org/jabref/logic/crawler/CrawlerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;

import org.jabref.logic.bibtex.FieldContentFormatterPreferences;
import org.jabref.logic.citationkeypattern.CitationKeyPatternPreferences;
Expand Down Expand Up @@ -51,14 +52,12 @@ public void testWhetherAllFilesAreCreated() throws Exception {
assertTrue(Files.exists(Path.of(tempRepositoryDirectory.toString(), hashCodeQuantum + " - Quantum")));
assertTrue(Files.exists(Path.of(tempRepositoryDirectory.toString(), hashCodeCloudComputing + " - Cloud Computing")));

assertTrue(Files.exists(Path.of(tempRepositoryDirectory.toString(), hashCodeQuantum + " - Quantum", "ArXiv.bib")));
assertTrue(Files.exists(Path.of(tempRepositoryDirectory.toString(), hashCodeCloudComputing + " - Cloud Computing", "ArXiv.bib")));

assertTrue(Files.exists(Path.of(tempRepositoryDirectory.toString(), hashCodeQuantum + " - Quantum", "Springer.bib")));
assertTrue(Files.exists(Path.of(tempRepositoryDirectory.toString(), hashCodeCloudComputing + " - Cloud Computing", "Springer.bib")));

assertTrue(Files.exists(Path.of(tempRepositoryDirectory.toString(), hashCodeQuantum + " - Quantum", "result.bib")));
assertTrue(Files.exists(Path.of(tempRepositoryDirectory.toString(), hashCodeCloudComputing + " - Cloud Computing", "result.bib")));
List<String> filesToAssert = List.of("ArXiv.bib", "Springer.bib", "result.bib", "Medline_PubMed.bib");
filesToAssert.forEach(
fileName -> {
assertTrue(Files.exists(Path.of(tempRepositoryDirectory.toString(), hashCodeQuantum + " - Quantum", fileName)));
assertTrue(Files.exists(Path.of(tempRepositoryDirectory.toString(), hashCodeCloudComputing + " - Cloud Computing", fileName)));
});
assertTrue(Files.exists(Path.of(tempRepositoryDirectory.toString(), "studyResult.bib")));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.net.URL;
import java.nio.file.Path;
import java.util.List;
import java.util.stream.Collectors;

import org.jabref.logic.bibtex.FieldContentFormatterPreferences;
import org.jabref.logic.exporter.SavePreferences;
Expand Down Expand Up @@ -58,9 +59,10 @@ public void getActiveFetcherInstances() throws Exception {
StudyDatabaseToFetcherConverter converter = new StudyDatabaseToFetcherConverter(studyRepository.getActiveLibraryEntries(), importFormatPreferences);
List<SearchBasedFetcher> result = converter.getActiveFetchers();

Assertions.assertEquals(2, result.size());
Assertions.assertEquals(result.get(0).getName(), "Springer");
Assertions.assertEquals(result.get(1).getName(), "ArXiv");
Assertions.assertEquals(
List.of("Springer", "ArXiv", "Medline/PubMed"),
result.stream().map(SearchBasedFetcher::getName).collect(Collectors.toList())
);
}

private void copyTestStudyDefinitionFileIntoDirectory(Path destination) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ void setupStudy() throws Exception {
String studyName = "TestStudyName";
List<String> researchQuestions = List.of("Question1", "Question2");
List<StudyQuery> queryEntries = List.of(new StudyQuery("Quantum"), new StudyQuery("Cloud Computing"), new StudyQuery("\"Software Engineering\""));
List<StudyDatabase> libraryEntries = List.of(new StudyDatabase("Springer", true), new StudyDatabase("ArXiv", true), new StudyDatabase("IEEEXplore", false));
List<StudyDatabase> libraryEntries = List.of(new StudyDatabase("Springer", true), new StudyDatabase("ArXiv", true),
new StudyDatabase("Medline/PubMed", true), new StudyDatabase("IEEEXplore", false));

expectedStudy = new Study(authors, studyName, researchQuestions, queryEntries, libraryEntries);
expectedStudy.setLastSearchDate(LocalDate.parse("2020-11-26"));
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/org/jabref/logic/crawler/study.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ queries:
databases:
- name: Springer
- name: ArXiv
- name: Medline/PubMed
- name: IEEEXplore
enabled: false

0 comments on commit 5b27522

Please sign in to comment.