toolbox_conversion
Overview
The toolbox_conversion module triggers conversion of an article's publisher-specific XML into TEI XML by calling an endpoint on the external "toolbox" system (the same system metadata_toolbox_upload uploads metadata to). Rather than sending any file content itself, it calls a per-article conversion URL built from the article's toolbox ID and a "pipeline" name.
Recommended module ordering :
- It should run after whichever module writes the article's toolbox external identifier (likely
toolbox_ids, based on the same dependency seen inmetadata_toolbox_upload), sinceconvert()reads it viacommon.metadata.get_external_identifier.
The module contains two primary Python files:
flow.pytasks.py
flow.py
This file defines the main flow for toolbox XML conversion using the Prefect library, and uses prefect's get_run_logger to log various stages. It follows the standard previous_module / temp-<module> folder convention, and applies a small fixed delay (WAIT_TIME_BETWEEN_API_CALLS = 0.2 seconds) between successful conversion calls to avoid overwhelming the toolbox endpoint.
toolbox_conversion()
-
Required Parameters:
-
name_of_config_file(str): Name of the configuration file. Default is"conversion-test.json" -
test_copy(bool): Flag to indicate if it is a test run. Default isFalse -
Context for Use:
-
This function is the main entry point. It iterates every article of every journal in the module context, and for each eligible article, copies the previous module's content forward and calls
tasks.convertto trigger the toolbox conversion. On an HTTP 200 response, it writes ahistory.csventry and finalizes the module folder as usual; on any other status code, it logs an error and skips the article for this run (no stop folder is created). -
Example Usage:
-
python toolbox_conversion('conversion-test.json', test_copy=False) -
Example Output:
-
INFO: Module name: toolbox_conversion INFO: Set base path to: /mnt/.../wdm-test INFO: Module context: [{'ISSN': '2673-4532', 'position': 4, 'previous_module': 'relaxng_scanner', ...}] INFO: Starting XML format conversion for ISSN: 2673-4532. INFO: latest previous module: /mnt/.../relaxng_scanner_2025-01-17 INFO: Calling endpoint at https://.../jz...01?pipeline=mdpi_jats_relaxng_schem....rng INFO: Response: 200 INFO: Endpoint return value <Response [200]> INFO: Toolbox succeeded for 1 articles.
tasks.py
This file contains the task definitions used in the toolbox conversion flow. It handles resolving the article's toolbox ID and conversion pipeline name, building the conversion endpoint URL, and making the authenticated request.
convert()
-
Required Parameters:
-
module_name(str): Name of the current module -
latest_previous_module(pathlib.Path): Path to the latest previous module directory -
Context for Use:
-
This is the main Prefect
@task. It reads the article's toolbox external identifier (metadata.get_external_identifier) and derives the conversion pipeline name (get_pipeline_name), builds the conversion URL, and sends aGETrequest to it with HTTP Basic Auth. Returns therequests.Responseobject on a normal call. -
Example Usage:
-
python response = tasks.convert(module_name, latest_previous_module)
get_pipeline_name()
-
Required Parameters:
-
module_name(str): Name of the current module -
latest_previous_module(pathlib.Path): Path to the latest previous module directory -
Context for Use:
-
Reads the RelaxNG validation success indicator file from the current temp module directory, and extracts the pipeline/schema name from it, the line looks like a comma-separated value whose first field is a path (e.g.
Schemadateien2/mdpi_jats_relaxng_schema.rng,...), and only the filename portion after the last/is returned (e.g.mdpi_jats_relaxng_schema.rng). If the file doesn't exist, logs an error and returnsNone.
get_conversion_url()
-
Required Parameters:
-
toolbox_text_id(str): The article's toolbox ID -
pipeline_name(str): The conversion pipeline/schema name -
Context for Use:
-
Builds the full conversion endpoint URL from the configured base URL, conversion endpoint path, the toolbox ID, and the pipeline name as a query parameter. Returns the literal string
"Invalid Conversion url"if either the base URL or the endpoint could not be read from the config.
The lower-level helper functions in tasks.py are listed below.
get_base_url() / get_conversion_endpoint()
-
Context for Use:
-
Read the toolbox conversion base URL and endpoint path from the shared harvesting config JSON, each with a trailing slash appended. If the respective config key is missing, they return the literal placeholder strings
"Invalid Base_url"/"Invalid endpoint". Later in the module,get_conversion_urlchecks for these exact strings to decide whether to proceed.
get_auth()
-
Context for Use:
-
Builds an
HTTPBasicAuthobject from the harvesting config JSON. This differs from howmetadata_toolbox_uploadauthenticates to the same toolbox system (that module loads credentials from Prefect Secret blocks instead).
get_latest_commit()
-
Context for Use:
-
Fetches the HEAD commit hash of the harvesting repository via a GitLab API call (URL configured in the harvesting config). Returns the hash string, or an error message string if the API call fails. Used to populate the
Versionfield ofhistory.csventries.