Skip to content

Commit

Permalink
refactor: Merge StringLiteralV2 classes (#3133)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpro7 committed Mar 20, 2024
1 parent 2b7d239 commit 70cced2
Show file tree
Hide file tree
Showing 45 changed files with 441 additions and 512 deletions.
Expand Up @@ -189,7 +189,7 @@ class GroupsADME2ESpec extends E2ESpec with GroupsADMJsonProtocol {
val groupInfo: Group = AkkaHttpUtils.httpResponseToJson(response).fields("group").convertTo[Group]

groupInfo.name should be("NewGroup")
groupInfo.descriptions should be(Seq(StringLiteralV2("NewGroupDescription", Some("en"))))
groupInfo.descriptions should be(Seq(StringLiteralV2.from("NewGroupDescription", Some("en"))))
groupInfo.project should be(SharedTestDataADM.imagesProjectExternal)
groupInfo.status should be(true)
groupInfo.selfjoin should be(false)
Expand Down Expand Up @@ -239,7 +239,7 @@ class GroupsADME2ESpec extends E2ESpec with GroupsADMJsonProtocol {
val groupInfo: Group = AkkaHttpUtils.httpResponseToJson(response).fields("group").convertTo[Group]

groupInfo.name should be("UpdatedGroupName")
groupInfo.descriptions should be(Seq(StringLiteralV2("UpdatedGroupDescription", Some("en"))))
groupInfo.descriptions should be(Seq(StringLiteralV2.from("UpdatedGroupDescription", Some("en"))))
groupInfo.project should be(SharedTestDataADM.imagesProjectExternal)
groupInfo.status should be(true)
groupInfo.selfjoin should be(false)
Expand Down Expand Up @@ -268,7 +268,7 @@ class GroupsADME2ESpec extends E2ESpec with GroupsADMJsonProtocol {
val groupInfo: Group = AkkaHttpUtils.httpResponseToJson(response).fields("group").convertTo[Group]

groupInfo.name should be("UpdatedGroupName")
groupInfo.descriptions should be(Seq(StringLiteralV2("UpdatedGroupDescription", Some("en"))))
groupInfo.descriptions should be(Seq(StringLiteralV2.from("UpdatedGroupDescription", Some("en"))))
groupInfo.project should be(SharedTestDataADM.imagesProjectExternal)
groupInfo.status should be(false)
groupInfo.selfjoin should be(false)
Expand Down Expand Up @@ -315,7 +315,7 @@ class GroupsADME2ESpec extends E2ESpec with GroupsADMJsonProtocol {
val groupInfo: Group = AkkaHttpUtils.httpResponseToJson(response).fields("group").convertTo[Group]

groupInfo.name should be("UpdatedGroupName")
groupInfo.descriptions should be(Seq(StringLiteralV2("UpdatedGroupDescription", Some("en"))))
groupInfo.descriptions should be(Seq(StringLiteralV2.from("UpdatedGroupDescription", Some("en"))))
groupInfo.project should be(SharedTestDataADM.imagesProjectExternal)
groupInfo.status should be(true)
groupInfo.selfjoin should be(false)
Expand Down
Expand Up @@ -18,7 +18,6 @@ import scala.concurrent.Await
import scala.concurrent.Future
import scala.concurrent.duration.*

import dsp.valueobjects.V2
import org.knora.webapi.E2ESpec
import org.knora.webapi.IRI
import org.knora.webapi.e2e.ClientTestDataCollector
Expand All @@ -27,6 +26,7 @@ import org.knora.webapi.e2e.TestDataFilePath
import org.knora.webapi.messages.admin.responder.projectsmessages.*
import org.knora.webapi.messages.admin.responder.usersmessages.UsersADMJsonProtocol.*
import org.knora.webapi.messages.store.triplestoremessages.RdfDataObject
import org.knora.webapi.messages.store.triplestoremessages.StringLiteralV2
import org.knora.webapi.messages.util.rdf.RdfModel
import org.knora.webapi.sharedtestdata.SharedTestDataADM
import org.knora.webapi.slice.admin.domain.model.User
Expand Down Expand Up @@ -222,7 +222,7 @@ class ProjectsADME2ESpec extends E2ESpec with ProjectsADMJsonProtocol {
result.shortname should be("newprojectWithIri")
result.longname should be(Some("new project with a custom IRI"))
result.keywords should be(Seq("projectIRI"))
result.description should be(Seq(V2.StringLiteralV2("a project created with a custom IRI", Some("en"))))
result.description should be(Seq(StringLiteralV2.from("a project created with a custom IRI", Some("en"))))

clientTestDataCollector.addFile(
TestDataFileContent(
Expand Down Expand Up @@ -303,7 +303,7 @@ class ProjectsADME2ESpec extends E2ESpec with ProjectsADMJsonProtocol {
result.shortname should be("newproject")
result.shortcode should be("1111")
result.longname should be(Some("project longname"))
result.description should be(Seq(V2.StringLiteralV2(value = "project description", language = Some("en"))))
result.description should be(Seq(StringLiteralV2.from(value = "project description", language = Some("en"))))
result.keywords should be(Seq("keywords"))
result.logo should be(Some("/fu/bar/baz.jpg"))
result.status should be(true)
Expand Down Expand Up @@ -450,7 +450,7 @@ class ProjectsADME2ESpec extends E2ESpec with ProjectsADMJsonProtocol {
result.shortcode should be("1111")
result.longname should be(Some("updated project longname"))
result.description should be(
Seq(V2.StringLiteralV2(value = "updated project description", language = Some("en"))),
Seq(StringLiteralV2.from(value = "updated project description", language = Some("en"))),
)
result.keywords.sorted should be(Seq("updated", "keywords").sorted)
result.logo should be(Some("/fu/bar/baz-updated.jpg"))
Expand Down Expand Up @@ -498,8 +498,8 @@ class ProjectsADME2ESpec extends E2ESpec with ProjectsADMJsonProtocol {

val result: Project = AkkaHttpUtils.httpResponseToJson(response).fields("project").convertTo[Project]
result.description.size should be(2)
result.description should contain(V2.StringLiteralV2(value = "Test Project", language = Some("en")))
result.description should contain(V2.StringLiteralV2(value = "Test Project", language = Some("se")))
result.description should contain(StringLiteralV2.from(value = "Test Project", language = Some("en")))
result.description should contain(StringLiteralV2.from(value = "Test Project", language = Some("se")))

clientTestDataCollector.addFile(
TestDataFileContent(
Expand Down
Expand Up @@ -100,7 +100,7 @@ class CreateListItemsRouteADME2ESpec extends E2ESpec with TriplestoreJsonProtoco

val labels: Seq[StringLiteralV2] = listInfo.labels.stringLiterals
labels.size should be(1)
labels.head should be(StringLiteralV2(value = "New list with a custom IRI", language = Some("en")))
labels.head should be(StringLiteralV2.from(value = "New list with a custom IRI", language = Some("en")))

clientTestDataCollector.addFile(
TestDataFileContent(
Expand Down Expand Up @@ -232,7 +232,7 @@ class CreateListItemsRouteADME2ESpec extends E2ESpec with TriplestoreJsonProtoco

val labels: Seq[StringLiteralV2] = listInfo.labels.stringLiterals
labels.size should be(1)
labels.head should be(StringLiteralV2(value = "Neue Liste", language = Some("de")))
labels.head should be(StringLiteralV2.from(value = "Neue Liste", language = Some("de")))

val comments = receivedList.listinfo.comments.stringLiterals
comments.isEmpty should be(false)
Expand Down Expand Up @@ -394,12 +394,12 @@ class CreateListItemsRouteADME2ESpec extends E2ESpec with TriplestoreJsonProtoco
// check labels
val labels: Seq[StringLiteralV2] = childNodeInfo.labels.stringLiterals
labels.size should be(1)
labels.sorted should be(Seq(StringLiteralV2(value = label, language = Some("en"))))
labels.sorted should be(Seq(StringLiteralV2.from(value = label, language = Some("en"))))

// check comments
val comments = childNodeInfo.comments.stringLiterals
comments.size should be(1)
comments.sorted should be(Seq(StringLiteralV2(value = comment, language = Some("en"))))
comments.sorted should be(Seq(StringLiteralV2.from(value = comment, language = Some("en"))))

// check position
val position = childNodeInfo.position
Expand Down Expand Up @@ -463,12 +463,12 @@ class CreateListItemsRouteADME2ESpec extends E2ESpec with TriplestoreJsonProtoco
// check labels
val labels: Seq[StringLiteralV2] = childNodeInfo.labels.stringLiterals
labels.size should be(1)
labels.sorted should be(Seq(StringLiteralV2(value = label, language = Some("en"))))
labels.sorted should be(Seq(StringLiteralV2.from(value = label, language = Some("en"))))

// check comments
val comments = childNodeInfo.comments.stringLiterals
comments.size should be(1)
comments.sorted should be(Seq(StringLiteralV2(value = comment, language = Some("en"))))
comments.sorted should be(Seq(StringLiteralV2.from(value = comment, language = Some("en"))))

// check position
val position = childNodeInfo.position
Expand Down Expand Up @@ -538,12 +538,12 @@ class CreateListItemsRouteADME2ESpec extends E2ESpec with TriplestoreJsonProtoco
// check labels
val labels: Seq[StringLiteralV2] = childNodeInfo.labels.stringLiterals
labels.size should be(1)
labels.sorted should be(Seq(StringLiteralV2(value = label, language = Some("en"))))
labels.sorted should be(Seq(StringLiteralV2.from(value = label, language = Some("en"))))

// check comments
val comments = childNodeInfo.comments.stringLiterals
comments.size should be(1)
comments.sorted should be(Seq(StringLiteralV2(value = comment, language = Some("en"))))
comments.sorted should be(Seq(StringLiteralV2.from(value = comment, language = Some("en"))))

// check position
val position = childNodeInfo.position
Expand Down Expand Up @@ -609,12 +609,12 @@ class CreateListItemsRouteADME2ESpec extends E2ESpec with TriplestoreJsonProtoco
// check labels
val labels: Seq[StringLiteralV2] = childNodeInfo.labels.stringLiterals
labels.size should be(1)
labels.sorted should be(Seq(StringLiteralV2(value = label, language = Some("en"))))
labels.sorted should be(Seq(StringLiteralV2.from(value = label, language = Some("en"))))

// check comments
val comments = childNodeInfo.comments.stringLiterals
comments.size should be(1)
comments.sorted should be(Seq(StringLiteralV2(value = comment, language = Some("en"))))
comments.sorted should be(Seq(StringLiteralV2.from(value = comment, language = Some("en"))))

// check position
val position = childNodeInfo.position
Expand Down
Expand Up @@ -148,7 +148,7 @@ class UpdateListItemsRouteADME2ESpec extends E2ESpec with TriplestoreJsonProtoco

val labels: Seq[StringLiteralV2] = receivedListInfo.labels.stringLiterals
labels.size should be(1)
labels should contain(StringLiteralV2(value = "nya märkningen", language = Some("se")))
labels should contain(StringLiteralV2.from(value = "nya märkningen", language = Some("se")))

clientTestDataCollector.addFile(
TestDataFileContent(
Expand Down Expand Up @@ -193,7 +193,7 @@ class UpdateListItemsRouteADME2ESpec extends E2ESpec with TriplestoreJsonProtoco

val comments: Seq[StringLiteralV2] = receivedListInfo.comments.stringLiterals
comments.size should be(1)
comments should contain(StringLiteralV2(value = "nya kommentarer", language = Some("se")))
comments should contain(StringLiteralV2.from(value = "nya kommentarer", language = Some("se")))

clientTestDataCollector.addFile(
TestDataFileContent(
Expand Down Expand Up @@ -299,7 +299,7 @@ class UpdateListItemsRouteADME2ESpec extends E2ESpec with TriplestoreJsonProtoco
AkkaHttpUtils.httpResponseToJson(response).fields("nodeinfo").convertTo[ListChildNodeInfoADM]
val labels: Seq[StringLiteralV2] = receivedNodeInfo.labels.stringLiterals
labels.size should be(1)
labels should contain(StringLiteralV2(value = "nya märkningen för nod", language = Some("se")))
labels should contain(StringLiteralV2.from(value = "nya märkningen för nod", language = Some("se")))

clientTestDataCollector.addFile(
TestDataFileContent(
Expand Down Expand Up @@ -344,7 +344,7 @@ class UpdateListItemsRouteADME2ESpec extends E2ESpec with TriplestoreJsonProtoco
AkkaHttpUtils.httpResponseToJson(response).fields("nodeinfo").convertTo[ListChildNodeInfoADM]
val comments: Seq[StringLiteralV2] = receivedNodeInfo.comments.stringLiterals
comments.size should be(1)
comments should contain(StringLiteralV2(value = "nya kommentarer för nod", language = Some("se")))
comments should contain(StringLiteralV2.from(value = "nya kommentarer för nod", language = Some("se")))

clientTestDataCollector.addFile(
TestDataFileContent(
Expand Down
Expand Up @@ -26,13 +26,13 @@ class ListsMessagesADMSpec extends CoreSpec with ListADMJsonProtocol {
projectIri = "http://rdfh.ch/projects/00FF",
labels = StringLiteralSequenceV2(
Vector(
StringLiteralV2("Title", Some("en")),
StringLiteralV2("Titel", Some("de")),
StringLiteralV2("Titre", Some("fr")),
StringLiteralV2.from("Title", Some("en")),
StringLiteralV2.from("Titel", Some("de")),
StringLiteralV2.from("Titre", Some("fr")),
),
),
comments = StringLiteralSequenceV2(
Vector(StringLiteralV2("Hierarchisches Stichwortverzeichnis / Signatur der Bilder", Some("de"))),
Vector(StringLiteralV2.from("Hierarchisches Stichwortverzeichnis / Signatur der Bilder", Some("de"))),
),
)

Expand All @@ -49,7 +49,7 @@ class ListsMessagesADMSpec extends CoreSpec with ListADMJsonProtocol {
val listNodeInfo = ListChildNodeInfoADM(
id = "http://rdfh.ch/lists/00FF/526f26ed04",
name = Some("sommer"),
labels = StringLiteralSequenceV2(Vector(StringLiteralV2("Sommer"))),
labels = StringLiteralSequenceV2(Vector(StringLiteralV2.from("Sommer", None))),
comments = StringLiteralSequenceV2.empty,
position = 0,
hasRootNode = "http://rdfh.ch/lists/00FF/d19af9ab",
Expand All @@ -68,7 +68,7 @@ class ListsMessagesADMSpec extends CoreSpec with ListADMJsonProtocol {
val listNode: ListNodeADM = ListChildNodeADM(
id = "http://rdfh.ch/lists/00FF/526f26ed04",
name = Some("sommer"),
labels = StringLiteralSequenceV2(Vector(StringLiteralV2("Sommer"))),
labels = StringLiteralSequenceV2(Vector(StringLiteralV2.from("Sommer", None))),
comments = StringLiteralSequenceV2.empty,
children = Seq.empty[ListChildNodeADM],
position = 0,
Expand Down
Expand Up @@ -7,9 +7,9 @@ package org.knora.webapi.messages.admin.responder.projectsmessages

import dsp.errors.BadRequestException
import dsp.errors.OntologyConstraintException
import dsp.valueobjects.V2
import org.knora.webapi.*
import org.knora.webapi.messages.admin.responder.projectsmessages.ProjectIdentifierADM.*
import org.knora.webapi.messages.store.triplestoremessages.StringLiteralV2
import org.knora.webapi.sharedtestdata.SharedTestDataADM

/**
Expand All @@ -24,7 +24,7 @@ class ProjectsMessagesADMSpec extends CoreSpec {
shortcode = "1111",
shortname = "shortname",
longname = None,
description = Seq.empty[V2.StringLiteralV2],
description = Seq.empty[StringLiteralV2],
keywords = Seq.empty[String],
logo = None,
ontologies = Seq.empty[IRI],
Expand Down
Expand Up @@ -19,9 +19,9 @@ class TriplestoreMessagesSpec extends AnyWordSpecLike with Matchers with ListADM

"Conversion from case class to JSON and back" should {

"work for a 'StringLiteralV2' without language tag" in {
"work for a 'StringLiteralV2' without language iso" in {

val string = StringLiteralV2("stringwithoutlang", None)
val string = StringLiteralV2.from("stringwithoutlang", None)
val json = string.toJson.compactPrint

json should be("{\"value\":\"stringwithoutlang\"}")
Expand All @@ -31,9 +31,9 @@ class TriplestoreMessagesSpec extends AnyWordSpecLike with Matchers with ListADM
converted should be(string)
}

"work for a 'StringLiteralV2' with language tag" in {
"work for a 'StringLiteralV2' with language iso" in {

val string = StringLiteralV2("stringwithlang", Some("de"))
val string = StringLiteralV2.from("stringwithlang", Some("de"))
val json = string.toJson.compactPrint

json should be("{\"value\":\"stringwithlang\",\"language\":\"de\"}")
Expand All @@ -45,9 +45,9 @@ class TriplestoreMessagesSpec extends AnyWordSpecLike with Matchers with ListADM
}

"Creating a `StringLiteralV2`" should {
"fail when language tag is given but value is missing" in {
"fail when language iso is given but value is missing" in {
val caught = intercept[BadRequestException](
StringLiteralV2("", Some("de")),
StringLiteralV2.from("", Some("de")),
)
assert(caught.getMessage === "String value is missing.")
}
Expand Down
Expand Up @@ -203,15 +203,15 @@ object InputOntologyV2Spec {
"http://www.w3.org/2000/01/rdf-schema#label".toSmartIri -> PredicateInfoV2(
predicateIri = "http://www.w3.org/2000/01/rdf-schema#label".toSmartIri,
objects = Seq(
StringLiteralV2("has name", Some("en")),
StringLiteralV2("hat Namen", Some("de")),
StringLiteralV2.from("has name", Some("en")),
StringLiteralV2.from("hat Namen", Some("de")),
),
),
"http://www.w3.org/2000/01/rdf-schema#comment".toSmartIri -> PredicateInfoV2(
predicateIri = "http://www.w3.org/2000/01/rdf-schema#comment".toSmartIri,
objects = Seq(
StringLiteralV2("The name of a 'Thing'", Some("en")),
StringLiteralV2("Der Name eines Dinges", Some("de")),
StringLiteralV2.from("The name of a 'Thing'", Some("en")),
StringLiteralV2.from("Der Name eines Dinges", Some("de")),
),
),
),
Expand All @@ -234,11 +234,11 @@ object InputOntologyV2Spec {
),
"http://www.w3.org/2000/01/rdf-schema#label".toSmartIri -> PredicateInfoV2(
predicateIri = "http://www.w3.org/2000/01/rdf-schema#label".toSmartIri,
objects = Seq(StringLiteralV2("wild thing", Some("en"))),
objects = Seq(StringLiteralV2.from("wild thing", Some("en"))),
),
"http://www.w3.org/2000/01/rdf-schema#comment".toSmartIri -> PredicateInfoV2(
predicateIri = "http://www.w3.org/2000/01/rdf-schema#comment".toSmartIri,
objects = Seq(StringLiteralV2("A thing that is wild", Some("en"))),
objects = Seq(StringLiteralV2.from("A thing that is wild", Some("en"))),
),
),
classIri = "http://0.0.0.0:3333/ontology/0001/anything/v2#WildThing".toSmartIri,
Expand Down

0 comments on commit 70cced2

Please sign in to comment.