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 checking of label of newly created resource #1453

Merged
merged 1 commit into from
Sep 30, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,10 @@ class ResourcesResponderV2(responderData: ResponderData) extends ResponderWithSt
throw AssertionException(s"Resource <$resourceIri> was saved, but it has the wrong permissions")
}

_ = if (resource.label != resourceReadyToCreate.sparqlTemplateResourceToCreate.resourceLabel) {
// Undo any escapes in the submitted rdfs:label to compare it with the saved one.
unescapedLabel: String = stringFormatter.fromSparqlEncodedString(resourceReadyToCreate.sparqlTemplateResourceToCreate.resourceLabel)

_ = if (resource.label != unescapedLabel) {
throw AssertionException(s"Resource <$resourceIri> was saved, but it has the wrong label")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -762,8 +762,15 @@ object JsonLDUtil {
* @return a JSON-LD object containing `@value` and `@type` predicates.
*/
def datatypeValueToJsonLDObject(value: String, datatype: SmartIri): JsonLDObject = {
// Normalise the formatting of decimal values to ensure consistency in tests.
val strValue: String = if (datatype.toString == OntologyConstants.Xsd.Decimal) {
BigDecimal(value).underlying.stripTrailingZeros.toPlainString
} else {
value
}

JsonLDObject(Map(
JsonLDConstants.VALUE -> JsonLDString(value),
JsonLDConstants.VALUE -> JsonLDString(strValue),
JsonLDConstants.TYPE -> JsonLDString(datatype.toString)
))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"@type" : "anything:Thing",
"knora-api:attachedToProject" : {
"@id" : "http://rdfh.ch/projects/0001"
},
"rdfs:label": "Pr\u00e9sentation du projet à \"Lausanne\"",
"@context" : {
"rdf" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"knora-api" : "http://api.knora.org/ontology/knora-api/v2#",
"rdfs" : "http://www.w3.org/2000/01/rdf-schema#",
"xsd" : "http://www.w3.org/2001/XMLSchema#",
"anything" : "http://0.0.0.0:3333/ontology/0001/anything/v2#"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,16 @@ class ResourcesRouteV2E2ESpec extends E2ESpec(ResourcesRouteV2E2ESpec.config) {
assert(text == "this is text with standoff")
}

"create a resource whose label contains a Unicode escape and quotation marks" in {
val jsonLDEntity: String = FileUtil.readTextFile(new File("src/test/resources/test-data/resourcesR2RV2/ThingWithUnicodeEscape.jsonld"))
val request = Post(s"$baseApiUrl/v2/resources", HttpEntity(RdfMediaTypes.`application/ld+json`, jsonLDEntity)) ~> addCredentials(BasicHttpCredentials(anythingUserEmail, password))
val response: HttpResponse = singleAwaitingRequest(request)
assert(response.status == StatusCodes.OK, response.toString)
val responseJsonDoc: JsonLDDocument = responseToJsonLDDocument(response)
val resourceIri: IRI = responseJsonDoc.body.requireStringWithValidation(JsonLDConstants.ID, stringFormatter.validateAndEscapeIri)
assert(resourceIri.toSmartIri.isKnoraDataIri)
}

"create a resource with a custom creation date" in {
val creationDate: Instant = Instant.parse("2019-01-09T15:45:54.502951Z")

Expand Down