Skip to content

Commit

Permalink
datacite: fix related identifiers serialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandromumo authored and zzacharo committed Oct 27, 2023
1 parent 949b339 commit 7bca45a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
41 changes: 33 additions & 8 deletions invenio_rdm_records/resources/serializers/datacite/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,29 @@
from ...serializers.ui.schema import current_default_locale
from ..utils import get_preferred_identifier, get_vocabulary_props

RELATED_IDENTIFIER_SCHEMES = {
"ark",
"arxiv",
"bibcode",
"doi",
"ean13",
"eissn",
"handle",
"igsn",
"isbn",
"issn",
"istc",
"lissn",
"lsid1",
"pmid",
"purl",
"upc",
"url",
"urn",
"w3id",
}
"""Allowed related identifier schemes for DataCite. Vocabulary taken from DataCite 4.3 schema definition."""


def get_scheme_datacite(scheme, config_name, default=None):
"""Returns the datacite equivalent of a scheme."""
Expand Down Expand Up @@ -362,7 +385,8 @@ def get_related_identifiers(self, obj):
default=scheme,
)

if id_scheme:
# Only serialize related identifiers with a valid scheme for DataCite.
if id_scheme and id_scheme.lower() in RELATED_IDENTIFIER_SCHEMES:
serialized_identifier = {
"relatedIdentifier": rel_id["identifier"],
"relationType": props.get("datacite", ""),
Expand Down Expand Up @@ -423,13 +447,14 @@ def get_related_identifiers(self, obj):
"RDM_RECORDS_IDENTIFIERS_SCHEMES",
default="doi",
)
serialized_identifiers.append(
{
"relatedIdentifier": parent_doi["identifier"],
"relationType": "IsVersionOf",
"relatedIdentifierType": id_scheme,
}
)
if id_scheme.lower() in RELATED_IDENTIFIER_SCHEMES:
serialized_identifiers.append(
{
"relatedIdentifier": parent_doi["identifier"],
"relationType": "IsVersionOf",
"relatedIdentifierType": id_scheme,
}
)

# adding communities
communities = obj.get("parent", {}).get("communities", {}).get("ids", [])
Expand Down
6 changes: 3 additions & 3 deletions tests/resources/serializers/test_datacite_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,8 @@ def test_datacite43_serializer_with_unknown_id_schemes(
assert expected_pid_id_2 in serialized_record["identifiers"]
assert len(serialized_record["identifiers"]) == 5

assert expected_related_id in serialized_record["relatedIdentifiers"]
assert len(serialized_record["relatedIdentifiers"]) == 2
assert expected_related_id not in serialized_record["relatedIdentifiers"]
assert len(serialized_record["relatedIdentifiers"]) == 1

creator_ids = serialized_record["creators"][0]["nameIdentifiers"]
assert expected_creator_id in creator_ids
Expand All @@ -386,5 +386,5 @@ def test_datacite43_xml_serializer_with_unknown_id_schemes(

assert expected_pid_id in serialized_record
assert expected_pid_id_2 in serialized_record
assert expected_related_id in serialized_record
assert expected_related_id not in serialized_record
assert expected_creator_id in serialized_record

0 comments on commit 7bca45a

Please sign in to comment.