diff --git a/invenio.cfg b/invenio.cfg index 8dd9ddb5..9d955672 100644 --- a/invenio.cfg +++ b/invenio.cfg @@ -1105,6 +1105,15 @@ APP_RDM_RECORD_EXPORTERS = { "params": {"options": {"indent": 2, "sort_keys": True}}, "content-type": "application/vnd.datacite.datacite+json", "filename": "{id}.json", + }, + "datacite-xml": { + "name": _("DataCite XML"), + "serializer": ( + "zenodo_rdm.serializers:ZenodoDataciteXMLSerializer" + ), + "params": {}, + "content-type": "application/vnd.datacite.datacite+xml", + "filename": "{id}.xml", }, "cff": { "name": _("Citation File Format"), @@ -1113,4 +1122,5 @@ APP_RDM_RECORD_EXPORTERS = { "content-type": "application/x-yaml", "filename": "{id}.yaml", }, + } \ No newline at end of file diff --git a/site/zenodo_rdm/serializers/__init__.py b/site/zenodo_rdm/serializers/__init__.py index d1c1ac04..9e631dab 100644 --- a/site/zenodo_rdm/serializers/__init__.py +++ b/site/zenodo_rdm/serializers/__init__.py @@ -9,11 +9,12 @@ from .bibtex import ZenodoBibtexSerializer from .cff import ZenodoCFFSerializer from .codemeta import ZenodoCodemetaSerializer -from .datacite import ZenodoDataciteJSONSerializer +from .datacite import ZenodoDataciteJSONSerializer, ZenodoDataciteXMLSerializer __all__ = ( "ZenodoBibtexSerializer", "ZenodoCodemetaSerializer", "ZenodoDataciteJSONSerializer", + "ZenodoDataciteXMLSerializer", "ZenodoCFFSerializer", ) diff --git a/site/zenodo_rdm/serializers/datacite.py b/site/zenodo_rdm/serializers/datacite.py index 2f78e836..61d571e6 100644 --- a/site/zenodo_rdm/serializers/datacite.py +++ b/site/zenodo_rdm/serializers/datacite.py @@ -6,9 +6,10 @@ # it under the terms of the MIT License; see LICENSE file for more details. """Zenodo datacite serializer.""" +from datacite import schema43 from flask import current_app from flask_resources import BaseListSchema, MarshmallowSerializer -from flask_resources.serializers import JSONSerializer +from flask_resources.serializers import JSONSerializer, SimpleSerializer from invenio_rdm_records.contrib.journal.processors import JournalDataciteDumper from invenio_rdm_records.resources.serializers.datacite.schema import DataCite43Schema from marshmallow import missing @@ -25,9 +26,9 @@ def get_related_identifiers(self, obj): _url = f"{current_app.config['SWH_UI_BASE_URL']}/{swhid}" ret.append( { - "relation": "isIdenticalTo", "relatedIdentifier": _url, - "relatedIdentifierType": "url", + "relatedIdentifierType": "URL", + "relationType": "IsIdenticalTo", } ) return ret or missing @@ -45,3 +46,18 @@ def __init__(self, **options): schema_kwargs={"dumpers": [JournalDataciteDumper()]}, # Order matters **options, ) + + +class ZenodoDataciteXMLSerializer(MarshmallowSerializer): + """Zenodo Datacite XML serializer.""" + + def __init__(self, **options): + """Instantiate serializer.""" + encoder = options.get("encoder", schema43.tostring) + super().__init__( + format_serializer_cls=SimpleSerializer, + object_schema_cls=ZenodoDataciteSchema, + list_schema_cls=BaseListSchema, + schema_kwargs={"dumpers": [JournalDataciteDumper()]}, # Order matters + encoder=encoder, + )