Skip to content

Commit

Permalink
schema: added identifiers in subjects for datacite
Browse files Browse the repository at this point in the history
  • Loading branch information
0einstein0 committed Nov 28, 2024
1 parent e20bd90 commit 04fa07c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion invenio_rdm_records/records/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
),
Expand Down
22 changes: 14 additions & 8 deletions invenio_rdm_records/resources/serializers/datacite/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 04fa07c

Please sign in to comment.