Skip to content

Commit

Permalink
implement method for getting non related field names of PaNOSC entity #…
Browse files Browse the repository at this point in the history
  • Loading branch information
VKTB committed Jan 24, 2022
1 parent 95319a8 commit 4ced97a
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions datagateway_api/src/search_api/panosc_mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,32 @@ def get_panosc_related_entity_name(

return panosc_related_entity_name

def get_panosc_non_related_field_names(self, panosc_entity_name):
"""
This function retrieves the names of the non related fields of a given PaNOSC
entity.
:param panosc_entity_name: A PaNOSC entity name e.g. "Dataset"
:type panosc_entity_name: :class:`str`
:return: List containing the names of the non related fields of the given
PaNOSC entity
:raises FilterError: If mappings for the given entity name cannot be found
"""
try:
entity_mappings = self.mappings[panosc_entity_name]
except KeyError:
raise FilterError(
f"Cannot find mappings for {[panosc_entity_name]} PaNOSC entity",
)

non_related_field_names = []
for mapping_key, mapping_value in entity_mappings.items():
# The mappings for the non-related fields are of type `str` whereas for
# the related fields, they are of type `dict`. We only need the former.
if mapping_key != "base_icat_entity" and isinstance(mapping_value, str):
non_related_field_names.append(mapping_key)

return non_related_field_names


mappings = PaNOSCMappings()

0 comments on commit 4ced97a

Please sign in to comment.