Skip to content

Commit

Permalink
Fix parsing of JabRef v5.7 study.yml files (#9124)
Browse files Browse the repository at this point in the history
  • Loading branch information
koppor authored Sep 3, 2022
1 parent ad9aa62 commit 73f1ad5
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
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)
- We reworked the Define study parameters dialog. [#9123](https://github.com/JabRef/jabref/pull/9123)

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

0 comments on commit 73f1ad5

Please sign in to comment.