Skip to content

Commit

Permalink
fix: retrieve non-related fields that have a list of ICAT relations #265
Browse files Browse the repository at this point in the history
  • Loading branch information
VKTB committed Jan 27, 2022
1 parent 23200cd commit 2c5edc5
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions datagateway_api/src/search_api/panosc_mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,11 @@ def get_panosc_non_related_field_names(self, panosc_entity_name):

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):
# The mappings for the non-related fields are of type `str` and sometimes
# `list' whereas for the related fields, they are of type `dict`.
if mapping_key != "base_icat_entity" and (
isinstance(mapping_value, str) or isinstance(mapping_value, list)
):
non_related_field_names.append(mapping_key)

return non_related_field_names
Expand All @@ -141,13 +143,17 @@ def get_icat_relations_for_panosc_non_related_fields(self, panosc_entity_name):
for field_name in field_names:
_, icat_mapping = self.get_icat_mapping(panosc_entity_name, field_name)

split_icat_mapping = icat_mapping.split(".")
if len(split_icat_mapping) > 1:
# Remove the last split element because it is an ICAT
# field name and is not therefore part of the relation
split_icat_mapping = split_icat_mapping[:-1]
icat_mapping = ".".join(split_icat_mapping)
icat_relations.append(icat_mapping)
if not isinstance(icat_mapping, list):
icat_mapping = [icat_mapping]

for mapping in icat_mapping:
split_mapping = mapping.split(".")
if len(split_mapping) > 1:
# Remove the last split element because it is an ICAT
# field name and is not therefore part of the relation
split_mapping = split_mapping[:-1]
split_mapping = ".".join(split_mapping)
icat_relations.append(split_mapping)

return icat_relations

Expand Down

0 comments on commit 2c5edc5

Please sign in to comment.