Skip to content

Commit

Permalink
refactor: Make Project.keywords typed
Browse files Browse the repository at this point in the history
  • Loading branch information
seakayone committed Nov 15, 2024
1 parent d418c7b commit 804e35a
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ class ProjectsADME2ESpec extends E2ESpec with SprayJsonSupport {
result.description should be(
Seq(StringLiteralV2.from(value = "updated project description", language = Some("en"))),
)
result.keywords.sorted should be(Seq("updated", "keywords").sorted)
result.keywords.map(_.value).sorted should be(Seq("updated", "keywords").sorted)
result.logo should be(Some("/fu/bar/baz-updated.jpg"))
result.status should be(Status.Active)
result.selfjoin should be(SelfJoin.CanJoin)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import org.knora.webapi.slice.admin.api.model.ProjectMembersGetResponseADM
import org.knora.webapi.slice.admin.api.model.ProjectOperationResponseADM
import org.knora.webapi.slice.admin.domain.model.Group
import org.knora.webapi.slice.admin.domain.model.KnoraProject.CopyrightAttribution
import org.knora.webapi.slice.admin.domain.model.KnoraProject.Keyword
import org.knora.webapi.slice.admin.domain.model.KnoraProject.License
import org.knora.webapi.slice.admin.domain.model.KnoraProject.Logo
import org.knora.webapi.slice.admin.domain.model.KnoraProject.Longname
Expand Down Expand Up @@ -241,6 +242,10 @@ object IntegrationTestAdminJsonProtocol extends TriplestoreJsonProtocol {
override val from: String => Either[String, Logo] = Logo.from
}

implicit object KeywordFormat extends StringValueFormat[Keyword] {
override val from: String => Either[String, Keyword] = Keyword.from
}

trait BooleanValueFormat[T <: BooleanValue] extends JsonFormat[T] { self =>
def from: Boolean => T
override def write(v: T): JsValue = JsString(v.value.toString)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ class ProjectRestServiceSpec extends CoreSpec with ImplicitSender {
),
),
)
received.project.keywords.sorted should be(Seq("updated", "keywords").sorted)
received.project.keywords.map(_.value).sorted should be(List("updated", "keywords").sorted)
received.project.logo should be(Some("/fu/bar/baz-updated.jpg"))
received.project.status should be(Status.Active)
received.project.selfjoin should be(SelfJoin.CanJoin)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import org.knora.webapi.messages.store.triplestoremessages.StringLiteralV2
import org.knora.webapi.messages.util.KnoraSystemInstances
import org.knora.webapi.slice.admin.api.model.Project
import org.knora.webapi.slice.admin.domain.model.Group
import org.knora.webapi.slice.admin.domain.model.KnoraProject.Keyword
import org.knora.webapi.slice.admin.domain.model.KnoraProject.Logo
import org.knora.webapi.slice.admin.domain.model.KnoraProject.Longname
import org.knora.webapi.slice.admin.domain.model.KnoraProject.ProjectIri
Expand Down Expand Up @@ -166,7 +167,7 @@ object SharedTestDataADM {
shortcode = Shortcode.unsafeFrom("FFFF"),
longname = Some(Longname.unsafeFrom("Knora System Project")),
description = Seq(StringLiteralV2.from(value = "Knora System Project", language = Some("en"))),
keywords = Seq.empty[String],
keywords = List.empty,
logo = None,
ontologies = Seq(
OntologyConstants.KnoraBase.KnoraBaseOntologyIri,
Expand All @@ -187,7 +188,7 @@ object SharedTestDataADM {
shortcode = Shortcode.unsafeFrom("0000"),
longname = Some(Longname.unsafeFrom("Default Knora Shared Ontologies Project")),
description = Seq(StringLiteralV2.from(value = "Default Knora Shared Ontologies Project", language = Some("en"))),
keywords = Seq.empty[String],
keywords = List.empty,
logo = None,
ontologies = Seq.empty[IRI],
status = Status.Active,
Expand Down Expand Up @@ -301,7 +302,7 @@ object SharedTestDataADM {
shortcode = Shortcode.unsafeFrom("00FF"),
longname = Some(Longname.unsafeFrom("Image Collection Demo")),
description = Seq(StringLiteralV2.from(value = "A demo project of a collection of images", language = Some("en"))),
keywords = Seq("images", "collection").sorted,
keywords = List("images", "collection").map(Keyword.unsafeFrom),
logo = None,
ontologies = Seq(SharedOntologyTestDataADM.IMAGES_ONTOLOGY_IRI),
status = Status.Active,
Expand All @@ -317,7 +318,7 @@ object SharedTestDataADM {
shortcode = Shortcode.unsafeFrom("00FF"),
longname = Some(Longname.unsafeFrom("Image Collection Demo")),
description = Seq(StringLiteralV2.from(value = "A demo project of a collection of images", language = Some("en"))),
keywords = Seq("images", "collection").sorted,
keywords = List("images", "collection").map(Keyword.unsafeFrom),
logo = None,
ontologies = Seq(SharedOntologyTestDataADM.IMAGES_ONTOLOGY_IRI_LocalHost),
status = Status.Active,
Expand Down Expand Up @@ -467,7 +468,7 @@ object SharedTestDataADM {
language = None,
),
),
keywords = Seq(
keywords = List(
"Basler Frühdrucke",
"Inkunabel",
"Narrenschiff",
Expand All @@ -482,7 +483,7 @@ object SharedTestDataADM {
"Letterpress Printing",
"Basel",
"Contectualisation of images",
).sorted,
).map(Keyword.unsafeFrom),
logo = Some(Logo.unsafeFrom("incunabula_logo.png")),
ontologies = Seq(SharedOntologyTestDataADM.INCUNABULA_ONTOLOGY_IRI),
status = Status.Active,
Expand All @@ -504,7 +505,7 @@ object SharedTestDataADM {
language = None,
),
),
keywords = Seq(
keywords = List(
"Basler Frühdrucke",
"Inkunabel",
"Narrenschiff",
Expand All @@ -519,7 +520,7 @@ object SharedTestDataADM {
"Letterpress Printing",
"Basel",
"Contectualisation of images",
).sorted,
).map(Keyword.unsafeFrom),
logo = Some(Logo.unsafeFrom("incunabula_logo.png")),
ontologies = Seq(SharedOntologyTestDataADM.INCUNABULA_ONTOLOGY_IRI_LocalHost),
status = Status.Active,
Expand Down Expand Up @@ -633,7 +634,7 @@ object SharedTestDataADM {
shortcode = Shortcode.unsafeFrom("0001"),
longname = Some(Longname.unsafeFrom("Anything Project")),
description = Seq(StringLiteralV2.from(value = "Anything Project", language = None)),
keywords = Seq("things", "arbitrary test data").sorted,
keywords = List("things", "arbitrary test data").map(Keyword.unsafeFrom),
logo = None,
ontologies = Seq(SharedOntologyTestDataADM.ANYTHING_ONTOLOGY_IRI, SharedOntologyTestDataADM.SomethingOntologyIri),
status = Status.Active,
Expand All @@ -648,7 +649,7 @@ object SharedTestDataADM {
shortcode = Shortcode.unsafeFrom("0001"),
longname = Some(Longname.unsafeFrom("Anything Project")),
description = Seq(StringLiteralV2.from(value = "Anything Project", language = None)),
keywords = Seq("things", "arbitrary test data").sorted,
keywords = List("things", "arbitrary test data").map(Keyword.unsafeFrom),
logo = None,
ontologies = Seq(
SharedOntologyTestDataADM.ANYTHING_ONTOLOGY_IRI_LocalHost,
Expand Down Expand Up @@ -685,7 +686,7 @@ object SharedTestDataADM {
shortcode = Shortcode.unsafeFrom("0801"),
longname = Some(Longname.unsafeFrom("Bernoulli-Euler Online")),
description = Seq(StringLiteralV2.from(value = "Bernoulli-Euler Online", language = None)),
keywords = Seq.empty[String],
keywords = List.empty,
logo = None,
ontologies = Seq(
"http://www.knora.org/ontology/0801/beol",
Expand Down Expand Up @@ -741,7 +742,7 @@ object SharedTestDataADM {
shortcode = Shortcode.unsafeFrom("0804"),
longname = Some(Longname.unsafeFrom("Dokubib")),
description = Seq(StringLiteralV2.from(value = "Dokubib", language = None)),
keywords = Seq.empty[String],
keywords = List.empty,
logo = None,
ontologies = Seq("http://www.knora.org/ontology/0804/dokubib"),
status = Status.Inactive,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import org.knora.webapi.slice.admin.domain.model.GroupName
import org.knora.webapi.slice.admin.domain.model.GroupSelfJoin
import org.knora.webapi.slice.admin.domain.model.GroupStatus
import org.knora.webapi.slice.admin.domain.model.KnoraProject.CopyrightAttribution
import org.knora.webapi.slice.admin.domain.model.KnoraProject.Keyword
import org.knora.webapi.slice.admin.domain.model.KnoraProject.License
import org.knora.webapi.slice.admin.domain.model.KnoraProject.Longname
import org.knora.webapi.slice.admin.domain.model.KnoraProject.ProjectIri
Expand Down Expand Up @@ -95,7 +96,7 @@ object Examples {
shortcode = Shortcode.unsafeFrom("0001"),
longname = Some(Longname.unsafeFrom("Example Project")),
description = Seq(StringLiteralV2.from("An example project", Some("en"))),
keywords = Seq("example", "project"),
keywords = List("example", "project").map(Keyword.unsafeFrom),
logo = None,
status = Active,
ontologies = Seq.empty,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ case class Project(
shortcode: Shortcode,
longname: Option[Longname],
description: Seq[StringLiteralV2],
keywords: Seq[String],
keywords: List[Keyword],
logo: Option[Logo],
ontologies: Seq[IRI],
status: Status,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ final case class ProjectService(
knoraProject.shortcode,
knoraProject.longname,
knoraProject.description.map(_.value),
knoraProject.keywords.map(_.value),
knoraProject.keywords,
knoraProject.logo,
ontologies,
knoraProject.status,
Expand All @@ -70,7 +70,7 @@ final case class ProjectService(
description = NonEmptyChunk
.fromIterable(project.description.head, project.description.tail)
.map(Description.unsafeFrom),
keywords = project.keywords.map(Keyword.unsafeFrom).toList,
keywords = project.keywords,
logo = project.logo,
status = project.status,
selfjoin = project.selfjoin,
Expand Down

0 comments on commit 804e35a

Please sign in to comment.