From 73f1ad5e55188fd5e198de971b27ef3851732069 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Sat, 3 Sep 2022 13:08:25 +0200 Subject: [PATCH] Fix parsing of JabRef v5.7 study.yml files (#9124) --- CHANGELOG.md | 3 ++- .../jabref/logic/crawler/StudyYamlParser.java | 5 ----- src/main/java/org/jabref/model/study/Study.java | 3 +++ .../logic/crawler/StudyYamlParserTest.java | 12 ++++++++++++ .../jabref/logic/crawler/study-jabref-5.7.yml | 17 +++++++++++++++++ 5 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 src/test/resources/org/jabref/logic/crawler/study-jabref-5.7.yml diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a0cfc8b3ac..762f29b556e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) - We reworked the Define study parameters dialog. [#9123](https://github.com/JabRef/jabref/pull/9123) diff --git a/src/main/java/org/jabref/logic/crawler/StudyYamlParser.java b/src/main/java/org/jabref/logic/crawler/StudyYamlParser.java index df2138434d2..db1bb1b9a9f 100644 --- a/src/main/java/org/jabref/logic/crawler/StudyYamlParser.java +++ b/src/main/java/org/jabref/logic/crawler/StudyYamlParser.java @@ -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 { @@ -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); } @@ -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); } } diff --git a/src/main/java/org/jabref/model/study/Study.java b/src/main/java/org/jabref/model/study/Study.java index 3748f0962bc..c9a416eda4e 100644 --- a/src/main/java/org/jabref/model/study/Study.java +++ b/src/main/java/org/jabref/model/study/Study.java @@ -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; @@ -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 authors; diff --git a/src/test/java/org/jabref/logic/crawler/StudyYamlParserTest.java b/src/test/java/org/jabref/logic/crawler/StudyYamlParserTest.java index 1b169f7f00a..d4e63f64bc1 100644 --- a/src/test/java/org/jabref/logic/crawler/StudyYamlParserTest.java +++ b/src/test/java/org/jabref/logic/crawler/StudyYamlParserTest.java @@ -18,6 +18,7 @@ class StudyYamlParserTest { @TempDir static Path testDirectory; + Study expectedStudy; @BeforeEach @@ -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); + } } diff --git a/src/test/resources/org/jabref/logic/crawler/study-jabref-5.7.yml b/src/test/resources/org/jabref/logic/crawler/study-jabref-5.7.yml new file mode 100644 index 00000000000..3b5b45bbb66 --- /dev/null +++ b/src/test/resources/org/jabref/logic/crawler/study-jabref-5.7.yml @@ -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