Skip to content

Commit

Permalink
"study.yml" is static now (#9125)
Browse files Browse the repository at this point in the history
  • Loading branch information
koppor authored Sep 3, 2022
1 parent 069eedc commit 8b48e96
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 22 deletions.
3 changes: 2 additions & 1 deletion src/main/java/org/jabref/gui/slr/StartNewStudyAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.jabref.gui.StateManager;
import org.jabref.gui.theme.ThemeManager;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.crawler.StudyRepository;
import org.jabref.logic.crawler.StudyYamlParser;
import org.jabref.model.study.Study;
import org.jabref.model.util.FileUpdateMonitor;
Expand All @@ -25,7 +26,7 @@ public StartNewStudyAction(JabRefFrame frame, FileUpdateMonitor fileUpdateMonito
@Override
protected void setupRepository(Path studyRepositoryRoot) throws IOException, GitAPIException {
StudyYamlParser studyYAMLParser = new StudyYamlParser();
studyYAMLParser.writeStudyYamlFile(newStudy, studyRepositoryRoot.resolve("study.yml"));
studyYAMLParser.writeStudyYamlFile(newStudy, studyRepositoryRoot.resolve(StudyRepository.STUDY_DEFINITION_FILE_NAME));
}

@Override
Expand Down
22 changes: 13 additions & 9 deletions src/main/java/org/jabref/logic/crawler/StudyRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@
* the structured persistence of the crawling results for the study within the file based repository,
* as well as the sharing, and versioning of results using git.
*/
class StudyRepository {
public class StudyRepository {
// Tests work with study.yml
private static final String STUDY_DEFINITION_FILE_NAME = "study.yml";
public static final String STUDY_DEFINITION_FILE_NAME = "study.yml";

private static final Logger LOGGER = LoggerFactory.getLogger(StudyRepository.class);
private static final Pattern MATCHCOLON = Pattern.compile(":");
private static final Pattern MATCHILLEGALCHARACTERS = Pattern.compile("[^A-Za-z0-9_.\\s=-]");
Expand Down Expand Up @@ -217,11 +218,8 @@ public Study getStudy() {
*/
public void persist(List<QueryResult> crawlResults) throws IOException, GitAPIException, SaveException {
updateWorkAndSearchBranch();
persistStudy();
gitHandler.createCommitOnCurrentBranch("Update search date", true);
gitHandler.checkoutBranch(SEARCH_BRANCH);
persistResults(crawlResults);
persistStudy();
try {
// First commit changes to search branch and update remote
String commitMessage = "Conducted search: " + LocalDateTime.now().truncatedTo(ChronoUnit.SECONDS);
Expand All @@ -245,10 +243,15 @@ public void persist(List<QueryResult> crawlResults) throws IOException, GitAPIEx
*/
private void updateRemoteSearchAndWorkBranch() throws IOException, GitAPIException {
String currentBranch = gitHandler.getCurrentlyCheckedOutBranch();

// update remote search branch
gitHandler.checkoutBranch(SEARCH_BRANCH);
gitHandler.pushCommitsToRemoteRepository();

// update remote work branch
gitHandler.checkoutBranch(WORK_BRANCH);
gitHandler.pushCommitsToRemoteRepository();

gitHandler.checkoutBranch(currentBranch);
}

Expand All @@ -258,15 +261,16 @@ private void updateRemoteSearchAndWorkBranch() throws IOException, GitAPIExcepti
*/
private void updateWorkAndSearchBranch() throws IOException, GitAPIException {
String currentBranch = gitHandler.getCurrentlyCheckedOutBranch();

// update search branch
gitHandler.checkoutBranch(SEARCH_BRANCH);
gitHandler.pullOnCurrentBranch();

// update work branch
gitHandler.checkoutBranch(WORK_BRANCH);
gitHandler.pullOnCurrentBranch();
gitHandler.checkoutBranch(currentBranch);
}

private void persistStudy() throws IOException {
new StudyYamlParser().writeStudyYamlFile(study, studyDefinitionFile);
gitHandler.checkoutBranch(currentBranch);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/jabref/logic/git/SlrGitHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import java.util.Optional;
import java.util.StringJoiner;

import org.jabref.logic.crawler.StudyRepository;

import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.diff.DiffEntry;
Expand Down Expand Up @@ -101,7 +103,7 @@ Map<Path, String> parsePatchForAddedEntries(String patch) throws IOException, Gi
if (currentToken.startsWith("diff --git a/")) {
// If the diff is related to a different file, save the diff for the previous file
if (!(Objects.isNull(relativePath) || Objects.isNull(joiner))) {
if (!relativePath.contains("study.yml")) {
if (!relativePath.contains(StudyRepository.STUDY_DEFINITION_FILE_NAME)) {
diffsPerFile.put(Path.of(repositoryPath.toString(), relativePath), joiner.toString());
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/jabref/logic/crawler/CrawlerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ private void setUpRepository() throws Exception {
}

private void setUpTestStudyDefinitionFile() throws Exception {
Path destination = tempRepositoryDirectory.resolve("study.yml");
URL studyDefinition = this.getClass().getResource("study.yml");
Path destination = tempRepositoryDirectory.resolve(StudyRepository.STUDY_DEFINITION_FILE_NAME);
URL studyDefinition = this.getClass().getResource(StudyRepository.STUDY_DEFINITION_FILE_NAME);
FileUtil.copyFile(Path.of(studyDefinition.toURI()), destination, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void setUpMocks() {

@Test
public void getActiveFetcherInstances() throws Exception {
Path studyDefinition = tempRepositoryDirectory.resolve("study.yml");
Path studyDefinition = tempRepositoryDirectory.resolve(StudyRepository.STUDY_DEFINITION_FILE_NAME);
copyTestStudyDefinitionFileIntoDirectory(studyDefinition);

StudyRepository studyRepository = new StudyRepository(
Expand All @@ -83,7 +83,7 @@ public void getActiveFetcherInstances() throws Exception {
}

private void copyTestStudyDefinitionFileIntoDirectory(Path destination) throws Exception {
URL studyDefinition = this.getClass().getResource("study.yml");
URL studyDefinition = this.getClass().getResource(StudyRepository.STUDY_DEFINITION_FILE_NAME);
FileUtil.copyFile(Path.of(studyDefinition.toURI()), destination, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ private StudyRepository getTestStudyRepository() throws Exception {
* Copies the study definition file into the test repository
*/
private void setUpTestStudyDefinitionFile() throws Exception {
Path destination = tempRepositoryDirectory.resolve("study.yml");
URL studyDefinition = this.getClass().getResource("study.yml");
Path destination = tempRepositoryDirectory.resolve(StudyRepository.STUDY_DEFINITION_FILE_NAME);
URL studyDefinition = this.getClass().getResource(StudyRepository.STUDY_DEFINITION_FILE_NAME);
FileUtil.copyFile(Path.of(studyDefinition.toURI()), destination, false);
}

Expand Down
10 changes: 5 additions & 5 deletions src/test/java/org/jabref/logic/crawler/StudyYamlParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class StudyYamlParserTest {

@BeforeEach
void setupStudy() throws Exception {
Path destination = testDirectory.resolve("study.yml");
URL studyDefinition = StudyYamlParser.class.getResource("study.yml");
Path destination = testDirectory.resolve(StudyRepository.STUDY_DEFINITION_FILE_NAME);
URL studyDefinition = StudyYamlParser.class.getResource(StudyRepository.STUDY_DEFINITION_FILE_NAME);
FileUtil.copyFile(Path.of(studyDefinition.toURI()), destination, true);

List<String> authors = List.of("Jab Ref");
Expand All @@ -39,14 +39,14 @@ void setupStudy() throws Exception {

@Test
public void parseStudyFileSuccessfully() throws Exception {
Study study = new StudyYamlParser().parseStudyYamlFile(testDirectory.resolve("study.yml"));
Study study = new StudyYamlParser().parseStudyYamlFile(testDirectory.resolve(StudyRepository.STUDY_DEFINITION_FILE_NAME));
assertEquals(expectedStudy, study);
}

@Test
public void writeStudyFileSuccessfully() throws Exception {
new StudyYamlParser().writeStudyYamlFile(expectedStudy, testDirectory.resolve("study.yml"));
Study study = new StudyYamlParser().parseStudyYamlFile(testDirectory.resolve("study.yml"));
new StudyYamlParser().writeStudyYamlFile(expectedStudy, testDirectory.resolve(StudyRepository.STUDY_DEFINITION_FILE_NAME));
Study study = new StudyYamlParser().parseStudyYamlFile(testDirectory.resolve(StudyRepository.STUDY_DEFINITION_FILE_NAME));
assertEquals(expectedStudy, study);
}

Expand Down

0 comments on commit 8b48e96

Please sign in to comment.