diff --git a/integration/src/test/scala/org/knora/webapi/e2e/admin/ProjectsADME2ESpec.scala b/integration/src/test/scala/org/knora/webapi/e2e/admin/ProjectsADME2ESpec.scala index 1e78aa45c3..e4df5dcc4f 100644 --- a/integration/src/test/scala/org/knora/webapi/e2e/admin/ProjectsADME2ESpec.scala +++ b/integration/src/test/scala/org/knora/webapi/e2e/admin/ProjectsADME2ESpec.scala @@ -787,7 +787,7 @@ class ProjectsADME2ESpec extends E2ESpec with ProjectsADMJsonProtocol { ) val response = singleAwaitingRequest(request) assert(response.status === StatusCodes.OK) - assert(responseToString(response) === """{"size":"pct:1","watermark":false}""") + assert(responseToString(response) === """{"size":"pct:1"}""") } "return the `BadRequest` if the size value is invalid" in { @@ -822,12 +822,11 @@ class ProjectsADME2ESpec extends E2ESpec with ProjectsADMJsonProtocol { } "used to set RestrictedViewSize by project Shortcode" should { - "return requested value to be set with 200 Response Status" in { + "when setting watermark to false return default size with 200 Response Status" in { val shortcode = SharedTestDataADM.imagesProject.shortcode val payload = """ |{ - | "size":"!512,512", - | "watermark":true + | "watermark": false |}""".stripMargin val request = Post( @@ -838,7 +837,7 @@ class ProjectsADME2ESpec extends E2ESpec with ProjectsADMJsonProtocol { ) val response: HttpResponse = singleAwaitingRequest(request) assert(response.status === StatusCodes.OK) - assert(responseToString(response) === """{"size":"!512,512","watermark":true}""") + assert(responseToString(response) === """{"size":"!128,128"}""") } "return the `BadRequest` if the size value is invalid" in { 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 194141fc9c..f1c54c3320 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 @@ -31,7 +31,6 @@ import org.knora.webapi.slice.admin.api.model.ProjectsEndpointsRequestsAndRespon import org.knora.webapi.slice.admin.api.model.ProjectsEndpointsRequestsAndResponses.ProjectUpdateRequest import org.knora.webapi.slice.admin.domain.model.KnoraProject.ProjectIri import org.knora.webapi.slice.admin.domain.model.RestrictedView -import org.knora.webapi.slice.admin.domain.model.RestrictedViewSize import org.knora.webapi.slice.admin.domain.model.User import org.knora.webapi.slice.admin.domain.model.UserIri import org.knora.webapi.slice.admin.domain.service.ProjectADMService @@ -745,10 +744,7 @@ final case class ProjectsResponderADMLive( ) // create permissions for admins and members of the new group _ <- createPermissionsForAdminsAndMembersOfNewProject(newProjectIRI) - _ <- projectService.setProjectRestrictedView( - newProjectADM, - RestrictedView(RestrictedViewSize.default, watermark = false) - ) + _ <- projectService.setProjectRestrictedView(newProjectADM, RestrictedView.default) } yield ProjectOperationResponseADM(project = newProjectADM.unescape) diff --git a/webapi/src/main/scala/org/knora/webapi/slice/admin/api/Codecs.scala b/webapi/src/main/scala/org/knora/webapi/slice/admin/api/Codecs.scala index 7fc1e805e8..48c40ed189 100644 --- a/webapi/src/main/scala/org/knora/webapi/slice/admin/api/Codecs.scala +++ b/webapi/src/main/scala/org/knora/webapi/slice/admin/api/Codecs.scala @@ -17,6 +17,12 @@ import org.knora.webapi.slice.admin.domain.model.ListProperties.Labels import org.knora.webapi.slice.admin.domain.model.ListProperties.ListIri import org.knora.webapi.slice.admin.domain.model.ListProperties.ListName import org.knora.webapi.slice.admin.domain.model.ListProperties.Position +import org.knora.webapi.slice.admin.domain.model.Password +import org.knora.webapi.slice.admin.domain.model.RestrictedView +import org.knora.webapi.slice.admin.domain.model.SystemAdmin +import org.knora.webapi.slice.admin.domain.model.UserIri +import org.knora.webapi.slice.admin.domain.model.UserStatus +import org.knora.webapi.slice.admin.domain.model.Username import org.knora.webapi.slice.admin.domain.model.* import org.knora.webapi.slice.common.Value.BooleanValue import org.knora.webapi.slice.common.Value.IntValue @@ -42,7 +48,6 @@ object Codecs { implicit val logo: StringCodec[Logo] = stringCodec(Logo.from) implicit val longname: StringCodec[Longname] = stringCodec(Longname.from) implicit val projectIri: StringCodec[ProjectIri] = stringCodec(ProjectIri.from) - implicit val restrictedViewSize: StringCodec[RestrictedViewSize] = stringCodec(RestrictedViewSize.from) implicit val selfJoin: StringCodec[SelfJoin] = booleanCodec(SelfJoin.from) implicit val shortcode: StringCodec[Shortcode] = stringCodec(Shortcode.from) implicit val shortname: StringCodec[Shortname] = stringCodec(Shortname.from) @@ -89,11 +94,14 @@ object Codecs { implicit val assetId: StringCodec[AssetId] = stringCodec(AssetId.from, _.value) // project - implicit val keyword: StringCodec[Keyword] = stringCodec(Keyword.from) - implicit val logo: StringCodec[Logo] = stringCodec(Logo.from) - implicit val longname: StringCodec[Longname] = stringCodec(Longname.from) - implicit val projectIri: StringCodec[ProjectIri] = stringCodec(ProjectIri.from) - implicit val restrictedViewSize: StringCodec[RestrictedViewSize] = stringCodec(RestrictedViewSize.from) + implicit val keyword: StringCodec[Keyword] = stringCodec(Keyword.from) + implicit val logo: StringCodec[Logo] = stringCodec(Logo.from) + implicit val longname: StringCodec[Longname] = stringCodec(Longname.from) + implicit val projectIri: StringCodec[ProjectIri] = stringCodec(ProjectIri.from) + implicit val restrictedViewSize: StringCodec[RestrictedView.Size] = stringCodec(RestrictedView.Size.from) + implicit val restrictedViewWatermark: StringCodec[RestrictedView.Watermark] = booleanCodec( + RestrictedView.Watermark.from + ) implicit val selfJoin: StringCodec[SelfJoin] = booleanCodec(SelfJoin.from) implicit val shortcode: StringCodec[Shortcode] = stringCodec(Shortcode.from) implicit val shortname: StringCodec[Shortname] = stringCodec(Shortname.from) diff --git a/webapi/src/main/scala/org/knora/webapi/slice/admin/api/ProjectsEndpoints.scala b/webapi/src/main/scala/org/knora/webapi/slice/admin/api/ProjectsEndpoints.scala index d3aa662f63..c226ab1ceb 100644 --- a/webapi/src/main/scala/org/knora/webapi/slice/admin/api/ProjectsEndpoints.scala +++ b/webapi/src/main/scala/org/knora/webapi/slice/admin/api/ProjectsEndpoints.scala @@ -24,7 +24,7 @@ import org.knora.webapi.slice.admin.api.model.ProjectsEndpointsRequestsAndRespon import org.knora.webapi.slice.admin.api.model.ProjectsEndpointsRequestsAndResponses.ProjectUpdateRequest import org.knora.webapi.slice.admin.api.model.ProjectsEndpointsRequestsAndResponses.RestrictedViewResponse import org.knora.webapi.slice.admin.api.model.ProjectsEndpointsRequestsAndResponses.SetRestrictedViewRequest -import org.knora.webapi.slice.admin.domain.model.RestrictedViewSize +import org.knora.webapi.slice.admin.domain.model.RestrictedView import org.knora.webapi.slice.common.api.BaseEndpoints final case class ProjectsEndpoints( @@ -94,17 +94,19 @@ final case class ProjectsEndpoints( object Secured { private val bodyProjectSetRestrictedViewSizeRequest = zioJsonBody[SetRestrictedViewRequest] - .default(SetRestrictedViewRequest(RestrictedViewSize.default, watermark = Some(false))) .description( - "The restricted view settings to be set.\n" + - "The image restrictions support two of the (IIIF size)[https://iiif.io/api/image/3.0/#42-size] forms:\n" + + "Set how all still image resources of a projects should be displayed when viewed as restricted.\n" + + "This can be either a size restriction or a watermark.\n" + + "For that, we support two of the (IIIF size)[https://iiif.io/api/image/3.0/#42-size] forms:\n" + "* `!d,d` The returned image is scaled so that the width and height of the returned image are not " + "greater than d, while maintaining the aspect ratio.\n" + "* `pct:n` The width and height of the returned image is scaled to n percent of the width and height " + "of the extracted region. 1<= n <= 100.\n\n" + - "If the watermark is set to `true`, the returned image will be watermarked." + "If the watermark is set to `true`, the returned image will be watermarked, " + + "otherwise the default size " + RestrictedView.Size.default.value + " is set.\n\n" + + "It is only possible to set either the size or the watermark, not both at the same time." ) - .example(SetRestrictedViewRequest(RestrictedViewSize.default, watermark = Some(false))) + .example(SetRestrictedViewRequest(Some(RestrictedView.Size.default), None)) val postAdminProjectsByProjectIriRestrictedViewSettings = baseEndpoints.securedEndpoint.post .in(projectsByIri / restrictedViewSettings) diff --git a/webapi/src/main/scala/org/knora/webapi/slice/admin/api/model/ProjectsEndpointsRequestsAndResponses.scala b/webapi/src/main/scala/org/knora/webapi/slice/admin/api/model/ProjectsEndpointsRequestsAndResponses.scala index a7118131ce..a3ab66465f 100644 --- a/webapi/src/main/scala/org/knora/webapi/slice/admin/api/model/ProjectsEndpointsRequestsAndResponses.scala +++ b/webapi/src/main/scala/org/knora/webapi/slice/admin/api/model/ProjectsEndpointsRequestsAndResponses.scala @@ -5,12 +5,15 @@ package org.knora.webapi.slice.admin.api.model +import zio.IO +import zio.ZIO import zio.json.DeriveJsonCodec import zio.json.JsonCodec +import dsp.errors.BadRequestException import org.knora.webapi.slice.admin.api.Codecs.ZioJsonCodec.* import org.knora.webapi.slice.admin.domain.model.KnoraProject.* -import org.knora.webapi.slice.admin.domain.model.RestrictedViewSize +import org.knora.webapi.slice.admin.domain.model.RestrictedView object ProjectsEndpointsRequestsAndResponses { @@ -42,13 +45,34 @@ object ProjectsEndpointsRequestsAndResponses { implicit val codec: JsonCodec[ProjectUpdateRequest] = DeriveJsonCodec.gen[ProjectUpdateRequest] } - final case class SetRestrictedViewRequest(size: RestrictedViewSize, watermark: Option[Boolean]) + final case class SetRestrictedViewRequest( + size: Option[RestrictedView.Size], + watermark: Option[RestrictedView.Watermark] + ) { + def toRestrictedView: IO[BadRequestException, RestrictedView] = + (size, watermark) match { + case (Some(size), None) => ZIO.succeed(size) + case (None, Some(watermark)) => ZIO.succeed(RestrictedView.Watermark.from(watermark.value)) + case _ => + ZIO.fail(BadRequestException("Specify either the size or the watermark; if none was provided, include one.")) + } + } + object SetRestrictedViewRequest { implicit val codec: JsonCodec[SetRestrictedViewRequest] = DeriveJsonCodec.gen[SetRestrictedViewRequest] } - final case class RestrictedViewResponse(size: RestrictedViewSize, watermark: Boolean) + final case class RestrictedViewResponse( + size: Option[RestrictedView.Size], + watermark: Option[RestrictedView.Watermark] + ) object RestrictedViewResponse { implicit val codec: JsonCodec[RestrictedViewResponse] = DeriveJsonCodec.gen[RestrictedViewResponse] + + def from(restrictedView: RestrictedView): RestrictedViewResponse = + restrictedView match { + case size: RestrictedView.Size => RestrictedViewResponse(Some(size), None) + case watermark: RestrictedView.Watermark => RestrictedViewResponse(None, Some(watermark)) + } } } 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 063fd9b8ed..d40a616fd1 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 @@ -23,7 +23,6 @@ import org.knora.webapi.slice.admin.api.model.ProjectsEndpointsRequestsAndRespon import org.knora.webapi.slice.admin.domain.model.KnoraProject.ProjectIri import org.knora.webapi.slice.admin.domain.model.KnoraProject.Shortcode import org.knora.webapi.slice.admin.domain.model.KnoraProject.Status -import org.knora.webapi.slice.admin.domain.model.RestrictedView import org.knora.webapi.slice.admin.domain.model.User import org.knora.webapi.slice.admin.domain.service.KnoraProjectRepo import org.knora.webapi.slice.admin.domain.service.ProjectADMService @@ -274,7 +273,7 @@ final case class ProjectsADMRestServiceLive( * @param id The project's id represented by iri, shortcode or shortname. * @param user Requesting user. * @param req Contains the values to be set. - * @return [[ProjectRestrictedViewSizeResponseADM]]. + * @return [[RestrictedViewResponse]]. */ override def updateProjectRestrictedViewSettings( id: ProjectIdentifierADM, @@ -282,11 +281,11 @@ final case class ProjectsADMRestServiceLive( req: SetRestrictedViewRequest ): Task[RestrictedViewResponse] = for { - project <- projectRepo.findById(id).someOrFail(NotFoundException(s"Project '${getId(id)}' not found.")) - _ <- permissionService.ensureSystemAdminOrProjectAdmin(user, project) - watermarkBool = req.watermark.getOrElse(false) - _ <- projectService.setProjectRestrictedView(project, RestrictedView(req.size, watermarkBool)) - } yield RestrictedViewResponse(req.size, watermarkBool) + project <- projectRepo.findById(id).someOrFail(NotFoundException(s"Project '${getId(id)}' not found.")) + _ <- permissionService.ensureSystemAdminOrProjectAdmin(user, project) + restrictedView <- req.toRestrictedView + newSettings <- projectService.setProjectRestrictedView(project, restrictedView) + } yield RestrictedViewResponse.from(newSettings) override def exportProject(shortcodeStr: String, user: User): Task[Unit] = convertStringToShortcodeId(shortcodeStr).flatMap(exportProject(_, user)) diff --git a/webapi/src/main/scala/org/knora/webapi/slice/admin/domain/model/RestrictedView.scala b/webapi/src/main/scala/org/knora/webapi/slice/admin/domain/model/RestrictedView.scala index 4673b98b91..2451de0ef4 100644 --- a/webapi/src/main/scala/org/knora/webapi/slice/admin/domain/model/RestrictedView.scala +++ b/webapi/src/main/scala/org/knora/webapi/slice/admin/domain/model/RestrictedView.scala @@ -8,27 +8,42 @@ package org.knora.webapi.slice.admin.domain.model import scala.util.matching.Regex import org.knora.webapi.slice.common.StringValueCompanion +import org.knora.webapi.slice.common.Value.BooleanValue import org.knora.webapi.slice.common.Value.StringValue -final case class RestrictedView(size: RestrictedViewSize, watermark: Boolean) +sealed trait RestrictedView -final case class RestrictedViewSize private (value: String) extends AnyVal with StringValue +object RestrictedView { -object RestrictedViewSize extends StringValueCompanion[RestrictedViewSize] { + val default: RestrictedView = Size.default - // matches strings "pct:n" with n between 1 and 100 - private val percentagePattern: Regex = "pct:(?:100|[1-9][0-9]?)$".r + final case class Watermark private (value: Boolean) extends RestrictedView with BooleanValue + object Watermark { - // matches strings "!x,x" where x is a positive integer and represents the dimensions of the restricted view - private val dimensionsPattern: Regex = "!(\\d+),(\\1)$".r + val On: Watermark = Watermark(true) + val Off: Watermark = Watermark(false) - val default: RestrictedViewSize = RestrictedViewSize.unsafeFrom("!512,512") + def from(value: Boolean): Watermark = if (value) On else Off + } - def from(value: String): Either[String, RestrictedViewSize] = - value match { - case _ if value.isEmpty => Left("RestrictedViewSize cannot be empty.") - case _ if percentagePattern.matches(value) => Right(RestrictedViewSize(value)) - case _ if dimensionsPattern.matches(value) => Right(RestrictedViewSize(value)) - case _ => Left(s"Invalid RestrictedViewSize: $value") - } + final case class Size private (value: String) extends RestrictedView with StringValue + + object Size extends StringValueCompanion[Size] { + + // matches strings "pct:n" with n between 1 and 100 + private val percentagePattern: Regex = "pct:(?:100|[1-9][0-9]?)$".r + + // matches strings "!x,x" where x is a positive integer and represents the dimensions of the restricted view + private val dimensionsPattern: Regex = "!(\\d+),(\\1)$".r + + val default: Size = Size.unsafeFrom("!128,128") + + def from(value: String): Either[String, Size] = + value match { + case _ if value.isEmpty => Left("RestrictedViewSize cannot be empty.") + case _ if percentagePattern.matches(value) => Right(Size(value)) + case _ if dimensionsPattern.matches(value) => Right(Size(value)) + case _ => Left(s"Invalid RestrictedViewSize: $value") + } + } } diff --git a/webapi/src/main/scala/org/knora/webapi/slice/admin/domain/service/ProjectADMService.scala b/webapi/src/main/scala/org/knora/webapi/slice/admin/domain/service/ProjectADMService.scala index 14cf0a93b4..27609165ef 100644 --- a/webapi/src/main/scala/org/knora/webapi/slice/admin/domain/service/ProjectADMService.scala +++ b/webapi/src/main/scala/org/knora/webapi/slice/admin/domain/service/ProjectADMService.scala @@ -96,10 +96,15 @@ final case class ProjectADMService( .map(_ :+ projectGraph) } - def setProjectRestrictedView(project: KnoraProject, settings: RestrictedView): Task[Unit] = - projectRepo.setProjectRestrictedView(project, settings) + def setProjectRestrictedView(project: KnoraProject, settings: RestrictedView): Task[RestrictedView] = { + val newSettings = settings match { + case RestrictedView.Watermark(false) => RestrictedView.default + case s => s + } + projectRepo.setProjectRestrictedView(project, newSettings).as(newSettings) + } - def setProjectRestrictedView(project: ProjectADM, settings: RestrictedView): Task[Unit] = + def setProjectRestrictedView(project: ProjectADM, settings: RestrictedView): Task[RestrictedView] = setProjectRestrictedView(toKnoraProject(project), settings) } diff --git a/webapi/src/main/scala/org/knora/webapi/slice/admin/repo/rdf/Vocabulary.scala b/webapi/src/main/scala/org/knora/webapi/slice/admin/repo/rdf/Vocabulary.scala index 395c7f2b08..e74ad7617a 100644 --- a/webapi/src/main/scala/org/knora/webapi/slice/admin/repo/rdf/Vocabulary.scala +++ b/webapi/src/main/scala/org/knora/webapi/slice/admin/repo/rdf/Vocabulary.scala @@ -41,6 +41,10 @@ object Vocabulary { val belongsToProject: Iri = Rdf.iri(KnoraAdminPrefixExpansion, "belongsToProject") val groupName: Iri = Rdf.iri(KnoraAdminPrefixExpansion, "groupName") val groupDescriptions: Iri = Rdf.iri(KnoraAdminPrefixExpansion, "groupDescriptions") + + // project properties + val projectRestrictedViewSize: Iri = Rdf.iri(KnoraAdminPrefixExpansion, "projectRestrictedViewSize") + val projectRestrictedViewWatermark: Iri = Rdf.iri(KnoraAdminPrefixExpansion, "projectRestrictedViewWatermark") } object KnoraBase { diff --git a/webapi/src/main/scala/org/knora/webapi/slice/admin/repo/service/KnoraProjectRepoLive.scala b/webapi/src/main/scala/org/knora/webapi/slice/admin/repo/service/KnoraProjectRepoLive.scala index f85cdc5589..0c61fdac9f 100644 --- a/webapi/src/main/scala/org/knora/webapi/slice/admin/repo/service/KnoraProjectRepoLive.scala +++ b/webapi/src/main/scala/org/knora/webapi/slice/admin/repo/service/KnoraProjectRepoLive.scala @@ -5,9 +5,11 @@ package org.knora.webapi.slice.admin.repo.service +import org.eclipse.rdf4j.model.vocabulary.RDF import org.eclipse.rdf4j.sparqlbuilder.core.SparqlBuilder.`var` as variable import org.eclipse.rdf4j.sparqlbuilder.core.query.Queries import org.eclipse.rdf4j.sparqlbuilder.graphpattern.GraphPatterns.tp +import org.eclipse.rdf4j.sparqlbuilder.rdf.Rdf import zio.* import dsp.errors.InconsistentRepositoryDataException @@ -16,7 +18,6 @@ import org.knora.webapi.messages.admin.responder.projectsmessages.ProjectIdentif import org.knora.webapi.slice.admin.domain.model.KnoraProject import org.knora.webapi.slice.admin.domain.model.KnoraProject.* import org.knora.webapi.slice.admin.domain.model.RestrictedView -import org.knora.webapi.slice.admin.domain.model.RestrictedViewSize import org.knora.webapi.slice.admin.domain.service.KnoraProjectRepo import org.knora.webapi.slice.admin.repo.rdf.RdfConversions.* import org.knora.webapi.slice.admin.repo.rdf.Vocabulary @@ -99,7 +100,7 @@ final case class KnoraProjectRepoLive( project: KnoraProject, settings: RestrictedView ): Task[Unit] = - triplestore.query(Update(ProjectQueries.setProjectRestrictedView(project.id, settings.size, settings.watermark))) + triplestore.query(ProjectQueries.setProjectRestrictedView(project.id, settings)) } @@ -160,31 +161,32 @@ object KnoraProjectRepoLive { Construct(query.getQueryString) } - def setProjectRestrictedView(projectIri: ProjectIri, size: RestrictedViewSize, watermark: Boolean): String = - s""" - |PREFIX rdf: - |PREFIX xsd: - |PREFIX knora-admin: - | - |WITH - |DELETE { - | <${projectIri.value}> knora-admin:projectRestrictedViewSize ?prevSize . - | <${projectIri.value}> knora-admin:projectRestrictedViewWatermark ?prevWatermark. - |} - |INSERT { - | <${projectIri.value}> knora-admin:projectRestrictedViewSize "${size.value}"^^xsd:string . - | <${projectIri.value}> knora-admin:projectRestrictedViewWatermark "$watermark"^^xsd:boolean. - |} - |WHERE { - | <${projectIri.value}> a knora-admin:knoraProject . - | OPTIONAL { - | <${projectIri.value}> knora-admin:projectRestrictedViewSize ?prevSize . - | } - | OPTIONAL { - | <${projectIri.value}> knora-admin:projectRestrictedViewWatermark ?prevWatermark . - | } - |} - |""".stripMargin + def setProjectRestrictedView(projectIri: ProjectIri, restriction: RestrictedView): Update = { + val project = Rdf.iri(projectIri.value) + val (prevSize, prevWatermark) = (variable("prevSize"), variable("prevWatermark")) + val query = Queries + .MODIFY() + .prefix(Vocabulary.KnoraAdmin.NS, RDF.NS) + .`with`(Vocabulary.NamedGraphs.knoraAdminIri) + .delete( + project.has(Vocabulary.KnoraAdmin.projectRestrictedViewSize, prevSize), + project.has(Vocabulary.KnoraAdmin.projectRestrictedViewWatermark, prevWatermark) + ) + .insert( + restriction match { + case RestrictedView.Watermark(value) => + project.has(Vocabulary.KnoraAdmin.projectRestrictedViewWatermark, value) + case RestrictedView.Size(value) => + project.has(Vocabulary.KnoraAdmin.projectRestrictedViewSize, value) + } + ) + .where( + project.isA(Vocabulary.KnoraAdmin.KnoraProject), + project.has(Vocabulary.KnoraAdmin.projectRestrictedViewSize, prevSize).optional(), + project.has(Vocabulary.KnoraAdmin.projectRestrictedViewWatermark, prevWatermark).optional() + ) + Update(query.getQueryString) + } } val layer = ZLayer.derive[KnoraProjectRepoLive] diff --git a/webapi/src/test/scala/dsp/valueobjects/RestrictedViewSpec.scala b/webapi/src/test/scala/dsp/valueobjects/RestrictedViewSpec.scala index e42c34df57..b3fcc5b7d7 100644 --- a/webapi/src/test/scala/dsp/valueobjects/RestrictedViewSpec.scala +++ b/webapi/src/test/scala/dsp/valueobjects/RestrictedViewSpec.scala @@ -8,11 +8,8 @@ package dsp.valueobjects import zio.Scope import zio.test.* -import org.knora.webapi.slice.admin.domain.model.RestrictedViewSize +import org.knora.webapi.slice.admin.domain.model.RestrictedView -/** - * This spec is used to test the [[RestrictedViewSize]] value object creation. - */ object RestrictedViewSpec extends ZIOSpecDefault { def spec: Spec[TestEnvironment & Scope, Nothing] = suite("RestrictedViewSize")( @@ -21,8 +18,8 @@ object RestrictedViewSpec extends ZIOSpecDefault { val gen = Gen.int(-1000, +1000) check(gen) { n => val param = s"pct:$n" - if (1 <= n && n <= 100) assertTrue(RestrictedViewSize.from(param).map(_.value) == Right(param)) - else assertTrue(RestrictedViewSize.from(param) == Left(s"Invalid RestrictedViewSize: pct:$n")) + if (1 <= n && n <= 100) assertTrue(RestrictedView.Size.from(param).map(_.value) == Right(param)) + else assertTrue(RestrictedView.Size.from(param) == Left(s"Invalid RestrictedViewSize: pct:$n")) } } ), @@ -31,24 +28,24 @@ object RestrictedViewSpec extends ZIOSpecDefault { val gen = Gen.int(1, 1000) check(gen) { n => val param = s"!$n,$n" - assertTrue(RestrictedViewSize.from(param).map(_.value) == Right(param)) + assertTrue(RestrictedView.Size.from(param).map(_.value) == Right(param)) } }, test("should fail on passing negative x y dimensions") { val gen = Gen.int(-1000, -1) check(gen) { n => val param = s"!$n,$n" - assertTrue(RestrictedViewSize.from(param).map(_.value) == Left(s"Invalid RestrictedViewSize: $param")) + assertTrue(RestrictedView.Size.from(param).map(_.value) == Left(s"Invalid RestrictedViewSize: $param")) } }, test("should fail on passing incorrect values") { val gen = Gen.fromIterable(Seq("!512,100", "pct:-1", "pct:0", "pct:101")) check(gen) { invalid => - assertTrue(RestrictedViewSize.from(invalid) == Left(s"Invalid RestrictedViewSize: $invalid")) + assertTrue(RestrictedView.Size.from(invalid) == Left(s"Invalid RestrictedViewSize: $invalid")) } }, test("should fail on passing empty value") { - assertTrue(RestrictedViewSize.from("") == Left("RestrictedViewSize cannot be empty.")) + assertTrue(RestrictedView.Size.from("") == Left("RestrictedViewSize cannot be empty.")) } ) )