def get_es_data(): """ :return: the json response with the data from elasticsearch """ form_data = request.form index_name = sanitise_parameter(form_data.get('index_name')) raw_es_query = sanitise_parameter(form_data.get('es_query')) raw_context = sanitise_parameter(form_data.get('context_obj')) raw_contextual_sort_data = sanitise_parameter( form_data.get('contextual_sort_data')) app_logging.debug(f'index_name: {index_name}') app_logging.debug(f'raw_es_query: {raw_es_query}') app_logging.debug(f'raw_context: {raw_context}') app_logging.debug(f'raw_contextual_sort_data: {raw_contextual_sort_data}') try: json_response = es_proxy_service.get_es_data(index_name, raw_es_query, raw_context, raw_contextual_sort_data) http_response = jsonify(json_response) http_cache_utils.add_cache_headers_to_response(http_response) return http_response except es_proxy_service.ESProxyServiceError as error: abort(500, msg=f'Internal server error: {str(error)}')
def get_es_doc(index_name, doc_id): """ :param index_name: name of the index to which the doc belongs :param doc_id: id of the document to search for :return: the json response with the es_doc data """ try: json_response = es_proxy_service.get_es_doc(index_name, doc_id) http_response = jsonify(json_response) http_cache_utils.add_cache_headers_to_response(http_response) return http_response except es_proxy_service.ESProxyServiceError as error: abort(500, msg=f'Internal server error: {str(error)}') except es_proxy_service.ESDataNotFoundError as error: abort(404)
def shorten_url(): """ :return: the json response with the shortened url """ form_data = request.form long_url = form_data.get('long_url') try: shortening_data = url_shortening_service.shorten_url(long_url) http_response = jsonify(shortening_data) http_cache_utils.add_cache_headers_to_response(http_response) return http_response except url_shortening_service.URLShorteningError as error: abort(500, repr(error))
def get_index_id_properties(index_name): """ :param index_name: name of the index for which to get the id properties :return: the response for requests asking for facet group configurations """ try: id_properties = properties_config_service.get_index_properties_of_index( index_name) http_response = jsonify(id_properties) http_cache_utils.add_cache_headers_to_response(http_response) return http_response except properties_config_service.PropertiesConfigServiceError as error: abort(500, repr(error))
def get_all_configured_properties_for_index(index_name): """ :param index_name: name of the index for which to get the all the properties config :return: the json response with the all properties configuration """ try: all_properties_configured = properties_config_service.get_all_configured_properties_for_index( index_name) http_response = jsonify(all_properties_configured) http_cache_utils.add_cache_headers_to_response(http_response) return http_response except properties_config_service.PropertiesConfigServiceError as error: abort(500, repr(error))
def get_facet_group_config(index_name, group_name): """ :param index_name: name of the index to which the facet group belongs :param group_name: name of the group to check :return: the response for requests asking for facet group configurations """ try: facet_group_config = properties_config_service.get_facets_group_config( index_name, group_name) http_response = jsonify(facet_group_config) http_cache_utils.add_cache_headers_to_response(http_response) return http_response except properties_config_service.PropertiesConfigServiceError as error: abort(500, repr(error))
def get_property_config(index_name, property_id): """ :param index_name: name of the index to which the property belongs :param property_id: id of the property to check :return: the response for requests asking for property configurations """ try: properties_config = properties_config_service.get_property_config( index_name, property_id) http_response = jsonify(properties_config) http_cache_utils.add_cache_headers_to_response(http_response) return http_response except properties_config_service.PropertiesConfigServiceError as error: abort(500, repr(error))
def parse_free_text_search(): """ :return: the json response with the query to use in elasticsearch """ form_data = request.form search_term = form_data.get('search_term') es_indexes = form_data.get('es_indexes') selected_es_index = form_data.get('selected_es_index') try: raw_response = search_parsing_service.parse_search( search_term, es_indexes, selected_es_index) http_response = jsonify(raw_response) http_cache_utils.add_cache_headers_to_response(http_response) return http_response except search_parsing_service.SearchParsingServiceError as error: abort(500, repr(error))
def get_context_data(): """ :return: the json response with the context data """ form_data = request.form context_type = form_data.get('context_type') context_id = form_data.get('context_id') delayed_jobs_base_url = form_data.get('delayed_jobs_base_url') context_dict = { 'context_type': context_type, 'context_id': context_id, 'delayed_jobs_base_url': delayed_jobs_base_url } try: context_data = contexts_service.get_context_data(context_dict) http_response = jsonify(context_data) http_cache_utils.add_cache_headers_to_response(http_response) return http_response except contexts_service.ContextError as error: abort(500, repr(error))