diff --git a/omero_search_engine/api/v1/resources/resource_analyser.py b/omero_search_engine/api/v1/resources/resource_analyser.py index 58f298b..bf62305 100644 --- a/omero_search_engine/api/v1/resources/resource_analyser.py +++ b/omero_search_engine/api/v1/resources/resource_analyser.py @@ -1051,3 +1051,23 @@ def get_resource_keys(resource, data_source): json.loads(resource_keys_template.substitute(data_source=data_source)), ) return res["aggregations"]["value_search"]["required_name"]["buckets"] + + +def get_containets_from_name(container_name=None, returned_data_source=None): + act_names =[]# {} + pr_names = get_resource_names("all") + for resourse, names_ in pr_names.items(): + if len(names_)>0: + print (names_.keys()) + + for data_source, names in names_.items(): + act_names.append( [ + {"id": name["id"], "name": name["name"], "data_source":data_source, "image count":name["no_images"], "type":resourse} + for name in names + if not container_name or(name.get("name") and container_name.lower() in name.get("name").lower()) and (not returned_data_source or returned_data_source==data_source) + ]) + return act_names + +def return_containes_images(): + data = get_containets_from_name() + return {"Error": None, "results": {"results":data}} diff --git a/omero_search_engine/api/v1/resources/swagger_docs/submitquery_returncontainers.yml b/omero_search_engine/api/v1/resources/swagger_docs/submitquery_returncontainers.yml index 5202ea9..8366447 100644 --- a/omero_search_engine/api/v1/resources/swagger_docs/submitquery_returncontainers.yml +++ b/omero_search_engine/api/v1/resources/swagger_docs/submitquery_returncontainers.yml @@ -2,6 +2,7 @@ A searchengine endpoint to accept complex query but it will return the container API endpoint to search the annotation (key/value pair), the main difference between this endpoint and searchannotation is this one can be used to search different resources and return the container (screen or project) which includes the images which satisfy the search conditions. The container can be used as a resource instead of a project or screen if the user is not sure about the container type. The query data has a similar format to the query for searchannotation. +If no query is provided, it will return all the available containers. Example: { @@ -60,7 +61,7 @@ parameters: required: false - name: data in: body - required: true + required: false #examples: - name: data_source in: query diff --git a/omero_search_engine/api/v1/resources/urls.py b/omero_search_engine/api/v1/resources/urls.py index f348382..55d96f9 100644 --- a/omero_search_engine/api/v1/resources/urls.py +++ b/omero_search_engine/api/v1/resources/urls.py @@ -34,6 +34,7 @@ get_resource_names, get_key_values_return_contents, query_cashed_bucket_part_value_keys, + return_containes_images, ) from omero_search_engine.api.v1.resources.utils import get_resource_annotation_table from omero_search_engine.api.v1.resources.query_handler import ( @@ -363,8 +364,10 @@ def submit_query_return_containers(): except Exception: query = None if not query: - return jsonify(build_error_message("No query is provided")) - adjust_query_for_container(query) + query={} + #return jsonify(build_error_message("No query is provided")) + if len(query)>0: + adjust_query_for_container(query) return_columns = request.args.get("return_columns") data_source = request.args.get("data_source") if data_source: @@ -374,18 +377,21 @@ def submit_query_return_containers(): return_columns = json.loads(return_columns.lower()) except Exception: return_columns = False - validation_results = query_validator(query) - if validation_results == "OK": - return jsonify( - determine_search_results_( + if len(query)>0: + validation_results = query_validator(query) + if validation_results == "OK": + return jsonify( + determine_search_results_( query, data_source=data_source, return_columns=return_columns, return_containers=True, ) ) + else: + return jsonify(build_error_message(validation_results)) else: - return jsonify(build_error_message(validation_results)) + return jsonify(return_containes_images()) @resources.route("/submitquery/", methods=["POST"])