diff --git a/invenio_rdm_records/records/api.py b/invenio_rdm_records/records/api.py index 377ef6c82..83180c770 100644 --- a/invenio_rdm_records/records/api.py +++ b/invenio_rdm_records/records/api.py @@ -184,7 +184,7 @@ class CommonFieldsMixin: ), subjects=PIDListRelation( "metadata.subjects", - keys=["subject", "scheme", "props"], + keys=["subject", "scheme", "props", "identifiers"], pid_field=Subject.pid, cache_key="subjects", ), diff --git a/invenio_rdm_records/resources/serializers/datacite/schema.py b/invenio_rdm_records/resources/serializers/datacite/schema.py index 82d685e41..41af4300f 100644 --- a/invenio_rdm_records/resources/serializers/datacite/schema.py +++ b/invenio_rdm_records/resources/serializers/datacite/schema.py @@ -538,14 +538,20 @@ def get_subjects(self, obj): for subject in subjects: entry = {"subject": subject.get("subject")} - id_ = subject.get("id") - if id_: - entry["subjectScheme"] = subject.get("scheme") - try: - validator(id_) - entry["valueURI"] = id_ - except ValidationError: - pass + subject_scheme = subject.get("scheme") + if subject_scheme: + entry["subjectScheme"] = subject_scheme + + # Get identifiers and assign valueURI if scheme is 'url' + identifiers = subject.get("identifiers", []) + for identifier in identifiers: + if identifier.get("scheme") == "url": + entry["valueURI"] = identifier.get("identifier") + break + + # Add id as valueURI if no 'url' scheme is found + if "valueURI" not in entry and subject.get("id"): + entry["valueURI"] = subject.get("id") serialized_subjects.append(entry)