common.configuration
Overview
common.configuration contains helper functions for reading the WDM harvesting configuration and deriving module-specific workflow information from it.
The module is responsible for:
- determining which journals a module should process,
- resolving the position of a module within a journal workflow,
- identifying the previous module,
- resolving journal-specific or source-level schemas and metadata formats,
- extracting ISSN lists,
- pairing ISSNs with schema definitions,
- filtering ISSNs by publisher,
- extracting configured metadata filters.
Several functions are implemented as Prefect tasks so that configuration lookup can appear as part of a Prefect flow execution.
Dependencies
The module uses:
jsonpathlib.Pathprefect.task
Configuration Structure
The functions in this module expect a JSON configuration with a top-level Sources list.
A simplified structure is:
{
"Sources": [
{
"source-name": "Source",
"standard-schemas": ["Schemadateien/relaxng_schema.rng"],
"standard-metadata-format":"crossref",
"standard-modules": [
"crossrefcrawler",
"validate_metadata",
"mdpi",
"image_format_converter",
"relaxng_scanner",
"toolbox_ids",
"create_bags",
"archivematica_ingest",
"archivematica_dip_export",
"dspace_article_ingest",
"metadata_toolbox_upload"
],
"Journals": [
{
"issn-e": "1234-5678",
"journal-name": "Journal",
}
]
}
]
}
Some journal-level fields are optional because the module falls back to source-level defaults.
Configuration Resolution Rules
For each journal, the following precedence rules are used.
| Setting | Journal-level key | Source-level fallback |
|---|---|---|
| Modules | modules |
standard-modules |
| Schemas | schemas |
standard-schemas |
| Metadata format | metadata-format |
standard-metadata-format |
| Metadata filters | metadata-filter |
standard-metadata-filter |
The journal ISSN is read from:
issn-e
API Reference
common.configuration.get_module_context(config_path, module_name)
Builds the module context for all journals configured to run the specified module.
For every matching journal, the returned context contains its ISSN, the module's position in the workflow, the preceding module, schemas, and metadata format.
Parameters
config_path
Path to the JSON configuration file.
The value is passed to:
Path(config_path).open()
and may therefore be a string or another value accepted by pathlib.Path.
module_name
Name of the module whose configuration context should be resolved.
The module name is searched within the effective module list of every configured journal.
Returns
list[dict]
A list containing one dictionary for each journal whose effective module list contains module_name.
Each dictionary has the following structure:
{
"ISSN": issn,
"position": position,
"previous_module": previous_module,
"schemas": schemas,
"metadata-format": metadata_format,
}
Returned fields
ISSN
Electronic ISSN from the journal's issn-e field.
position
Zero-based index of module_name within the effective module list.
previous_module
Name of the module immediately preceding module_name.
If module_name is the first module, the value is None.
schemas
Journal-specific schemas value when present; otherwise the source-level standard-schemas value.
metadata-format
Journal-specific metadata-format value when present; otherwise the source-level standard-metadata-format value.
Raises
FileNotFoundError
May be raised if the configuration file does not exist.
json.JSONDecodeError
May be raised if the configuration file does not contain valid JSON.
KeyError
May be raised when required configuration keys such as Sources, Journals, issn-e, or required fallback fields are missing.
Other exceptions from filesystem or JSON handling propagate to the caller.
Processing
- Open the configuration file.
- Parse the JSON content.
- Iterate through
Sources. - Iterate through each source's
Journals. - Read the journal's
issn-e. - Resolve the effective module list.
- Resolve schemas.
- Resolve metadata format.
- Check whether
module_nameis present. - Determine the module's zero-based position.
- Determine the previous module, when applicable.
- Append the resulting context dictionary.
Prefect Behavior
The function is decorated with @task and is therefore executed as a Prefect task when called from a Prefect flow.
common.configuration.convert_config_list_to_issn_list(config_list)
Converts a module-context list into a list containing only journal ISSNs.
Parameters
config_list
Iterable of dictionaries containing an ISSN key.
The typical input is the result of get_module_context().
Returns
list
A list containing the ISSN value from every element.
Equivalent to:
[element["ISSN"] for element in config_list]
Raises
KeyError
Raised if an element does not contain the ISSN key.
TypeError
May be raised if config_list is not iterable or its elements do not support dictionary-style access.
Prefect Behavior
The function is decorated with @task.
common.configuration.get_issn_schema_pairs(config_list)
Creates ISSN/schema pairs from a module-context list.
Parameters
config_list
Iterable of dictionaries containing both ISSN and schemas keys.
The typical input is the result of get_module_context().
Returns
list[tuple]
A list of two-element tuples:
[
(element["ISSN"], element["schemas"])
for element in config_list
]
Raises
KeyError
Raised if an element does not contain ISSN or schemas.
TypeError
May be raised if the supplied value is not iterable or its elements cannot be indexed as dictionaries.
Side Effects
None.
This function is not decorated as a Prefect task.
common.configuration.get_previous_module(config_list)
Returns the previous module recorded in the first entry of a module-context list.
Parameters
config_list
Sequence containing at least one configuration-context dictionary with the key previous_module.
The intended input is the result of get_module_context().
Returns
The value of:
config_list[0]["previous_module"]
The result is normally either the name of the preceding module or None if the current module is first in the workflow.
Raises
IndexError
Raised when config_list is empty.
KeyError
Raised when the first dictionary does not contain previous_module.
TypeError
May be raised if the supplied object does not support sequence or dictionary-style indexing.
Notes
Only the first entry in config_list is inspected.
If multiple journals are present, the function assumes that the first entry provides the relevant previous-module value for the caller.
Prefect Behavior
The function is decorated with @task.
common.configuration.get_issn_list_from_config_file_for_publishers(config_path, publisher_list)
Returns ISSNs belonging to configured sources whose source-name occurs in a supplied publisher list.
Parameters
config_path
Path to the JSON configuration file.
publisher_list
Collection of publisher/source names.
Each source's source-name value is checked using:
source["source-name"] in publisher_list
Returns
list
A list containing the issn-e values for journals belonging to matching sources.
Raises
FileNotFoundError
May be raised if the configuration file does not exist.
json.JSONDecodeError
May be raised for invalid JSON.
KeyError
May be raised when required keys such as Sources, source-name, Journals, or issn-e are missing.
Processing
- Open the configuration file.
- Parse the JSON.
- Iterate through
Sources. - Check whether
source["source-name"]is inpublisher_list. - For matching sources, iterate through
Journals. - Append each journal's
issn-e. - Return the accumulated ISSN list.
Prefect Behavior
The function is decorated with @task.
common.configuration.get_metadata_filters(config_path)
Attempts to extract configured metadata filters from journal-level or source-level configuration.
Journal-level metadata-filter takes precedence. If it is absent, the function falls back to standard-metadata-filter from the source.
Parameters
config_path
Path to the JSON configuration file containing metadata-filter definitions.
Returns
dict
Dictionary intended to map filter names to their configured values.
If no applicable metadata-filter list is found for a processed journal, the function returns an empty dictionary.
Raises
FileNotFoundError
May be raised if the configuration file does not exist.
json.JSONDecodeError
May be raised if the file contains invalid JSON.
KeyError
May be raised by the current filter assignment logic when a configured filter value is not also a key in the same filter dictionary.
Processing
- Open and parse the configuration file.
- Read
Sources, defaulting to an empty list when absent. - Iterate through each source.
- Read
Journals, defaulting to an empty list. - For each journal, try
metadata-filter. - If absent, use the source's
standard-metadata-filter. - For each filter entry, read
filterandvalueand add an entry tofilters_dictwhen both are present. - Return the resulting dictionary.
Current Implementation Detail
The current implementation assigns filter entries using:
filters_dict[filter_key] = item[filter_value]
This means the value of the value field is used as another dictionary key.
For example, with:
{
"filter": "type",
"value": "journal-article"
}
the function attempts to evaluate:
item["journal-article"]
rather than assigning:
filters_dict["type"] = "journal-article"
Unless the filter dictionary also contains a key named journal-article, this raises KeyError.
Early Return Behavior
When neither a journal-level nor source-level metadata filter is available for a processed journal, the function immediately returns an empty dictionary.
This means later sources or journals are not inspected after that point.
Prefect Behavior
The function is decorated with @task.
Workflow Context Example
Given:
{
"Sources": [
{
"source-name": "Example Publisher",
"standard-modules": [
"crossrefcrawler",
"image_format_converter",
"create_bags"
],
"standard-schemas": [
"example-schema"
],
"standard-metadata-format": "xml",
"Journals": [
{
"issn-e": "1234-5678"
}
]
}
]
}
calling:
get_module_context(
"config.json",
"image_format_converter",
)
produces a context equivalent to:
[
{
"ISSN": "1234-5678",
"position": 1,
"previous_module": "crossrefcrawler",
"schemas": ["example-schema"],
"metadata-format": "xml",
}
]
The exact result depends on the values present in the supplied configuration.
Operational Considerations
Journal-Level Overrides
Journal-level values override source defaults for:
- modules,
- schemas,
- metadata format,
- metadata filters.
This allows a source to define common defaults while individual journals provide exceptions.
Required and Optional Keys
get_module_context() uses direct dictionary access for several keys. Missing required fields therefore raise KeyError rather than being silently ignored.
Empty Module Context
If no journal contains the requested module, get_module_context() returns an empty list.
Calling get_previous_module() with that empty result raises IndexError.
Configuration Validation
The module does not perform comprehensive schema validation of the JSON configuration.
It assumes that required keys and expected value types are already valid.