Skip to content

Commit

Permalink
#139: Fix independent use of skip filter
Browse files Browse the repository at this point in the history
- Grabs max num of entities from ICAT properties and applies that to the count element of the tuple - the currently configured number is 10000, which should be more than enough for any applicable use cases of this API
  • Loading branch information
MRichards99 committed Aug 21, 2020
1 parent 93eb468 commit 39ab528
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
15 changes: 15 additions & 0 deletions common/config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import json
import sys
from pathlib import Path
import requests
import logging

log = logging.getLogger()

class Config(object):
def __init__(self):
Expand Down Expand Up @@ -68,5 +71,17 @@ def get_port(self):
except:
sys.exit("Missing config value, port")

def get_icat_properties(self):
"""
ICAT properties can be retrieved using Python ICAT's client object, however this
requires the client object to be authenticated which may not always be the case
when requesting these properties, hence a HTTP request is sent as an alternative
"""
properties_url = f"{config.get_icat_url()}/icat/properties"
r = requests.request("GET", properties_url, verify=config.get_icat_check_cert())
icat_properties = r.json()
log.debug("ICAT Properties: %s", icat_properties)

return icat_properties

config = Config()
5 changes: 0 additions & 5 deletions common/filter_order_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ def apply_filters(self, query):
:param query: The query to have filters applied to
"""
self.sort_filters()

"""
if any(isinstance(filter, PythonICATOrderFilter) for filter in self.filters):
PythonICATOrderFilter.result_order = []
"""

for filter in self.filters:
filter.apply_filter(query)
10 changes: 6 additions & 4 deletions common/icat/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
IncludeFilter,
)
from common.exceptions import FilterError
from common.config import config

log = logging.getLogger()

Expand Down Expand Up @@ -101,7 +102,8 @@ def __init__(self, skip_value):
super().__init__(skip_value)

def apply_filter(self, query):
icat_set_limit(query, self.skip_value, False)
icat_properties = config.get_icat_properties()
icat_set_limit(query, self.skip_value, icat_properties["maxEntities"])


class PythonICATLimitFilter(LimitFilter):
Expand All @@ -119,10 +121,10 @@ def icat_set_limit(query, skip_number, limit_number):
:param query: ICAT Query object to execute within Python ICAT
:type query: :class:`icat.query.Query`
:param skip_number:
:param skip_number: Number of results to skip
:type skip_number: :class:`int`
:param limit_number:
:type limit_number: :class:`int
:param limit_number: Number of results to limit in the query
:type limit_number: :class:`int`
:raises FilterError: If the tuple is not of two elements, or the elements aren't of
the valid type
"""
Expand Down

0 comments on commit 39ab528

Please sign in to comment.