Top Description Fields Constructors Methods
org.jabref.logic.crawler

public Class StudyRepository

extends Object
Class Inheritance
Imports
java.io.IOException, java.nio.charset.StandardCharsets, .UnsupportedCharsetException, java.nio.file.Files, .Path, java.time.LocalDateTime, java.time.temporal.ChronoUnit, java.util.List, java.util.regex.Pattern, java.util.stream.Collectors, org.jabref.logic.citationkeypattern.CitationKeyGenerator, org.jabref.logic.database.DatabaseMerger, org.jabref.logic.exporter.AtomicFileWriter, .BibWriter, .BibtexDatabaseWriter, .SaveException, .SelfContainedSaveConfiguration, org.jabref.logic.git.SlrGitHandler, org.jabref.logic.importer.OpenDatabase, .SearchBasedFetcher, org.jabref.logic.l10n.Localization, org.jabref.logic.util.OS, org.jabref.logic.util.io.FileNameCleaner, org.jabref.model.database.BibDatabase, .BibDatabaseContext, org.jabref.model.entry.BibEntryTypesManager, org.jabref.model.metadata.SaveOrder, .SelfContainedSaveOrder, org.jabref.model.study.FetchResult, .QueryResult, .Study, .StudyDatabase, .StudyQuery, org.jabref.model.util.FileUpdateMonitor, org.jabref.preferences.PreferencesService, org.eclipse.jgit.api.errors.GitAPIException, org.slf4j.Logger, .LoggerFactory

This class manages all aspects of the study process related to the repository. It includes the parsing of the study definition file (study.bib) into a Study instance, 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.

Field Summary

Modifier and TypeField and Description
private final BibEntryTypesManager
private final FileUpdateMonitor
private final SlrGitHandler
private static final Logger
private static final Pattern
private static final Pattern
private final PreferencesService
private static final String
private final Path
private static final String
private final Study
public static final String
private final Path
private static final String

Constructor Summary

AccessConstructor and Description
public
StudyRepository(Path
Where the repository root is located.
pathToRepository
,
SlrGitHandler
The git handler that manages any interaction with the remote repository
gitHandler
,
PreferencesService preferencesService, FileUpdateMonitor fileUpdateMonitor, BibEntryTypesManager bibEntryTypesManager)

Creates a study repository.

Method Summary

Modifier and TypeMethod and Description
private String
computeIDForQuery(String query)

Helper to compute the query id for folder name creation.

private void
private void
private void
private void
private void
createQueryResultFolder(String
The query the folder is created for
query
)

Creates a folder using the query and its corresponding query id. This folder name is unique for each query, as long as the query id in the study definition is unique for each query.

private void
private void
generateCiteKeys(BibDatabaseContext existingEntries, BibDatabase targetEntries)

public List<StudyDatabase>

Returns:

List of BibEntries of type Library
getActiveLibraryEntries
()

Extracts all active fetchers from the library entries.

public BibDatabaseContext
getFetcherResultEntries(String query, String fetcherName)

Returns entries stored in the repository for a certain query and fetcher

private Path
private Path
private Path
private Path
public BibDatabaseContext
getQueryResultEntries(String query)

Returns the merged entries stored in the repository for a certain query

public List<String>

Returns:

List of all queries as Strings.
getSearchQueryStrings
()

Returns all query strings of the study definition

public Study
public BibDatabaseContext
getStudyResultEntries()

Returns the merged entries stored in the repository for all queries

private Study

Returns:

Returns the BibEntries parsed from the study definition file.
parseStudyFile
()

The study definition file contains all the definitions of a study.

public void
persist(List<QueryResult> crawlResults)

