diff --git a/integration/src/test/scala/org/knora/sipi/SipiIT.scala b/integration/src/test/scala/org/knora/sipi/SipiIT.scala index d0fbd56a14..2c97b45c65 100644 --- a/integration/src/test/scala/org/knora/sipi/SipiIT.scala +++ b/integration/src/test/scala/org/knora/sipi/SipiIT.scala @@ -42,10 +42,11 @@ object SipiIT extends ZIOSpecDefault { .map(Request.get) .flatMap(Client.request(_)) - private val getToken = JwtService - .createJwt(SystemUser) - .map(_.jwtString) - .provide(JwtServiceLive.layer, AppConfig.layer) + private val getToken = + ZIO + .serviceWithZIO[JwtService](_.createJwt(SystemUser)) + .map(_.jwtString) + .provide(JwtServiceLive.layer, AppConfig.layer) private val cookiesSuite = suite("Given a request is authorized using cookies")( diff --git a/integration/src/test/scala/org/knora/webapi/CoreSpec.scala b/integration/src/test/scala/org/knora/webapi/CoreSpec.scala index 48aef9a728..8136c0ed5e 100644 --- a/integration/src/test/scala/org/knora/webapi/CoreSpec.scala +++ b/integration/src/test/scala/org/knora/webapi/CoreSpec.scala @@ -13,6 +13,7 @@ import org.scalatest.BeforeAndAfterAll import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AnyWordSpec import zio.* +import zio.ZIO import scala.concurrent.ExecutionContext import scala.concurrent.duration.FiniteDuration @@ -24,7 +25,9 @@ import org.knora.webapi.core.AppServer import org.knora.webapi.core.LayersTest.DefaultTestEnvironmentWithoutSipi import org.knora.webapi.core.TestStartupUtils import org.knora.webapi.messages.store.triplestoremessages.RdfDataObject +import org.knora.webapi.routing.JwtService import org.knora.webapi.routing.UnsafeZioRun +import org.knora.webapi.slice.admin.domain.model.User import org.knora.webapi.util.LogAspect abstract class CoreSpec @@ -114,4 +117,5 @@ abstract class CoreSpec runtime.unsafe.shutdown() } + protected def createJwtTokenString(user: User) = ZIO.serviceWithZIO[JwtService](_.createJwt(user)).map(_.jwtString) } diff --git a/integration/src/test/scala/org/knora/webapi/core/LayersTest.scala b/integration/src/test/scala/org/knora/webapi/core/LayersTest.scala index b78b76832d..006c2aa904 100644 --- a/integration/src/test/scala/org/knora/webapi/core/LayersTest.scala +++ b/integration/src/test/scala/org/knora/webapi/core/LayersTest.scala @@ -37,6 +37,7 @@ import org.knora.webapi.slice.admin.api.service.ProjectsADMRestServiceLive import org.knora.webapi.slice.admin.api.service.StoreRestService import org.knora.webapi.slice.admin.api.service.UsersRestService import org.knora.webapi.slice.admin.domain.service.* +import org.knora.webapi.slice.admin.domain.service.MaintenanceService import org.knora.webapi.slice.admin.repo.service.KnoraGroupRepoLive import org.knora.webapi.slice.admin.repo.service.KnoraProjectRepoLive import org.knora.webapi.slice.admin.repo.service.KnoraUserRepoLive @@ -201,7 +202,7 @@ object LayersTest { MaintenanceEndpoints.layer, MaintenanceEndpointsHandlers.layer, MaintenanceRestService.layer, - MaintenanceServiceLive.layer, + MaintenanceService.layer, ManagementRoutes.layer, MessageRelayLive.layer, OntologyCacheLive.layer, diff --git a/integration/src/test/scala/org/knora/webapi/messages/admin/responder/permissionsmessages/PermissionsMessagesADMSpec.scala b/integration/src/test/scala/org/knora/webapi/messages/admin/responder/permissionsmessages/PermissionsMessagesADMSpec.scala index 529d6dc3c1..e467b758e2 100644 --- a/integration/src/test/scala/org/knora/webapi/messages/admin/responder/permissionsmessages/PermissionsMessagesADMSpec.scala +++ b/integration/src/test/scala/org/knora/webapi/messages/admin/responder/permissionsmessages/PermissionsMessagesADMSpec.scala @@ -5,6 +5,8 @@ package org.knora.webapi.messages.admin.responder.permissionsmessages +import zio.ZIO + import java.util.UUID import dsp.errors.BadRequestException @@ -481,7 +483,8 @@ class PermissionsMessagesADMSpec extends CoreSpec { permissionCode = Some(8), ), ) - val exit = UnsafeZioRun.run(PermissionsResponderADM.verifyHasPermissionsDOAP(hasPermissions)) + val exit = + UnsafeZioRun.run(ZIO.serviceWithZIO[PermissionsResponderADM](_.verifyHasPermissionsDOAP(hasPermissions))) assertFailsWithA[BadRequestException]( exit, "Invalid value for name parameter of hasPermissions: invalid, it should be one of " + @@ -499,7 +502,8 @@ class PermissionsMessagesADMSpec extends CoreSpec { ), ) - val exit = UnsafeZioRun.run(PermissionsResponderADM.verifyHasPermissionsDOAP(hasPermissions)) + val exit = + UnsafeZioRun.run(ZIO.serviceWithZIO[PermissionsResponderADM](_.verifyHasPermissionsDOAP(hasPermissions))) assertFailsWithA[BadRequestException]( exit, s"Invalid value for permissionCode parameter of hasPermissions: $invalidCode, it should be one of " + @@ -518,7 +522,8 @@ class PermissionsMessagesADMSpec extends CoreSpec { ), ) - val exit = UnsafeZioRun.run(PermissionsResponderADM.verifyHasPermissionsDOAP(hasPermissions)) + val exit = + UnsafeZioRun.run(ZIO.serviceWithZIO[PermissionsResponderADM](_.verifyHasPermissionsDOAP(hasPermissions))) assertFailsWithA[BadRequestException]( exit, s"Given permission code $code and permission name $name are not consistent.", @@ -535,7 +540,8 @@ class PermissionsMessagesADMSpec extends CoreSpec { ), ) - val exit = UnsafeZioRun.run(PermissionsResponderADM.verifyHasPermissionsDOAP(hasPermissions)) + val exit = + UnsafeZioRun.run(ZIO.serviceWithZIO[PermissionsResponderADM](_.verifyHasPermissionsDOAP(hasPermissions))) assertFailsWithA[BadRequestException]( exit, s"One of permission code or permission name must be provided for a default object access permission.", @@ -551,7 +557,8 @@ class PermissionsMessagesADMSpec extends CoreSpec { permissionCode = Some(8), ), ) - val exit = UnsafeZioRun.run(PermissionsResponderADM.verifyHasPermissionsDOAP(hasPermissions)) + val exit = + UnsafeZioRun.run(ZIO.serviceWithZIO[PermissionsResponderADM](_.verifyHasPermissionsDOAP(hasPermissions))) assertFailsWithA[BadRequestException]( exit, s"additionalInformation of a default object access permission type cannot be empty.", diff --git a/integration/src/test/scala/org/knora/webapi/responders/admin/GroupsResponderADMSpec.scala b/integration/src/test/scala/org/knora/webapi/responders/admin/GroupsResponderADMSpec.scala index a6df5dcf90..8a7ab066b4 100644 --- a/integration/src/test/scala/org/knora/webapi/responders/admin/GroupsResponderADMSpec.scala +++ b/integration/src/test/scala/org/knora/webapi/responders/admin/GroupsResponderADMSpec.scala @@ -5,6 +5,8 @@ package org.knora.webapi.responders.admin +import zio.* + import java.util.UUID import dsp.errors.* @@ -33,7 +35,7 @@ class GroupsResponderADMSpec extends CoreSpec { "The GroupsResponder " when { "asked about all groups" should { "return a list" in { - val groups = UnsafeZioRun.runOrThrow(GroupsResponderADM.groupsGetADM) + val groups = UnsafeZioRun.runOrThrow(ZIO.serviceWithZIO[GroupsResponderADM](_.groupsGetADM)) assert(groups.nonEmpty) assert(groups.size == 2) } @@ -41,14 +43,15 @@ class GroupsResponderADMSpec extends CoreSpec { "asked about a group identified by 'iri' " should { "return group info if the group is known " in { - val group = UnsafeZioRun.runOrThrow(GroupsResponderADM.groupGetADM(imagesReviewerGroup.id)) + val group = + UnsafeZioRun.runOrThrow(ZIO.serviceWithZIO[GroupsResponderADM](_.groupGetADM(imagesReviewerGroup.id))) assert(group.nonEmpty) assert(group.map(_.id).contains(imagesReviewerGroup.id)) } "return 'None' when the group is unknown " in { val iri = "http://rdfh.ch/groups/notexisting" - val response = UnsafeZioRun.runOrThrow(GroupsResponderADM.groupGetADM(iri)) + val response = UnsafeZioRun.runOrThrow(ZIO.serviceWithZIO[GroupsResponderADM](_.groupGetADM(iri))) assert(response.isEmpty) } } @@ -58,24 +61,26 @@ class GroupsResponderADMSpec extends CoreSpec { "CREATE the group and return the group's info if the supplied group name is unique" in { val response = UnsafeZioRun.runOrThrow( - GroupsResponderADM.createGroup( - GroupCreateRequest( - id = None, - name = GroupName.unsafeFrom("NewGroup"), - descriptions = GroupDescriptions - .unsafeFrom( - Seq( - V2.StringLiteralV2( - value = """NewGroupDescription with "quotes" and """, - language = Some("en"), + ZIO.serviceWithZIO[GroupsResponderADM]( + _.createGroup( + GroupCreateRequest( + id = None, + name = GroupName.unsafeFrom("NewGroup"), + descriptions = GroupDescriptions + .unsafeFrom( + Seq( + V2.StringLiteralV2( + value = """NewGroupDescription with "quotes" and """, + language = Some("en"), + ), ), ), - ), - project = ProjectIri.unsafeFrom(imagesProjectIri), - status = GroupStatus.active, - selfjoin = GroupSelfJoin.disabled, + project = ProjectIri.unsafeFrom(imagesProjectIri), + status = GroupStatus.active, + selfjoin = GroupSelfJoin.disabled, + ), + UUID.randomUUID, ), - UUID.randomUUID, ), ) @@ -95,17 +100,19 @@ class GroupsResponderADMSpec extends CoreSpec { "return a 'DuplicateValueException' if the supplied group name is not unique" in { val groupName = GroupName.unsafeFrom("NewGroup") val exit = UnsafeZioRun.run( - GroupsResponderADM.createGroup( - GroupCreateRequest( - id = Some(GroupIri.unsafeFrom(imagesReviewerGroup.id)), - name = groupName, - descriptions = GroupDescriptions - .unsafeFrom(Seq(V2.StringLiteralV2(value = "NewGroupDescription", language = Some("en")))), - project = ProjectIri.unsafeFrom(imagesProjectIri), - status = GroupStatus.active, - selfjoin = GroupSelfJoin.disabled, + ZIO.serviceWithZIO[GroupsResponderADM]( + _.createGroup( + GroupCreateRequest( + id = Some(GroupIri.unsafeFrom(imagesReviewerGroup.id)), + name = groupName, + descriptions = GroupDescriptions + .unsafeFrom(Seq(V2.StringLiteralV2(value = "NewGroupDescription", language = Some("en")))), + project = ProjectIri.unsafeFrom(imagesProjectIri), + status = GroupStatus.active, + selfjoin = GroupSelfJoin.disabled, + ), + UUID.randomUUID, ), - UUID.randomUUID, ), ) assertFailsWithA[DuplicateValueException]( @@ -116,19 +123,21 @@ class GroupsResponderADMSpec extends CoreSpec { "UPDATE a group" in { val response = UnsafeZioRun.runOrThrow( - GroupsResponderADM.updateGroup( - groupIri = GroupIri.unsafeFrom(newGroupIri.get), - GroupUpdateRequest( - name = Some(GroupName.unsafeFrom("UpdatedGroupName")), - descriptions = Some( - GroupDescriptions.unsafeFrom( - Seq(V2.StringLiteralV2("""UpdatedDescription with "quotes" and """, Some("en"))), + ZIO.serviceWithZIO[GroupsResponderADM]( + _.updateGroup( + groupIri = GroupIri.unsafeFrom(newGroupIri.get), + GroupUpdateRequest( + name = Some(GroupName.unsafeFrom("UpdatedGroupName")), + descriptions = Some( + GroupDescriptions.unsafeFrom( + Seq(V2.StringLiteralV2("""UpdatedDescription with "quotes" and """, Some("en"))), + ), ), + status = Some(GroupStatus.active), + selfjoin = Some(GroupSelfJoin.disabled), ), - status = Some(GroupStatus.active), - selfjoin = Some(GroupSelfJoin.disabled), + UUID.randomUUID, ), - UUID.randomUUID, ), ) val updatedGroupInfo = response.group @@ -144,18 +153,20 @@ class GroupsResponderADMSpec extends CoreSpec { "return 'NotFound' if a not-existing group IRI is submitted during update" in { val groupIri = "http://rdfh.ch/groups/0000/notexisting" val exit = UnsafeZioRun.run( - GroupsResponderADM.updateGroup( - groupIri = GroupIri.unsafeFrom(groupIri), - GroupUpdateRequest( - name = Some(GroupName.unsafeFrom("UpdatedGroupName")), - descriptions = Some( - GroupDescriptions - .unsafeFrom(Seq(V2.StringLiteralV2(value = "UpdatedDescription", language = Some("en")))), + ZIO.serviceWithZIO[GroupsResponderADM]( + _.updateGroup( + groupIri = GroupIri.unsafeFrom(groupIri), + GroupUpdateRequest( + name = Some(GroupName.unsafeFrom("UpdatedGroupName")), + descriptions = Some( + GroupDescriptions + .unsafeFrom(Seq(V2.StringLiteralV2(value = "UpdatedDescription", language = Some("en")))), + ), + status = Some(GroupStatus.active), + selfjoin = Some(GroupSelfJoin.disabled), ), - status = Some(GroupStatus.active), - selfjoin = Some(GroupSelfJoin.disabled), + UUID.randomUUID, ), - UUID.randomUUID, ), ) assertFailsWithA[NotFoundException]( @@ -167,18 +178,20 @@ class GroupsResponderADMSpec extends CoreSpec { "return 'BadRequest' if the new group name already exists inside the project" in { val groupName = GroupName.unsafeFrom("Image reviewer") val exit = UnsafeZioRun.run( - GroupsResponderADM.updateGroup( - GroupIri.unsafeFrom(newGroupIri.get), - GroupUpdateRequest( - name = Some(groupName), - descriptions = Some( - GroupDescriptions - .unsafeFrom(Seq(V2.StringLiteralV2(value = "UpdatedDescription", language = Some("en")))), + ZIO.serviceWithZIO[GroupsResponderADM]( + _.updateGroup( + GroupIri.unsafeFrom(newGroupIri.get), + GroupUpdateRequest( + name = Some(groupName), + descriptions = Some( + GroupDescriptions + .unsafeFrom(Seq(V2.StringLiteralV2(value = "UpdatedDescription", language = Some("en")))), + ), + status = Some(GroupStatus.active), + selfjoin = Some(GroupSelfJoin.disabled), ), - status = Some(GroupStatus.active), - selfjoin = Some(GroupSelfJoin.disabled), + UUID.randomUUID, ), - UUID.randomUUID, ), ) assertFailsWithA[BadRequestException]( @@ -189,10 +202,12 @@ class GroupsResponderADMSpec extends CoreSpec { "return 'BadRequest' if nothing would be changed during the update" in { val exit = UnsafeZioRun.run( - GroupsResponderADM.updateGroup( - GroupIri.unsafeFrom(newGroupIri.get), - GroupUpdateRequest(None, None, None, None), - UUID.randomUUID, + ZIO.serviceWithZIO[GroupsResponderADM]( + _.updateGroup( + GroupIri.unsafeFrom(newGroupIri.get), + GroupUpdateRequest(None, None, None, None), + UUID.randomUUID, + ), ), ) assertFailsWithA[BadRequestException]( @@ -206,7 +221,7 @@ class GroupsResponderADMSpec extends CoreSpec { "return all members of a group identified by IRI" in { val iri = GroupIri.unsafeFrom(imagesReviewerGroup.id) val received = - UnsafeZioRun.runOrThrow(GroupsResponderADM.groupMembersGetRequest(iri, rootUser)) + UnsafeZioRun.runOrThrow(ZIO.serviceWithZIO[GroupsResponderADM](_.groupMembersGetRequest(iri, rootUser))) received.members.map(_.id) should contain allElementsOf Seq( multiuserUser.ofType(UserInformationType.Restricted), @@ -216,26 +231,32 @@ class GroupsResponderADMSpec extends CoreSpec { "remove all members when group is deactivated" in { val group = UnsafeZioRun.runOrThrow( - GroupsResponderADM.groupMembersGetRequest( - GroupIri.unsafeFrom(imagesReviewerGroup.id), - rootUser, + ZIO.serviceWithZIO[GroupsResponderADM]( + _.groupMembersGetRequest( + GroupIri.unsafeFrom(imagesReviewerGroup.id), + rootUser, + ), ), ) group.members.size shouldBe 2 val statusChangeResponse = UnsafeZioRun.runOrThrow( - GroupsResponderADM.updateGroupStatus( - GroupIri.unsafeFrom(imagesReviewerGroup.id), - GroupStatusUpdateRequest(GroupStatus.inactive), - UUID.randomUUID(), + ZIO.serviceWithZIO[GroupsResponderADM]( + _.updateGroupStatus( + GroupIri.unsafeFrom(imagesReviewerGroup.id), + GroupStatusUpdateRequest(GroupStatus.inactive), + UUID.randomUUID(), + ), ), ) statusChangeResponse.group.status shouldBe false val anotherGroup = UnsafeZioRun.runOrThrow( - GroupsResponderADM.groupMembersGetRequest( - GroupIri.unsafeFrom(imagesReviewerGroup.id), - rootUser, + ZIO.serviceWithZIO[GroupsResponderADM]( + _.groupMembersGetRequest( + GroupIri.unsafeFrom(imagesReviewerGroup.id), + rootUser, + ), ), ) anotherGroup.members.size shouldBe 0 @@ -244,9 +265,11 @@ class GroupsResponderADMSpec extends CoreSpec { "return 'NotFound' when the group IRI is unknown" in { val groupIri = "http://rdfh.ch/groups/0000/notexisting" val exit = UnsafeZioRun.run( - GroupsResponderADM.groupMembersGetRequest( - GroupIri.unsafeFrom(groupIri), - rootUser, + ZIO.serviceWithZIO[GroupsResponderADM]( + _.groupMembersGetRequest( + GroupIri.unsafeFrom(groupIri), + rootUser, + ), ), ) assertFailsWithA[NotFoundException]( diff --git a/integration/src/test/scala/org/knora/webapi/responders/admin/PermissionsResponderADMSpec.scala b/integration/src/test/scala/org/knora/webapi/responders/admin/PermissionsResponderADMSpec.scala index ef962c91f8..e5607a4e73 100644 --- a/integration/src/test/scala/org/knora/webapi/responders/admin/PermissionsResponderADMSpec.scala +++ b/integration/src/test/scala/org/knora/webapi/responders/admin/PermissionsResponderADMSpec.scala @@ -8,6 +8,7 @@ package org.knora.webapi.responders.admin import org.apache.pekko.actor.Status.Failure import org.apache.pekko.testkit.ImplicitSender import zio.NonEmptyChunk +import zio.ZIO import java.util.UUID import scala.collection.Map @@ -159,8 +160,10 @@ class PermissionsResponderADMSpec extends CoreSpec with ImplicitSender { "ask for userAdministrativePermissionsGetADM" should { "return user's administrative permissions (helper method used in queries before)" in { val result: Map[IRI, Set[PermissionADM]] = UnsafeZioRun.runOrThrow( - PermissionsResponderADM.userAdministrativePermissionsGetADM( - multiuserUser.permissions.groupsPerProject, + ZIO.serviceWithZIO[PermissionsResponderADM]( + _.userAdministrativePermissionsGetADM( + multiuserUser.permissions.groupsPerProject, + ), ), ) result should equal(multiuserUser.permissions.administrativePermissionsPerProject) @@ -171,7 +174,7 @@ class PermissionsResponderADMSpec extends CoreSpec with ImplicitSender { "return all AdministrativePermissions for project" in { val result = UnsafeZioRun.runOrThrow( - PermissionsResponderADM.getPermissionsApByProjectIri(imagesProjectIri), + ZIO.serviceWithZIO[PermissionsResponderADM](_.getPermissionsApByProjectIri(imagesProjectIri)), ) result shouldEqual AdministrativePermissionsForProjectGetResponseADM( Seq(perm002_a1.p, perm002_a3.p, perm002_a2.p), @@ -180,9 +183,11 @@ class PermissionsResponderADMSpec extends CoreSpec with ImplicitSender { "return AdministrativePermission for project and group" in { val result = UnsafeZioRun.runOrThrow( - PermissionsResponderADM.getPermissionsApByProjectAndGroupIri( - imagesProjectIri, - OntologyConstants.KnoraAdmin.ProjectMember, + ZIO.serviceWithZIO[PermissionsResponderADM]( + _.getPermissionsApByProjectAndGroupIri( + imagesProjectIri, + OntologyConstants.KnoraAdmin.ProjectMember, + ), ), ) result shouldEqual AdministrativePermissionGetResponseADM(perm002_a1.p) @@ -216,14 +221,16 @@ class PermissionsResponderADMSpec extends CoreSpec with ImplicitSender { "asked to create an administrative permission" should { "fail and return a 'DuplicateValueException' when permission for project and group combination already exists" in { val exit = UnsafeZioRun.run( - PermissionsResponderADM.createAdministrativePermission( - CreateAdministrativePermissionAPIRequestADM( - forProject = imagesProjectIri, - forGroup = OntologyConstants.KnoraAdmin.ProjectMember, - hasPermissions = Set(PermissionADM.ProjectResourceCreateAllPermission), + ZIO.serviceWithZIO[PermissionsResponderADM]( + _.createAdministrativePermission( + CreateAdministrativePermissionAPIRequestADM( + forProject = imagesProjectIri, + forGroup = OntologyConstants.KnoraAdmin.ProjectMember, + hasPermissions = Set(PermissionADM.ProjectResourceCreateAllPermission), + ), + rootUser, + UUID.randomUUID(), ), - rootUser, - UUID.randomUUID(), ), ) assertFailsWithA[DuplicateValueException]( @@ -238,15 +245,17 @@ class PermissionsResponderADMSpec extends CoreSpec with ImplicitSender { "create and return an administrative permission with a custom IRI" in { val customIri = "http://rdfh.ch/permissions/0001/24RD7QcoTKqEJKrDBE885Q" val actual = UnsafeZioRun.runOrThrow( - PermissionsResponderADM.createAdministrativePermission( - CreateAdministrativePermissionAPIRequestADM( - id = Some(customIri), - forProject = SharedTestDataADM.anythingProjectIri, - forGroup = SharedTestDataADM.thingSearcherGroup.id, - hasPermissions = Set(PermissionADM.ProjectResourceCreateAllPermission), + ZIO.serviceWithZIO[PermissionsResponderADM]( + _.createAdministrativePermission( + CreateAdministrativePermissionAPIRequestADM( + id = Some(customIri), + forProject = SharedTestDataADM.anythingProjectIri, + forGroup = SharedTestDataADM.thingSearcherGroup.id, + hasPermissions = Set(PermissionADM.ProjectResourceCreateAllPermission), + ), + rootUser, + UUID.randomUUID(), ), - rootUser, - UUID.randomUUID(), ), ) assert(actual.administrativePermission.iri == customIri) @@ -271,15 +280,17 @@ class PermissionsResponderADMSpec extends CoreSpec with ImplicitSender { ), ) val actual = UnsafeZioRun.runOrThrow( - PermissionsResponderADM.createAdministrativePermission( - CreateAdministrativePermissionAPIRequestADM( - id = Some(customIri), - forProject = SharedTestDataADM.anythingProjectIri, - forGroup = OntologyConstants.KnoraAdmin.KnownUser, - hasPermissions = hasPermissions, + ZIO.serviceWithZIO[PermissionsResponderADM]( + _.createAdministrativePermission( + CreateAdministrativePermissionAPIRequestADM( + id = Some(customIri), + forProject = SharedTestDataADM.anythingProjectIri, + forGroup = OntologyConstants.KnoraAdmin.KnownUser, + hasPermissions = hasPermissions, + ), + rootUser, + UUID.randomUUID(), ), - rootUser, - UUID.randomUUID(), ), ) assert(actual.administrativePermission.iri == customIri) @@ -333,8 +344,10 @@ class PermissionsResponderADMSpec extends CoreSpec with ImplicitSender { "return all DefaultObjectAccessPermissions for project" in { val actual = UnsafeZioRun.runOrThrow( - PermissionsResponderADM.getPermissionsDaopByProjectIri( - ProjectIri.unsafeFrom(imagesProjectIri), + ZIO.serviceWithZIO[PermissionsResponderADM]( + _.getPermissionsDaopByProjectIri( + ProjectIri.unsafeFrom(imagesProjectIri), + ), ), ) actual shouldEqual DefaultObjectAccessPermissionsForProjectGetResponseADM( @@ -422,14 +435,16 @@ class PermissionsResponderADMSpec extends CoreSpec with ImplicitSender { "create a DefaultObjectAccessPermission for project and group" in { val actual = UnsafeZioRun.runOrThrow( - PermissionsResponderADM.createDefaultObjectAccessPermission( - CreateDefaultObjectAccessPermissionAPIRequestADM( - forProject = SharedTestDataADM.anythingProjectIri, - forGroup = Some(SharedTestDataADM.thingSearcherGroup.id), - hasPermissions = Set(PermissionADM.restrictedViewPermission(SharedTestDataADM.thingSearcherGroup.id)), + ZIO.serviceWithZIO[PermissionsResponderADM]( + _.createDefaultObjectAccessPermission( + CreateDefaultObjectAccessPermissionAPIRequestADM( + forProject = SharedTestDataADM.anythingProjectIri, + forGroup = Some(SharedTestDataADM.thingSearcherGroup.id), + hasPermissions = Set(PermissionADM.restrictedViewPermission(SharedTestDataADM.thingSearcherGroup.id)), + ), + rootUser, + UUID.randomUUID(), ), - rootUser, - UUID.randomUUID(), ), ) @@ -445,15 +460,17 @@ class PermissionsResponderADMSpec extends CoreSpec with ImplicitSender { "create a DefaultObjectAccessPermission for project and group with custom IRI" in { val customIri = "http://rdfh.ch/permissions/0001/4PnSvolsTEa86KJ2EG76SQ" val received = UnsafeZioRun.runOrThrow( - PermissionsResponderADM.createDefaultObjectAccessPermission( - createRequest = CreateDefaultObjectAccessPermissionAPIRequestADM( - id = Some(customIri), - forProject = SharedTestDataADM.anythingProjectIri, - forGroup = Some(OntologyConstants.KnoraAdmin.UnknownUser), - hasPermissions = Set(PermissionADM.restrictedViewPermission(OntologyConstants.KnoraAdmin.UnknownUser)), + ZIO.serviceWithZIO[PermissionsResponderADM]( + _.createDefaultObjectAccessPermission( + createRequest = CreateDefaultObjectAccessPermissionAPIRequestADM( + id = Some(customIri), + forProject = SharedTestDataADM.anythingProjectIri, + forGroup = Some(OntologyConstants.KnoraAdmin.UnknownUser), + hasPermissions = Set(PermissionADM.restrictedViewPermission(OntologyConstants.KnoraAdmin.UnknownUser)), + ), + rootUser, + UUID.randomUUID(), ), - rootUser, - UUID.randomUUID(), ), ) assert(received.defaultObjectAccessPermission.iri == customIri) @@ -467,14 +484,16 @@ class PermissionsResponderADMSpec extends CoreSpec with ImplicitSender { "create a DefaultObjectAccessPermission for project and resource class" in { val actual = UnsafeZioRun.runOrThrow( - PermissionsResponderADM.createDefaultObjectAccessPermission( - CreateDefaultObjectAccessPermissionAPIRequestADM( - forProject = imagesProjectIri, - forResourceClass = Some(SharedOntologyTestDataADM.IMAGES_BILD_RESOURCE_CLASS), - hasPermissions = Set(PermissionADM.modifyPermission(OntologyConstants.KnoraAdmin.KnownUser)), + ZIO.serviceWithZIO[PermissionsResponderADM]( + _.createDefaultObjectAccessPermission( + CreateDefaultObjectAccessPermissionAPIRequestADM( + forProject = imagesProjectIri, + forResourceClass = Some(SharedOntologyTestDataADM.IMAGES_BILD_RESOURCE_CLASS), + hasPermissions = Set(PermissionADM.modifyPermission(OntologyConstants.KnoraAdmin.KnownUser)), + ), + rootUser, + UUID.randomUUID(), ), - rootUser, - UUID.randomUUID(), ), ) assert(actual.defaultObjectAccessPermission.forProject == imagesProjectIri) @@ -490,14 +509,16 @@ class PermissionsResponderADMSpec extends CoreSpec with ImplicitSender { "create a DefaultObjectAccessPermission for project and property" in { val actual = UnsafeZioRun.runOrThrow( - PermissionsResponderADM.createDefaultObjectAccessPermission( - CreateDefaultObjectAccessPermissionAPIRequestADM( - forProject = imagesProjectIri, - forProperty = Some(SharedOntologyTestDataADM.IMAGES_TITEL_PROPERTY), - hasPermissions = Set(PermissionADM.changeRightsPermission(OntologyConstants.KnoraAdmin.Creator)), + ZIO.serviceWithZIO[PermissionsResponderADM]( + _.createDefaultObjectAccessPermission( + CreateDefaultObjectAccessPermissionAPIRequestADM( + forProject = imagesProjectIri, + forProperty = Some(SharedOntologyTestDataADM.IMAGES_TITEL_PROPERTY), + hasPermissions = Set(PermissionADM.changeRightsPermission(OntologyConstants.KnoraAdmin.Creator)), + ), + rootUser, + UUID.randomUUID(), ), - rootUser, - UUID.randomUUID(), ), ) assert(actual.defaultObjectAccessPermission.forProject == imagesProjectIri) @@ -513,14 +534,16 @@ class PermissionsResponderADMSpec extends CoreSpec with ImplicitSender { "fail and return a 'DuplicateValueException' when a doap permission for project and group combination already exists" in { val exit = UnsafeZioRun.run( - PermissionsResponderADM.createDefaultObjectAccessPermission( - CreateDefaultObjectAccessPermissionAPIRequestADM( - forProject = SharedTestDataADM2.incunabulaProjectIri, - forGroup = Some(OntologyConstants.KnoraAdmin.ProjectMember), - hasPermissions = Set(PermissionADM.changeRightsPermission(OntologyConstants.KnoraAdmin.ProjectMember)), + ZIO.serviceWithZIO[PermissionsResponderADM]( + _.createDefaultObjectAccessPermission( + CreateDefaultObjectAccessPermissionAPIRequestADM( + forProject = SharedTestDataADM2.incunabulaProjectIri, + forGroup = Some(OntologyConstants.KnoraAdmin.ProjectMember), + hasPermissions = Set(PermissionADM.changeRightsPermission(OntologyConstants.KnoraAdmin.ProjectMember)), + ), + rootUser, + UUID.randomUUID(), ), - rootUser, - UUID.randomUUID(), ), ) assertFailsWithA[DuplicateValueException]( @@ -535,17 +558,19 @@ class PermissionsResponderADMSpec extends CoreSpec with ImplicitSender { "fail and return a 'DuplicateValueException' when a doap permission for project and resourceClass combination already exists" in { val exit = UnsafeZioRun.run( - PermissionsResponderADM.createDefaultObjectAccessPermission( - CreateDefaultObjectAccessPermissionAPIRequestADM( - forProject = SharedTestDataADM2.incunabulaProjectIri, - forResourceClass = Some(SharedOntologyTestDataADM.INCUNABULA_BOOK_RESOURCE_CLASS), - hasPermissions = Set( - PermissionADM.changeRightsPermission(OntologyConstants.KnoraAdmin.Creator), - PermissionADM.modifyPermission(OntologyConstants.KnoraAdmin.ProjectMember), + ZIO.serviceWithZIO[PermissionsResponderADM]( + _.createDefaultObjectAccessPermission( + CreateDefaultObjectAccessPermissionAPIRequestADM( + forProject = SharedTestDataADM2.incunabulaProjectIri, + forResourceClass = Some(SharedOntologyTestDataADM.INCUNABULA_BOOK_RESOURCE_CLASS), + hasPermissions = Set( + PermissionADM.changeRightsPermission(OntologyConstants.KnoraAdmin.Creator), + PermissionADM.modifyPermission(OntologyConstants.KnoraAdmin.ProjectMember), + ), ), + rootUser, + UUID.randomUUID(), ), - rootUser, - UUID.randomUUID(), ), ) assertFailsWithA[DuplicateValueException]( @@ -560,16 +585,18 @@ class PermissionsResponderADMSpec extends CoreSpec with ImplicitSender { "fail and return a 'DuplicateValueException' when a doap permission for project and property combination already exists" in { val exit = UnsafeZioRun.run( - PermissionsResponderADM.createDefaultObjectAccessPermission( - CreateDefaultObjectAccessPermissionAPIRequestADM( - forProject = SharedTestDataADM2.incunabulaProjectIri, - forProperty = Some(SharedOntologyTestDataADM.INCUNABULA_PartOf_Property), - hasPermissions = Set( - PermissionADM.modifyPermission(OntologyConstants.KnoraAdmin.KnownUser), + ZIO.serviceWithZIO[PermissionsResponderADM]( + _.createDefaultObjectAccessPermission( + CreateDefaultObjectAccessPermissionAPIRequestADM( + forProject = SharedTestDataADM2.incunabulaProjectIri, + forProperty = Some(SharedOntologyTestDataADM.INCUNABULA_PartOf_Property), + hasPermissions = Set( + PermissionADM.modifyPermission(OntologyConstants.KnoraAdmin.KnownUser), + ), ), + rootUser, + UUID.randomUUID(), ), - rootUser, - UUID.randomUUID(), ), ) assertFailsWithA[DuplicateValueException]( @@ -584,18 +611,20 @@ class PermissionsResponderADMSpec extends CoreSpec with ImplicitSender { "fail and return a 'DuplicateValueException' when a doap permission for project, resource class, and property combination already exists" in { val exit = UnsafeZioRun.run( - PermissionsResponderADM.createDefaultObjectAccessPermission( - CreateDefaultObjectAccessPermissionAPIRequestADM( - forProject = SharedTestDataADM2.incunabulaProjectIri, - forResourceClass = Some(SharedOntologyTestDataADM.INCUNABULA_PAGE_RESOURCE_CLASS), - forProperty = Some(SharedOntologyTestDataADM.INCUNABULA_PartOf_Property), - hasPermissions = Set( - PermissionADM.changeRightsPermission(OntologyConstants.KnoraAdmin.Creator), - PermissionADM.modifyPermission(OntologyConstants.KnoraAdmin.ProjectMember), + ZIO.serviceWithZIO[PermissionsResponderADM]( + _.createDefaultObjectAccessPermission( + CreateDefaultObjectAccessPermissionAPIRequestADM( + forProject = SharedTestDataADM2.incunabulaProjectIri, + forResourceClass = Some(SharedOntologyTestDataADM.INCUNABULA_PAGE_RESOURCE_CLASS), + forProperty = Some(SharedOntologyTestDataADM.INCUNABULA_PartOf_Property), + hasPermissions = Set( + PermissionADM.changeRightsPermission(OntologyConstants.KnoraAdmin.Creator), + PermissionADM.modifyPermission(OntologyConstants.KnoraAdmin.ProjectMember), + ), ), + rootUser, + UUID.randomUUID(), ), - rootUser, - UUID.randomUUID(), ), ) assertFailsWithA[DuplicateValueException]( @@ -618,14 +647,16 @@ class PermissionsResponderADMSpec extends CoreSpec with ImplicitSender { ), ) val actual = UnsafeZioRun.runOrThrow( - PermissionsResponderADM.createDefaultObjectAccessPermission( - CreateDefaultObjectAccessPermissionAPIRequestADM( - forProject = imagesProjectIri, - forGroup = Some(OntologyConstants.KnoraAdmin.UnknownUser), - hasPermissions = hasPermissions, + ZIO.serviceWithZIO[PermissionsResponderADM]( + _.createDefaultObjectAccessPermission( + CreateDefaultObjectAccessPermissionAPIRequestADM( + forProject = imagesProjectIri, + forGroup = Some(OntologyConstants.KnoraAdmin.UnknownUser), + hasPermissions = hasPermissions, + ), + rootUser, + UUID.randomUUID(), ), - rootUser, - UUID.randomUUID(), ), ) assert(actual.defaultObjectAccessPermission.forProject == imagesProjectIri) @@ -653,14 +684,16 @@ class PermissionsResponderADMSpec extends CoreSpec with ImplicitSender { ), ) val actual = UnsafeZioRun.runOrThrow( - PermissionsResponderADM.createDefaultObjectAccessPermission( - CreateDefaultObjectAccessPermissionAPIRequestADM( - forProject = imagesProjectIri, - forGroup = Some(OntologyConstants.KnoraAdmin.ProjectAdmin), - hasPermissions = hasPermissions, + ZIO.serviceWithZIO[PermissionsResponderADM]( + _.createDefaultObjectAccessPermission( + CreateDefaultObjectAccessPermissionAPIRequestADM( + forProject = imagesProjectIri, + forGroup = Some(OntologyConstants.KnoraAdmin.ProjectAdmin), + hasPermissions = hasPermissions, + ), + rootUser, + UUID.randomUUID(), ), - rootUser, - UUID.randomUUID(), ), ) assert(actual.defaultObjectAccessPermission.forProject == imagesProjectIri) @@ -673,15 +706,19 @@ class PermissionsResponderADMSpec extends CoreSpec with ImplicitSender { "return all permissions for 'image' project" in { val actual = UnsafeZioRun.runOrThrow( - PermissionsResponderADM.getPermissionsByProjectIri(ProjectIri.unsafeFrom(imagesProjectIri)), + ZIO.serviceWithZIO[PermissionsResponderADM]( + _.getPermissionsByProjectIri(ProjectIri.unsafeFrom(imagesProjectIri)), + ), ) actual.allPermissions.size should be(10) } "return all permissions for 'incunabula' project" in { val actual = UnsafeZioRun.runOrThrow( - PermissionsResponderADM.getPermissionsByProjectIri( - ProjectIri.unsafeFrom(SharedTestDataADM.incunabulaProjectIri), + ZIO.serviceWithZIO[PermissionsResponderADM]( + _.getPermissionsByProjectIri( + ProjectIri.unsafeFrom(SharedTestDataADM.incunabulaProjectIri), + ), ), ) actual shouldEqual @@ -888,8 +925,9 @@ class PermissionsResponderADMSpec extends CoreSpec with ImplicitSender { val permissionIri = PermissionIri.unsafeFrom("http://rdfh.ch/permissions/00FF/buxHAlz8SHuu0FuiLN_tKQ") val newGroupIri = GroupIri.unsafeFrom("http://rdfh.ch/groups/00FF/images-reviewer") val actual = UnsafeZioRun.runOrThrow( - PermissionsResponderADM - .updatePermissionsGroup(permissionIri, newGroupIri, rootUser, UUID.randomUUID()), + ZIO.serviceWithZIO[PermissionsResponderADM]( + _.updatePermissionsGroup(permissionIri, newGroupIri, rootUser, UUID.randomUUID()), + ), ) val ap = actual.asInstanceOf[AdministrativePermissionGetResponseADM].administrativePermission assert(ap.iri == permissionIri.value) @@ -900,8 +938,9 @@ class PermissionsResponderADMSpec extends CoreSpec with ImplicitSender { val permissionIri = PermissionIri.unsafeFrom("http://rdfh.ch/permissions/00FF/buxHAlz8SHuu0FuiLN_tKQ") val newGroupIri = GroupIri.unsafeFrom("http://rdfh.ch/groups/00FF/images-reviewer") val exit = UnsafeZioRun.run( - PermissionsResponderADM - .updatePermissionsGroup(permissionIri, newGroupIri, imagesUser02, UUID.randomUUID()), + ZIO.serviceWithZIO[PermissionsResponderADM]( + _.updatePermissionsGroup(permissionIri, newGroupIri, imagesUser02, UUID.randomUUID()), + ), ) assertFailsWithA[ForbiddenException]( exit, @@ -913,8 +952,9 @@ class PermissionsResponderADMSpec extends CoreSpec with ImplicitSender { val permissionIri = PermissionIri.unsafeFrom("http://rdfh.ch/permissions/00FF/Mck2xJDjQ_Oimi_9z4aFaA") val newGroupIri = GroupIri.unsafeFrom("http://rdfh.ch/groups/00FF/images-reviewer") val actual = UnsafeZioRun.runOrThrow( - PermissionsResponderADM - .updatePermissionsGroup(permissionIri, newGroupIri, rootUser, UUID.randomUUID()), + ZIO.serviceWithZIO[PermissionsResponderADM]( + _.updatePermissionsGroup(permissionIri, newGroupIri, rootUser, UUID.randomUUID()), + ), ) val doap = actual.asInstanceOf[DefaultObjectAccessPermissionGetResponseADM].defaultObjectAccessPermission assert(doap.iri == permissionIri.value) @@ -925,8 +965,9 @@ class PermissionsResponderADMSpec extends CoreSpec with ImplicitSender { val permissionIri = PermissionIri.unsafeFrom("http://rdfh.ch/permissions/00FF/sdHG20U6RoiwSu8MeAT1vA") val newGroupIri = GroupIri.unsafeFrom(projectMember) val actual = UnsafeZioRun.runOrThrow( - PermissionsResponderADM - .updatePermissionsGroup(permissionIri, newGroupIri, rootUser, UUID.randomUUID()), + ZIO.serviceWithZIO[PermissionsResponderADM]( + _.updatePermissionsGroup(permissionIri, newGroupIri, rootUser, UUID.randomUUID()), + ), ) val doap = actual.asInstanceOf[DefaultObjectAccessPermissionGetResponseADM].defaultObjectAccessPermission assert(doap.iri == permissionIri.value) @@ -938,8 +979,9 @@ class PermissionsResponderADMSpec extends CoreSpec with ImplicitSender { val permissionIri = PermissionIri.unsafeFrom("http://rdfh.ch/permissions/0000/KMjKHCNQQmC4uHPQwlEexw") val newGroupIri = GroupIri.unsafeFrom(projectMember) val actual = UnsafeZioRun.runOrThrow( - PermissionsResponderADM - .updatePermissionsGroup(permissionIri, newGroupIri, rootUser, UUID.randomUUID()), + ZIO.serviceWithZIO[PermissionsResponderADM]( + _.updatePermissionsGroup(permissionIri, newGroupIri, rootUser, UUID.randomUUID()), + ), ) val doap = actual.asInstanceOf[DefaultObjectAccessPermissionGetResponseADM].defaultObjectAccessPermission assert(doap.iri == permissionIri.value) @@ -954,13 +996,14 @@ class PermissionsResponderADMSpec extends CoreSpec with ImplicitSender { val hasPermissions = NonEmptyChunk(PermissionADM.ProjectResourceCreateAllPermission) val exit = UnsafeZioRun.run( - PermissionsResponderADM - .updatePermissionHasPermissions( + ZIO.serviceWithZIO[PermissionsResponderADM]( + _.updatePermissionHasPermissions( PermissionIri.unsafeFrom(permissionIri), hasPermissions, imagesUser02, UUID.randomUUID(), ), + ), ) assertFailsWithA[ForbiddenException]( @@ -973,13 +1016,14 @@ class PermissionsResponderADMSpec extends CoreSpec with ImplicitSender { val permissionIri = "http://rdfh.ch/permissions/00FF/buxHAlz8SHuu0FuiLN_tKQ" val hasPermissions = NonEmptyChunk(PermissionADM.ProjectResourceCreateAllPermission) val actual = UnsafeZioRun.runOrThrow( - PermissionsResponderADM - .updatePermissionHasPermissions( + ZIO.serviceWithZIO[PermissionsResponderADM]( + _.updatePermissionHasPermissions( PermissionIri.unsafeFrom(permissionIri), hasPermissions, rootUser, UUID.randomUUID(), ), + ), ) val ap = actual.asInstanceOf[AdministrativePermissionGetResponseADM].administrativePermission @@ -998,13 +1042,14 @@ class PermissionsResponderADMSpec extends CoreSpec with ImplicitSender { ), ) val actual = UnsafeZioRun.runOrThrow( - PermissionsResponderADM - .updatePermissionHasPermissions( + ZIO.serviceWithZIO[PermissionsResponderADM]( + _.updatePermissionHasPermissions( PermissionIri.unsafeFrom(permissionIri), hasPermissions, rootUser, UUID.randomUUID(), ), + ), ) val ap = actual.asInstanceOf[AdministrativePermissionGetResponseADM].administrativePermission assert(ap.iri == permissionIri) @@ -1021,13 +1066,14 @@ class PermissionsResponderADMSpec extends CoreSpec with ImplicitSender { ) val actual = UnsafeZioRun.runOrThrow( - PermissionsResponderADM - .updatePermissionHasPermissions( + ZIO.serviceWithZIO[PermissionsResponderADM]( + _.updatePermissionHasPermissions( PermissionIri.unsafeFrom(permissionIri), hasPermissions, rootUser, UUID.randomUUID(), ), + ), ) val doap = actual.asInstanceOf[DefaultObjectAccessPermissionGetResponseADM].defaultObjectAccessPermission @@ -1055,13 +1101,14 @@ class PermissionsResponderADMSpec extends CoreSpec with ImplicitSender { ) val actual = UnsafeZioRun.runOrThrow( - PermissionsResponderADM - .updatePermissionHasPermissions( + ZIO.serviceWithZIO[PermissionsResponderADM]( + _.updatePermissionHasPermissions( PermissionIri.unsafeFrom(permissionIri), hasPermissions, rootUser, UUID.randomUUID(), ), + ), ) val doap = actual.asInstanceOf[DefaultObjectAccessPermissionGetResponseADM].defaultObjectAccessPermission assert(doap.iri == permissionIri) @@ -1086,13 +1133,14 @@ class PermissionsResponderADMSpec extends CoreSpec with ImplicitSender { ), ) val actual = UnsafeZioRun.runOrThrow( - PermissionsResponderADM - .updatePermissionHasPermissions( + ZIO.serviceWithZIO[PermissionsResponderADM]( + _.updatePermissionHasPermissions( PermissionIri.unsafeFrom(permissionIri), hasPermissions, rootUser, UUID.randomUUID(), ), + ), ) val doap = actual.asInstanceOf[DefaultObjectAccessPermissionGetResponseADM].defaultObjectAccessPermission assert(doap.iri == permissionIri) @@ -1111,13 +1159,14 @@ class PermissionsResponderADMSpec extends CoreSpec with ImplicitSender { ), ) val exit = UnsafeZioRun.run( - PermissionsResponderADM - .updatePermissionHasPermissions( + ZIO.serviceWithZIO[PermissionsResponderADM]( + _.updatePermissionHasPermissions( PermissionIri.unsafeFrom(permissionIri), hasPermissions, rootUser, UUID.randomUUID(), ), + ), ) assertFailsWithA[BadRequestException]( exit, @@ -1137,13 +1186,14 @@ class PermissionsResponderADMSpec extends CoreSpec with ImplicitSender { ) val exit = UnsafeZioRun.run( - PermissionsResponderADM - .updatePermissionHasPermissions( + ZIO.serviceWithZIO[PermissionsResponderADM]( + _.updatePermissionHasPermissions( PermissionIri.unsafeFrom(permissionIri), hasPermissions, rootUser, UUID.randomUUID(), ), + ), ) assertFailsWithA[BadRequestException]( exit, @@ -1164,13 +1214,14 @@ class PermissionsResponderADMSpec extends CoreSpec with ImplicitSender { ) val exit = UnsafeZioRun.run( - PermissionsResponderADM - .updatePermissionHasPermissions( + ZIO.serviceWithZIO[PermissionsResponderADM]( + _.updatePermissionHasPermissions( PermissionIri.unsafeFrom(permissionIri), hasPermissions, rootUser, UUID.randomUUID(), ), + ), ) assertFailsWithA[BadRequestException]( exit, @@ -1190,13 +1241,14 @@ class PermissionsResponderADMSpec extends CoreSpec with ImplicitSender { ) val exit = UnsafeZioRun.run( - PermissionsResponderADM - .updatePermissionHasPermissions( + ZIO.serviceWithZIO[PermissionsResponderADM]( + _.updatePermissionHasPermissions( PermissionIri.unsafeFrom(permissionIri), hasPermissions, rootUser, UUID.randomUUID(), ), + ), ) assertFailsWithA[BadRequestException]( exit, @@ -1210,13 +1262,14 @@ class PermissionsResponderADMSpec extends CoreSpec with ImplicitSender { val resourceClassIri = SharedOntologyTestDataADM.INCUNABULA_PAGE_RESOURCE_CLASS val exit = UnsafeZioRun.run( - PermissionsResponderADM - .updatePermissionResourceClass( + ZIO.serviceWithZIO[PermissionsResponderADM]( + _.updatePermissionResourceClass( PermissionIri.unsafeFrom(permissionIri), ChangePermissionResourceClassApiRequestADM(resourceClassIri), incunabulaMemberUser, UUID.randomUUID(), ), + ), ) assertFailsWithA[ForbiddenException]( @@ -1229,13 +1282,14 @@ class PermissionsResponderADMSpec extends CoreSpec with ImplicitSender { val resourceClassIri = SharedOntologyTestDataADM.INCUNABULA_PAGE_RESOURCE_CLASS val actual = UnsafeZioRun.runOrThrow( - PermissionsResponderADM - .updatePermissionResourceClass( + ZIO.serviceWithZIO[PermissionsResponderADM]( + _.updatePermissionResourceClass( PermissionIri.unsafeFrom(permissionIri), ChangePermissionResourceClassApiRequestADM(resourceClassIri), rootUser, UUID.randomUUID(), ), + ), ) val doap = actual.asInstanceOf[DefaultObjectAccessPermissionGetResponseADM].defaultObjectAccessPermission assert(doap.iri == permissionIri) @@ -1246,13 +1300,14 @@ class PermissionsResponderADMSpec extends CoreSpec with ImplicitSender { val permissionIri = "http://rdfh.ch/permissions/00FF/Q3OMWyFqStGYK8EXmC7KhQ" val resourceClassIri = SharedOntologyTestDataADM.INCUNABULA_BOOK_RESOURCE_CLASS val actual = UnsafeZioRun.runOrThrow( - PermissionsResponderADM - .updatePermissionResourceClass( + ZIO.serviceWithZIO[PermissionsResponderADM]( + _.updatePermissionResourceClass( PermissionIri.unsafeFrom(permissionIri), ChangePermissionResourceClassApiRequestADM(resourceClassIri), rootUser, UUID.randomUUID(), ), + ), ) val doap = actual.asInstanceOf[DefaultObjectAccessPermissionGetResponseADM].defaultObjectAccessPermission assert(doap.iri == permissionIri) @@ -1264,13 +1319,14 @@ class PermissionsResponderADMSpec extends CoreSpec with ImplicitSender { val permissionIri = "http://rdfh.ch/permissions/00FF/OySsjGn8QSqIpXUiSYnSSQ" val resourceClassIri = SharedOntologyTestDataADM.INCUNABULA_BOOK_RESOURCE_CLASS val exit = UnsafeZioRun.run( - PermissionsResponderADM - .updatePermissionResourceClass( + ZIO.serviceWithZIO[PermissionsResponderADM]( + _.updatePermissionResourceClass( PermissionIri.unsafeFrom(permissionIri), ChangePermissionResourceClassApiRequestADM(resourceClassIri), rootUser, UUID.randomUUID(), ), + ), ) assertFailsWithA[ForbiddenException]( exit, @@ -1285,13 +1341,14 @@ class PermissionsResponderADMSpec extends CoreSpec with ImplicitSender { val propertyIri = SharedOntologyTestDataADM.IMAGES_TITEL_PROPERTY val exit = UnsafeZioRun.run( - PermissionsResponderADM - .updatePermissionProperty( + ZIO.serviceWithZIO[PermissionsResponderADM]( + _.updatePermissionProperty( PermissionIri.unsafeFrom(permissionIri), ChangePermissionPropertyApiRequestADM(propertyIri), rootUser, UUID.randomUUID(), ), + ), ) assertFailsWithA[ForbiddenException]( exit, @@ -1304,13 +1361,14 @@ class PermissionsResponderADMSpec extends CoreSpec with ImplicitSender { val propertyIri = OntologyConstants.KnoraBase.TextFileValue val exit = UnsafeZioRun.run( - PermissionsResponderADM - .updatePermissionProperty( + ZIO.serviceWithZIO[PermissionsResponderADM]( + _.updatePermissionProperty( PermissionIri.unsafeFrom(permissionIri), ChangePermissionPropertyApiRequestADM(propertyIri), normalUser, UUID.randomUUID(), ), + ), ) assertFailsWithA[ForbiddenException]( exit, @@ -1322,13 +1380,14 @@ class PermissionsResponderADMSpec extends CoreSpec with ImplicitSender { val propertyIri = OntologyConstants.KnoraBase.TextFileValue val actual = UnsafeZioRun.runOrThrow( - PermissionsResponderADM - .updatePermissionProperty( + ZIO.serviceWithZIO[PermissionsResponderADM]( + _.updatePermissionProperty( PermissionIri.unsafeFrom(permissionIri), ChangePermissionPropertyApiRequestADM(propertyIri), rootUser, UUID.randomUUID(), ), + ), ) val doap = actual.asInstanceOf[DefaultObjectAccessPermissionGetResponseADM].defaultObjectAccessPermission assert(doap.iri == permissionIri) @@ -1340,11 +1399,13 @@ class PermissionsResponderADMSpec extends CoreSpec with ImplicitSender { val propertyIri = SharedOntologyTestDataADM.IMAGES_TITEL_PROPERTY val actual = UnsafeZioRun.runOrThrow( - PermissionsResponderADM.updatePermissionProperty( - PermissionIri.unsafeFrom(permissionIri), - ChangePermissionPropertyApiRequestADM(propertyIri), - rootUser, - UUID.randomUUID(), + ZIO.serviceWithZIO[PermissionsResponderADM]( + _.updatePermissionProperty( + PermissionIri.unsafeFrom(permissionIri), + ChangePermissionPropertyApiRequestADM(propertyIri), + rootUser, + UUID.randomUUID(), + ), ), ) val doap = actual.asInstanceOf[DefaultObjectAccessPermissionGetResponseADM].defaultObjectAccessPermission @@ -1358,7 +1419,7 @@ class PermissionsResponderADMSpec extends CoreSpec with ImplicitSender { "throw BadRequestException if given IRI is not a permission IRI" in { val permissionIri = PermissionIri.unsafeFrom("http://rdfh.ch/permissions/00FF/RkVssk8XRVO9hZ3VR5IpLA") val exit = UnsafeZioRun.run( - PermissionsResponderADM.deletePermission(permissionIri, rootUser, UUID.randomUUID()), + ZIO.serviceWithZIO[PermissionsResponderADM](_.deletePermission(permissionIri, rootUser, UUID.randomUUID())), ) assertFailsWithA[NotFoundException]( exit, @@ -1369,7 +1430,9 @@ class PermissionsResponderADMSpec extends CoreSpec with ImplicitSender { "throw ForbiddenException if user requesting PermissionDeleteResponseADM is not a system or project admin" in { val permissionIri = PermissionIri.unsafeFrom("http://rdfh.ch/permissions/00FF/Mck2xJDjQ_Oimi_9z4aFaA") val exit = UnsafeZioRun.run( - PermissionsResponderADM.deletePermission(permissionIri, SharedTestDataADM.imagesUser02, UUID.randomUUID()), + ZIO.serviceWithZIO[PermissionsResponderADM]( + _.deletePermission(permissionIri, SharedTestDataADM.imagesUser02, UUID.randomUUID()), + ), ) assertFailsWithA[ForbiddenException]( exit, @@ -1380,7 +1443,7 @@ class PermissionsResponderADMSpec extends CoreSpec with ImplicitSender { "erase a permission with given IRI" in { val permissionIri = PermissionIri.unsafeFrom("http://rdfh.ch/permissions/00FF/Mck2xJDjQ_Oimi_9z4aFaA") val actual = UnsafeZioRun.runOrThrow( - PermissionsResponderADM.deletePermission(permissionIri, rootUser, UUID.randomUUID()), + ZIO.serviceWithZIO[PermissionsResponderADM](_.deletePermission(permissionIri, rootUser, UUID.randomUUID())), ) assert(actual.deleted) } diff --git a/integration/src/test/scala/org/knora/webapi/responders/admin/ProjectsResponderADMSpec.scala b/integration/src/test/scala/org/knora/webapi/responders/admin/ProjectsResponderADMSpec.scala index 80dfb89e65..67cd052179 100644 --- a/integration/src/test/scala/org/knora/webapi/responders/admin/ProjectsResponderADMSpec.scala +++ b/integration/src/test/scala/org/knora/webapi/responders/admin/ProjectsResponderADMSpec.scala @@ -11,6 +11,7 @@ package org.knora.webapi.responders.admin import org.apache.pekko.actor.Status.Failure import org.apache.pekko.testkit.ImplicitSender +import zio.ZIO import java.util.UUID @@ -39,10 +40,12 @@ class ProjectsResponderADMSpec extends CoreSpec with ImplicitSender { private val notExistingProjectButValidProjectIri = "http://rdfh.ch/projects/notexisting" + private val ProjectsResponderADM = ZIO.serviceWithZIO[ProjectsResponderADM] + "The ProjectsResponderADM" when { "used to query for project information" should { "return information for every project excluding system projects" in { - val received = UnsafeZioRun.runOrThrow(ProjectsResponderADM.getNonSystemProjects) + val received = UnsafeZioRun.runOrThrow(ProjectsResponderADM(_.getNonSystemProjects)) assert(received.projects.contains(SharedTestDataADM.imagesProject)) assert(received.projects.contains(SharedTestDataADM.incunabulaProject)) assert(!received.projects.map(_.id).contains(SharedTestDataADM.systemProjectIri)) @@ -102,8 +105,8 @@ class ProjectsResponderADMSpec extends CoreSpec with ImplicitSender { "return restricted view settings using project IRI" in { val actual = UnsafeZioRun.runOrThrow( - ProjectsResponderADM.projectRestrictedViewSettingsGetADM( - IriIdentifier.unsafeFrom(SharedTestDataADM.imagesProject.id), + ProjectsResponderADM( + _.projectRestrictedViewSettingsGetADM(IriIdentifier.unsafeFrom(SharedTestDataADM.imagesProject.id)), ), ) actual shouldEqual Some(expectedResult) @@ -111,8 +114,10 @@ class ProjectsResponderADMSpec extends CoreSpec with ImplicitSender { "return restricted view settings using project SHORTNAME" in { val actual = UnsafeZioRun.runOrThrow( - ProjectsResponderADM.projectRestrictedViewSettingsGetADM( - ShortnameIdentifier.unsafeFrom(SharedTestDataADM.imagesProject.shortname), + ProjectsResponderADM( + _.projectRestrictedViewSettingsGetADM( + ShortnameIdentifier.unsafeFrom(SharedTestDataADM.imagesProject.shortname), + ), ), ) actual shouldEqual Some(expectedResult) @@ -120,8 +125,10 @@ class ProjectsResponderADMSpec extends CoreSpec with ImplicitSender { "return restricted view settings using project SHORTCODE" in { val actual = UnsafeZioRun.runOrThrow( - ProjectsResponderADM.projectRestrictedViewSettingsGetADM( - ShortcodeIdentifier.unsafeFrom(SharedTestDataADM.imagesProject.shortcode), + ProjectsResponderADM( + _.projectRestrictedViewSettingsGetADM( + ShortcodeIdentifier.unsafeFrom(SharedTestDataADM.imagesProject.shortcode), + ), ), ) actual shouldEqual Some(expectedResult) @@ -129,8 +136,10 @@ class ProjectsResponderADMSpec extends CoreSpec with ImplicitSender { "return 'NotFoundException' when the project IRI is unknown" in { val exit = UnsafeZioRun.run( - ProjectsResponderADM.projectRestrictedViewSettingsGetRequestADM( - IriIdentifier.unsafeFrom(notExistingProjectButValidProjectIri), + ProjectsResponderADM( + _.projectRestrictedViewSettingsGetRequestADM( + IriIdentifier.unsafeFrom(notExistingProjectButValidProjectIri), + ), ), ) assertFailsWithA[NotFoundException](exit, s"Project '$notExistingProjectButValidProjectIri' not found.") @@ -138,15 +147,17 @@ class ProjectsResponderADMSpec extends CoreSpec with ImplicitSender { "return 'NotFoundException' when the project SHORTCODE is unknown" in { val exit = UnsafeZioRun.run( - ProjectsResponderADM.projectRestrictedViewSettingsGetRequestADM(ShortcodeIdentifier.unsafeFrom("9999")), + ProjectsResponderADM(_.projectRestrictedViewSettingsGetRequestADM(ShortcodeIdentifier.unsafeFrom("9999"))), ) assertFailsWithA[NotFoundException](exit, s"Project '9999' not found.") } "return 'NotFoundException' when the project SHORTNAME is unknown" in { val exit = UnsafeZioRun.run( - ProjectsResponderADM.projectRestrictedViewSettingsGetRequestADM( - ShortnameIdentifier.unsafeFrom("wrongshortname"), + ProjectsResponderADM( + _.projectRestrictedViewSettingsGetRequestADM( + ShortnameIdentifier.unsafeFrom("wrongshortname"), + ), ), ) assertFailsWithA[NotFoundException](exit, s"Project 'wrongshortname' not found.") @@ -186,7 +197,9 @@ class ProjectsResponderADMSpec extends CoreSpec with ImplicitSender { // Check Administrative Permissions val receivedApAdmin = - UnsafeZioRun.runOrThrow(PermissionsResponderADM.getPermissionsApByProjectIri(received.project.id)) + UnsafeZioRun.runOrThrow( + ZIO.serviceWithZIO[PermissionsResponderADM](_.getPermissionsApByProjectIri(received.project.id)), + ) val hasAPForProjectAdmin = receivedApAdmin.administrativePermissions.filter { (ap: AdministrativePermissionADM) => @@ -208,7 +221,9 @@ class ProjectsResponderADMSpec extends CoreSpec with ImplicitSender { // Check Default Object Access permissions val receivedDoaps = UnsafeZioRun.runOrThrow( - PermissionsResponderADM.getPermissionsDaopByProjectIri(ProjectIri.unsafeFrom(received.project.id)), + ZIO.serviceWithZIO[PermissionsResponderADM]( + _.getPermissionsDaopByProjectIri(ProjectIri.unsafeFrom(received.project.id)), + ), ) // Check Default Object Access permission of ProjectAdmin @@ -409,11 +424,12 @@ class ProjectsResponderADMSpec extends CoreSpec with ImplicitSender { "used to query members" should { "return all members of a project identified by IRI" in { val actual = UnsafeZioRun.runOrThrow( - ProjectsResponderADM - .projectMembersGetRequestADM( + ProjectsResponderADM( + _.projectMembersGetRequestADM( IriIdentifier.unsafeFrom(SharedTestDataADM.imagesProject.id), SharedTestDataADM.rootUser, ), + ), ) val members = actual.members @@ -428,11 +444,12 @@ class ProjectsResponderADMSpec extends CoreSpec with ImplicitSender { "return all members of a project identified by shortname" in { val actual = UnsafeZioRun.runOrThrow( - ProjectsResponderADM - .projectMembersGetRequestADM( + ProjectsResponderADM( + _.projectMembersGetRequestADM( ShortnameIdentifier.unsafeFrom(SharedTestDataADM.imagesProject.shortname), SharedTestDataADM.rootUser, ), + ), ) val members = actual.members @@ -447,11 +464,12 @@ class ProjectsResponderADMSpec extends CoreSpec with ImplicitSender { "return all members of a project identified by shortcode" in { val actual = UnsafeZioRun.runOrThrow( - ProjectsResponderADM - .projectMembersGetRequestADM( + ProjectsResponderADM( + _.projectMembersGetRequestADM( ShortcodeIdentifier.unsafeFrom(SharedTestDataADM.imagesProject.shortcode), SharedTestDataADM.rootUser, ), + ), ) val members = actual.members @@ -466,9 +484,11 @@ class ProjectsResponderADMSpec extends CoreSpec with ImplicitSender { "return 'NotFound' when the project IRI is unknown (project membership)" in { val exit = UnsafeZioRun.run( - ProjectsResponderADM.projectMembersGetRequestADM( - IriIdentifier.unsafeFrom(notExistingProjectButValidProjectIri), - SharedTestDataADM.rootUser, + ProjectsResponderADM( + _.projectMembersGetRequestADM( + IriIdentifier.unsafeFrom(notExistingProjectButValidProjectIri), + SharedTestDataADM.rootUser, + ), ), ) assertFailsWithA[NotFoundException](exit, s"Project '$notExistingProjectButValidProjectIri' not found.") @@ -476,9 +496,11 @@ class ProjectsResponderADMSpec extends CoreSpec with ImplicitSender { "return 'NotFound' when the project shortname is unknown (project membership)" in { val exit = UnsafeZioRun.run( - ProjectsResponderADM.projectMembersGetRequestADM( - ShortnameIdentifier.unsafeFrom("wrongshortname"), - SharedTestDataADM.rootUser, + ProjectsResponderADM( + _.projectMembersGetRequestADM( + ShortnameIdentifier.unsafeFrom("wrongshortname"), + SharedTestDataADM.rootUser, + ), ), ) assertFailsWithA[NotFoundException](exit, s"Project 'wrongshortname' not found.") @@ -486,9 +508,11 @@ class ProjectsResponderADMSpec extends CoreSpec with ImplicitSender { "return 'NotFound' when the project shortcode is unknown (project membership)" in { val exit = UnsafeZioRun.run( - ProjectsResponderADM.projectMembersGetRequestADM( - ShortcodeIdentifier.unsafeFrom("9999"), - SharedTestDataADM.rootUser, + ProjectsResponderADM( + _.projectMembersGetRequestADM( + ShortcodeIdentifier.unsafeFrom("9999"), + SharedTestDataADM.rootUser, + ), ), ) assertFailsWithA[NotFoundException](exit, s"Project '9999' not found.") @@ -496,9 +520,11 @@ class ProjectsResponderADMSpec extends CoreSpec with ImplicitSender { "return all project admin members of a project identified by IRI" in { val received = UnsafeZioRun.runOrThrow( - ProjectsResponderADM.projectAdminMembersGetRequestADM( - IriIdentifier.unsafeFrom(SharedTestDataADM.imagesProject.id), - SharedTestDataADM.rootUser, + ProjectsResponderADM( + _.projectAdminMembersGetRequestADM( + IriIdentifier.unsafeFrom(SharedTestDataADM.imagesProject.id), + SharedTestDataADM.rootUser, + ), ), ) @@ -512,9 +538,11 @@ class ProjectsResponderADMSpec extends CoreSpec with ImplicitSender { "return all project admin members of a project identified by shortname" in { val received = UnsafeZioRun.runOrThrow( - ProjectsResponderADM.projectAdminMembersGetRequestADM( - ShortnameIdentifier.unsafeFrom(SharedTestDataADM.imagesProject.shortname), - SharedTestDataADM.rootUser, + ProjectsResponderADM( + _.projectAdminMembersGetRequestADM( + ShortnameIdentifier.unsafeFrom(SharedTestDataADM.imagesProject.shortname), + SharedTestDataADM.rootUser, + ), ), ) @@ -528,9 +556,11 @@ class ProjectsResponderADMSpec extends CoreSpec with ImplicitSender { "return all project admin members of a project identified by shortcode" in { val received = UnsafeZioRun.runOrThrow( - ProjectsResponderADM.projectAdminMembersGetRequestADM( - ShortcodeIdentifier.unsafeFrom(SharedTestDataADM.imagesProject.shortcode), - SharedTestDataADM.rootUser, + ProjectsResponderADM( + _.projectAdminMembersGetRequestADM( + ShortcodeIdentifier.unsafeFrom(SharedTestDataADM.imagesProject.shortcode), + SharedTestDataADM.rootUser, + ), ), ) @@ -544,9 +574,11 @@ class ProjectsResponderADMSpec extends CoreSpec with ImplicitSender { "return 'NotFound' when the project IRI is unknown (project admin membership)" in { val exit = UnsafeZioRun.run( - ProjectsResponderADM.projectAdminMembersGetRequestADM( - IriIdentifier.unsafeFrom(notExistingProjectButValidProjectIri), - SharedTestDataADM.rootUser, + ProjectsResponderADM( + _.projectAdminMembersGetRequestADM( + IriIdentifier.unsafeFrom(notExistingProjectButValidProjectIri), + SharedTestDataADM.rootUser, + ), ), ) @@ -555,9 +587,11 @@ class ProjectsResponderADMSpec extends CoreSpec with ImplicitSender { "return 'NotFound' when the project shortname is unknown (project admin membership)" in { val exit = UnsafeZioRun.run( - ProjectsResponderADM.projectAdminMembersGetRequestADM( - ShortnameIdentifier.unsafeFrom("wrongshortname"), - SharedTestDataADM.rootUser, + ProjectsResponderADM( + _.projectAdminMembersGetRequestADM( + ShortnameIdentifier.unsafeFrom("wrongshortname"), + SharedTestDataADM.rootUser, + ), ), ) assertFailsWithA[NotFoundException](exit, s"Project 'wrongshortname' not found.") @@ -565,9 +599,11 @@ class ProjectsResponderADMSpec extends CoreSpec with ImplicitSender { "return 'NotFound' when the project shortcode is unknown (project admin membership)" in { val exit = UnsafeZioRun.run( - ProjectsResponderADM.projectAdminMembersGetRequestADM( - ShortcodeIdentifier.unsafeFrom("9999"), - SharedTestDataADM.rootUser, + ProjectsResponderADM( + _.projectAdminMembersGetRequestADM( + ShortcodeIdentifier.unsafeFrom("9999"), + SharedTestDataADM.rootUser, + ), ), ) assertFailsWithA[NotFoundException](exit, s"Project '9999' not found.") @@ -576,14 +612,16 @@ class ProjectsResponderADMSpec extends CoreSpec with ImplicitSender { "used to query keywords" should { "return all unique keywords for all projects" in { - val received = UnsafeZioRun.runOrThrow(ProjectsResponderADM.projectsKeywordsGetRequestADM()) + val received = UnsafeZioRun.runOrThrow(ProjectsResponderADM(_.projectsKeywordsGetRequestADM())) received.keywords.size should be(21) } "return all keywords for a single project" in { val received = UnsafeZioRun.runOrThrow( - ProjectsResponderADM.projectKeywordsGetRequestADM( - ProjectIri.unsafeFrom(SharedTestDataADM.incunabulaProject.id), + ProjectsResponderADM( + _.projectKeywordsGetRequestADM( + ProjectIri.unsafeFrom(SharedTestDataADM.incunabulaProject.id), + ), ), ) received.keywords should be(SharedTestDataADM.incunabulaProject.keywords) @@ -591,14 +629,18 @@ class ProjectsResponderADMSpec extends CoreSpec with ImplicitSender { "return empty list for a project without keywords" in { val received = UnsafeZioRun.runOrThrow( - ProjectsResponderADM.projectKeywordsGetRequestADM(ProjectIri.unsafeFrom(SharedTestDataADM.dokubibProject.id)), + ProjectsResponderADM( + _.projectKeywordsGetRequestADM(ProjectIri.unsafeFrom(SharedTestDataADM.dokubibProject.id)), + ), ) received.keywords should be(Seq.empty[String]) } "return 'NotFound' when the project IRI is unknown" in { val exit = UnsafeZioRun.run( - ProjectsResponderADM.projectKeywordsGetRequestADM(ProjectIri.unsafeFrom(notExistingProjectButValidProjectIri)), + ProjectsResponderADM( + _.projectKeywordsGetRequestADM(ProjectIri.unsafeFrom(notExistingProjectButValidProjectIri)), + ), ) assertFailsWithA[NotFoundException](exit, s"Project '$notExistingProjectButValidProjectIri' not found.") } diff --git a/integration/src/test/scala/org/knora/webapi/responders/admin/UsersRestServiceSpec.scala b/integration/src/test/scala/org/knora/webapi/responders/admin/UsersRestServiceSpec.scala index 61ca3b7adb..b6380504ce 100644 --- a/integration/src/test/scala/org/knora/webapi/responders/admin/UsersRestServiceSpec.scala +++ b/integration/src/test/scala/org/knora/webapi/responders/admin/UsersRestServiceSpec.scala @@ -436,9 +436,11 @@ class UsersRestServiceSpec extends CoreSpec with ImplicitSender { membershipsAfterUpdate.projects.map(_.id) should equal(Chunk(imagesProject.id)) val received = UnsafeZioRun.runOrThrow( - ProjectsResponderADM.projectMembersGetRequestADM( - IriIdentifier.unsafeFrom(imagesProject.id), - KnoraSystemInstances.Users.SystemUser, + ZIO.serviceWithZIO[ProjectsResponderADM]( + _.projectMembersGetRequestADM( + IriIdentifier.unsafeFrom(imagesProject.id), + KnoraSystemInstances.Users.SystemUser, + ), ), ) received.members.map(_.id) should contain(normalUser.id) @@ -458,9 +460,11 @@ class UsersRestServiceSpec extends CoreSpec with ImplicitSender { ) val received = UnsafeZioRun.runOrThrow( - ProjectsResponderADM.projectMembersGetRequestADM( - IriIdentifier.unsafeFrom(incunabulaProject.id), - KnoraSystemInstances.Users.SystemUser, + ZIO.serviceWithZIO[ProjectsResponderADM]( + _.projectMembersGetRequestADM( + IriIdentifier.unsafeFrom(incunabulaProject.id), + KnoraSystemInstances.Users.SystemUser, + ), ), ) received.members.map(_.id) should contain(normalUser.id) @@ -497,7 +501,9 @@ class UsersRestServiceSpec extends CoreSpec with ImplicitSender { // also check that the user has been removed from the project's list of users val received = UnsafeZioRun.runOrThrow( - ProjectsResponderADM.projectMembersGetRequestADM(IriIdentifier.unsafeFrom(imagesProject.id), rootUser), + ZIO.serviceWithZIO[ProjectsResponderADM]( + _.projectMembersGetRequestADM(IriIdentifier.unsafeFrom(imagesProject.id), rootUser), + ), ) received.members should not contain normalUser.ofType(UserInformationType.Restricted) } @@ -541,7 +547,9 @@ class UsersRestServiceSpec extends CoreSpec with ImplicitSender { // get project admins for images project (should contain normal user) val received = UnsafeZioRun.runOrThrow( - ProjectsResponderADM.projectAdminMembersGetRequestADM(IriIdentifier.unsafeFrom(imagesProject.id), rootUser), + ZIO.serviceWithZIO[ProjectsResponderADM]( + _.projectAdminMembersGetRequestADM(IriIdentifier.unsafeFrom(imagesProject.id), rootUser), + ), ) received.members.map(_.id) should contain(normalUser.id) } @@ -564,7 +572,9 @@ class UsersRestServiceSpec extends CoreSpec with ImplicitSender { membershipsAfterUpdate.projects should equal(Seq()) val received = UnsafeZioRun.runOrThrow( - ProjectsResponderADM.projectAdminMembersGetRequestADM(IriIdentifier.unsafeFrom(imagesProject.id), rootUser), + ZIO.serviceWithZIO[ProjectsResponderADM]( + _.projectAdminMembersGetRequestADM(IriIdentifier.unsafeFrom(imagesProject.id), rootUser), + ), ) received.members should not contain normalUser.ofType(UserInformationType.Restricted) } @@ -586,9 +596,11 @@ class UsersRestServiceSpec extends CoreSpec with ImplicitSender { membershipsAfterUpdate.map(_.id) should equal(Seq(imagesReviewerGroup.id)) val received = UnsafeZioRun.runOrThrow( - GroupsResponderADM.groupMembersGetRequest( - GroupIri.unsafeFrom(imagesReviewerGroup.id), - rootUser, + ZIO.serviceWithZIO[GroupsResponderADM]( + _.groupMembersGetRequest( + GroupIri.unsafeFrom(imagesReviewerGroup.id), + rootUser, + ), ), ) received.members.map(_.id) should contain(normalUser.id) @@ -610,9 +622,11 @@ class UsersRestServiceSpec extends CoreSpec with ImplicitSender { membershipsAfterUpdate should equal(Seq()) val received = UnsafeZioRun.runOrThrow( - GroupsResponderADM.groupMembersGetRequest( - GroupIri.unsafeFrom(imagesReviewerGroup.id), - rootUser, + ZIO.serviceWithZIO[GroupsResponderADM]( + _.groupMembersGetRequest( + GroupIri.unsafeFrom(imagesReviewerGroup.id), + rootUser, + ), ), ) received.members.map(_.id) should not contain normalUser diff --git a/integration/src/test/scala/org/knora/webapi/routing/AuthenticatorSpec.scala b/integration/src/test/scala/org/knora/webapi/routing/AuthenticatorSpec.scala index 9d2d89b6a8..00de3146e9 100644 --- a/integration/src/test/scala/org/knora/webapi/routing/AuthenticatorSpec.scala +++ b/integration/src/test/scala/org/knora/webapi/routing/AuthenticatorSpec.scala @@ -57,8 +57,7 @@ class AuthenticatorSpec extends CoreSpec with ImplicitSender with PrivateMethodT "succeed with correct token" in { val isAuthenticated = UnsafeZioRun.runOrThrow( for { - token <- - JwtService.createJwt(testUserAdmFromIri("http://rdfh.ch/users/X-T8IkfQTKa86UWuISpbOA")).map(_.jwtString) + token <- createJwtTokenString(testUserAdmFromIri("http://rdfh.ch/users/X-T8IkfQTKa86UWuISpbOA")) tokenCreds = KnoraJWTTokenCredentialsV2(token) result <- Authenticator.authenticateCredentialsV2(Some(tokenCreds)) } yield result, @@ -68,8 +67,7 @@ class AuthenticatorSpec extends CoreSpec with ImplicitSender with PrivateMethodT "fail with invalidated token" in { val actual = UnsafeZioRun .run(for { - token <- - JwtService.createJwt(testUserAdmFromIri("http://rdfh.ch/users/X-T8IkfQTKa86UWuISpbOA")).map(_.jwtString) + token <- createJwtTokenString(testUserAdmFromIri("http://rdfh.ch/users/X-T8IkfQTKa86UWuISpbOA")) tokenCreds = KnoraJWTTokenCredentialsV2(token) _ = CacheUtil.put(AUTHENTICATION_INVALIDATION_CACHE_NAME, tokenCreds.jwtToken, tokenCreds.jwtToken) result <- Authenticator.authenticateCredentialsV2(Some(tokenCreds)) diff --git a/integration/src/test/scala/org/knora/webapi/routing/JwtServiceSpec.scala b/integration/src/test/scala/org/knora/webapi/routing/JwtServiceSpec.scala index 3837b720d3..ff46a7b53c 100644 --- a/integration/src/test/scala/org/knora/webapi/routing/JwtServiceSpec.scala +++ b/integration/src/test/scala/org/knora/webapi/routing/JwtServiceSpec.scala @@ -27,10 +27,12 @@ class JwtServiceSpec extends CoreSpec with ImplicitSender { "create a token" in { val runZio = for { - token <- JwtService.createJwt(SharedTestDataADM.anythingUser1, Map("foo" -> JsString("bar"))).map(_.jwtString) - useriri <- JwtService.extractUserIriFromToken(token) + token <- + ZIO + .serviceWithZIO[JwtService](_.createJwt(SharedTestDataADM.anythingUser1, Map("foo" -> JsString("bar")))) + .map(_.jwtString) + useriri <- ZIO.serviceWithZIO[JwtService](_.extractUserIriFromToken(token)) } yield useriri - UnsafeZioRun.runOrThrow(runZio) should be(Some(SharedTestDataADM.anythingUser1.id)) } @@ -41,7 +43,7 @@ class JwtServiceSpec extends CoreSpec with ImplicitSender { } def createTokenAndExtractAudience(user: User) = for { - token <- JwtService.createJwt(user) + token <- ZIO.serviceWithZIO[JwtService](_.createJwt(user)) jwtConfig <- ZIO.service[JwtConfig] decoded = JwtSprayJson.decodeAll(token.jwtString, jwtConfig.secret, Seq(JwtAlgorithm.HS256)) audience = decoded.toOption.flatMap { case (_, claims, _) => claims.audience }.head @@ -54,47 +56,47 @@ class JwtServiceSpec extends CoreSpec with ImplicitSender { } "validate a token" in { - val tokenValid = JwtService.validateToken(validToken) + val tokenValid = ZIO.serviceWithZIO[JwtService](_.validateToken(validToken)) UnsafeZioRun.runOrThrow(tokenValid) should be(true) } "extract the user's IRI" in { - val runZio = JwtService.extractUserIriFromToken(validToken) + val runZio = ZIO.serviceWithZIO[JwtService](_.extractUserIriFromToken(validToken)) UnsafeZioRun.runOrThrow(runZio) should be(Some(SharedTestDataADM.anythingUser1.id)) } "not decode an invalid token" in { val invalidToken: String = "foobareyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJLbm9yYSIsInN1YiI6Imh0dHA6Ly9yZGZoLmNoL3VzZXJzLzlYQkNyRFYzU1JhN2tTMVd3eW5CNFEiLCJhdWQiOlsiS25vcmEiLCJTaXBpIl0sImV4cCI6NDY5NTE5MzYwNSwiaWF0IjoxNTQxNTkzNjA1LCJqdGkiOiJsZmdreWJqRlM5Q1NiV19NeVA0SGV3IiwiZm9vIjoiYmFyIn0.qPMJjv8tVOM7KKDxR4Dmdz_kB0FzTOtJBYHSp62Dilk" - val runZio = JwtService.extractUserIriFromToken(invalidToken) + val runZio = ZIO.serviceWithZIO[JwtService](_.extractUserIriFromToken(invalidToken)) UnsafeZioRun.runOrThrow(runZio) should be(None) } "not decode a token with an invalid user IRI" in { val tokenWithInvalidSubject = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJLbm9yYSIsInN1YiI6ImludmFsaWQiLCJhdWQiOlsiS25vcmEiLCJTaXBpIl0sImV4cCI6NDY5NTE5MzYwNSwiaWF0IjoxNTQxNTkzNjA1LCJqdGkiOiJsZmdreWJqRlM5Q1NiV19NeVA0SGV3IiwiZm9vIjoiYmFyIn0.9uPJahn_KtCCZrnr5e4OHbEh3DsSIiX_b3ZB6H3ptY4" - val runZio = JwtService.extractUserIriFromToken(tokenWithInvalidSubject) + val runZio = ZIO.serviceWithZIO[JwtService](_.extractUserIriFromToken(tokenWithInvalidSubject)) UnsafeZioRun.runOrThrow(runZio) should be(None) } "not decode a token with missing required content" in { val tokenWithMissingExp = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJLbm9yYSIsInN1YiI6Imh0dHA6Ly9yZGZoLmNoL3VzZXJzLzlYQkNyRFYzU1JhN2tTMVd3eW5CNFEiLCJhdWQiOlsiS25vcmEiLCJTaXBpIl0sImlhdCI6MTU0MTU5MzYwNSwianRpIjoibGZna3liakZTOUNTYldfTXlQNEhldyIsImZvbyI6ImJhciJ9.-ugb7OCoQq1JvBSso2HlfqVRBWM97b8burJTp3J9WeQ" - val runZio = JwtService.extractUserIriFromToken(tokenWithMissingExp) + val runZio = ZIO.serviceWithZIO[JwtService](_.extractUserIriFromToken(tokenWithMissingExp)) UnsafeZioRun.runOrThrow(runZio) should be(None) } "not decode an expired token" in { val expiredToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJLbm9yYSIsInN1YiI6Imh0dHA6Ly9yZGZoLmNoL3VzZXJzLzlYQkNyRFYzU1JhN2tTMVd3eW5CNFEiLCJhdWQiOlsiS25vcmEiLCJTaXBpIl0sImV4cCI6MTU0MTU5MzYwNiwiaWF0IjoxNTQxNTkzNjA1LCJqdGkiOiJsZmdreWJqRlM5Q1NiV19NeVA0SGV3IiwiZm9vIjoiYmFyIn0.gahFI5-xg_gKLAwHRkKNbF0p_PzBTWC2m36vAYJPkz4" - val runZio = JwtService.extractUserIriFromToken(expiredToken) + val runZio = ZIO.serviceWithZIO[JwtService](_.extractUserIriFromToken(expiredToken)) UnsafeZioRun.runOrThrow(runZio) should be(None) } "reject a token with a different issuer than the one who created the token" in { val tokenWithDifferentIssuer = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJibGFibGEiLCJzdWIiOiJodHRwOi8vcmRmaC5jaC91c2Vycy85WEJDckRWM1NSYTdrUzFXd3luQjRRIiwiYXVkIjpbIktub3JhIiwiU2lwaSJdLCJleHAiOjQ4MDE0NjkyNzgsImlhdCI6MTY0Nzg2OTI3OCwianRpIjoiYU9HRExCYnJUbi1iQUIwVXZzTDZMZyIsImZvbyI6ImJhciJ9.ewFp0uXjPkn6GSGvDcph1MZRPpip669IrpXQ8Qv3Vpw" - val runZio = JwtService.validateToken(tokenWithDifferentIssuer) + val runZio = ZIO.serviceWithZIO[JwtService](_.validateToken(tokenWithDifferentIssuer)) UnsafeZioRun.runOrThrow(runZio) should be(false) } } diff --git a/webapi/src/main/scala/org/knora/webapi/core/AppRouter.scala b/webapi/src/main/scala/org/knora/webapi/core/AppRouter.scala index 0a498b965a..05fdcee907 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/AppRouter.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/AppRouter.scala @@ -7,7 +7,6 @@ package org.knora.webapi.core import org.apache.pekko import zio.* -import zio.macros.accessible import org.knora.webapi.core import org.knora.webapi.messages.util.ConstructResponseUtilV2 @@ -24,11 +23,7 @@ import org.knora.webapi.slice.ontology.repo.service.OntologyCache import pekko.actor.{ActorRef, Props} import pekko.routing.RoundRobinPool -@accessible -trait AppRouter { - val system: pekko.actor.ActorSystem - val ref: ActorRef -} +final case class AppRouter private (system: pekko.actor.ActorSystem, ref: ActorRef) object AppRouter { val layer: ZLayer[ @@ -39,22 +34,17 @@ object AppRouter { ] = ZLayer { for { - as <- ZIO.service[pekko.actor.ActorSystem] + system <- ZIO.service[pekko.actor.ActorSystem] messageRelay <- ZIO.service[MessageRelay] runtime <- ZIO.runtime[ CardinalityHandler & CardinalityService & ConstructResponseUtilV2 & OntologyCache & OntologyHelpers & OntologyRepo & PermissionUtilADM & ResourceUtilV2 & StandoffTagUtilV2, ] - } yield new AppRouter { - implicit val system: org.apache.pekko.actor.ActorSystem = as - - val ref: ActorRef = system.actorOf( - Props( - core.actors.RoutingActor(messageRelay, runtime), - ).withRouter(new RoundRobinPool(1_000)), - name = APPLICATION_MANAGER_ACTOR_NAME, - ) - } + ref = system.actorOf( + Props(core.actors.RoutingActor(messageRelay, runtime)).withRouter(new RoundRobinPool(1_000)), + name = APPLICATION_MANAGER_ACTOR_NAME, + ) + } yield AppRouter(system, ref) }.tap(_ => ZIO.logInfo(">>> AppRouter Initialized <<<")) } diff --git a/webapi/src/main/scala/org/knora/webapi/core/LayersLive.scala b/webapi/src/main/scala/org/knora/webapi/core/LayersLive.scala index 1bbfe44227..915e41c7ea 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/LayersLive.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/LayersLive.scala @@ -141,7 +141,7 @@ object LayersLive { MaintenanceEndpoints.layer, MaintenanceEndpointsHandlers.layer, MaintenanceRestService.layer, - MaintenanceServiceLive.layer, + MaintenanceService.layer, ManagementRoutes.layer, MessageRelayLive.layer, OntologyCacheLive.layer, diff --git a/webapi/src/main/scala/org/knora/webapi/core/State.scala b/webapi/src/main/scala/org/knora/webapi/core/State.scala index 45b45aa80c..5ce1a5e9fd 100644 --- a/webapi/src/main/scala/org/knora/webapi/core/State.scala +++ b/webapi/src/main/scala/org/knora/webapi/core/State.scala @@ -6,32 +6,17 @@ package org.knora.webapi.core import zio.* -import zio.macros.accessible import org.knora.webapi.core.domain.AppState -@accessible -trait State { - def set(v: AppState): UIO[Unit] - val getAppState: UIO[AppState] +final case class State private (private val state: Ref[AppState]) { + def set(v: AppState): UIO[Unit] = state.set(v) *> ZIO.logInfo(s"AppState set to ${v.toString()}") + def getAppState: UIO[AppState] = state.get } object State { val layer: ZLayer[Any, Nothing, State] = - ZLayer { - for { - ref <- Ref.make[AppState](AppState.Stopped) - } yield new StateImpl(ref) {} + ZLayer(Ref.make[AppState](AppState.Stopped).map(State.apply)) + .tap(_ => ZIO.logInfo(">>> AppStateService initialized <<<")) - }.tap(_ => ZIO.logInfo(">>> AppStateService initialized <<<")) - - sealed abstract private class StateImpl(state: Ref[AppState]) extends State { - - override def set(v: AppState): UIO[Unit] = - state.set(v) *> ZIO.logInfo(s"AppState set to ${v.toString()}") - - override val getAppState: UIO[AppState] = - state.get - - } } diff --git a/webapi/src/main/scala/org/knora/webapi/messages/util/search/gravsearch/prequery/InferenceOptimizationService.scala b/webapi/src/main/scala/org/knora/webapi/messages/util/search/gravsearch/prequery/InferenceOptimizationService.scala index 9be2cb3d43..5e11de774a 100644 --- a/webapi/src/main/scala/org/knora/webapi/messages/util/search/gravsearch/prequery/InferenceOptimizationService.scala +++ b/webapi/src/main/scala/org/knora/webapi/messages/util/search/gravsearch/prequery/InferenceOptimizationService.scala @@ -6,7 +6,6 @@ package org.knora.webapi.messages.util.search.gravsearch.prequery import zio.* -import zio.macros.accessible import org.knora.webapi.InternalSchema import org.knora.webapi.core.MessageRelay @@ -29,7 +28,6 @@ import org.knora.webapi.messages.util.search.ValuesPattern import org.knora.webapi.messages.util.search.WhereClause import org.knora.webapi.slice.ontology.repo.service.OntologyCache -@accessible trait InferenceOptimizationService { /** diff --git a/webapi/src/main/scala/org/knora/webapi/messages/v2/responder/valuemessages/ValueMessagesV2.scala b/webapi/src/main/scala/org/knora/webapi/messages/v2/responder/valuemessages/ValueMessagesV2.scala index 95ca9aa122..8eb38baba6 100644 --- a/webapi/src/main/scala/org/knora/webapi/messages/v2/responder/valuemessages/ValueMessagesV2.scala +++ b/webapi/src/main/scala/org/knora/webapi/messages/v2/responder/valuemessages/ValueMessagesV2.scala @@ -5,7 +5,7 @@ package org.knora.webapi.messages.v2.responder.valuemessages -import zio.* +import zio.ZIO import java.time.Instant import java.util.UUID @@ -1143,8 +1143,13 @@ object ValueContentV2 { metadata <- ingestState match { case AssetIngestState.AssetIngested => val assetId = AssetId.unsafeFrom(internalFilename.substring(0, internalFilename.indexOf('.'))) - SipiService.getFileMetadataFromDspIngest(Shortcode.unsafeFrom(shortcode), assetId).logError - case AssetIngestState.AssetInTemp => SipiService.getFileMetadataFromSipiTemp(internalFilename) + ZIO + .serviceWithZIO[SipiService]( + _.getFileMetadataFromDspIngest(Shortcode.unsafeFrom(shortcode), assetId), + ) + .logError + case AssetIngestState.AssetInTemp => + ZIO.serviceWithZIO[SipiService](_.getFileMetadataFromSipiTemp(internalFilename)) } } yield FileInfo(internalFilename, metadata) } diff --git a/webapi/src/main/scala/org/knora/webapi/responders/admin/GroupsResponderADM.scala b/webapi/src/main/scala/org/knora/webapi/responders/admin/GroupsResponderADM.scala index db759008e2..d0a2ab9fb9 100644 --- a/webapi/src/main/scala/org/knora/webapi/responders/admin/GroupsResponderADM.scala +++ b/webapi/src/main/scala/org/knora/webapi/responders/admin/GroupsResponderADM.scala @@ -7,7 +7,6 @@ package org.knora.webapi.responders.admin import com.typesafe.scalalogging.LazyLogging import zio.* -import zio.macros.accessible import java.util.UUID @@ -51,7 +50,6 @@ import org.knora.webapi.util.ZioHelper /** * Returns information about groups. */ -@accessible trait GroupsResponderADM { /** diff --git a/webapi/src/main/scala/org/knora/webapi/responders/admin/PermissionsResponderADM.scala b/webapi/src/main/scala/org/knora/webapi/responders/admin/PermissionsResponderADM.scala index e31182dbde..1a7b8491a9 100644 --- a/webapi/src/main/scala/org/knora/webapi/responders/admin/PermissionsResponderADM.scala +++ b/webapi/src/main/scala/org/knora/webapi/responders/admin/PermissionsResponderADM.scala @@ -4,9 +4,9 @@ */ package org.knora.webapi.responders.admin + import com.typesafe.scalalogging.LazyLogging import zio.* -import zio.macros.accessible import java.util.UUID import scala.collection.immutable.Iterable @@ -57,7 +57,6 @@ import org.knora.webapi.util.ZioHelper /** * Provides information about permissions to other responders. */ -@accessible trait PermissionsResponderADM { /** diff --git a/webapi/src/main/scala/org/knora/webapi/responders/admin/ProjectsResponderADM.scala b/webapi/src/main/scala/org/knora/webapi/responders/admin/ProjectsResponderADM.scala index e868dbc2d7..4320c0cc50 100644 --- a/webapi/src/main/scala/org/knora/webapi/responders/admin/ProjectsResponderADM.scala +++ b/webapi/src/main/scala/org/knora/webapi/responders/admin/ProjectsResponderADM.scala @@ -6,7 +6,6 @@ package org.knora.webapi.responders.admin import com.typesafe.scalalogging.LazyLogging import zio.* -import zio.macros.accessible import java.util.UUID @@ -45,7 +44,6 @@ import org.knora.webapi.store.triplestore.api.TriplestoreService.Queries.Update /** * Returns information about projects. */ -@accessible trait ProjectsResponderADM { /** diff --git a/webapi/src/main/scala/org/knora/webapi/routing/JwtService.scala b/webapi/src/main/scala/org/knora/webapi/routing/JwtService.scala index 82e0ec4dcb..7521963f2a 100644 --- a/webapi/src/main/scala/org/knora/webapi/routing/JwtService.scala +++ b/webapi/src/main/scala/org/knora/webapi/routing/JwtService.scala @@ -22,7 +22,6 @@ import zio.URLayer import zio.ZIO import zio.ZLayer import zio.durationInt -import zio.macros.accessible import scala.util.Failure import scala.util.Success @@ -41,7 +40,6 @@ case class Jwt(jwtString: String, expiration: Long) /** * Provides functions for creating, decoding, and validating JWT tokens. */ -@accessible trait JwtService { /** diff --git a/webapi/src/main/scala/org/knora/webapi/slice/admin/api/service/GroupsRestService.scala b/webapi/src/main/scala/org/knora/webapi/slice/admin/api/service/GroupsRestService.scala index ffe976e7d2..63f6abbcb1 100644 --- a/webapi/src/main/scala/org/knora/webapi/slice/admin/api/service/GroupsRestService.scala +++ b/webapi/src/main/scala/org/knora/webapi/slice/admin/api/service/GroupsRestService.scala @@ -6,7 +6,6 @@ package org.knora.webapi.slice.admin.api.service import zio.* -import zio.macros.accessible import dsp.errors.NotFoundException import org.knora.webapi.messages.admin.responder.groupsmessages.* @@ -20,7 +19,6 @@ import org.knora.webapi.slice.admin.domain.model.User import org.knora.webapi.slice.common.api.AuthorizationRestService import org.knora.webapi.slice.common.api.KnoraResponseRenderer -@accessible trait GroupsRestService { def getGroups: Task[GroupsGetResponseADM] def getGroupByIri(iri: GroupIri): Task[GroupGetResponseADM] diff --git a/webapi/src/main/scala/org/knora/webapi/slice/admin/api/service/ProjectsADMRestService.scala b/webapi/src/main/scala/org/knora/webapi/slice/admin/api/service/ProjectsADMRestService.scala index 0410784da5..808a23268f 100644 --- a/webapi/src/main/scala/org/knora/webapi/slice/admin/api/service/ProjectsADMRestService.scala +++ b/webapi/src/main/scala/org/knora/webapi/slice/admin/api/service/ProjectsADMRestService.scala @@ -6,7 +6,6 @@ package org.knora.webapi.slice.admin.api.service import zio.* -import zio.macros.accessible import dsp.errors.BadRequestException import dsp.errors.NotFoundException @@ -31,7 +30,6 @@ import org.knora.webapi.slice.admin.domain.service.ProjectImportService import org.knora.webapi.slice.common.api.AuthorizationRestService import org.knora.webapi.slice.common.api.KnoraResponseRenderer -@accessible trait ProjectADMRestService { def listAllProjects(): Task[ProjectsGetResponse] diff --git a/webapi/src/main/scala/org/knora/webapi/slice/admin/domain/service/DspIngestClient.scala b/webapi/src/main/scala/org/knora/webapi/slice/admin/domain/service/DspIngestClient.scala index 7f110aa981..f0f8816c1a 100644 --- a/webapi/src/main/scala/org/knora/webapi/slice/admin/domain/service/DspIngestClient.scala +++ b/webapi/src/main/scala/org/knora/webapi/slice/admin/domain/service/DspIngestClient.scala @@ -25,7 +25,6 @@ import zio.http.URL import zio.json.DecoderOps import zio.json.DeriveJsonDecoder import zio.json.JsonDecoder -import zio.macros.accessible import zio.nio.file.Files import zio.nio.file.Path import zio.stream.ZSink @@ -38,7 +37,6 @@ import org.knora.webapi.routing.JwtService import org.knora.webapi.slice.admin.api.model.MaintenanceRequests.AssetId import org.knora.webapi.slice.admin.domain.model.KnoraProject.Shortcode -@accessible trait DspIngestClient { def exportProject(shortcode: Shortcode): ZIO[Scope, Throwable, Path] diff --git a/webapi/src/main/scala/org/knora/webapi/slice/admin/domain/service/MaintenanceService.scala b/webapi/src/main/scala/org/knora/webapi/slice/admin/domain/service/MaintenanceService.scala index aac1c23c16..b6a097bd8e 100644 --- a/webapi/src/main/scala/org/knora/webapi/slice/admin/domain/service/MaintenanceService.scala +++ b/webapi/src/main/scala/org/knora/webapi/slice/admin/domain/service/MaintenanceService.scala @@ -9,7 +9,6 @@ import zio.IO import zio.Task import zio.ZIO import zio.ZLayer -import zio.macros.accessible import zio.stream.ZStream import org.knora.webapi.slice.admin.api.model.MaintenanceRequests.* @@ -20,18 +19,13 @@ import org.knora.webapi.store.triplestore.api.TriplestoreService import org.knora.webapi.store.triplestore.api.TriplestoreService.Queries.Select import org.knora.webapi.store.triplestore.api.TriplestoreService.Queries.Update -@accessible -trait MaintenanceService { - def fixTopLeftDimensions(report: ProjectsWithBakfilesReport): Task[Unit] -} - -final case class MaintenanceServiceLive( +final case class MaintenanceService( projectRepo: KnoraProjectRepo, triplestoreService: TriplestoreService, mapper: PredicateObjectMapper, -) extends MaintenanceService { +) { - override def fixTopLeftDimensions(report: ProjectsWithBakfilesReport): Task[Unit] = { + def fixTopLeftDimensions(report: ProjectsWithBakfilesReport): Task[Unit] = { def processProject(project: ProjectWithBakFiles): ZStream[Any, Throwable, Unit] = getKnoraProject(project).flatMap { knoraProject => ZStream @@ -149,6 +143,6 @@ final case class MaintenanceServiceLive( } } -object MaintenanceServiceLive { - val layer = ZLayer.derive[MaintenanceServiceLive] +object MaintenanceService { + val layer = ZLayer.derive[MaintenanceService] } diff --git a/webapi/src/main/scala/org/knora/webapi/slice/admin/domain/service/ProjectExportService.scala b/webapi/src/main/scala/org/knora/webapi/slice/admin/domain/service/ProjectExportService.scala index 65d8fb7839..d065207ad2 100644 --- a/webapi/src/main/scala/org/knora/webapi/slice/admin/domain/service/ProjectExportService.scala +++ b/webapi/src/main/scala/org/knora/webapi/slice/admin/domain/service/ProjectExportService.scala @@ -17,7 +17,6 @@ import zio.Scope import zio.Task import zio.ZIO import zio.ZLayer -import zio.macros.accessible import zio.nio.file.Files import zio.nio.file.Path @@ -34,7 +33,6 @@ import org.knora.webapi.store.triplestore.api.TriplestoreService import org.knora.webapi.store.triplestore.api.TriplestoreService.Queries.Construct import org.knora.webapi.util.ZScopedJavaIoStreams -@accessible trait ProjectExportService { def exportProject(project: KnoraProject): Task[Path] diff --git a/webapi/src/main/scala/org/knora/webapi/store/iiif/api/SipiService.scala b/webapi/src/main/scala/org/knora/webapi/store/iiif/api/SipiService.scala index 0a52a9c0e1..da6c26adca 100644 --- a/webapi/src/main/scala/org/knora/webapi/store/iiif/api/SipiService.scala +++ b/webapi/src/main/scala/org/knora/webapi/store/iiif/api/SipiService.scala @@ -8,7 +8,6 @@ package org.knora.webapi.store.iiif.api import zio.* import zio.json.DeriveJsonDecoder import zio.json.JsonDecoder -import zio.macros.accessible import zio.nio.file.Path import org.knora.webapi.messages.store.sipimessages.* @@ -60,7 +59,6 @@ object FileMetadataSipiResponse { implicit val decoder: JsonDecoder[FileMetadataSipiResponse] = DeriveJsonDecoder.gen[FileMetadataSipiResponse] } -@accessible trait SipiService { /** diff --git a/webapi/src/test/scala/org/knora/webapi/slice/admin/api/service/MaintenanceServiceLiveSpec.scala b/webapi/src/test/scala/org/knora/webapi/slice/admin/api/service/MaintenanceServiceSpec.scala similarity index 88% rename from webapi/src/test/scala/org/knora/webapi/slice/admin/api/service/MaintenanceServiceLiveSpec.scala rename to webapi/src/test/scala/org/knora/webapi/slice/admin/api/service/MaintenanceServiceSpec.scala index 4e1b5ba794..2d12823b1b 100644 --- a/webapi/src/test/scala/org/knora/webapi/slice/admin/api/service/MaintenanceServiceLiveSpec.scala +++ b/webapi/src/test/scala/org/knora/webapi/slice/admin/api/service/MaintenanceServiceSpec.scala @@ -18,7 +18,6 @@ import org.knora.webapi.messages.StringFormatter import org.knora.webapi.slice.admin.api.model.MaintenanceRequests.* import org.knora.webapi.slice.admin.domain.repo.KnoraProjectRepoInMemory import org.knora.webapi.slice.admin.domain.service.MaintenanceService -import org.knora.webapi.slice.admin.domain.service.MaintenanceServiceLive import org.knora.webapi.slice.admin.domain.service.ProjectADMService import org.knora.webapi.slice.common.repo.service.PredicateObjectMapper import org.knora.webapi.slice.resourceinfo.domain.IriConverter @@ -29,7 +28,7 @@ import org.knora.webapi.store.triplestore.api.TriplestoreService.Queries.Select import org.knora.webapi.store.triplestore.api.TriplestoreServiceInMemory import org.knora.webapi.store.triplestore.api.TriplestoreServiceInMemory.emptyDatasetRefLayer -object MaintenanceServiceLiveSpec extends ZIOSpecDefault { +object MaintenanceServiceSpec extends ZIOSpecDefault { private val testProject = TestDataFactory.someProject private val createProject = ZIO.serviceWithZIO[KnoraProjectRepoInMemory](_.save(testProject)) @@ -75,18 +74,20 @@ object MaintenanceServiceLiveSpec extends ZIOSpecDefault { dim <- ZIO.fromEither(Dimensions.from(width, height)) } yield dim - val spec: Spec[Any, Any] = suite("MaintenanceServiceLive")( + val spec: Spec[Any, Any] = suite("MaintenanceService")( test("fixTopLeftDimensions should not fail for an empty report") { createProject *> saveStillImageFileValueWithDimensions(width = expectedDimension.height, height = expectedDimension.width) *> - MaintenanceService.fixTopLeftDimensions(ProjectsWithBakfilesReport(Chunk.empty)).as(assertCompletes) + ZIO + .serviceWithZIO[MaintenanceService](_.fixTopLeftDimensions(ProjectsWithBakfilesReport(Chunk.empty))) + .as(assertCompletes) }, test("fixTopLeftDimensions should not fail if no StillImageFileValue is found") { createProject *> - MaintenanceService.fixTopLeftDimensions(testReport).as(assertCompletes) + ZIO.serviceWithZIO[MaintenanceService](_.fixTopLeftDimensions(testReport)).as(assertCompletes) }, test("fixTopLeftDimensions should not fail if project is not found") { - MaintenanceService.fixTopLeftDimensions(testReport).as(assertCompletes) + ZIO.serviceWithZIO[MaintenanceService](_.fixTopLeftDimensions(testReport)).as(assertCompletes) }, test("fixTopLeftDimensions should transpose dimension for an existing StillImageFileValue") { for { @@ -94,7 +95,7 @@ object MaintenanceServiceLiveSpec extends ZIOSpecDefault { _ <- createProject _ <- saveStillImageFileValueWithDimensions(width = expectedDimension.height, height = expectedDimension.width) // when - _ <- MaintenanceService.fixTopLeftDimensions(testReport) + _ <- ZIO.serviceWithZIO[MaintenanceService](_.fixTopLeftDimensions(testReport)) // then actualDimension <- queryForDim() } yield assertTrue(actualDimension == expectedDimension) @@ -107,13 +108,13 @@ object MaintenanceServiceLiveSpec extends ZIOSpecDefault { _ <- createProject _ <- saveStillImageFileValueWithDimensions(width = expectedDimension.width, height = expectedDimension.height) // when - _ <- MaintenanceService.fixTopLeftDimensions(testReport) + _ <- ZIO.serviceWithZIO[MaintenanceService](_.fixTopLeftDimensions(testReport)) // then actualDimension <- queryForDim() } yield assertTrue(actualDimension == expectedDimension) }, ).provide( - MaintenanceServiceLive.layer, + MaintenanceService.layer, KnoraProjectRepoInMemory.layer, emptyDatasetRefLayer >>> TriplestoreServiceInMemory.layer, PredicateObjectMapper.layer, diff --git a/webapi/src/test/scala/org/knora/webapi/slice/admin/domain/service/DspIngestClientLiveSpec.scala b/webapi/src/test/scala/org/knora/webapi/slice/admin/domain/service/DspIngestClientLiveSpec.scala index 7dc334103a..97467116a3 100644 --- a/webapi/src/test/scala/org/knora/webapi/slice/admin/domain/service/DspIngestClientLiveSpec.scala +++ b/webapi/src/test/scala/org/knora/webapi/slice/admin/domain/service/DspIngestClientLiveSpec.scala @@ -57,6 +57,9 @@ object DspIngestClientLiveSpec extends ZIOSpecDefault { private val testShortcode = Shortcode.unsafeFrom(testShortcodeStr) private val testContent = "testContent".getBytes() + private val withDspIngestClient = ZIO.serviceWithZIO[DspIngestClient] + private val getTokenForDspIngest = ZIO.serviceWithZIO[JwtService](_.createJwtForDspIngest()).map(_.jwtString) + private val exportProjectSuite = suite("exportProject")(test("should download a project export") { val expectedUrl = s"/projects/$testShortcodeStr/export" for { @@ -71,10 +74,10 @@ object DspIngestClientLiveSpec extends ZIOSpecDefault { ) // when - path <- DspIngestClient.exportProject(testShortcode) + path <- withDspIngestClient(_.exportProject(testShortcode)) // then - mockJwt <- JwtService.createJwtForDspIngest().map(_.jwtString) + mockJwt <- getTokenForDspIngest _ <- HttpMockServer.verify.request( postRequestedFor(urlPathEqualTo(expectedUrl)) .withHeader("Authorization", equalTo(s"Bearer $mockJwt")), @@ -101,10 +104,10 @@ object DspIngestClientLiveSpec extends ZIOSpecDefault { _ <- HttpMockServer.stub.getResponseJsonBody(expectedUrl, 200, expected) // when - assetInfo <- DspIngestClient.getAssetInfo(testShortcode, assetId) + assetInfo <- withDspIngestClient(_.getAssetInfo(testShortcode, assetId)) // then - mockJwt <- JwtService.createJwtForDspIngest().map(_.jwtString) + mockJwt <- getTokenForDspIngest _ <- HttpMockServer.verify.request( getRequestedFor(urlPathEqualTo(expectedUrl)) .withHeader("Authorization", equalTo(s"Bearer $mockJwt")),