Skip to content

Commit

Permalink
Merge branch 'main' into feat/add-copyright-holder-and-authorship-to-…
Browse files Browse the repository at this point in the history
…filevalue
  • Loading branch information
seakayone committed Jan 23, 2025
2 parents c3c1955 + 513848a commit 9b473ec
Show file tree
Hide file tree
Showing 25 changed files with 585 additions and 170 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ class ProjectsADME2ESpec extends E2ESpec with SprayJsonSupport {
result.id should be(customProjectIri)

// check the rest of project info
result.shortcode should be("3333")
result.shortname should be("newprojectWithIri")
result.shortcode.value should be("3333")
result.shortname.value 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(StringLiteralV2.from("a project created with a custom IRI", Some("en"))))
Expand Down Expand Up @@ -229,8 +229,8 @@ class ProjectsADME2ESpec extends E2ESpec with SprayJsonSupport {
response.status should be(StatusCodes.OK)

val result = AkkaHttpUtils.httpResponseToJson(response).fields("project").convertTo[Project]
result.shortname should be("newproject")
result.shortcode should be("1111")
result.shortname.value should be("newproject")
result.shortcode.value should be("1111")
result.longname should be(Some("project longname"))
result.description should be(Seq(StringLiteralV2.from(value = "project description", language = Some("en"))))
result.keywords should be(Seq("keywords"))
Expand Down Expand Up @@ -354,8 +354,8 @@ class ProjectsADME2ESpec extends E2ESpec with SprayJsonSupport {
response.status should be(StatusCodes.OK)

val result: Project = AkkaHttpUtils.httpResponseToJson(response).fields("project").convertTo[Project]
result.shortname should be("newproject")
result.shortcode should be("1111")
result.shortname.value should be("newproject")
result.shortcode.value should be("1111")
result.longname should be(Some("updated project longname"))
result.description should be(
Seq(StringLiteralV2.from(value = "updated project description", language = Some("en"))),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,9 @@ import org.knora.webapi.slice.admin.api.model.Project
import org.knora.webapi.slice.admin.api.model.ProjectAdminMembersGetResponseADM
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.CopyrightHolder
import org.knora.webapi.slice.admin.domain.model.Group
import org.knora.webapi.slice.admin.domain.model.LicenseIdentifier
import org.knora.webapi.slice.admin.domain.model.LicenseUri
import org.knora.webapi.slice.admin.domain.model.User
import org.knora.webapi.slice.admin.domain.model.*
import org.knora.webapi.slice.admin.domain.model.KnoraProject.Shortcode
import org.knora.webapi.slice.admin.domain.model.KnoraProject.Shortname
import org.knora.webapi.slice.common.Value.StringValue

/**
Expand Down Expand Up @@ -216,6 +214,14 @@ object IntegrationTestAdminJsonProtocol extends TriplestoreJsonProtocol {
override val from: String => Either[String, LicenseUri] = LicenseUri.from
}

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

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

implicit val groupFormat: JsonFormat[Group] = jsonFormat6(Group.apply)

implicit val projectAdminMembersGetResponseADMFormat: RootJsonFormat[ProjectAdminMembersGetResponseADM] = rootFormat(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ import org.knora.webapi.messages.v2.responder.resourcemessages.CreateResourceV2
import org.knora.webapi.messages.v2.responder.resourcemessages.CreateValueInNewResourceV2
import org.knora.webapi.sharedtestdata.SharedTestDataADM
import org.knora.webapi.slice.admin.api.model.Project
import org.knora.webapi.slice.admin.domain.model.Authorship
import org.knora.webapi.slice.admin.domain.model.CopyrightHolder
import org.knora.webapi.slice.admin.domain.model.LicenseIdentifier
import org.knora.webapi.slice.admin.domain.model.LicenseUri
import org.knora.webapi.slice.admin.domain.model.*
import org.knora.webapi.slice.admin.domain.model.KnoraProject.*

sealed abstract case class UploadFileRequest private (
fileType: FileType,
Expand All @@ -41,7 +39,7 @@ sealed abstract case class UploadFileRequest private (
* @return JSON-LD serialization of the request.
*/
def toJsonLd(
shortcode: String = "0001",
shortcode: Shortcode = Shortcode.unsafeFrom("0001"),
ontologyName: String = "knora-api",
className: Option[String] = None,
ontologyIRI: Option[String] = None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import org.knora.webapi.messages.v2.responder.resourcemessages.CreateValueInNewR
import org.knora.webapi.messages.v2.responder.valuemessages.DocumentFileValueContentV2
import org.knora.webapi.messages.v2.responder.valuemessages.FileValueV2
import org.knora.webapi.sharedtestdata.SharedTestDataADM
import org.knora.webapi.slice.admin.domain.model.KnoraProject.Shortcode

class FileModelsSpec extends CoreSpec {
implicit val stringFormatter: StringFormatter = StringFormatter.getGeneralInstance
Expand Down Expand Up @@ -414,8 +415,8 @@ class FileModelsSpec extends CoreSpec {

"creating a ChangeFileRequest," should {
"create a valid representation of a DocumentRepresentation with default values" in {
val resourceIRI = stringFormatter.makeRandomResourceIri("0000")
val valueIRI = stringFormatter.makeRandomResourceIri("0000")
val resourceIRI = stringFormatter.makeRandomResourceIri(Shortcode.unsafeFrom("0000"))
val valueIRI = stringFormatter.makeRandomResourceIri(Shortcode.unsafeFrom("0000"))

val change = ChangeFileRequest.make(
fileType = FileType.DocumentFile(),
Expand All @@ -438,8 +439,8 @@ class FileModelsSpec extends CoreSpec {
}

"create a valid representation of a DocumentRepresentation with custom values" in {
val resourceIRI = stringFormatter.makeRandomResourceIri("0000")
val valueIRI = stringFormatter.makeRandomResourceIri("0000")
val resourceIRI = stringFormatter.makeRandomResourceIri(Shortcode.unsafeFrom("0000"))
val valueIRI = stringFormatter.makeRandomResourceIri(Shortcode.unsafeFrom("0000"))
val pageCount = Some(33)
val dimX = Some(44)
val dimY = Some(55)
Expand Down Expand Up @@ -473,8 +474,8 @@ class FileModelsSpec extends CoreSpec {
}

"create a valid representation of a StillImageRepresentation with default values" in {
val resourceIRI = stringFormatter.makeRandomResourceIri("0000")
val valueIRI = stringFormatter.makeRandomResourceIri("0000")
val resourceIRI = stringFormatter.makeRandomResourceIri(Shortcode.unsafeFrom("0000"))
val valueIRI = stringFormatter.makeRandomResourceIri(Shortcode.unsafeFrom("0000"))

val change = ChangeFileRequest.make(
fileType = FileType.StillImageFile(),
Expand All @@ -496,8 +497,8 @@ class FileModelsSpec extends CoreSpec {
}

"create a valid representation of a MovingImageRepresentation with default values" in {
val resourceIRI = stringFormatter.makeRandomResourceIri("0000")
val valueIRI = stringFormatter.makeRandomResourceIri("0000")
val resourceIRI = stringFormatter.makeRandomResourceIri(Shortcode.unsafeFrom("0000"))
val valueIRI = stringFormatter.makeRandomResourceIri(Shortcode.unsafeFrom("0000"))

val change = ChangeFileRequest.make(
fileType = FileType.MovingImageFile(),
Expand All @@ -519,8 +520,8 @@ class FileModelsSpec extends CoreSpec {
}

"create a valid representation of a AudioRepresentation with default values" in {
val resourceIRI = stringFormatter.makeRandomResourceIri("0000")
val valueIRI = stringFormatter.makeRandomResourceIri("0000")
val resourceIRI = stringFormatter.makeRandomResourceIri(Shortcode.unsafeFrom("0000"))
val valueIRI = stringFormatter.makeRandomResourceIri(Shortcode.unsafeFrom("0000"))

val change = ChangeFileRequest.make(
fileType = FileType.AudioFile,
Expand All @@ -537,8 +538,8 @@ class FileModelsSpec extends CoreSpec {
}

"create a valid representation of a TextRepresentation with default values" in {
val resourceIRI = stringFormatter.makeRandomResourceIri("0000")
val valueIRI = stringFormatter.makeRandomResourceIri("0000")
val resourceIRI = stringFormatter.makeRandomResourceIri(Shortcode.unsafeFrom("0000"))
val valueIRI = stringFormatter.makeRandomResourceIri(Shortcode.unsafeFrom("0000"))

val change = ChangeFileRequest.make(
fileType = FileType.TextFile,
Expand All @@ -555,8 +556,8 @@ class FileModelsSpec extends CoreSpec {
}

"create a valid representation of a ArchiveRepresentation with default values" in {
val resourceIRI = stringFormatter.makeRandomResourceIri("0000")
val valueIRI = stringFormatter.makeRandomResourceIri("0000")
val resourceIRI = stringFormatter.makeRandomResourceIri(Shortcode.unsafeFrom("0000"))
val valueIRI = stringFormatter.makeRandomResourceIri(Shortcode.unsafeFrom("0000"))

val change = ChangeFileRequest.make(
fileType = FileType.ArchiveFile,
Expand All @@ -575,8 +576,8 @@ class FileModelsSpec extends CoreSpec {

"generating a JSON-LD representation of a ChangeFileRequest," should {
"correctly serialize a DocumentRepresentation with default values" in {
val resourceIRI = stringFormatter.makeRandomResourceIri("7777")
val valueIRI = stringFormatter.makeRandomResourceIri("7777")
val resourceIRI = stringFormatter.makeRandomResourceIri(Shortcode.unsafeFrom("7777"))
val valueIRI = stringFormatter.makeRandomResourceIri(Shortcode.unsafeFrom("7777"))

val documentRepresentation = ChangeFileRequest.make(
fileType = FileType.DocumentFile(),
Expand Down Expand Up @@ -604,8 +605,8 @@ class FileModelsSpec extends CoreSpec {
}

"correctly serialize a DocumentRepresentation with custom values" in {
val resourceIRI = stringFormatter.makeRandomResourceIri("7777")
val valueIRI = stringFormatter.makeRandomResourceIri("7777")
val resourceIRI = stringFormatter.makeRandomResourceIri(Shortcode.unsafeFrom("7777"))
val valueIRI = stringFormatter.makeRandomResourceIri(Shortcode.unsafeFrom("7777"))
val className = "CustomDocumentRepresentation"
val prefix = "onto"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class ProjectRestServiceSpec extends CoreSpec with ImplicitSender {

"return information about a project identified by shortname" in {
val actual = UnsafeZioRun.runOrThrow(
ProjectRestService(_.findByShortname(SharedTestDataADM.incunabulaProject.getShortname)),
ProjectRestService(_.findByShortname(SharedTestDataADM.incunabulaProject.shortname)),
)
assert(actual == ProjectGetResponse(toExternal(SharedTestDataADM.incunabulaProject)))
}
Expand Down Expand Up @@ -106,7 +106,7 @@ class ProjectRestServiceSpec extends CoreSpec with ImplicitSender {
"return restricted view settings using project SHORTNAME" in {
val actual = UnsafeZioRun.runOrThrow(
ProjectRestService(
_.getProjectRestrictedViewSettingsByShortname(SharedTestDataADM.imagesProject.getShortname),
_.getProjectRestrictedViewSettingsByShortname(SharedTestDataADM.imagesProject.shortname),
),
)
actual shouldEqual expectedResult
Expand All @@ -115,7 +115,7 @@ class ProjectRestServiceSpec extends CoreSpec with ImplicitSender {
"return restricted view settings using project SHORTCODE" in {
val actual = UnsafeZioRun.runOrThrow(
ProjectRestService(
_.getProjectRestrictedViewSettingsByShortcode(SharedTestDataADM.imagesProject.getShortcode),
_.getProjectRestrictedViewSettingsByShortcode(SharedTestDataADM.imagesProject.shortcode),
),
)
actual shouldEqual expectedResult
Expand Down Expand Up @@ -168,8 +168,8 @@ class ProjectRestServiceSpec extends CoreSpec with ImplicitSender {
),
)

received.project.shortname should be("newproject")
received.project.shortcode should be(shortcode.toUpperCase) // upper case
received.project.shortname.value should be("newproject")
received.project.shortcode.value should be(shortcode.toUpperCase) // upper case
received.project.longname should contain("project longname")
received.project.description should be(
Seq(StringLiteralV2.from(value = "project description", language = Some("en"))),
Expand Down Expand Up @@ -262,8 +262,8 @@ class ProjectRestServiceSpec extends CoreSpec with ImplicitSender {
),
)

received.project.shortname should be("newproject2")
received.project.shortcode should be("1112")
received.project.shortname.value should be("newproject2")
received.project.shortcode.value should be("1112")
received.project.longname should contain("project longname")
received.project.description should be(
Seq(StringLiteralV2.from(value = "project description", language = Some("en"))),
Expand Down Expand Up @@ -382,8 +382,8 @@ class ProjectRestServiceSpec extends CoreSpec with ImplicitSender {
),
),
)
received.project.shortname should be("newproject")
received.project.shortcode should be("111C")
received.project.shortname.value should be("newproject")
received.project.shortcode.value should be("111C")
received.project.longname should be(Some("updated project longname"))
received.project.description should be(
Seq(
Expand Down Expand Up @@ -436,7 +436,7 @@ class ProjectRestServiceSpec extends CoreSpec with ImplicitSender {
"return all members of a project identified by shortname" in {
val actual = UnsafeZioRun.runOrThrow(
ProjectRestService(
_.getProjectMembersByShortname(SharedTestDataADM.rootUser, SharedTestDataADM.imagesProject.getShortname),
_.getProjectMembersByShortname(SharedTestDataADM.rootUser, SharedTestDataADM.imagesProject.shortname),
),
)

Expand All @@ -453,7 +453,7 @@ class ProjectRestServiceSpec extends CoreSpec with ImplicitSender {
"return all members of a project identified by shortcode" in {
val actual = UnsafeZioRun.runOrThrow(
ProjectRestService(
_.getProjectMembersByShortcode(SharedTestDataADM.rootUser, SharedTestDataADM.imagesProject.getShortcode),
_.getProjectMembersByShortcode(SharedTestDataADM.rootUser, SharedTestDataADM.imagesProject.shortcode),
),
)

Expand Down Expand Up @@ -512,7 +512,7 @@ class ProjectRestServiceSpec extends CoreSpec with ImplicitSender {
ProjectRestService(
_.getProjectAdminMembersByShortname(
SharedTestDataADM.rootUser,
SharedTestDataADM.imagesProject.getShortname,
SharedTestDataADM.imagesProject.shortname,
),
),
)
Expand All @@ -530,7 +530,7 @@ class ProjectRestServiceSpec extends CoreSpec with ImplicitSender {
ProjectRestService(
_.getProjectAdminMembersByShortcode(
SharedTestDataADM.rootUser,
SharedTestDataADM.imagesProject.getShortcode,
SharedTestDataADM.imagesProject.shortcode,
),
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ case class ProjectInfo(
)

object ProjectInfo {
def from(projectADM: Project): ProjectInfo =
def from(project: Project): ProjectInfo =
ProjectInfo(
id = projectADM.id,
shortname = projectADM.shortname,
shortcode = projectADM.shortcode,
longname = projectADM.longname,
description = projectADM.description.headOption.map(_.value),
keywords = projectADM.keywords.headOption.map(_ => projectADM.keywords.mkString(", ")),
logo = projectADM.logo,
ontologies = projectADM.ontologies,
status = projectADM.status,
selfjoin = projectADM.selfjoin,
id = project.id,
shortname = project.shortname.value,
shortcode = project.shortcode.value,
longname = project.longname,
description = project.description.headOption.map(_.value),
keywords = project.keywords.headOption.map(_ => project.keywords.mkString(", ")),
logo = project.logo,
ontologies = project.ontologies,
status = project.status,
selfjoin = project.selfjoin,
)
}
Loading

0 comments on commit 9b473ec

Please sign in to comment.