Exemple #1
0
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 delete_resource(**kwargs):
    resource_uri = build_instance_uri(kwargs["id"])
    try:
        username = kwargs["user"]
    except Exception:
        logger.error("Missing username", exc_info=True)
        return "Bad request: missing username", 400, {}

    request_args: Dict[str, str] = {
        "resource": resource_uri,
        "g": generate_graph(username)
    }
    return query_manager.delete_query(ENDPOINT, request_args=request_args)
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, {}