def construct_insert_signinghub_session_query(signinghub_session,
                                              signinghub_session_uri):
    signinghub_token_uri = SIGNINGHUB_TOKEN_BASE_URI + generate_uuid()
    expiry_time = signinghub_session.last_successful_auth_time + signinghub_session.access_token_expiry_time
    query_template = Template("""
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX mu: <http://mu.semte.ch/vocabularies/core/>
PREFIX oauth-2.0: <http://kanselarij.vo.data.gift/vocabularies/oauth-2.0-session/>

INSERT DATA {
    GRAPH $session_graph {
        $signinghub_session a oauth-2.0:OauthSession ;
            oauth-2.0:hasEndpointURI $signinghub_token_endpoint ;
            oauth-2.0:hasTokenValue $token_uri .
        $token_uri a oauth-2.0:BearerToken ;
            dct:created $creation_time ;
            oauth-2.0:hasTokenValue $token_value ;
            oauth-2.0:hasExpirytime $expiry_time .
    }
}""")

    query_string = query_template.substitute(
        session_graph=sparql_escape_uri(SESSION_GRAPH),
        signinghub_session=sparql_escape_uri(signinghub_session_uri),
        signinghub_token_endpoint=sparql_escape_uri(SIGNINGHUB_OAUTH_TOKEN_EP),
        token_uri=sparql_escape_uri(signinghub_token_uri),
        creation_time=sparql_escape_datetime(
            signinghub_session.last_successful_auth_time.astimezone(TIMEZONE)),
        expiry_time=sparql_escape_datetime(expiry_time.astimezone(TIMEZONE)),
        token_value=sparql_escape_string(signinghub_session.access_token))
    return query_string
def construct_get_signinghub_session_query(mu_session_uri):
    # TODO: Model connection betheen Signinghub Session and user/account (now "ext:shSessionAccount").
    query_template = Template("""
PREFIX mu: <http://mu.semte.ch/vocabularies/core/>
PREFIX session: <http://mu.semte.ch/vocabularies/session/>
PREFIX ext: <http://mu.semte.ch/vocabularies/ext/>
PREFIX oauth-2.0: <http://kanselarij.vo.data.gift/vocabularies/oauth-2.0-session/>

SELECT (?signinghubSession AS ?uri) ?expiryTime ?token
WHERE {
    GRAPH $session_graph {
        $mu_session session:account ?account .
        ?signinghubSession ext:shSessionAccount ?account .
        ?signinghubSession oauth-2.0:hasEndpointURI $signinghub_token_endpoint ;
            oauth-2.0:hasTokenValue ?tokenUri.
        ?tokenUri oauth-2.0:hasTokenValue ?token ;
            oauth-2.0:hasExpirytime ?expiryTime .
        BIND($now as ?now)
        FILTER (?now < ?expiryTime)
    }
}
ORDER BY DESC(?expiryTime)
LIMIT 1
""")
    query_string = query_template.substitute(
        session_graph=sparql_escape_uri(SESSION_GRAPH),
        mu_session=sparql_escape_uri(mu_session_uri),
        signinghub_token_endpoint=sparql_escape_uri(SIGNINGHUB_OAUTH_TOKEN_EP),
        now=sparql_escape_datetime(datetime.now(tz=TIMEZONE)))
    return query_string
def construct_get_signinghub_machine_user_session_query():
    query_template = Template("""
PREFIX mu: <http://mu.semte.ch/vocabularies/core/>
PREFIX oauth-2.0: <http://kanselarij.vo.data.gift/vocabularies/oauth-2.0-session/>
PREFIX ext: <http://mu.semte.ch/vocabularies/ext/>

SELECT (?signinghubSession AS ?uri) ?expiryTime ?token
WHERE {
    GRAPH $session_graph {
        ?signinghubSession a ext:SigninghubSudoSession .
        ?signinghubSession oauth-2.0:hasEndpointURI $signinghub_token_endpoint ;
            oauth-2.0:hasTokenValue ?tokenUri.
        ?tokenUri oauth-2.0:hasTokenValue ?token ;
            oauth-2.0:hasExpirytime ?expiryTime .
        BIND($now as ?now)
        FILTER (?now < ?expiryTime)
    }
}
ORDER BY DESC(?expiryTime)
LIMIT 1
""")
    query_string = query_template.substitute(
        session_graph=sparql_escape_uri(SESSION_GRAPH),
        signinghub_token_endpoint=sparql_escape_uri(SIGNINGHUB_OAUTH_TOKEN_EP),
        now=sparql_escape_datetime(datetime.now(tz=TIMEZONE)))
    return query_string
