Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/client-cache-#209
Browse files Browse the repository at this point in the history
  • Loading branch information
MRichards99 committed Apr 20, 2021
2 parents 85e52f0 + c3c607f commit a643145
Show file tree
Hide file tree
Showing 24 changed files with 779 additions and 336 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ jobs:
run: |
sed -i -e "s/^payara_user: \"glassfish\"/payara_user: \"runner\"/" icat-ansible/group_vars/all/vars.yml
# Force hostname to localhost - bug fix for previous ICAT Ansible issues on Actions
- name: Change hostname to localhost
run: sudo hostname -b localhost

# Create local instance of ICAT
- name: Run ICAT Ansible Playbook
run: |
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,13 @@ PowerShell:
> flask run
```

The Flask app can be configured so that code changes are monitored and the server will
reload itself when a change is detected. This setting can be toggled using
`flask_reloader` in `config.json`. This is useful for development purposes. It should be
noted that when this setting is enabled, the API will go through the startup process
twice. In the case of the ICAT backend, this could dramatically increase startup time if
the API is configured with a large initial client pool size.


## Authentication
Each request requires a valid session ID to be provided in the Authorization header.
Expand Down
1 change: 0 additions & 1 deletion datagateway_api/common/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def create_backend(backend_type):
elif backend_type == "python_icat":
backend = PythonICATBackend()
else:
# Might turn to a warning so the abstract class can be tested?
sys.exit(f"Invalid config value '{backend_type}' for config option backend")

return backend
6 changes: 6 additions & 0 deletions datagateway_api/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ def get_db_url(self):
except KeyError:
sys.exit("Missing config value, DB_URL")

def is_flask_reloader(self):
try:
return self.config["flask_reloader"]
except KeyError:
sys.exit("Missing config value, flask_reloader")

def get_icat_url(self):
try:
return self.config["ICAT_URL"]
Expand Down
28 changes: 18 additions & 10 deletions datagateway_api/common/icat/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,22 +117,30 @@ def __init__(self, fields):
def apply_filter(self, query):
try:
log.info("Adding ICAT distinct filter to ICAT query")
if (
query.aggregate == "COUNT"
or query.aggregate == "AVG"
or query.aggregate == "SUM"
):
log.debug("Fields for distinct filter: %s", self.fields)

# These aggregate keywords not currently used in the API, but conditional
# present in case they're used in the future
if query.aggregate == "AVG" or query.aggregate == "SUM":
# Distinct can be combined with other aggregate functions
query.setAggregate(f"{query.aggregate}:DISTINCT")
elif query.aggregate == "COUNT":
# When count and distinct keywords are used together when selecting
# multiple attributes, Python ICAT will always throw an error on query
# execution (more info:
# https://github.com/icatproject/python-icat/issues/76). This appears to
# be a JPQL limitation, something that cannot be fixed in Python ICAT.
# As a result, the API will get the distinct results and manually
# perform `len()` on the list, using `manual_count` as a flag to
# recognise this situation
query.setAggregate("DISTINCT")
log.debug("Manual count flag enabled")
query.manual_count = True
else:
query.setAggregate("DISTINCT")

# Using where filters to identify which fields to apply distinct too
for field in self.fields:
where_filter = PythonICATWhereFilter(field, "null", "ne")
where_filter.apply_filter(query)
query.setAttributes(self.fields)

log.debug("Fields for distinct filter: %s", self.fields)
except ValueError as e:
raise FilterError(e)

Expand Down
2 changes: 2 additions & 0 deletions datagateway_api/common/icat/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ def get_facility_cycles_for_instrument(

query_aggregate = "COUNT:DISTINCT" if count_query else "DISTINCT"
query = ICATQuery(client, "FacilityCycle", aggregate=query_aggregate)
query.isis_endpoint = True

instrument_id_check = PythonICATWhereFilter(
"facility.instruments.id", instrument_id, "eq",
Expand Down Expand Up @@ -657,6 +658,7 @@ def get_investigations_for_instrument_in_facility_cycle(

query_aggregate = "COUNT:DISTINCT" if count_query else "DISTINCT"
query = ICATQuery(client, "Investigation", aggregate=query_aggregate)
query.isis_endpoint = True

instrument_id_check = PythonICATWhereFilter(
"facility.instruments.id", instrument_id, "eq",
Expand Down
Loading

0 comments on commit a643145

Please sign in to comment.