Skip to content

Commit 73f1ad5

Browse files
authored
Fix parsing of JabRef v5.7 study.yml files (#9124)
1 parent ad9aa62 commit 73f1ad5

File tree

5 files changed

+34
-6
lines changed

5 files changed

+34
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
2424
- We call backup files `.bak` and temporary writing files now `.sav`.
2525
- 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)
2626
- We changed the button label from "Return to JabRef" to "Return to library" to better indicate the purpose of the action.
27-
- We removed "last-search-date" from the SLR feature, because the last-search-date can be deducted from the git logs.
27+
- 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)
28+
- A user can now add arbitrary data into `study.yml`. JabRef just ignores this data. [#9124](https://github.com/JabRef/jabref/pull/9124)
2829
- We reworked the External Changes Resolver dialog. [#9021](https://github.com/JabRef/jabref/pull/9021)
2930
- We reworked the Define study parameters dialog. [#9123](https://github.com/JabRef/jabref/pull/9123)
3031

src/main/java/org/jabref/logic/crawler/StudyYamlParser.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88
import org.jabref.model.study.Study;
99

1010
import com.fasterxml.jackson.databind.ObjectMapper;
11-
import com.fasterxml.jackson.databind.SerializationFeature;
1211
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
1312
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;
14-
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
1513

1614
public class StudyYamlParser {
1715

@@ -20,7 +18,6 @@ public class StudyYamlParser {
2018
*/
2119
public Study parseStudyYamlFile(Path studyYamlFile) throws IOException {
2220
ObjectMapper yamlMapper = new ObjectMapper(new YAMLFactory());
23-
yamlMapper.registerModule(new JavaTimeModule());
2421
try (InputStream fileInputStream = new FileInputStream(studyYamlFile.toFile())) {
2522
return yamlMapper.readValue(fileInputStream, Study.class);
2623
}
@@ -32,8 +29,6 @@ public Study parseStudyYamlFile(Path studyYamlFile) throws IOException {
3229
public void writeStudyYamlFile(Study study, Path studyYamlFile) throws IOException {
3330
ObjectMapper yamlMapper = new ObjectMapper(new YAMLFactory().disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER)
3431
.enable(YAMLGenerator.Feature.MINIMIZE_QUOTES));
35-
yamlMapper.registerModule(new JavaTimeModule());
36-
yamlMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
3732
yamlMapper.writeValue(studyYamlFile.toFile(), study);
3833
}
3934
}

src/main/java/org/jabref/model/study/Study.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.List;
44
import java.util.Objects;
55

6+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
67
import com.fasterxml.jackson.annotation.JsonProperty;
78
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
89

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

src/test/java/org/jabref/logic/crawler/StudyYamlParserTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
class StudyYamlParserTest {
1919
@TempDir
2020
static Path testDirectory;
21+
2122
Study expectedStudy;
2223

2324
@BeforeEach
@@ -48,4 +49,15 @@ public void writeStudyFileSuccessfully() throws Exception {
4849
Study study = new StudyYamlParser().parseStudyYamlFile(testDirectory.resolve("study.yml"));
4950
assertEquals(expectedStudy, study);
5051
}
52+
53+
@Test
54+
public void readsJabRef57StudySuccessfully() throws Exception {
55+
// The field "last-search-date" was removed
56+
// If the field is "just" removed from the datamodel, one gets following exception:
57+
// 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"])
58+
// This tests ensures that this exception does not occur
59+
URL studyDefinition = StudyYamlParser.class.getResource("study-jabref-5.7.yml");
60+
Study study = new StudyYamlParser().parseStudyYamlFile(Path.of(studyDefinition.toURI()));
61+
assertEquals(expectedStudy, study);
62+
}
5163
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
authors:
2+
- Jab Ref
3+
title: TestStudyName
4+
last-search-date: 2020-11-26
5+
research-questions:
6+
- Question1
7+
- Question2
8+
queries:
9+
- query: Quantum
10+
- query: Cloud Computing
11+
- query: '"Software Engineering"'
12+
databases:
13+
- name: Springer
14+
- name: ArXiv
15+
- name: Medline/PubMed
16+
- name: IEEEXplore
17+
enabled: false

0 commit comments

Comments
 (0)