diff --git a/scripts/metadata_checks.py b/scripts/metadata_checks.py index a6b8ca15..96321b94 100644 --- a/scripts/metadata_checks.py +++ b/scripts/metadata_checks.py @@ -20,6 +20,7 @@ from invenio_communities.proxies import current_communities from invenio_db import db from werkzeug.local import LocalProxy +from flask import current_app community_service = LocalProxy(lambda: current_communities.service) @@ -50,10 +51,43 @@ } ], }, + { + "id": "cern:doi/prefix-community", + "title": "CERN DOI prefix required", + "message": "Records with publisher CERN must use the CERN DOI prefix.", + "description": "Ensures records published by CERN use the configured DataCite prefix when a DOI is provided.", + "level": "error", + "error_path": "pids.doi", + "condition": { + "type": "logical", + "operator": "and", + "expressions": [ + { + "type": "comparison", + "left": {"type": "field", "path": "metadata.publisher"}, + "operator": "==", + "right": "CERN", + }, + { + "type": "comparison", + "left": {"type": "field", "path": "pids.doi.identifier"}, + "operator": "!=", + "right": "", + }, + ], + }, + "checks": [ + { + "type": "comparison", + "left": {"type": "field", "path": "pids.doi.identifier"}, + "operator": "^=", + "right": current_app.config["DATACITE_PREFIX"], + } + ], + }, ] } -from flask import current_app CDS_CERN_SCIENTIFIC_COMMUNITY_ID = current_app.config[ "CDS_CERN_SCIENTIFIC_COMMUNITY_ID"