Persists the result locally and remotely by following the steps: Precondition: Currently checking out work branch

  1. Update the work and search branch
  2. Persist the results on the search branch
  3. Manually patch the diff of the search branch onto the work branch (as the merging will not work in certain cases without a conflict as it is context sensitive. But for this use case we do not need it to be context sensitive. So we can just prepend the patch without checking the "context" lines.
  4. Update the remote tracking branches of the work and search branch
private void
persistResults(List<QueryResult>
The results that shall be persisted.
crawlResults
)

Persists the crawling results in the local file based repository.

private void
setUpRepositoryStructureForQueriesAndFetchers()

Create for each query a folder, and for each fetcher a bib file in the query folder to store its results.

private String

Returns:

a unique folder name for any query.
trimNameAndAddID
(String
that is trimmed and combined with its query id
query
)

Returns a string that can be used as a folder name.

private void
updateRemoteSearchAndWorkBranch()

Update the remote tracking branches of the work and search branches The currently checked out branch is not changed if the method is executed successfully

private void
updateWorkAndSearchBranch()

Updates the local work and search branches with changes from their tracking remote branches The currently checked out branch is not changed if the method is executed successfully

private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bibEntryTypesManagerback to summary
private final BibEntryTypesManager bibEntryTypesManager
fileUpdateMonitorback to summary
private final FileUpdateMonitor fileUpdateMonitor
gitHandlerback to summary
private final SlrGitHandler gitHandler
LOGGERback to summary
private static final Logger LOGGER
MATCH_COLONback to summary
private static final Pattern MATCH_COLON
MATCH_ILLEGAL_CHARACTERSback to summary
private static final Pattern MATCH_ILLEGAL_CHARACTERS
preferencesServiceback to summary
private final PreferencesService preferencesService
REMOTEback to summary
private static final String REMOTE
repositoryPathback to summary
private final Path repositoryPath
SEARCH_BRANCHback to summary
private static final String SEARCH_BRANCH
studyback to summary
private final Study study
STUDY_DEFINITION_FILE_NAMEback to summary
public static final String STUDY_DEFINITION_FILE_NAME
studyDefinitionFileback to summary
private final Path studyDefinitionFile
WORK_BRANCHback to summary
private static final String WORK_BRANCH

Constructor Detail

StudyRepositoryback to summary
public StudyRepository(Path pathToRepository, SlrGitHandler gitHandler, PreferencesService preferencesService, FileUpdateMonitor fileUpdateMonitor, BibEntryTypesManager bibEntryTypesManager) throws IOException

Creates a study repository.

Parameters
pathToRepository:Path

Where the repository root is located.

gitHandler:SlrGitHandler

The git handler that manages any interaction with the remote repository

Exceptions
IOException:
Thrown if the given repository does not exist, or the study definition file does not exist
IllegalArgumentException:
If the repository root directory does not exist, or the root directory does not contain the study definition file.

Method Detail

computeIDForQueryback to summary
private String computeIDForQuery(String query)

Helper to compute the query id for folder name creation.

createBibFileback to summary
private void createBibFile(Path file)
createFetcherResultFileback to summary
private void createFetcherResultFile(String query, SearchBasedFetcher searchBasedFetcher)
createFolderback to summary
private void createFolder(Path folder) throws IOException
createQueryResultFileback to summary
private void createQueryResultFile(String query)
createQueryResultFolderback to summary
private void createQueryResultFolder(String query) throws IOException

Creates a folder using the query and its corresponding query id. This folder name is unique for each query, as long as the query id in the study definition is unique for each query.

Parameters
query:String

The query the folder is created for

createStudyResultFileback to summary
private void createStudyResultFile()
generateCiteKeysback to summary
private void generateCiteKeys(BibDatabaseContext existingEntries, BibDatabase targetEntries)
getActiveLibraryEntriesback to summary
public List<StudyDatabase> getActiveLibraryEntries() throws IllegalArgumentException

Extracts all active fetchers from the library entries.

Returns:List<StudyDatabase>

List of BibEntries of type Library

Exceptions
IllegalArgumentException:
If a transformation from Library entry to LibraryDefinition fails
getFetcherResultEntriesback to summary
public BibDatabaseContext getFetcherResultEntries(String query, String fetcherName) throws IOException

Returns entries stored in the repository for a certain query and fetcher

getPathToFetcherResultFileback to summary
private Path getPathToFetcherResultFile(String query, String fetcherName)
getPathToQueryDirectoryback to summary
private Path getPathToQueryDirectory(String query)
getPathToQueryResultFileback to summary
private Path getPathToQueryResultFile(String query)
getPathToStudyResultFileback to summary
private Path getPathToStudyResultFile()
getQueryResultEntriesback to summary
public BibDatabaseContext getQueryResultEntries(String query) throws IOException

Returns the merged entries stored in the repository for a certain query

getSearchQueryStringsback to summary
public List<String> getSearchQueryStrings()

Returns all query strings of the study definition

Returns:List<String>

List of all queries as Strings.

getStudyback to summary
public Study getStudy()
getStudyResultEntriesback to summary
public BibDatabaseContext getStudyResultEntries() throws IOException

Returns the merged entries stored in the repository for all queries

parseStudyFileback to summary
private Study parseStudyFile() throws IOException

The study definition file contains all the definitions of a study. This method extracts this study from the yaml study definition file

Returns:Study

Returns the BibEntries parsed from the study definition file.

Exceptions
IOException:
Problem opening the input stream.
persistback to summary
public void persist(List<QueryResult> crawlResults) throws IOException, org.eclipse.jgit.api.errors.GitAPIException, SaveException

Persists the result locally and remotely by following the steps: Precondition: Currently checking out work branch

  1. Update the work and search branch
  2. Persist the results on the search branch
  3. Manually patch the diff of the search branch onto the work branch (as the merging will not work in certain cases without a conflict as it is context sensitive. But for this use case we do not need it to be context sensitive. So we can just prepend the patch without checking the "context" lines.
  4. Update the remote tracking branches of the work and search branch
persistResultsback to summary
private void persistResults(List<QueryResult> crawlResults) throws IOException, SaveException

Persists the crawling results in the local file based repository.

Parameters
crawlResults:List<QueryResult>

The results that shall be persisted.

setUpRepositoryStructureForQueriesAndFetchersback to summary
private void setUpRepositoryStructureForQueriesAndFetchers() throws IOException

Create for each query a folder, and for each fetcher a bib file in the query folder to store its results.

trimNameAndAddIDback to summary
private String trimNameAndAddID(String query)

Returns a string that can be used as a folder name. This removes all characters from the query that are illegal for directory names. Structure: ID-trimmed query Examples: Input: '(title: test-title AND abstract: Test)' as a query entry with id 12345678 Output: '12345678 - title= test-title AND abstract= Test' Input: 'abstract: Test*' as a query entry with id 87654321 Output: '87654321 - abstract= Test' Input: '"test driven"' as a query entry with id 12348765 Output: '12348765 - test driven' Note that this method might be similar to org.jabref.logic.util.io.FileUtil#getValidFileName(String) or org.jabref.logic.util.io.FileNameCleaner#cleanFileName(String)

Parameters
query:String

that is trimmed and combined with its query id

Returns:String

a unique folder name for any query.

updateRemoteSearchAndWorkBranchback to summary
private void updateRemoteSearchAndWorkBranch() throws IOException, org.eclipse.jgit.api.errors.GitAPIException

Update the remote tracking branches of the work and search branches The currently checked out branch is not changed if the method is executed successfully

updateWorkAndSearchBranchback to summary
private void updateWorkAndSearchBranch() throws IOException, org.eclipse.jgit.api.errors.GitAPIException

Updates the local work and search branches with changes from their tracking remote branches The currently checked out branch is not changed if the method is executed successfully

writeResultToFileback to summary
private void writeResultToFile(Path pathToFile, BibDatabaseContext context) throws SaveException