diff --git a/integration/src/test/scala/org/knora/webapi/e2e/admin/ProjectsADME2ESpec.scala b/integration/src/test/scala/org/knora/webapi/e2e/admin/ProjectsADME2ESpec.scala index 441c453faf..2261f09572 100644 --- a/integration/src/test/scala/org/knora/webapi/e2e/admin/ProjectsADME2ESpec.scala +++ b/integration/src/test/scala/org/knora/webapi/e2e/admin/ProjectsADME2ESpec.scala @@ -42,7 +42,7 @@ class ProjectsADME2ESpec extends E2ESpec with SprayJsonSupport { private val testPass = SharedTestDataADM.testPass private val projectIri = SharedTestDataADM.imagesProject.id private val projectIriEnc = URLEncoder.encode(projectIri, "utf-8") - private val projectShortname = SharedTestDataADM.imagesProject.shortname.value + private val projectShortname = SharedTestDataADM.imagesProject.shortname private val projectShortcode = SharedTestDataADM.imagesProject.shortcode override lazy val rdfDataObjects: List[RdfDataObject] = List( @@ -170,7 +170,7 @@ class ProjectsADME2ESpec extends E2ESpec with SprayJsonSupport { result.id should be(customProjectIri) // check the rest of project info - result.shortcode should be("3333") + 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")) @@ -230,7 +230,7 @@ class ProjectsADME2ESpec extends E2ESpec with SprayJsonSupport { val result = AkkaHttpUtils.httpResponseToJson(response).fields("project").convertTo[Project] result.shortname.value should be("newproject") - result.shortcode should be("1111") + 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")) @@ -355,7 +355,7 @@ class ProjectsADME2ESpec extends E2ESpec with SprayJsonSupport { val result: Project = AkkaHttpUtils.httpResponseToJson(response).fields("project").convertTo[Project] result.shortname.value should be("newproject") - result.shortcode should be("1111") + 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"))), @@ -429,9 +429,10 @@ class ProjectsADME2ESpec extends E2ESpec with SprayJsonSupport { } "return all members of a project identified by shortcode" in { - val request = Get(baseApiUrl + s"/admin/projects/shortcode/$projectShortcode/members") ~> addCredentials( - BasicHttpCredentials(rootEmail, testPass), - ) + val request = + Get(baseApiUrl + s"/admin/projects/shortcode/$projectShortcode/members") ~> addCredentials( + BasicHttpCredentials(rootEmail, testPass), + ) val response: HttpResponse = singleAwaitingRequest(request) assert(response.status === StatusCodes.OK) @@ -465,9 +466,10 @@ class ProjectsADME2ESpec extends E2ESpec with SprayJsonSupport { } "return all admin members of a project identified by shortcode" in { - val request = Get(baseApiUrl + s"/admin/projects/shortcode/$projectShortcode/admin-members") ~> addCredentials( - BasicHttpCredentials(rootEmail, testPass), - ) + val request = + Get(baseApiUrl + s"/admin/projects/shortcode/$projectShortcode/admin-members") ~> addCredentials( + BasicHttpCredentials(rootEmail, testPass), + ) val response: HttpResponse = singleAwaitingRequest(request) assert(response.status === StatusCodes.OK) diff --git a/integration/src/test/scala/org/knora/webapi/messages/admin/responder/IntegrationTestAdminJsonProtocol.scala b/integration/src/test/scala/org/knora/webapi/messages/admin/responder/IntegrationTestAdminJsonProtocol.scala index 01692e065a..a3031d7e65 100644 --- a/integration/src/test/scala/org/knora/webapi/messages/admin/responder/IntegrationTestAdminJsonProtocol.scala +++ b/integration/src/test/scala/org/knora/webapi/messages/admin/responder/IntegrationTestAdminJsonProtocol.scala @@ -48,6 +48,7 @@ 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.LicenseText import org.knora.webapi.slice.admin.domain.model.KnoraProject.LicenseUri +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.admin.domain.model.User import org.knora.webapi.slice.common.Value.StringValue @@ -221,6 +222,10 @@ object IntegrationTestAdminJsonProtocol extends TriplestoreJsonProtocol { 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( diff --git a/integration/src/test/scala/org/knora/webapi/models/filemodels/FileModelsSpec.scala b/integration/src/test/scala/org/knora/webapi/models/filemodels/FileModelsSpec.scala index 9c895f0ea7..9b49f1d299 100644 --- a/integration/src/test/scala/org/knora/webapi/models/filemodels/FileModelsSpec.scala +++ b/integration/src/test/scala/org/knora/webapi/models/filemodels/FileModelsSpec.scala @@ -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 @@ -263,7 +264,7 @@ class FileModelsSpec extends CoreSpec { .toJsonLd( className = className, ontologyName = ontologyName, - shortcode = shortcode, + shortcode = shortcode.value, ontologyIRI = ontologyIRI, ) .parseJson @@ -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(), @@ -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) @@ -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(), @@ -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(), @@ -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, @@ -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, @@ -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, @@ -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(), @@ -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" diff --git a/integration/src/test/scala/org/knora/webapi/responders/admin/ProjectRestServiceSpec.scala b/integration/src/test/scala/org/knora/webapi/responders/admin/ProjectRestServiceSpec.scala index 08a60840f1..711eac2425 100644 --- a/integration/src/test/scala/org/knora/webapi/responders/admin/ProjectRestServiceSpec.scala +++ b/integration/src/test/scala/org/knora/webapi/responders/admin/ProjectRestServiceSpec.scala @@ -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 @@ -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), ), ) @@ -530,7 +530,7 @@ class ProjectRestServiceSpec extends CoreSpec with ImplicitSender { ProjectRestService( _.getProjectAdminMembersByShortcode( SharedTestDataADM.rootUser, - SharedTestDataADM.imagesProject.getShortcode, + SharedTestDataADM.imagesProject.shortcode, ), ), ) diff --git a/integration/src/test/scala/org/knora/webapi/sharedtestdata/ProjectInfo.scala b/integration/src/test/scala/org/knora/webapi/sharedtestdata/ProjectInfo.scala index 42ef792243..8280ea98dd 100644 --- a/integration/src/test/scala/org/knora/webapi/sharedtestdata/ProjectInfo.scala +++ b/integration/src/test/scala/org/knora/webapi/sharedtestdata/ProjectInfo.scala @@ -39,7 +39,7 @@ object ProjectInfo { ProjectInfo( id = project.id, shortname = project.shortname.value, - shortcode = project.shortcode, + shortcode = project.shortcode.value, longname = project.longname, description = project.description.headOption.map(_.value), keywords = project.keywords.headOption.map(_ => project.keywords.mkString(", ")), diff --git a/integration/src/test/scala/org/knora/webapi/sharedtestdata/SharedTestDataADM.scala b/integration/src/test/scala/org/knora/webapi/sharedtestdata/SharedTestDataADM.scala index 28232858c4..1a209f2654 100644 --- a/integration/src/test/scala/org/knora/webapi/sharedtestdata/SharedTestDataADM.scala +++ b/integration/src/test/scala/org/knora/webapi/sharedtestdata/SharedTestDataADM.scala @@ -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.Shortcode import org.knora.webapi.slice.admin.domain.model.KnoraProject.Shortname import org.knora.webapi.slice.admin.domain.model.Permission import org.knora.webapi.slice.admin.domain.model.User @@ -157,7 +158,7 @@ object SharedTestDataADM { def systemProject: Project = Project( id = KnoraProjectRepo.builtIn.SystemProject.id.value, shortname = Shortname.unsafeFrom("SystemProject"), - shortcode = "FFFF", + shortcode = Shortcode.unsafeFrom("FFFF"), longname = Some("Knora System Project"), description = Seq(StringLiteralV2.from(value = "Knora System Project", language = Some("en"))), keywords = Seq.empty[String], @@ -176,7 +177,7 @@ object SharedTestDataADM { def defaultSharedOntologiesProject: Project = Project( id = OntologyConstants.KnoraAdmin.DefaultSharedOntologiesProject, shortname = Shortname.unsafeFrom("DefaultSharedOntologiesProject"), - shortcode = "0000", + shortcode = Shortcode.unsafeFrom("0000"), longname = Some("Default Knora Shared Ontologies Project"), description = Seq(StringLiteralV2.from(value = "Default Knora Shared Ontologies Project", language = Some("en"))), keywords = Seq.empty[String], @@ -288,7 +289,7 @@ object SharedTestDataADM { def imagesProject: Project = Project( id = imagesProjectIri, shortname = Shortname.unsafeFrom("images"), - shortcode = "00FF", + shortcode = Shortcode.unsafeFrom("00FF"), longname = Some("Image Collection Demo"), description = Seq(StringLiteralV2.from(value = "A demo project of a collection of images", language = Some("en"))), keywords = Seq("images", "collection").sorted, @@ -302,7 +303,7 @@ object SharedTestDataADM { def imagesProjectExternal: Project = Project( id = imagesProjectIri, shortname = Shortname.unsafeFrom("images"), - shortcode = "00FF", + shortcode = Shortcode.unsafeFrom("00FF"), longname = Some("Image Collection Demo"), description = Seq(StringLiteralV2.from(value = "A demo project of a collection of images", language = Some("en"))), keywords = Seq("images", "collection").sorted, @@ -444,7 +445,7 @@ object SharedTestDataADM { def incunabulaProject: Project = Project( id = incunabulaProjectIri, shortname = Shortname.unsafeFrom("incunabula"), - shortcode = "0803", + shortcode = Shortcode.unsafeFrom("0803"), longname = Some("Bilderfolgen Basler Frühdrucke"), description = Seq( StringLiteralV2.from( @@ -479,7 +480,7 @@ object SharedTestDataADM { def incunabulaProjectExternal: Project = Project( id = incunabulaProjectIri, shortname = Shortname.unsafeFrom("incunabula"), - shortcode = "0803", + shortcode = Shortcode.unsafeFrom("0803"), longname = Some("Bilderfolgen Basler Frühdrucke"), description = Seq( StringLiteralV2.from( @@ -612,7 +613,7 @@ object SharedTestDataADM { def anythingProject: Project = Project( id = anythingProjectIri, shortname = Shortname.unsafeFrom("anything"), - shortcode = "0001", + shortcode = Shortcode.unsafeFrom("0001"), longname = Some("Anything Project"), description = Seq(StringLiteralV2.from(value = "Anything Project", language = None)), keywords = Seq("things", "arbitrary test data").sorted, @@ -625,7 +626,7 @@ object SharedTestDataADM { def anythingProjectExternal: Project = Project( id = anythingProjectIri, shortname = Shortname.unsafeFrom("anything"), - shortcode = "0001", + shortcode = Shortcode.unsafeFrom("0001"), longname = Some("Anything Project"), description = Seq(StringLiteralV2.from(value = "Anything Project", language = None)), keywords = Seq("things", "arbitrary test data").sorted, @@ -660,7 +661,7 @@ object SharedTestDataADM { def beolProject: Project = Project( id = beolProjectIri, shortname = Shortname.unsafeFrom("beol"), - shortcode = "0801", + shortcode = Shortcode.unsafeFrom("0801"), longname = Some("Bernoulli-Euler Online"), description = Seq(StringLiteralV2.from(value = "Bernoulli-Euler Online", language = None)), keywords = Seq.empty[String], @@ -714,7 +715,7 @@ object SharedTestDataADM { def dokubibProject: Project = Project( id = dokubibProjectIri, shortname = Shortname.unsafeFrom("dokubib"), - shortcode = "0804", + shortcode = Shortcode.unsafeFrom("0804"), longname = Some("Dokubib"), description = Seq(StringLiteralV2.from(value = "Dokubib", language = None)), keywords = Seq.empty[String], diff --git a/webapi/src/main/scala/org/knora/webapi/messages/StringFormatter.scala b/webapi/src/main/scala/org/knora/webapi/messages/StringFormatter.scala index a9051c3402..7662b0511d 100644 --- a/webapi/src/main/scala/org/knora/webapi/messages/StringFormatter.scala +++ b/webapi/src/main/scala/org/knora/webapi/messages/StringFormatter.scala @@ -1590,9 +1590,9 @@ class StringFormatter private ( * @param projectShortcode the project's shortcode. * @return a new resource IRI. */ - def makeRandomResourceIri(projectShortcode: String): IRI = { + def makeRandomResourceIri(shortcode: Shortcode): IRI = { val knoraResourceID = UuidUtil.makeRandomBase64EncodedUuid - s"http://$IriDomain/$projectShortcode/$knoraResourceID" + s"http://$IriDomain/${shortcode.value}/$knoraResourceID" } /** diff --git a/webapi/src/main/scala/org/knora/webapi/slice/admin/api/Examples.scala b/webapi/src/main/scala/org/knora/webapi/slice/admin/api/Examples.scala index 3dd7fb8782..0f839be34f 100644 --- a/webapi/src/main/scala/org/knora/webapi/slice/admin/api/Examples.scala +++ b/webapi/src/main/scala/org/knora/webapi/slice/admin/api/Examples.scala @@ -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.ProjectIri +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.admin.domain.model.User import org.knora.webapi.slice.admin.domain.model.UserIri @@ -86,7 +87,7 @@ object Examples { private val project: Project = Project( id = ProjectExample.projectIri.value, shortname = Shortname.unsafeFrom("example"), - shortcode = "0001", + shortcode = Shortcode.unsafeFrom("0001"), longname = Some("Example Project"), description = Seq(StringLiteralV2.from("An example project", Some("en"))), keywords = Seq("example", "project"), diff --git a/webapi/src/main/scala/org/knora/webapi/slice/admin/api/model/ProjectsMessagesADM.scala b/webapi/src/main/scala/org/knora/webapi/slice/admin/api/model/ProjectsMessagesADM.scala index d7c0b6809c..79bc017c6d 100644 --- a/webapi/src/main/scala/org/knora/webapi/slice/admin/api/model/ProjectsMessagesADM.scala +++ b/webapi/src/main/scala/org/knora/webapi/slice/admin/api/model/ProjectsMessagesADM.scala @@ -11,6 +11,7 @@ import zio.json.JsonCodec import org.knora.webapi.IRI import org.knora.webapi.messages.admin.responder.AdminKnoraResponseADM import org.knora.webapi.messages.store.triplestoremessages.StringLiteralV2 +import org.knora.webapi.slice.admin.api.Codecs.ZioJsonCodec.shortcode import org.knora.webapi.slice.admin.api.Codecs.ZioJsonCodec.shortname import org.knora.webapi.slice.admin.domain.model.KnoraProject.* import org.knora.webapi.slice.admin.domain.model.RestrictedView @@ -33,7 +34,7 @@ import org.knora.webapi.slice.admin.domain.model.User case class Project( id: IRI, shortname: Shortname, - shortcode: String, + shortcode: Shortcode, longname: Option[String], description: Seq[StringLiteralV2], keywords: Seq[String], @@ -45,8 +46,6 @@ case class Project( def projectIri: ProjectIri = ProjectIri.unsafeFrom(id) - def getShortcode: Shortcode = Shortcode.unsafeFrom(shortcode) - /** * Allows to sort collections of ProjectADM. Sorting is done by the id. */ diff --git a/webapi/src/main/scala/org/knora/webapi/slice/admin/domain/service/ProjectService.scala b/webapi/src/main/scala/org/knora/webapi/slice/admin/domain/service/ProjectService.scala index 104078ee73..ac440055a4 100644 --- a/webapi/src/main/scala/org/knora/webapi/slice/admin/domain/service/ProjectService.scala +++ b/webapi/src/main/scala/org/knora/webapi/slice/admin/domain/service/ProjectService.scala @@ -48,7 +48,7 @@ final case class ProjectService( Project( knoraProject.id.value, knoraProject.shortname, - knoraProject.shortcode.value, + knoraProject.shortcode, knoraProject.longname.map(_.value), knoraProject.description.map(_.value), knoraProject.keywords.map(_.value), @@ -63,7 +63,7 @@ final case class ProjectService( KnoraProject( id = ProjectIri.unsafeFrom(project.id), shortname = project.shortname, - shortcode = Shortcode.unsafeFrom(project.shortcode), + shortcode = project.shortcode, longname = project.longname.map(Longname.unsafeFrom), description = NonEmptyChunk .fromIterable(project.description.head, project.description.tail) @@ -93,10 +93,8 @@ object ProjectService { * @param project A [[ProjectADM]]. * @return the [[InternalIri]] of the project's data named graph. */ - def projectDataNamedGraphV2(project: Project): InternalIri = { - val shortcode = Shortcode.unsafeFrom(project.shortcode) - projectDataNamedGraphV2(shortcode, project.shortname) - } + def projectDataNamedGraphV2(project: Project): InternalIri = + projectDataNamedGraphV2(project.shortcode, project.shortname) /** * Given the [[KnoraProject]] constructs the project's data named graph. diff --git a/webapi/src/main/scala/org/knora/webapi/slice/common/ApiComplexV2JsonLdRequestParser.scala b/webapi/src/main/scala/org/knora/webapi/slice/common/ApiComplexV2JsonLdRequestParser.scala index 9653018045..e7d82b5d17 100644 --- a/webapi/src/main/scala/org/knora/webapi/slice/common/ApiComplexV2JsonLdRequestParser.scala +++ b/webapi/src/main/scala/org/knora/webapi/slice/common/ApiComplexV2JsonLdRequestParser.scala @@ -238,9 +238,9 @@ final case class ApiComplexV2JsonLdRequestParser( project <- attachedToProject(r.resource) _ <- ZIO .fail("Resource IRI and project IRI must reference the same project") - .when(r.resourceIri.exists(_.shortcode != project.getShortcode)) + .when(r.resourceIri.exists(_.shortcode != project.shortcode)) attachedToUser <- attachedToUser(r.resource, requestingUser, project.projectIri) - values <- extractValues(r.resource, project.getShortcode) + values <- extractValues(r.resource, project.shortcode) } yield CreateResourceRequestV2( CreateResourceV2( r.resourceIri.map(_.smartIri), diff --git a/webapi/src/main/scala/org/knora/webapi/slice/common/ValueTypes.scala b/webapi/src/main/scala/org/knora/webapi/slice/common/ValueTypes.scala index 5a1db97fb9..3cc2ac9d08 100644 --- a/webapi/src/main/scala/org/knora/webapi/slice/common/ValueTypes.scala +++ b/webapi/src/main/scala/org/knora/webapi/slice/common/ValueTypes.scala @@ -12,6 +12,7 @@ import org.knora.webapi.slice.common.Value.StringValue trait Value[A] extends Any { def value: A + override def toString: String = value.toString } object Value { diff --git a/webapi/src/test/scala/org/knora/webapi/slice/admin/domain/service/ProjectServiceSpec.scala b/webapi/src/test/scala/org/knora/webapi/slice/admin/domain/service/ProjectServiceSpec.scala index def3f7bb8a..f45666a9f3 100644 --- a/webapi/src/test/scala/org/knora/webapi/slice/admin/domain/service/ProjectServiceSpec.scala +++ b/webapi/src/test/scala/org/knora/webapi/slice/admin/domain/service/ProjectServiceSpec.scala @@ -20,10 +20,10 @@ import org.knora.webapi.slice.resourceinfo.domain.IriTestConstants object ProjectServiceSpec extends ZIOSpecDefault { val spec: Spec[Any, Nothing] = - suite("projectDataNamedGraphV2 should return the data named graph of a project with shortcode for")( + suite("projectDataNamedGraphV2 shouldshortcodefor")( test("a ProjectADM") { val shortname = Shortname.unsafeFrom("someProject") - val shortcode = "0001" + val shortcode = Shortcode.unsafeFrom("0001") val p = Project( id = IriTestConstants.Project.TestProject, shortname = shortname, @@ -37,7 +37,9 @@ object ProjectServiceSpec extends ZIOSpecDefault { selfjoin = true, ) assertTrue( - ProjectService.projectDataNamedGraphV2(p).value == s"http://www.knora.org/data/$shortcode/${shortname.value}", + ProjectService + .projectDataNamedGraphV2(p) + .value == s"http://www.knora.org/data/${shortcode.value}/${shortname.value}", ) }, test("a KnoraProject") {