Skip to content

Commit

Permalink
serializers: added datacite XML with swhid
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandromumo authored and slint committed Nov 28, 2024
1 parent c3a1bda commit d6a7fe5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
10 changes: 10 additions & 0 deletions invenio.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -1113,4 +1122,5 @@ APP_RDM_RECORD_EXPORTERS = {
"content-type": "application/x-yaml",
"filename": "{id}.yaml",
},

}
3 changes: 2 additions & 1 deletion site/zenodo_rdm/serializers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
22 changes: 19 additions & 3 deletions site/zenodo_rdm/serializers/datacite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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,
)

0 comments on commit d6a7fe5

Please sign in to comment.