From ac0c6c47403669e48de48951c88040b07f4d185b Mon Sep 17 00:00:00 2001 From: Fatimah Zulfiqar Date: Tue, 1 Oct 2024 10:49:17 +0200 Subject: [PATCH] dumper: refactor and updated docstring --- .../records/dumpers/subject_hierarchy.py | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/invenio_rdm_records/records/dumpers/subject_hierarchy.py b/invenio_rdm_records/records/dumpers/subject_hierarchy.py index e95f7cac2..48dfa309f 100644 --- a/invenio_rdm_records/records/dumpers/subject_hierarchy.py +++ b/invenio_rdm_records/records/dumpers/subject_hierarchy.py @@ -18,6 +18,40 @@ class SubjectHierarchyDumperExt(SearchDumperExt): This dumper needs to be placed after the RelationDumper for subjects as it relies on dereferenced subjects with scheme, subject, and props. + + Example + "subjects" : + [ + { + "id" : "euroscivoc:425", + "subject" : "Energy and fuels", + "scheme" : "EuroSciVoc", + "props" : { + "parents" : "euroscivoc:25,euroscivoc:67", + }, + "@v" : "ef9f1c4c-b469-4645-a4b2-0db9b1c42096::1" + } + ] + + The above subject is dumped with hierarchy field and is transformed to + + "subjects" : + [ + { + "id" : "euroscivoc:425", + "subject" : "Energy and fuels", + "scheme" : "EuroSciVoc", + "props" : { + "parents" : "euroscivoc:25,euroscivoc:67", + "hierarchy" : [ + "euroscivoc:25", + "euroscivoc:25,euroscivoc:67", + "euroscivoc:25,euroscivoc:67,euroscivoc:425" + ] + }, + "@v" : "ef9f1c4c-b469-4645-a4b2-0db9b1c42096::1" + } + ] """ def __init__(self, splitchar=","): @@ -57,7 +91,8 @@ def build_hierarchy(parents_str, current_subject_id): subject_hierarchy = build_hierarchy(parents, current_subject_id) subject.setdefault("props", {})["hierarchy"] = subject_hierarchy - data["metadata"] = data.get("metadata", {}) + if awards: + data["metadata"]["funding"] = awards def load(self, data, record_cls): """Load the data from secondary storage (OpenSearch-like).