From 71b8a0db856dfb3acb416b99f6a1bcf662dd7b71 Mon Sep 17 00:00:00 2001 From: khaledk2 Date: Fri, 16 Aug 2024 20:20:19 +0100 Subject: [PATCH] add endpoint to return data_sources and develope to search by data source --- omero_search_engine/api/v1/resources/urls.py | 7 ++++++ omero_search_engine/api/v1/resources/utils.py | 23 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/omero_search_engine/api/v1/resources/urls.py b/omero_search_engine/api/v1/resources/urls.py index 77a3f037..7b1b0fd5 100644 --- a/omero_search_engine/api/v1/resources/urls.py +++ b/omero_search_engine/api/v1/resources/urls.py @@ -24,6 +24,7 @@ search_resource_annotation, build_error_message, adjust_query_for_container, + get_data_sources ) from omero_search_engine.api.v1.resources.resource_analyser import ( search_value_for_resource, @@ -45,6 +46,12 @@ def index(): return "OMERO search engine (API V1)" +@resources.route("/data_resources/", methods=["GET"]) +def return_data_resources(): + """ + used to return the available data resources + """ + return jsonify(get_data_sources()) @resources.route("//searchannotation_page/", methods=["POST"]) def search_resource_page(resource_table): diff --git a/omero_search_engine/api/v1/resources/utils.py b/omero_search_engine/api/v1/resources/utils.py index 23c69bd3..2743ceda 100644 --- a/omero_search_engine/api/v1/resources/utils.py +++ b/omero_search_engine/api/v1/resources/utils.py @@ -1074,6 +1074,7 @@ def search_resource_annotation( bookmark=None, pagination_dict=None, return_containers=False, + data_source=None ): """ @table_: the resource table, e.g. image. project, etc. @@ -1106,6 +1107,22 @@ def search_resource_annotation( return build_error_message( "{query} is not a valid query".format(query=query) ) + if data_source and data_source.lower()!= "all" : + clause={} + clause["name"]="data_source" + clause["value"]=data_source + clause["operator"]="equals" + #'resource': 'image' + + if main_attributes and len(main_attributes) > 0: + if main_attributes.get("and_main_attributes"): + main_attributes.get("and_main_attributes").append(clause) + else: + main_attributes["and_main_attributes"]=[clause] + else: + main_attributes={} + main_attributes["and_main_attributes"] = [clause] + and_filters = query_details.get("and_filters") or_filters = query_details.get("or_filters") case_sensitive = query_details.get("case_sensitive") @@ -1254,3 +1271,9 @@ def adjust_query_for_container(query): for filter in new_or_filters: or_filters.append(filter) + +def get_data_sources(): + data_sources=[] + for data_source in search_omero_app.config.database_connectors.keys(): + data_sources.append(data_source) + return data_sources