Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api-v2): Fix replacement of cardinalities (DSP-1402) #1829

Merged
merged 1 commit into from Mar 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -34,7 +34,13 @@ import scala.reflect.runtime.{universe => ru}
object MessageUtil {

// Set of case class field names to skip.
private val fieldsToSkip = Set("stringFormatter", "base64Decoder", "knoraIdUtil", "standoffLinkTagTargetResourceIris")
private val fieldsToSkip =
Set("stringFormatter",
"base64Decoder",
"knoraIdUtil",
"standoffLinkTagTargetResourceIris",
"knoraSettings",
"featureFactoryConfig")

/**
* Recursively converts a Scala object to Scala source code for constructing the object (with named parameters). This is useful
Expand Down Expand Up @@ -142,7 +148,7 @@ object MessageUtil {
val members: Iterable[String] = objType.members.filter(member => !member.isMethod).flatMap { member =>
val memberName = member.name.toString.trim

if (!(memberName.contains("$") || memberName.endsWith("Format"))) {
if (!(memberName.contains("$") || memberName.endsWith("Format") || fieldsToSkip.contains(memberName))) {
val fieldMirror = try {
instanceMirror.reflectField(member.asTerm)
} catch {
Expand Down
Expand Up @@ -49,32 +49,54 @@ PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX knora-base: <http://www.knora.org/ontology/knora-base#>
PREFIX salsah-gui: <http://www.knora.org/ontology/salsah-gui#>

@* Delete the existing cardinalities and insert the new ones in separate update operations,
because the WHERE clause for deleting the existing ones returns several solutions.
If the INSERT was done in the same update, it would be run once for each solution,
which would cause redundant blank nodes to be inserted. *@

DELETE {
GRAPH ?ontologyNamedGraph {
?ontology knora-base:lastModificationDate "@lastModificationDate"^^xsd:dateTime .
?class rdfs:subClassOf ?restriction .
GRAPH <@ontologyNamedGraphIri> {
<@classIri> rdfs:subClassOf ?restriction .
?restriction ?restrictionPred ?restrictionObj .
}
} INSERT {
GRAPH ?ontologyNamedGraph {
?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 {
GRAPH <@ontologyNamedGraphIri> {
<@ontologyIri> rdf:type owl:Ontology ;
knora-base:lastModificationDate "@lastModificationDate"^^xsd:dateTime .

<@classIri> rdf:type owl:Class .

OPTIONAL {
<@classIri> rdfs:subClassOf ?restriction .
FILTER isBlank(?restriction)
?restriction rdf:type owl:Restriction ;
?restrictionPred ?restrictionObj .
}
}
};
INSERT {
GRAPH <@ontologyNamedGraphIri> {
@for((propertyIri, knoraCardinality) <- newCardinalities) {

@defining(Cardinality.knoraCardinality2OwlCardinality(knoraCardinality)) { owlCardinalityInfo =>

?class rdfs:subClassOf [ rdf:type owl:Restriction ;
owl:onProperty <@propertyIri> ;
<@classIri> rdfs:subClassOf [ rdf:type owl:Restriction ;
owl:onProperty <@propertyIri> ;

@owlCardinalityInfo.guiOrder match {
case Some(guiOrder) => {
salsah-gui:guiOrder "@guiOrder"^^xsd:nonNegativeInteger ;
}
@owlCardinalityInfo.guiOrder match {
case Some(guiOrder) => {
salsah-gui:guiOrder "@guiOrder"^^xsd:nonNegativeInteger ;
}

case None => {}
}
case None => {}
}

<@owlCardinalityInfo.owlCardinalityIri> "@owlCardinalityInfo.owlCardinalityValue"^^xsd:nonNegativeInteger ] .
<@owlCardinalityInfo.owlCardinalityIri> "@owlCardinalityInfo.owlCardinalityValue"^^xsd:nonNegativeInteger ] .

}
}
Expand All @@ -85,21 +107,29 @@ DELETE {
USING <http://www.ontotext.com/explicit>
}
WHERE {
BIND(IRI("@ontologyNamedGraphIri") AS ?ontologyNamedGraph)
BIND(IRI("@ontologyIri") AS ?ontology)
BIND(IRI("@classIri") AS ?class)

GRAPH ?ontologyNamedGraph {
?ontology rdf:type owl:Ontology ;
GRAPH <@ontologyNamedGraphIri> {
<@ontologyIri> rdf:type owl:Ontology ;
knora-base:lastModificationDate "@lastModificationDate"^^xsd:dateTime .

?class rdf:type owl:Class .

OPTIONAL {
?class rdfs:subClassOf ?restriction .
FILTER isBlank(?restriction)
?restriction rdf:type owl:Restriction ;
?restrictionPred ?restrictionObj .
}
<@classIri> rdf:type owl:Class .
}
};
DELETE {
GRAPH <@ontologyNamedGraphIri> {
<@ontologyIri> knora-base:lastModificationDate "@lastModificationDate"^^xsd:dateTime .
}
} INSERT {
GRAPH <@ontologyNamedGraphIri> {
<@ontologyIri> 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 {
GRAPH <@ontologyNamedGraphIri> {
<@ontologyIri> rdf:type owl:Ontology ;
knora-base:lastModificationDate "@lastModificationDate"^^xsd:dateTime .
}
}