Commit 2721b2a0 authored by David Mendez's avatar David Mendez
Browse files

Merge branch 'staging' into 'master'

EUbOPEN: add properties configuration for probe profile

See merge request !86
parents 4693bc5e a7f50b84
......@@ -63,7 +63,8 @@ def get_es_doc(index_name, doc_id):
"""
try:
source = request.args.get('source')
json_response = es_proxy_service.get_es_doc(index_name, doc_id, source)
custom_id_property = request.args.get('custom_id_property')
json_response = es_proxy_service.get_es_doc(index_name, doc_id, source, custom_id_property)
http_response = jsonify(json_response)
http_cache_utils.add_cache_headers_to_response(http_response)
return http_response
......
......@@ -23,3 +23,4 @@ class ESProxyDoc(CommonSchema):
index_name = fields.String(required=True)
doc_id = fields.String(required=True)
source = fields.String()
custom_id_property = fields.String()
......@@ -62,16 +62,36 @@ def get_es_data(index_name, raw_es_query, raw_context, raw_contextual_sort_data,
return response
def get_es_doc(index_name, doc_id, source=None):
def get_es_doc(index_name, doc_id, source=None, custom_id_property=None):
"""
:param index_name: name of the index to which the doc belongs
:param doc_id: id of the document to search for
:param source: list of properties to get
:param custom_id_property: custom id property to use instead of _id
:return: the json response from elasticsearch of the document
"""
try:
response = es_data.get_es_doc(index_name, doc_id, source)
item_id = doc_id
use_custom_id_property = custom_id_property is not None
if use_custom_id_property:
es_query = {
"_source": source,
"query": {
"terms": {
custom_id_property: [
doc_id
]
}
}
}
search_response = es_data.get_es_response(index_name, es_query)
hits = search_response.get('hits', {}).get('hits', [])
if len(hits) == 0:
raise ESDataNotFoundError(f'No item found in index {index_name} with {custom_id_property} == {doc_id}')
item_id = hits[0]['_id']
response = es_data.get_es_doc(index_name, item_id, source)
return response
except es_data.ESDataNotFoundError as error:
raise ESDataNotFoundError(str(error))
......
......@@ -113,7 +113,7 @@ def get_es_doc(index_name, doc_id, source=None):
"""
properties_list = [] if source is None else source.split(',')
using_source = source is not None
cache_key = f'document-{index_name}-{doc_id}-{",".join(properties_list)}-{RUN_CONFIG.get("cache_key_suffix")}'
cache_key = f'document-{index_name}-{doc_id}-source:{",".join(properties_list)}-{RUN_CONFIG.get("cache_key_suffix")}'
app_logging.debug(f'cache_key: {cache_key}')
equivalent_query = {
......
......@@ -462,6 +462,9 @@ chembl_eubopen_target:
'molecule_properties.full_mwt':
label: 'Molecular Weight'
label_mini: 'Mol. Wt.'
chembl_eubopen_activity:
'_metadata.target_data.target_type':
label: 'Target Type'
......@@ -99,6 +99,12 @@ paths:
required: false
type: 'string'
default: 'molecule_chembl_id,pref_name'
- name: "custom_id_property"
in: "query"
description: "By default the doc_id will match with the _id field,
but you can pass another field here if you prefer"
type: 'string'
default: 'target_chembl_id'
responses:
'200':
description: "success"
......
......@@ -7,7 +7,8 @@ import argparse
from specific_tests import fun_test_simple_query, fun_test_query_with_context, \
fun_test_query_with_search_by_ids_context, fun_test_property_config, \
fun_test_group_config, fun_test_facets_group_config, fun_test_get_document, fun_test_id_properties, \
fun_test_group_config, fun_test_facets_group_config, fun_test_get_document, fun_test_get_document_by_custom_id_prop, \
fun_test_id_properties, \
fun_test_get_context_data, fun_test_search_parsing, fun_test_url_shortening, fun_test_element_usage, \
fun_test_go_slim_target_classification, fun_test_in_vivo_assay_classification, \
fun_test_organism_taxonomy_target_classification, fun_test_protein_target_classification, \
......@@ -34,6 +35,7 @@ def run():
for test_module in [fun_test_simple_query, fun_test_query_with_context,
fun_test_query_with_search_by_ids_context, fun_test_property_config,
fun_test_group_config, fun_test_facets_group_config, fun_test_get_document,
fun_test_get_document_by_custom_id_prop,
fun_test_id_properties,
fun_test_get_context_data, fun_test_search_parsing, fun_test_url_shortening,
fun_test_element_usage,
......
# pylint: disable=import-error,unused-argument
"""
Module that tests a group config
"""
from specific_tests import utils
def run_test(server_base_url, delayed_jobs_server_base_path):
"""
Tests getting the configuration of a group
:param server_base_url: base url of the running server. E.g. http://127.0.0.1:5000
:param delayed_jobs_server_base_path: base path for the delayed_jobs
"""
print('-------------------------------------------')
print('Testing getting a document by id')
print('-------------------------------------------')
url = f'{server_base_url}/es_data/get_es_document/chembl_eubopen_target/CHEMBL4524126'
params = {
'source': 'pref_name',
'custom_id_property': 'target_chembl_id'
}
utils.assert_get_request_succeeds(url, params)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment