Skip to content

Commit

Permalink
dumper: refactor and updated docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
0einstein0 committed Oct 3, 2024
1 parent 6d89b76 commit ac0c6c4
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion invenio_rdm_records/records/dumpers/subject_hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=","):
Expand Down Expand Up @@ -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).
Expand Down

0 comments on commit ac0c6c4

Please sign in to comment.