Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Permits external applications to add or remove specific triples from the VIVO data model. These changes use the standard data channels in VIVO, so the search index will be updated as appropriate, and the reasoner will add or remove inferences as needed.

Note

By default, the SPARQL Update API is disabled in VIVO, for security reasons. See Enabling the API.

 

Use Cases

Harvester

Previous implementations of the Harvester and similar tools have written directly to the VIVO triple-store, bypassing the usual data channels in VIVO. After ingesting, it was necessary to rebuild the search index, and to run the reasoner to add or remove inferences. Since the search index and the reasoner were not aware of the exact changes, the entire data model was re-indexed and re-inferenced.

...

CodeReason
200 OKSPARQL Update was successful.
400 Bad RequestIncorrect HTTP method; only POST is accepted.
HTTP request did not include an update parameter.
SPARQL Update request did not specify a GRAPH on which to operate.
SPARQL Update request was syntactically incorrect.
403 ForbiddenHTTP request did not include an email parameter.
HTTP request did not include a password parameter.
The combination of email and password is not valid.
The selected VIVO account is not authorized to use the SPARQL Update API.
500 Internal Server ErrorVIVO could not execute the request; internal code threw an exception.

Examples

This example, written in Python, shows some INSERT and DELETE operations These examples use the UNIX curl command to insert and delete data using the API. (Thanks to Ted Lawless of Brown University)

py
Code Block
languagebash
 

 

...

Enabling the API

Note

Before enabling the SPARQL update handler, you should secure the URL api/sparqlUpdate with HTTPS. Otherwise, email/password combinations will be sent across the network without encryption. Methods for securing the URL will depend on your site's configuration.

By default, the SPARQL Update handler is disabled in VIVO. To enable it, you must create an RDF file in the [vivo]/rdf/auth/everytime directory that will authorize your site administrators to use the API. Here is an example of such a filem using N3 syntax:

Code Block
titleauthorizeSparqlUpdate.n3
@prefix auth: <http://
true
"""
Examples of using the Vitro SPARQL update in development.
https://jira.duraspace.org/browse/VIVO-101
 
http://www.w3.org/Submission/SPARQL-Update/
"""
 
from SPARQLWrapper import SPARQLWrapper
 
import time
 
email = 'email@school.edu'
password = 'password'
endpoint = 'http://localhost:8080/vitro/sparql/'
 
 
def do_update(query):
    params = {
        'email': email,
        'password': password,
        'update': query
    }
    sparql = SPARQLWrapper(endpoint)
    sparql.customParameters = params
    sparql.method = 'GET'
    results = sparql.query()
    #print out the query url
    print results.response.geturl()
 
 
#insert some data.
q = """
PREFIX rdfs:  <http://www.w3.org/2000/01/rdf-schema#>
INSERT DATA INTO <http://vitro.mannlib.cornell.edu/defaultns/vitro-kb-2>
{ <http://vivo.school.edu/individual/n1234> rdfs:label "New Title" . }
"""
do_update(q)
 
#for testing purposes only - delay to check data in web app
time.sleep(5)
 
#modify it
q = """
PREFIX rdfs:  <http://www.w3.org/2000/01/rdf-schema#>
PREFIX bibo: <http://purl.org/ontology/bibo/>
DELETE DATA FROM <http://vitro.mannlib.cornell.edu/default/vitro-kb-2>
{ <http://vivo.school.edu/individual/n1234> rdfs:label "New Title" . }
INSERT DATA INTO <http://vitro.mannlib.cornell.edu/default/vitro-kb-2>
{ <http://vivo.school.edu/individual/n1234> rdfs:label "Second Title" . }
"""
do_update(q)
 
time.sleep(5)
 
#delete it
q = """
PREFIX rdfs:  <http://www.w3.org/2000/01/rdf-schema#>
DELETE DATA FROM <http://vitro.mannlib.cornell.edu/default/vitro-kb-2>
{ <http://vivo.school.edu/individual/n1234> rdfs:label "Second Title" . }
"""
do_update(q)

 

Enabling the API

Security

Authentication

...

/authorization#> .
@prefix simplePermission: <java:edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission#> .
 
# Authorize the ADMIN role to use the SPARQL Update API
auth:ADMIN auth:hasPermission simplePermission:UseSparqlUpdateApi .