Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(api-v2): Fix generated SPARQL for updating property comment (#1693)
  • Loading branch information
Benjamin Geer committed Aug 24, 2020
1 parent 8d7bee8 commit 7b70339
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 8 deletions.
Expand Up @@ -3251,7 +3251,7 @@ class OntologyResponderV2(responderData: ResponderData) extends Responder(respon
maybeUnescapedNewLinkValuePropertyDef: Option[PropertyInfoContentV2] = maybeLoadedLinkValuePropertyDef.map {
loadedLinkValuePropertyDef =>
val unescapedNewLinkPropertyDef = maybeCurrentLinkValueReadPropertyInfo.get.entityInfoContent.copy(
predicates = currentReadPropertyInfo.entityInfoContent.predicates + (changePropertyLabelsOrCommentsRequest.predicateToUpdate -> unescapedNewLabelOrCommentPredicate)
predicates = maybeCurrentLinkValueReadPropertyInfo.get.entityInfoContent.predicates + (changePropertyLabelsOrCommentsRequest.predicateToUpdate -> unescapedNewLabelOrCommentPredicate)
)

if (loadedLinkValuePropertyDef != unescapedNewLinkPropertyDef) {
Expand Down
Expand Up @@ -2851,6 +2851,38 @@ object SharedTestDataADM {
""".stripMargin
}

def addCommentToPropertyThatHasNoComment(anythingOntologyIri: IRI, anythingLastModDate: Instant): String = {
s"""{
| "@id": "$anythingOntologyIri",
| "@type": "owl:Ontology",
| "knora-api:lastModificationDate": {
| "@type": "xsd:dateTimeStamp",
| "@value": "$anythingLastModDate"
| },
| "@graph": [
| {
| "@id": "anything:hasBlueThing",
| "@type": "owl:ObjectProperty",
| "rdfs:comment": [
| {
| "@language": "en",
| "@value": "asdas asd as dasdasdas"
| }
| ]
| }
| ],
| "@context": {
| "anything": "http://0.0.0.0:3333/ontology/0001/anything/v2#",
| "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
| "rdfs": "http://www.w3.org/2000/01/rdf-schema#",
| "owl": "http://www.w3.org/2002/07/owl#",
| "xsd": "http://www.w3.org/2001/XMLSchema#",
| "knora-api": "http://api.knora.org/ontology/knora-api/v2#",
| "salsah-gui": "http://api.knora.org/ontology/salsah-gui/v2#"
| }
|}""".stripMargin
}

object AThing {
val iri: IRI = "http://rdfh.ch/0001/a-thing"
val iriEncoded: String = URLEncoder.encode(iri, "UTF-8")
Expand Down
Expand Up @@ -101,10 +101,11 @@ DELETE {
}
WHERE {
BIND(IRI("@ontologyNamedGraphIri") AS ?ontologyNamedGraph)
BIND(IRI("@ontologyIri") AS ?ontology)
BIND(IRI("@propertyIri") AS ?property)

GRAPH ?ontologyNamedGraph {
BIND(IRI("@ontologyIri") AS ?ontology)
BIND(IRI("@propertyIri") AS ?property)

?ontology rdf:type owl:Ontology ;
knora-base:lastModificationDate "@lastModificationDate"^^xsd:dateTime .

Expand Down
Expand Up @@ -162,7 +162,6 @@ class OntologyV2R2RSpec extends R2RSpec {
private val fooIri = new MutableTestIri
private var fooLastModDate: Instant = Instant.now

private val AnythingOntologyIri = "http://0.0.0.0:3333/ontology/0001/anything/v2".toSmartIri
private var anythingLastModDate: Instant = Instant.parse("2017-12-19T15:23:42.166Z")

private val uselessIri = new MutableTestIri
Expand Down Expand Up @@ -312,7 +311,7 @@ class OntologyV2R2RSpec extends R2RSpec {
}
}

"change the labels of a property" in {
"change the rdfs:label of a property" in {
val params = SharedTestDataADM.changePropertyLabel(SharedOntologyTestDataADM.ANYTHING_ONTOLOGY_IRI_LocalHost, anythingLastModDate)

// Convert the submitted JSON-LD to an InputOntologyV2, without SPARQL-escaping, so we can compare it to the response.
Expand All @@ -324,7 +323,7 @@ class OntologyV2R2RSpec extends R2RSpec {

// Convert the response to an InputOntologyV2 and compare the relevant part of it to the request.
val responseAsInput: InputOntologyV2 = InputOntologyV2.fromJsonLD(responseJsonDoc, parsingMode = TestResponseParsingModeV2).unescape
responseAsInput.properties.head._2.predicates(OntologyConstants.Rdfs.Label.toSmartIri).objects should ===(paramsAsInput.properties.head._2.predicates.head._2.objects)
responseAsInput.properties.head._2.predicates(OntologyConstants.Rdfs.Label.toSmartIri).objects should ===(paramsAsInput.properties.head._2.predicates(OntologyConstants.Rdfs.Label.toSmartIri).objects)

// Check that the ontology's last modification date was updated.
val newAnythingLastModDate = responseAsInput.ontologyMetadata.lastModificationDate.get
Expand All @@ -333,7 +332,7 @@ class OntologyV2R2RSpec extends R2RSpec {
}
}

"change the comments of a property" in {
"change the rdfs:comment of a property" in {
val params = SharedTestDataADM.changePropertyComment(SharedOntologyTestDataADM.ANYTHING_ONTOLOGY_IRI_LocalHost, anythingLastModDate)

// Convert the submitted JSON-LD to an InputOntologyV2, without SPARQL-escaping, so we can compare it to the response.
Expand All @@ -345,7 +344,28 @@ class OntologyV2R2RSpec extends R2RSpec {

// Convert the response to an InputOntologyV2 and compare the relevant part of it to the request.
val responseAsInput: InputOntologyV2 = InputOntologyV2.fromJsonLD(responseJsonDoc, parsingMode = TestResponseParsingModeV2).unescape
responseAsInput.properties.head._2.predicates(OntologyConstants.Rdfs.Comment.toSmartIri).objects should ===(paramsAsInput.properties.head._2.predicates.head._2.objects)
responseAsInput.properties.head._2.predicates(OntologyConstants.Rdfs.Comment.toSmartIri).objects should ===(paramsAsInput.properties.head._2.predicates(OntologyConstants.Rdfs.Comment.toSmartIri).objects)

// Check that the ontology's last modification date was updated.
val newAnythingLastModDate = responseAsInput.ontologyMetadata.lastModificationDate.get
assert(newAnythingLastModDate.isAfter(anythingLastModDate))
anythingLastModDate = newAnythingLastModDate
}
}

"add an rdfs:comment to a link property that has no rdfs:comment" in {
val params = SharedTestDataADM.addCommentToPropertyThatHasNoComment(SharedOntologyTestDataADM.ANYTHING_ONTOLOGY_IRI_LocalHost, anythingLastModDate)

// Convert the submitted JSON-LD to an InputOntologyV2, without SPARQL-escaping, so we can compare it to the response.
val paramsAsInput: InputOntologyV2 = InputOntologyV2.fromJsonLD(JsonLDUtil.parseJsonLD(params)).unescape

Put("/v2/ontologies/properties", HttpEntity(RdfMediaTypes.`application/ld+json`, params)) ~> addCredentials(BasicHttpCredentials(anythingUsername, password)) ~> ontologiesPath ~> check {
assert(status == StatusCodes.OK, response.toString)
val responseJsonDoc = responseToJsonLDDocument(response)

// Convert the response to an InputOntologyV2 and compare the relevant part of it to the request.
val responseAsInput: InputOntologyV2 = InputOntologyV2.fromJsonLD(responseJsonDoc, parsingMode = TestResponseParsingModeV2).unescape
responseAsInput.properties.head._2.predicates(OntologyConstants.Rdfs.Comment.toSmartIri).objects should ===(paramsAsInput.properties.head._2.predicates(OntologyConstants.Rdfs.Comment.toSmartIri).objects)

// Check that the ontology's last modification date was updated.
val newAnythingLastModDate = responseAsInput.ontologyMetadata.lastModificationDate.get
Expand Down

0 comments on commit 7b70339

Please sign in to comment.