/
changeOntologyMetadata.scala.txt
92 lines (86 loc) · 3.29 KB
/
changeOntologyMetadata.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
@*
* Copyright © 2015-2021 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.messages.SmartIri
@import java.time.Instant
@*
* Changes the metadata attached to an ontology.
*
* @param triplestore the name of the triplestore being used.
* @param ontologyNamedGraphIri the IRI of the named graph where the ontology should be stored.
* @param ontologyIri the IRI of the ontology to be created.
* @param newLabel the ontology's new label.
* @param hasOldComment true if the ontology has a comment.
* @param deleteOldComment true if the existing comment should be deleted.
* @param newComment the ontology's new comment.
* @param lastModificationDate the xsd:dateTimeStamp that was attached to the ontology when it was last modified.
* @param currentTime an xsd:dateTimeStamp that will be attached to the ontology.
*@
@(triplestore: String,
ontologyNamedGraphIri: SmartIri,
ontologyIri: SmartIri,
newLabel: Option[String],
hasOldComment: Boolean,
deleteOldComment: Boolean,
newComment: Option[String],
lastModificationDate: Instant,
currentTime: Instant)
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX knora-base: <http://www.knora.org/ontology/knora-base#>
DELETE {
GRAPH ?ontologyNamedGraph {
@if(newLabel.nonEmpty) {
?ontology rdfs:label ?oldLabel .
}
@if(hasOldComment && (deleteOldComment || newComment.nonEmpty)) {
?ontology rdfs:comment ?oldComment .
}
?ontology knora-base:lastModificationDate "@lastModificationDate"^^xsd:dateTime .
}
} INSERT {
GRAPH ?ontologyNamedGraph {
@if(newLabel.nonEmpty) {
?ontology rdfs:label """@newLabel.get"""^^xsd:string .
}
@if(newComment.nonEmpty) {
?ontology rdfs:comment """@newComment.get"""^^xsd:string .
}
?ontology knora-base:lastModificationDate "@currentTime"^^xsd:dateTime .
}
}
@* Ensure that inference is not used in the WHERE clause of this update. *@
@if(triplestore.startsWith("graphdb")) {
USING <http://www.ontotext.com/explicit>
}
WHERE {
BIND(IRI("@ontologyNamedGraphIri") AS ?ontologyNamedGraph)
BIND(IRI("@ontologyIri") AS ?ontology)
GRAPH ?ontologyNamedGraph {
?ontology rdf:type owl:Ontology ;
@if(newLabel.nonEmpty) {
rdfs:label ?oldLabel ;
}
@if(hasOldComment) {
rdfs:comment ?oldComment ;
}
knora-base:lastModificationDate "@lastModificationDate"^^xsd:dateTime .
}
}