/
updateListInfo.scala.txt
130 lines (104 loc) · 3.99 KB
/
updateListInfo.scala.txt
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
@*
* Copyright © 2015-2019 the contributors (see Contributors.md).
*
* This file is part of Knora.
*
* Knora is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Knora is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with Knora. If not, see <http://www.gnu.org/licenses/>.
*@
@import org.knora.webapi.IRI
@import org.knora.webapi.messages.store.triplestoremessages.StringLiteralV2
@**
* Updates an existing list with the provided values.
*
* @param dataNamedGraph the named graph to update.
* @param triplestore the name of the triplestore being used. The template uses this value to exclude inferred
results from the WHERE clause of the update.
* @param listIri the IRI of the list we want to update.
* @param projectIri the IRI of the list's project.
* @param listClassIri the IRI of the OWL class that the list should belong to.
* @param hasOldName the old name of the list.
* @param maybeName the new name of the list.
* @param maybelabels the new optional label values.
* @param maybeComments the new optional comment values.
*@
@(dataNamedGraph: IRI,
triplestore: String,
listIri: IRI,
projectIri: IRI,
listClassIri: IRI,
hasOldName: Boolean,
maybeName : Option[String],
maybeLabels: Option[Seq[StringLiteralV2]],
maybeComments: Option[Seq[StringLiteralV2]])
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX knora-base: <http://www.knora.org/ontology/knora-base#>
WITH <@dataNamedGraph>
DELETE {
@* Delete current values, for which we have a new one. *@
@if(maybeLabels.nonEmpty) {
?listIri rdfs:label ?currentLabels .
}
@if(hasOldName && maybeName.nonEmpty) {
?listIri knora-base:listNodeName ?currentListName .
}
@if(maybeComments.nonEmpty) {
?listIri rdfs:comment ?currentComments .
}
} INSERT {
@* Add the new values. *@
@if(maybeName.nonEmpty) {
?listIri knora-base:listNodeName "@maybeName.get"^^xsd:string .
}
@if(maybeLabels.nonEmpty) {
@for(label <- maybeLabels.get) {
@if(label.language.nonEmpty) {
?listIri rdfs:label """@label.value"""@@@{label.language.get} .
} else {
?listIri rdfs:label """@label.value"""^^xsd:string .
}
}
}
@if(maybeComments.nonEmpty) {
@for(comment <- maybeComments.get) {
@if(comment.language.nonEmpty) {
?listIri rdfs:comment """@comment.value"""@@@{comment.language.get} .
} else {
?listIri rdfs:comment """@comment.value"""^^xsd:string .
}
}
}
}
@*
GraphDB's consistency checking requires reasoning, but reasoning interferes with certain things
in the WHERE clauses of our SPARQL updates, so we set a GraphDB-specific flag to return only
explicit statements in the WHERE clause here.
*@
@triplestore match {
case "graphdb" | "graphdb-free" => {
USING <http://www.ontotext.com/explicit>
}
case other => {}
}
WHERE {
BIND(IRI("@listIri") AS ?listIri)
BIND(IRI("@projectIri") AS ?projectIri)
@* Get all current defined values. *@
?listIri rdf:type knora-base:ListNode .
?listIri knora-base:attachedToProject ?projectIri .
optional {?listIri knora-base:listNodeName ?currentListName .}
optional {?listIri rdfs:label ?currentLabels .}
optional {?listIri rdfs:comment ?currentComments .}
}