def construct_insert_document(document_name,
                              file_uri,
                              graph=APPLICATION_GRAPH):
    document = {"name": document_name, "created": datetime.now(TIMEZONE)}
    document["uuid"] = generate_uuid()
    document["uri"] = DOCUMENT_BASE_URI + document["uuid"]
    query_template = Template("""
PREFIX dossier: <https://data.vlaanderen.be/ns/dossier#>
PREFIX mu: <http://mu.semte.ch/vocabularies/core/>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX nfo: <http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#>
PREFIX ext: <http://mu.semte.ch/vocabularies/ext/>

INSERT {
    GRAPH $graph {
        $document a dossier:Stuk ;
            mu:uuid $uuid ;
            dct:title $name ;
            dct:created $created ;
            ext:file $file .
    }
}
WHERE {
    GRAPH $graph {
        $file a nfo:FileDataObject .
    }
}
""")
    return query_template.substitute(
        graph=sparql_escape_uri(graph),
        document=sparql_escape_uri(document["uri"]),
        uuid=sparql_escape_string(document["uuid"]),
        name=sparql_escape_string(document["name"]),
        created=sparql_escape_datetime(document["created"]),
        file=sparql_escape_uri(file_uri))
Пример #5
0
def construct_get_mandatee_by_email(mandatee_email, graph=APPLICATION_GRAPH):
    mail_uri = "mailto:{}".format(mandatee_email)
    maximal_end_date = datetime.now().replace(hour=0,
                                              minute=0,
                                              second=0,
                                              microsecond=0)  # Today
    # Sometimes a mandatee needs to sign some last docs a couple of days after the end of the mandate
    maximal_end_date = maximal_end_date - timedelta(days=30)
    query_template = Template("""
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX mandaat: <http://data.vlaanderen.be/ns/mandaat#>

SELECT ?mandatee
WHERE {
    GRAPH $graph {
        ?mandatee a mandaat:Mandataris ;
            mandaat:isBestuurlijkeAliasVan ?person ;
            mandaat:einde ?end_date ;
            mandaat:start ?start_date .
        ?person foaf:mbox $mail_uri .
        FILTER(?start_date < NOW())
        FILTER(?end_date > $end_date)
    }
}
ORDER BY DESC(?end_date)
""")
    return query_template.substitute(
        graph=sparql_escape_uri(graph),
        mail_uri=sparql_escape_uri(mail_uri),
        end_date=sparql_escape_datetime(maximal_end_date))
Пример #6
0
def __register_start_signing_flow(signflow_uri: str):
    timestamp = datetime.now()
    update_activities_command = __update_activities_template.substitute(
        graph=sparql_escape_uri(APPLICATION_GRAPH),
        signflow=sparql_escape_uri(signflow_uri),
        start_date=sparql_escape_datetime(timestamp))
    update(update_activities_command)
Пример #7
0
def construct_insert_file_query(file, physical_file, graph=APPLICATION_GRAPH):
    """
    Construct a SPARQL query for inserting a file.
    :param file: dict containing properties for file
    :param share_uri: 
    :returns: string containing SPARQL query
    """
    query_template = Template("""
PREFIX mu: <http://mu.semte.ch/vocabularies/core/>
PREFIX nfo: <http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#>
PREFIX nie: <http://www.semanticdesktop.org/ontologies/2007/01/19/nie#>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX dbpedia: <http://dbpedia.org/ontology/>

INSERT DATA {
    GRAPH $graph {
        $uri a nfo:FileDataObject ;
            mu:uuid $uuid ;
            nfo:fileName $name ;
            dct:format $mimetype ;
            dct:created $created ;
            nfo:fileSize $size ;
            dbpedia:fileExtension $extension .
        $physical_uri a nfo:FileDataObject ;
            mu:uuid $physical_uuid ;
            nfo:fileName $physical_name ;
            dct:format $mimetype ;
            dct:created $created ;
            nfo:fileSize $size ;
            dbpedia:fileExtension $extension ;
            nie:dataSource $uri .
    }
}
""")
    return query_template.substitute(
        graph=sparql_escape_uri(graph),
        uri=sparql_escape_uri(file["uri"]),
        uuid=sparql_escape_string(file["uuid"]),
        name=sparql_escape_string(file["name"]),
        mimetype=sparql_escape_string(file["mimetype"]),
        created=sparql_escape_datetime(file["created"]),
        size=sparql_escape_int(file["size"]),
        extension=sparql_escape_string(file["extension"]),
        physical_uri=sparql_escape_uri(physical_file["uri"]),
        physical_uuid=sparql_escape_string(physical_file["uuid"]),
        physical_name=sparql_escape_string(physical_file["name"]))
def construct_mark_signinghub_session_as_machine_users_query(
        signinghub_session_uri):
    # TODO: this is a hacky way of marking the machine user session.
    # Should think about way to model the service as an agent (with a mu session?)
    query_template = Template("""
PREFIX ext: <http://mu.semte.ch/vocabularies/ext/>
PREFIX oauth-2.0: <http://kanselarij.vo.data.gift/vocabularies/oauth-2.0-session/>

INSERT {
    GRAPH $session_graph {
        $signinghub_session a ext:SigninghubSudoSession .
    }
}
WHERE {
    GRAPH $session_graph {
        $signinghub_session a oauth-2.0:OauthSession .
    }
}
""")
    query_string = query_template.substitute(
        session_graph=sparql_escape_uri(SESSION_GRAPH),
        signinghub_session=sparql_escape_uri(signinghub_session_uri),
        now=sparql_escape_datetime(datetime.now(tz=TIMEZONE)))
    return query_string