Skip to content

Commit

Permalink
Merge branch 'feature/python-icat-get-with-filters-#137' into feature…
Browse files Browse the repository at this point in the history
…/python-icat-entity-id-endpoints-#136
  • Loading branch information
MRichards99 committed Aug 12, 2020
2 parents 511655e + 80b89e9 commit cc75ec0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
4 changes: 2 additions & 2 deletions common/python_icat_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from common.helpers import queries_records
from common.python_icat_helpers import requires_session_id, get_session_details_helper, logout_icat_client, \
refresh_client_session, get_entity_by_id, update_entity_by_id, \
delete_entity_by_id
delete_entity_by_id, get_entity_with_filters
from common.config import config
from common.exceptions import AuthenticationError
from common.models.db_models import SESSION
Expand Down Expand Up @@ -56,7 +56,7 @@ def logout(self, session_id):
@requires_session_id
@queries_records
def get_with_filters(self, session_id, table, filters):
pass
return get_entity_with_filters(self.client, table.__name__, filters)

@requires_session_id
@queries_records
Expand Down
16 changes: 15 additions & 1 deletion common/python_icat_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ def execute_icat_query(client, query, return_json_formattable=False):
:return: Data (of type list) from the executed query
"""

query_result = client.search(query)
try:
query_result = client.search(query)
except ICATValidationError as e:
raise PythonICATError(e)

if return_json_formattable:
data = []
Expand Down Expand Up @@ -325,3 +328,14 @@ def update_entity_by_id(client, table_name, id_, new_data):
# The record is re-obtained from Python ICAT (rather than using entity_id_data) to show to the
# user whether the change has actually been applied
return get_entity_by_id(client, table_name, id_, True)


def get_entity_with_filters(client, table_name, filters):
selected_entity_name = get_python_icat_entity_name(client, table_name)
query = construct_icat_query(client, selected_entity_name)
data = execute_icat_query(client, query, True)

if not data:
raise MissingRecordError("No results found")
else:
return data

0 comments on commit cc75ec0

Please sign in to comment.