Skip to content

Commit

Permalink
Add additional resource descriptions to index
Browse files Browse the repository at this point in the history
Updates index to add file_description from additional resource objects within HEPSubmission/DataSubmission objects to the OpenSearch index.
  • Loading branch information
ItIsJordan committed Jan 26, 2024
1 parent f6437b2 commit ea6e78f
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions hepdata/ext/opensearch/document_enhancers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from hepdata.ext.opensearch.config.record_mapping import mapping as os_mapping
from hepdata.modules.permissions.models import SubmissionParticipant
from hepdata.modules.submission.api import get_latest_hepsubmission
from hepdata.modules.submission.models import DataSubmission

FORMATS = ['json', 'root', 'yaml', 'csv', 'yoda']

Expand Down Expand Up @@ -127,6 +128,19 @@ def add_data_keywords(doc):
doc['data_keywords'] = dict(agg_keywords)


def add_data_resources(doc):
"""
Gets and adds additional resource descriptions for a DataSubmission object,
and adds it to the document object.
:param doc: The document object
:return:
"""

submission = DataSubmission.query.filter_by(doi=doc["doi"]).one()
doc["resources"] = [s.file_description for s in submission.resources]


def add_data_abstract(doc):
"""
Adds the data abstract from its associated HEPSubmission to the document object
Expand All @@ -139,6 +153,19 @@ def add_data_abstract(doc):
doc['data_abstract'] = submission.data_abstract


def add_submission_resources(doc):
"""
Gets and adds additional resource descriptions for a HEPSubmission object,
and adds it to the document object.
:param doc: The document object
:return:
"""

submission = get_latest_hepsubmission(publication_recid=doc['recid'], overall_status='finished')
doc['resources'] = [s.file_description for s in submission.resources]


def process_cmenergies(keywords):
cmenergies = []
if keywords['cmenergies']:
Expand Down Expand Up @@ -194,6 +221,7 @@ def enhance_data_document(doc):
add_data_table_urls(doc)
add_parent_publication(doc)
add_data_keywords(doc)
add_data_resources(doc)


def enhance_publication_document(doc):
Expand All @@ -205,3 +233,4 @@ def enhance_publication_document(doc):
process_last_updates(doc)
add_analyses(doc)
add_parent_child_info(doc)
add_submission_resources(doc)

0 comments on commit ea6e78f

Please sign in to comment.