From bf4b7dd8b7283b7c73bf64c687a70d1f77c9524b Mon Sep 17 00:00:00 2001 From: khaledk2 Date: Tue, 26 Nov 2024 17:52:39 +0000 Subject: [PATCH] allow using query with sub containers endpoint and add swagger documents for the new url --- .../api/v1/resources/resource_analyser.py | 12 ++----- .../swagger_docs/container_images.yml | 10 ++++++ .../swagger_docs/sub_container_images.yml | 25 +++++++++++++++ omero_search_engine/api/v1/resources/urls.py | 31 +++++++++++++++++-- 4 files changed, 67 insertions(+), 11 deletions(-) create mode 100644 omero_search_engine/api/v1/resources/swagger_docs/container_images.yml create mode 100644 omero_search_engine/api/v1/resources/swagger_docs/sub_container_images.yml diff --git a/omero_search_engine/api/v1/resources/resource_analyser.py b/omero_search_engine/api/v1/resources/resource_analyser.py index e3b250e..2c01786 100644 --- a/omero_search_engine/api/v1/resources/resource_analyser.py +++ b/omero_search_engine/api/v1/resources/resource_analyser.py @@ -934,7 +934,6 @@ def process_container_query( {"terms": {"field": "key_values.value.keyvalue","size": 10000}}}}}}}""" ) - """ Get all the keys bucket""" container_project_keys_template = { @@ -1005,13 +1004,10 @@ def process_container_query( def get_containers_no_images( - contianer, container_name, sub_container=None, query_details=None + contianer, container_name, query_details=None ): containers_subcontainers = {"project": "dataset", "screen": "plate"} - if not sub_container: - if not containers_subcontainers.get(contianer.lower()): - return "No sub container is found, please check the container type" - sub_container = containers_subcontainers[contianer] + sub_container = containers_subcontainers[contianer] res_index = resource_elasticsearchindex.get("image") aggs_part = container_returned_sub_container_template.substitute( container_attribute_name="%s_name.keyvalue" % contianer, @@ -1024,7 +1020,7 @@ def get_containers_no_images( and_filters = query_details.get("and_filters") or_filters = query_details.get("or_filters") case_sensitive = query_details.get("case_sensitive") - main_attributes = query.get("main_attributes") + main_attributes = query_details.get("main_attributes") from omero_search_engine.api.v1.resources.utils import ( elasticsearch_query_builder, ) @@ -1038,8 +1034,6 @@ def get_containers_no_images( query["aggs"] = json.loads(aggs_part) res = search_index_for_value(res_index, query) buckets = res["aggregations"]["values"]["uniquesTerms"]["buckets"] - print(len(buckets)) - print(buckets[0]) returned_results = [] for bucket in buckets: returned_results.append( diff --git a/omero_search_engine/api/v1/resources/swagger_docs/container_images.yml b/omero_search_engine/api/v1/resources/swagger_docs/container_images.yml new file mode 100644 index 0000000..2ead8c6 --- /dev/null +++ b/omero_search_engine/api/v1/resources/swagger_docs/container_images.yml @@ -0,0 +1,10 @@ +A searchengine endpoint to Return the available containers and the number of images in each. +--- +tags: + - Containers and the number of images in each. + +responses: + 200: + description: A JSON contains the search results + examples: + results: [] diff --git a/omero_search_engine/api/v1/resources/swagger_docs/sub_container_images.yml b/omero_search_engine/api/v1/resources/swagger_docs/sub_container_images.yml new file mode 100644 index 0000000..2d6c18e --- /dev/null +++ b/omero_search_engine/api/v1/resources/swagger_docs/sub_container_images.yml @@ -0,0 +1,25 @@ +A searchengine endpoint to return the available sub-container in a container (e.g. dataset in project) +A query can be provided to return only the search results +--- +tags: + - Available sub-containers inside a container +parameters: + - name: container + in: query + type: string + enum: ['project', 'screen'] + required: true + - name: container_name + description: The container name + in: query + type: string + required: true + - name: data + in: body + required: false + +responses: + 200: + description: A JSON contains the search results + examples: + results: [] diff --git a/omero_search_engine/api/v1/resources/urls.py b/omero_search_engine/api/v1/resources/urls.py index e955cb7..4fc7295 100644 --- a/omero_search_engine/api/v1/resources/urls.py +++ b/omero_search_engine/api/v1/resources/urls.py @@ -468,6 +468,9 @@ def container_keys_search(resource_table): @resources.route("/container_images/", methods=["GET"]) def container_images(): + """ + file: swagger_docs/container_images.yml + """ from omero_search_engine.api.v1.resources.resource_analyser import ( return_containes_images, ) @@ -476,12 +479,36 @@ def container_images(): # to do: add query to return the results withiz the sub-container -@resources.route("/sub_container_images/", methods=["GET"]) +@resources.route("/sub_container_images/", methods=["POST","GET"]) def sub_container_images(): + """ + file: swagger_docs/sub_container_images.yml + """ from omero_search_engine.api.v1.resources.resource_analyser import ( get_containers_no_images, ) container = request.args.get("container") container_name = request.args.get("container_name") - return get_containers_no_images(container, container_name) + if not container_name or not container: + return jsonify( + build_error_message( + "{error}".format(error="container and container name are required.") + ) + ) + data = request.data + query={} + if data: + try: + data = json.loads(data) + except Exception: + return jsonify( + build_error_message( + "{error}".format(error="No proper query data is provided.") + ) + ) + + if "query_details" in data: + query = data["query_details "] + + return get_containers_no_images(container, container_name, query)