-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb.rb
72 lines (60 loc) · 1.32 KB
/
web.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
CHECK_AUTHORIZATION_QUERY = <<QUERY
PREFIX mu: <http://mu.semte.ch/vocabularies/core/>
PREFIX esco: <http://data.europa.eu/esco/model#>
ASK
FROM <#{settings.graph}>
{
?x mu:uuid %uuid% ;
a esco:Graph ;
esco:status esco:Validated .
}
QUERY
UPDATE_METADATA_QUERY = <<QUERY
PREFIX mu: <http://mu.semte.ch/vocabularies/core/>
PREFIX esco: <http://data.europa.eu/esco/model#>
WITH <#{settings.graph}>
DELETE
{
?x esco:status ?previous .
}
INSERT
{
?x esco:status esco:Imported .
}
WHERE
{
?x mu:uuid %uuid% ;
a esco:Graph ;
esco:status ?previous .
}
QUERY
FIND_GRAPH_QUERY = <<QUERY
PREFIX mu: <http://mu.semte.ch/vocabularies/core/>
PREFIX esco: <http://data.europa.eu/esco/model#>
SELECT ?graph
FROM <#{settings.graph}>
WHERE
{
?x mu:uuid %uuid% ;
a esco:Graph ;
esco:graph ?graph .
}
QUERY
get "/move" do
uuid = params[:uuid]
if uuid.nil?
status 400
body "Argument uuid is required"
return
end
if !query(CHECK_AUTHORIZATION_QUERY.gsub("%uuid%", uuid.sparql_escape))
status 403
body "Unable to comply"
return
end
graph_uri = query(FIND_GRAPH_QUERY.gsub("%uuid%", uuid.sparql_escape)).first["graph"]
update("ADD GRAPH <#{graph_uri}> TO <#{settings.graph}>")
update("CLEAR GRAPH <#{graph_uri}>")
update(UPDATE_METADATA_QUERY.gsub("%uuid%", uuid.sparql_escape))
status 204
end