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

Fix parsing of JabRef v5.7 study.yml files #9124

Merged
merged 2 commits into from
Sep 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We call backup files `.bak` and temporary writing files now `.sav`.
- JabRef keeps 10 older versions of a `.bib` file in the [user data dir](https://github.com/harawata/appdirs#supported-directories) (instead of a single `.sav` (now: `.bak`) file in the directory of the `.bib` file)
- We changed the button label from "Return to JabRef" to "Return to library" to better indicate the purpose of the action.
- We removed "last-search-date" from the SLR feature, because the last-search-date can be deducted from the git logs.
- We removed "last-search-date" from the SLR feature, because the last-search-date can be deducted from the git logs. [#9116](https://github.com/JabRef/jabref/pull/9116)
- A user can now add arbitrary data into `study.yml`. JabRef just ignores this data. [#9124](https://github.com/JabRef/jabref/pull/9124)
- We reworked the External Changes Resolver dialog. [#9021](https://github.com/JabRef/jabref/pull/9021)


Expand Down
5 changes: 0 additions & 5 deletions src/main/java/org/jabref/logic/crawler/StudyYamlParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
import org.jabref.model.study.Study;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;

public class StudyYamlParser {

Expand All @@ -20,7 +18,6 @@ public class StudyYamlParser {
*/
public Study parseStudyYamlFile(Path studyYamlFile) throws IOException {
ObjectMapper yamlMapper = new ObjectMapper(new YAMLFactory());
yamlMapper.registerModule(new JavaTimeModule());
try (InputStream fileInputStream = new FileInputStream(studyYamlFile.toFile())) {
return yamlMapper.readValue(fileInputStream, Study.class);
}
Expand All @@ -32,8 +29,6 @@ public Study parseStudyYamlFile(Path studyYamlFile) throws IOException {
public void writeStudyYamlFile(Study study, Path studyYamlFile) throws IOException {
ObjectMapper yamlMapper = new ObjectMapper(new YAMLFactory().disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER)
.enable(YAMLGenerator.Feature.MINIMIZE_QUOTES));
yamlMapper.registerModule(new JavaTimeModule());
yamlMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
yamlMapper.writeValue(studyYamlFile.toFile(), study);
}
}
3 changes: 3 additions & 0 deletions src/main/java/org/jabref/model/study/Study.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.List;
import java.util.Objects;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

Expand All @@ -12,6 +13,8 @@
* This class defines all aspects of a scientific study relevant to the application. It is a proxy for the file based study definition.
*/
@JsonPropertyOrder({"authors", "title", "research-questions", "queries", "databases"})
// The user might add arbitrary content to the YAML
@JsonIgnoreProperties(ignoreUnknown = true)
public class Study {
private List<String> authors;

Expand Down
12 changes: 12 additions & 0 deletions src/test/java/org/jabref/logic/crawler/StudyYamlParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
class StudyYamlParserTest {
@TempDir
static Path testDirectory;

Study expectedStudy;

@BeforeEach
Expand Down Expand Up @@ -48,4 +49,15 @@ public void writeStudyFileSuccessfully() throws Exception {
Study study = new StudyYamlParser().parseStudyYamlFile(testDirectory.resolve("study.yml"));
assertEquals(expectedStudy, study);
}

@Test
public void readsJabRef57StudySuccessfully() throws Exception {
// The field "last-search-date" was removed
// If the field is "just" removed from the datamodel, one gets following exception:
// com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "last-search-date" (class org.jabref.model.study.Study), not marked as ignorable (5 known properties: "authors", "research-questions", "queries", "title", "databases"])
// This tests ensures that this exception does not occur
URL studyDefinition = StudyYamlParser.class.getResource("study-jabref-5.7.yml");
Study study = new StudyYamlParser().parseStudyYamlFile(Path.of(studyDefinition.toURI()));
assertEquals(expectedStudy, study);
}
}
17 changes: 17 additions & 0 deletions src/test/resources/org/jabref/logic/crawler/study-jabref-5.7.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
authors:
- Jab Ref
title: TestStudyName
last-search-date: 2020-11-26
research-questions:
- Question1
- Question2
queries:
- query: Quantum
- query: Cloud Computing
- query: '"Software Engineering"'
databases:
- name: Springer
- name: ArXiv
- name: Medline/PubMed
- name: IEEEXplore
enabled: false