def post_resource(**kwargs): """ Post a resource and generate the id :param kwargs: :type kwargs: :return: :rtype: """ body = kwargs["body"] rdf_type_uri = kwargs["rdf_type_uri"] if body.type and rdf_type_uri is not body.type: body.type.append(rdf_type_uri) else: body.type = [rdf_type_uri] body.id = generate_new_uri() try: username = kwargs["user"] except Exception: logger.error("Missing username", exc_info=True) return "Bad request: missing username", 400, {} body_json = prepare_jsonld(body) prefixes, triples = get_insert_query(body_json) prefixes = '\n'.join(prefixes) triples = '\n'.join(triples) request_args: Dict[str, str] = { "prefixes": prefixes, "triples": triples, "g": generate_graph(username) } if query_manager.insert_query(ENDPOINT, request_args=request_args): return body, 201, {} else: return "Error inserting query", 407, {}
def insert_all_resources(body, username): body_json = prepare_jsonld(body) prefixes, triples = get_insert_query(body_json) prefixes = '\n'.join(prefixes) triples = '\n'.join(triples) request_args: Dict[str, str] = { "prefixes": prefixes, "triples": triples, "g": generate_graph(username) } insert_response = query_manager.insert_query(UPDATE_ENDPOINT, request_args=request_args) return insert_response
def put_resource(**kwargs): resource_uri = build_instance_uri(kwargs["id"]) body = kwargs["body"] body.id = resource_uri try: username = kwargs["user"] except Exception: logger.error("Missing username", exc_info=True) return "Bad request: missing username", 400, {} ''' DELETE QUERY Since we are updating the resource, we don't want to delete the incoming_relations ''' request_args_delete: Dict[str, str] = { "resource": resource_uri, "g": generate_graph(username), "delete_incoming_relations": False } try: query_manager.delete_query(UPDATE_ENDPOINT, request_args=request_args_delete) except: logger.error("Exception occurred", exc_info=True) return "Error deleting query", 407, {} #INSERT QUERY body_json = prepare_jsonld(body) prefixes, triples = get_insert_query(body_json) prefixes = '\n'.join(prefixes) triples = '\n'.join(triples) request_args: Dict[str, str] = { "prefixes": prefixes, "triples": triples, "g": generate_graph(username) } if query_manager.insert_query(UPDATE_ENDPOINT, request_args=request_args): return body, 201, {} else: return "Error inserting query", 407, {}
def put_resource(**kwargs): resource_uri = build_instance_uri(kwargs["id"]) body = kwargs["body"] body.id = resource_uri try: username = kwargs["user"] except Exception: logger.error("Missing username", exc_info=True) return "Bad request: missing username", 400, {} #DELETE QUERY request_args_delete: Dict[str, str] = { "resource": resource_uri, "g": generate_graph(username) } try: query_manager.delete_query(ENDPOINT, request_args=request_args_delete) except: return "Error deleting query", 407, {} #INSERT QUERY body_json = prepare_jsonld(body) prefixes, triples = get_insert_query(body_json) prefixes = '\n'.join(prefixes) triples = '\n'.join(triples) request_args: Dict[str, str] = { "prefixes": prefixes, "triples": triples, "g": generate_graph(username) } if query_manager.insert_query(ENDPOINT, request_args=request_args): return body, 201, {} else: return "Error inserting query", 407, {}