diff --git a/invenio_rdm_records/resources/serializers/datacite/schema.py b/invenio_rdm_records/resources/serializers/datacite/schema.py index 17ed58d33..11fc1a9aa 100644 --- a/invenio_rdm_records/resources/serializers/datacite/schema.py +++ b/invenio_rdm_records/resources/serializers/datacite/schema.py @@ -10,6 +10,8 @@ """DataCite based Schema for Invenio RDM Records.""" +import json + from babel_edtf import parse_edtf from edtf.parser.grammar import ParseException from flask import current_app @@ -73,7 +75,6 @@ def get_name_identifiers(self, obj): """Get name identifier list.""" serialized_identifiers = [] identifiers = obj["person_or_org"].get("identifiers", []) - for identifier in identifiers: scheme = identifier["scheme"] id_scheme = get_scheme_datacite( @@ -81,10 +82,21 @@ def get_name_identifiers(self, obj): ) if id_scheme: + name_id = { "nameIdentifier": identifier["identifier"], "nameIdentifierScheme": id_scheme, } + + scheme_uri = "" + if scheme == "orcid": + scheme_uri = "http://orcid.org/" + elif scheme == "ror": + scheme_uri = "https://ror.org/" + + if scheme_uri: + name_id["schemeUri"] = scheme_uri + serialized_identifiers.append(name_id) return serialized_identifiers @@ -247,6 +259,19 @@ def _merge_main_and_additional(self, obj, field, default_type=None): result.append(item) + if field == "description": + # References + refs = obj["metadata"].get("references") + if refs: + result.append( + { + field: json.dumps( + {"references": [r["reference"] for r in refs]} + ), + f"{field}Type": "Other", + } + ) + return result or missing def get_titles(self, obj): @@ -563,6 +588,22 @@ def get_rights(self, obj): entry["rightsUri"] = link serialized_rights.append(entry) + # Adding access_status information + + access_status = obj.get("access", {}).get("status", "") + if access_status == "metadata-only": + access_status = "closed" + + access_right_formatted = access_status.capitalize() + " Access" + rights_uri = f"info:eu-repo/semantics/{access_status}Access" + + access_right_serialized = { + "rights": access_right_formatted, + "rightsUri": rights_uri, + } + + serialized_rights.append(access_right_serialized) + return serialized_rights if serialized_rights else missing def get_funding(self, obj): diff --git a/invenio_rdm_records/resources/serializers/dcat/datacite-to-dcat-ap.xsl b/invenio_rdm_records/resources/serializers/dcat/datacite-to-dcat-ap.xsl index 94b24da04..acfbdb405 100644 --- a/invenio_rdm_records/resources/serializers/dcat/datacite-to-dcat-ap.xsl +++ b/invenio_rdm_records/resources/serializers/dcat/datacite-to-dcat-ap.xsl @@ -1655,7 +1655,10 @@ +--> + + + diff --git a/tests/resources/serializers/test_datacite_serializer.py b/tests/resources/serializers/test_datacite_serializer.py index 12a7432c9..01f2d73c2 100644 --- a/tests/resources/serializers/test_datacite_serializer.py +++ b/tests/resources/serializers/test_datacite_serializer.py @@ -121,6 +121,7 @@ def test_datacite43_serializer(running_app, full_record_to_dict): { "nameIdentifier": "0000-0001-8135-3489", "nameIdentifierScheme": "ORCID", + "schemeUri": "http://orcid.org/", } ], "nameType": "Personal", @@ -144,6 +145,7 @@ def test_datacite43_serializer(running_app, full_record_to_dict): { "nameIdentifier": "0000-0001-8135-3489", "nameIdentifierScheme": "ORCID", + "schemeUri": "http://orcid.org/", } ], "nameType": "Personal", @@ -167,6 +169,10 @@ def test_datacite43_serializer(running_app, full_record_to_dict): "descriptionType": "Abstract", }, {"description": "Bla bla bla", "descriptionType": "Methods", "lang": "eng"}, + { + "description": '{"references": ["Nielsen et al,.."]}', + "descriptionType": "Other", + }, ], "formats": ["application/pdf"], "fundingReferences": [ @@ -224,6 +230,10 @@ def test_datacite43_serializer(running_app, full_record_to_dict): "rightsUri": "https://creativecommons.org/licenses/by/4.0/legalcode", }, {"rights": "No rightsUri license"}, + { + "rights": "Embargoed Access", + "rightsUri": "info:eu-repo/semantics/embargoedAccess", + }, ], "schemaVersion": "http://datacite.org/schema/kernel-4", "sizes": ["11 pages"], @@ -275,7 +285,7 @@ def test_datacite43_xml_serializer(running_app, full_record_to_dict): " Lars Holm\n" " Nielsen\n" " 0000-0001-8135-3489\n' + 'nameIdentifierScheme="ORCID" schemeURI="http://orcid.org/">0000-0001-8135-3489\n' " CERN\n" " free-text\n" " \n" @@ -303,7 +313,7 @@ def test_datacite43_xml_serializer(running_app, full_record_to_dict): " Lars Holm\n" " Nielsen\n" " 0000-0001-8135-3489\n' + 'nameIdentifierScheme="ORCID" schemeURI="http://orcid.org/">0000-0001-8135-3489\n' " CERN\n" " TU Wien\n" " \n" @@ -340,12 +350,14 @@ def test_datacite43_xml_serializer(running_app, full_record_to_dict): 'rightsURI="https://creativecommons.org/licenses/by/4.0/legalcode" ' 'rightsIdentifierScheme="spdx" rightsIdentifier="cc-by-4.0">Creative Commons ' "Attribution 4.0 International\n" + ' Embargoed Access\n' " \n" " \n" ' A description \n' "with HTML tags\n" ' Bla bla ' "bla\n" + ' {"references": ["Nielsen et al,.."]}\n' " \n" " \n" " \n" diff --git a/tests/resources/serializers/test_dcat_serializer.py b/tests/resources/serializers/test_dcat_serializer.py index cc6137b06..bc9c23db2 100644 --- a/tests/resources/serializers/test_dcat_serializer.py +++ b/tests/resources/serializers/test_dcat_serializer.py @@ -40,6 +40,7 @@ def test_dcat_serializer(running_app, full_record_to_dict): " \n" ' \n' ' \n' + ' 0000-0001-8135-3489\n' " Nielsen, Lars Holm\n" " Lars Holm\n" " Nielsen\n" @@ -107,6 +108,7 @@ def test_dcat_serializer(running_app, full_record_to_dict): " \n" ' \n' ' \n' + ' 0000-0001-8135-3489\n' " Nielsen, Lars Holm\n" " Lars Holm\n" " Nielsen\n" @@ -181,6 +183,7 @@ def test_dcat_serializer(running_app, full_record_to_dict): " Bla bla bla\n" " \n" " \n" + ' {"references": ["Nielsen et al,.."]}\n' " \n" " \n" " \n' " \n" " \n" + ' \n' + " \n" + ' \n' + " Embargoed Access\n" + " \n" + " \n" " \n" " \n" " \n" diff --git a/tests/services/pids/test_pids_tasks.py b/tests/services/pids/test_pids_tasks.py index 7989a06ea..516c7c36d 100644 --- a/tests/services/pids/test_pids_tasks.py +++ b/tests/services/pids/test_pids_tasks.py @@ -600,6 +600,7 @@ def test_full_record_register( { "nameIdentifier": "0000-0001-8135-3489", "nameIdentifierScheme": "ORCID", + "schemeUri": "http://orcid.org/", } ], "nameType": "Personal", @@ -622,6 +623,7 @@ def test_full_record_register( { "nameIdentifier": "0000-0001-8135-3489", "nameIdentifierScheme": "ORCID", + "schemeUri": "http://orcid.org/", } ], "nameType": "Personal", @@ -645,6 +647,10 @@ def test_full_record_register( "descriptionType": "Methods", "lang": "eng", }, + { + "description": '{"references": ["Nielsen et ' 'al,.."]}', + "descriptionType": "Other", + }, ], "formats": ["application/pdf"], "fundingReferences": [ @@ -702,6 +708,10 @@ def test_full_record_register( "rightsIdentifierScheme": "spdx", "rightsUri": "https://creativecommons.org/licenses/by/4.0/legalcode", }, + { + "rights": " Access", + "rightsUri": "info:eu-repo/semantics/Access", + }, ], "schemaVersion": "http://datacite.org/schema/kernel-4", "sizes": ["11 pages"],