def template_query(): """Template a query from a result Returns ------- json error: True if error, else False errorMessage: the error message of error, else an empty string """ try: json = request.get_json() result_info = {"id": json["id"]} result = Result(current_app, session, result_info) result.template_query(json["template"]) results_handler = ResultsHandler(current_app, session) files = results_handler.get_files_info() except Exception as e: traceback.print_exc(file=sys.stdout) return jsonify({ 'files': [], 'error': True, 'errorMessage': 'Failed to publish query: \n{}'.format(str(e)) }), 500 return jsonify({'files': files, 'error': False, 'errorMessage': ''})
def delete_result(): """Summary Returns ------- json files: list of all files of current user error: True if error, else False errorMessage: the error message of error, else an empty string """ try: files_id = request.get_json()["filesIdToDelete"] results_handler = ResultsHandler(current_app, session) remaining_files = results_handler.delete_results(files_id) except Exception as e: traceback.print_exc(file=sys.stdout) return jsonify({ 'remainingFiles': {}, 'error': True, 'errorMessage': str(e) }), 500 return jsonify({ 'remainingFiles': remaining_files, 'error': False, 'errorMessage': '' })
def set_description(): """Update a result description Returns ------- json files: all files error: True if error, else False errorMessage: the error message of error, else an empty string """ try: json = request.get_json() result_info = {"id": json["id"]} new_desc = json["newDesc"] result = Result(current_app, session, result_info) result.update_description(new_desc) results_handler = ResultsHandler(current_app, session) files = results_handler.get_files_info() except Exception as e: traceback.print_exc(file=sys.stdout) return jsonify({ 'files': [], 'error': True, 'errorMessage': str(e) }), 500 return jsonify({'files': files, 'error': False, 'errorMessage': ''})
def togle_public_query(): """Publish a query template from a result Returns ------- json error: True if error, else False errorMessage: the error message of error, else an empty string """ try: json = request.get_json() result_info = {"id": json["queryId"]} result = Result(current_app, session, result_info) result.publish_query(json["newStatus"], admin=True) results_handler = ResultsHandler(current_app, session) public_queries = results_handler.get_admin_public_queries() except Exception as e: traceback.print_exc(file=sys.stdout) return jsonify({ 'queries': [], 'error': True, 'errorMessage': 'Failed to publish query: \n{}'.format(str(e)) }), 500 return jsonify({ 'queries': public_queries, 'error': False, 'errorMessage': '' })
def get_results(): """Get ... Returns ------- json files: list of all files of current user error: True if error, else False errorMessage: the error message of error, else an empty string """ try: results_handler = ResultsHandler(current_app, session) files = results_handler.get_files_info() triplestore_max_rows = None try: triplestore_max_rows = current_app.iniconfig.getint( "triplestore", "result_set_max_rows") except Exception: pass except Exception as e: traceback.print_exc(file=sys.stdout) return jsonify({ 'files': [], 'triplestoreMaxRows': triplestore_max_rows, 'error': True, 'errorMessage': str(e) }), 500 return jsonify({ 'files': files, 'triplestoreMaxRows': triplestore_max_rows, 'error': False, 'errorMessage': '' })
def get_queries(): """Get all public queries Returns ------- json startpoint: list of public queries error: True if error, else False errorMessage: the error message of error, else an empty string """ try: results_handler = ResultsHandler(current_app, session) public_queries = results_handler.get_admin_public_queries() except Exception as e: traceback.print_exc(file=sys.stdout) return jsonify({ "queries": [], 'error': True, 'errorMessage': str(e) }), 500 return jsonify({ "queries": public_queries, 'error': False, 'errorMessage': '' })
def query(): """Get start points Returns ------- json startpoint: list of start points error: True if error, else False errorMessage: the error message of error, else an empty string """ try: tse = TriplestoreExplorer(current_app, session) results_handler = ResultsHandler(current_app, session) startpoints = tse.get_startpoints() public_queries = results_handler.get_public_queries() except Exception as e: traceback.print_exc(file=sys.stdout) return jsonify({ 'startpoints': [], "publicQueries": [], 'error': True, 'errorMessage': str(e) }), 500 return jsonify({ 'startpoints': startpoints, "publicQueries": public_queries, 'error': False, 'errorMessage': '' })
def form_query(): """Create a form from a result Returns ------- json error: True if error, else False errorMessage: the error message of error, else an empty string """ try: data = request.get_json() if not (data and data.get("id")): return jsonify({ 'files': [], 'error': True, 'errorMessage': "Missing id parameter" }), 400 result_info = {"id": data["id"]} result = Result(current_app, session, result_info) if not result: return jsonify({ 'files': [], 'error': True, 'errorMessage': 'Failed to publish query: \n{}'.format( "You do not have access to this query") }), 401 result.form_query(data.get("form", False)) results_handler = ResultsHandler(current_app, session) files = results_handler.get_files_info() except Exception as e: traceback.print_exc(file=sys.stdout) return jsonify({ 'files': [], 'error': True, 'errorMessage': 'Failed to create form template query: \n{}'.format(str(e)) }), 500 return jsonify({'files': files, 'error': False, 'errorMessage': ''})
def set_description(): """Update a result description Returns ------- json files: all files error: True if error, else False errorMessage: the error message of error, else an empty string """ try: data = request.get_json() if not (data and data.get("id") and data.get("newDesc")): return jsonify({ 'files': [], 'error': True, 'errorMessage': "Missing parameters" }), 400 result_info = {"id": data["id"]} new_desc = data["newDesc"] result = Result(current_app, session, result_info) if not result: return jsonify({ 'files': [], 'error': True, 'errorMessage': "You do not have access to this result" }), 500 result.update_description(new_desc) results_handler = ResultsHandler(current_app, session) files = results_handler.get_files_info() except Exception as e: traceback.print_exc(file=sys.stdout) return jsonify({ 'files': [], 'error': True, 'errorMessage': str(e) }), 500 return jsonify({'files': files, 'error': False, 'errorMessage': ''})
def query(): """Get start points Returns ------- json startpoint: list of start points error: True if error, else False errorMessage: the error message of error, else an empty string """ try: # If public datasets and queries are protected, dont return anything to unlogged users if "user" not in session and current_app.iniconfig.getboolean("askomics", "protect_public"): startpoints = [] public_queries = [] public_form_queries = [] else: tse = TriplestoreExplorer(current_app, session) results_handler = ResultsHandler(current_app, session) startpoints = tse.get_startpoints() public_queries = results_handler.get_public_queries() public_form_queries = results_handler.get_public_form_queries() except Exception as e: traceback.print_exc(file=sys.stdout) return jsonify({ 'startpoints': [], "publicQueries": [], "publicFormQueries": [], 'error': True, 'errorMessage': str(e) }), 500 return jsonify({ 'startpoints': startpoints, "publicQueries": public_queries, "publicFormQueries": public_form_queries, 'error': False, 'errorMessage': '' })