diff --git a/common/python_icat_backend.py b/common/python_icat_backend.py index 903b5297..6aaf694f 100644 --- a/common/python_icat_backend.py +++ b/common/python_icat_backend.py @@ -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 @@ -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 diff --git a/common/python_icat_helpers.py b/common/python_icat_helpers.py index 77059fb8..e72709a8 100644 --- a/common/python_icat_helpers.py +++ b/common/python_icat_helpers.py @@ -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 = [] @@ -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