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): Remove INFORMATION SEPARATOR TWO from text in the simple schema #1299

Merged
merged 1 commit into from
Apr 11, 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 @@ -1113,16 +1113,19 @@ case class TextValueContentV2(ontologySchema: OntologySchema,
override def toJsonLDValue(targetSchema: ApiV2Schema, projectADM: ProjectADM, settings: SettingsImpl): JsonLDValue = {
targetSchema match {
case ApiV2Simple =>
// Remove INFORMATION SEPARATOR TWO, which is used only internally.
val textForSimpleSchema = valueHasString.replace(StringFormatter.INFORMATION_SEPARATOR_TWO.toString, "")

valueHasLanguage match {
case Some(lang) =>
// In the simple schema, if this text value specifies a language, return it using a JSON-LD
// @language key as per <https://json-ld.org/spec/latest/json-ld/#string-internationalization>.
JsonLDUtil.objectWithLangToJsonLDObject(
obj = valueHasString,
obj = textForSimpleSchema,
lang = lang
)

case None => JsonLDString(valueHasString)
case None => JsonLDString(textForSimpleSchema)
}

case ApiV2WithValueObjects =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ class XMLToStandoffUtil(xmlNamespaces: Map[String, IRI] = Map.empty[IRI, String]
case (acc, hierarchicalTag: HierarchicalStandoffTag) =>
acc :+ hierarchicalTag

// It seems as if the following line should work, but it doesn't. See https://issues.scala-lang.org/browse/SI-10100
// It seems as if the following line should work, but it doesn't. See https://github.com/scala/bug/issues/10100
// case (_, clixTag: ClixMilestoneTag) => throw AssertionException(s"CLIX tag $clixTag cannot be in TextWithStandoff") // This should never happen

// Workaround:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,11 @@ class ResourcesRouteV2E2ESpec extends E2ESpec(ResourcesRouteV2E2ESpec.config) {
expectedClassIri = "http://0.0.0.0:3333/ontology/0001/anything/simple/v2#Thing".toSmartIri,
knoraRouteGet = doGetRequest
)

// Check that the text value with standoff is correct in the simple schema.
val resourceSimpleAsJsonLD: JsonLDDocument = JsonLDUtil.parseJsonLD(resourceSimpleGetResponseAsString)
val text: String = resourceSimpleAsJsonLD.body.requireString("http://0.0.0.0:3333/ontology/0001/anything/simple/v2#hasRichtext")
assert(text == "this is text with standoff")
}

"create a resource with a custom creation date" in {
Expand Down