Skip to content

Commit

Permalink
refactor: refactor entity relations code #268
Browse files Browse the repository at this point in the history
  • Loading branch information
MRichards99 committed Feb 7, 2022
1 parent 22a0ea8 commit 4343a2c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
3 changes: 0 additions & 3 deletions datagateway_api/src/common/filter_order_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ def add_icat_relations_for_panosc_non_related_fields(
:param panosc_entity_name: A PaNOSC entity name e.g. "Dataset"
:type panosc_entity_name: :class:`str`
:return: ICAT relations for the non related fields of the given PaNOSC entity
"""

icat_relations = mappings.get_icat_relations_for_panosc_non_related_fields(
Expand All @@ -129,8 +128,6 @@ def add_icat_relations_for_panosc_non_related_fields(
if icat_relations:
self.filters.append(PythonICATIncludeFilter(icat_relations))

return icat_relations

def merge_python_icat_limit_skip_filters(self):
"""
When there are both limit and skip filters in a request, merge them into the
Expand Down
16 changes: 11 additions & 5 deletions datagateway_api/src/search_api/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

from datagateway_api.src.common.exceptions import MissingRecordError
from datagateway_api.src.common.filter_order_handler import FilterOrderHandler
from datagateway_api.src.search_api.filters import SearchAPIWhereFilter
from datagateway_api.src.search_api.filters import (
SearchAPIIncludeFilter,
SearchAPIWhereFilter,
)
import datagateway_api.src.search_api.models as models
from datagateway_api.src.search_api.query import SearchAPIQuery
from datagateway_api.src.search_api.session_handler import (
Expand Down Expand Up @@ -32,13 +35,16 @@ def get_search(entity_name, filters):
log.info("Searching for %s using request's filters", entity_name)
log.debug("Entity Name: %s, Filters: %s", entity_name, filters)

entity_relations = []
for filter_ in filters:
if isinstance(filter_, SearchAPIIncludeFilter):
entity_relations.extend(filter_.included_filters)

query = SearchAPIQuery(entity_name)

filter_handler = FilterOrderHandler()
filter_handler.add_filters(filters)
icat_relations = filter_handler.add_icat_relations_for_panosc_non_related_fields(
entity_name,
)
filter_handler.add_icat_relations_for_panosc_non_related_fields(entity_name)
filter_handler.add_icat_relations_for_non_related_fields_of_panosc_related_entities(
entity_name,
)
Expand All @@ -51,7 +57,7 @@ def get_search(entity_name, filters):
panosc_data = []
for icat_data in icat_query_data:
panosc_model = getattr(models, entity_name)
panosc_record = panosc_model.from_icat(icat_data, icat_relations).json(
panosc_record = panosc_model.from_icat(icat_data, entity_relations).json(
by_alias=True,
)
panosc_data.append(json.loads(panosc_record))
Expand Down

0 comments on commit 4343a2c

Please sign in to comment.