From 3708cb615215e755d7cb16b290e6d0c98c708497 Mon Sep 17 00:00:00 2001 From: Raitis Veinbahs Date: Mon, 25 Nov 2024 10:51:36 +0100 Subject: [PATCH] remove moveTemporaryFileToPermanentStorage and serialization --- .../knora/sipi/SipiClientTestDelegator.scala | 13 ------- .../store/sipimessages/SipiMessages.scala | 10 ------ .../iiif/IIIFRequestMessageHandler.scala | 6 ++-- .../webapi/store/iiif/api/SipiService.scala | 11 ------ .../store/iiif/impl/SipiServiceLive.scala | 34 ------------------- .../store/iiif/impl/SipiServiceMock.scala | 15 -------- .../valuemessages/ValueContentV2Spec.scala | 6 ---- 7 files changed, 2 insertions(+), 93 deletions(-) diff --git a/integration/src/test/scala/org/knora/sipi/SipiClientTestDelegator.scala b/integration/src/test/scala/org/knora/sipi/SipiClientTestDelegator.scala index 75222b37c2..34d95938c2 100644 --- a/integration/src/test/scala/org/knora/sipi/SipiClientTestDelegator.scala +++ b/integration/src/test/scala/org/knora/sipi/SipiClientTestDelegator.scala @@ -10,10 +10,8 @@ import zio.ULayer import zio.ZLayer import zio.nio.file.Path -import org.knora.webapi.messages.store.sipimessages.MoveTemporaryFileToPermanentStorageRequest import org.knora.webapi.messages.store.sipimessages.SipiGetTextFileRequest import org.knora.webapi.messages.store.sipimessages.SipiGetTextFileResponse -import org.knora.webapi.messages.v2.responder.SuccessResponseV2 import org.knora.webapi.slice.admin.api.model.MaintenanceRequests.AssetId import org.knora.webapi.slice.admin.domain.model.KnoraProject import org.knora.webapi.slice.admin.domain.model.User @@ -57,17 +55,6 @@ case class SipiServiceTestDelegator( ): Task[FileMetadataSipiResponse] = sipiService.getFileMetadataFromDspIngest(shortcode, assetId) - /** - * Asks Sipi to move a file from temporary storage to permanent storage. - * - * @param moveTemporaryFileToPermanentStorageRequestV2 the request. - * @return a [[SuccessResponseV2]]. - */ - override def moveTemporaryFileToPermanentStorage( - moveTemporaryFileToPermanentStorageRequestV2: MoveTemporaryFileToPermanentStorageRequest, - ): Task[SuccessResponseV2] = - sipiService.moveTemporaryFileToPermanentStorage(moveTemporaryFileToPermanentStorageRequestV2) - /** * Asks Sipi for a text file used internally by Knora. * diff --git a/webapi/src/main/scala/org/knora/webapi/messages/store/sipimessages/SipiMessages.scala b/webapi/src/main/scala/org/knora/webapi/messages/store/sipimessages/SipiMessages.scala index 97589ad82b..148581394e 100644 --- a/webapi/src/main/scala/org/knora/webapi/messages/store/sipimessages/SipiMessages.scala +++ b/webapi/src/main/scala/org/knora/webapi/messages/store/sipimessages/SipiMessages.scala @@ -20,16 +20,6 @@ sealed trait IIIFRequest extends StoreRequest with RelayedMessage // NOTE: consider renaming all with Ingest prefixes sealed trait SipiRequest extends IIIFRequest -/** - * Asks Sipi to move a file from temporary to permanent storage. - * - * @param internalFilename the name of the file. - * @param prefix the prefix under which the file should be stored. - * @param requestingUser the user making the request. - */ -case class MoveTemporaryFileToPermanentStorageRequest(internalFilename: String, prefix: String, requestingUser: User) - extends SipiRequest - /** * Asks Sipi for a text file. Currently only for UTF8 encoded text files. * diff --git a/webapi/src/main/scala/org/knora/webapi/store/iiif/IIIFRequestMessageHandler.scala b/webapi/src/main/scala/org/knora/webapi/store/iiif/IIIFRequestMessageHandler.scala index 919ef1c6ca..dae3962ee1 100644 --- a/webapi/src/main/scala/org/knora/webapi/store/iiif/IIIFRequestMessageHandler.scala +++ b/webapi/src/main/scala/org/knora/webapi/store/iiif/IIIFRequestMessageHandler.scala @@ -11,7 +11,6 @@ import org.knora.webapi.core.MessageHandler import org.knora.webapi.core.MessageRelay import org.knora.webapi.messages.ResponderRequest import org.knora.webapi.messages.store.sipimessages.IIIFRequest -import org.knora.webapi.messages.store.sipimessages.MoveTemporaryFileToPermanentStorageRequest import org.knora.webapi.messages.store.sipimessages.SipiGetTextFileRequest import org.knora.webapi.store.iiif.api.SipiService @@ -23,9 +22,8 @@ final case class IIIFRequestMessageHandlerLive(iiifService: SipiService) extends message.isInstanceOf[IIIFRequest] override def handle(message: ResponderRequest): Task[Any] = message match { - case req: MoveTemporaryFileToPermanentStorageRequest => iiifService.moveTemporaryFileToPermanentStorage(req) - case req: SipiGetTextFileRequest => iiifService.getTextFileRequest(req) - case other => ZIO.logError(s"IIIFServiceManager received an unexpected message: $other") + case req: SipiGetTextFileRequest => iiifService.getTextFileRequest(req) + case other => ZIO.logError(s"IIIFServiceManager received an unexpected message: $other") } } 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 b7230669db..59e8f535dd 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 @@ -11,7 +11,6 @@ import zio.json.JsonDecoder import zio.nio.file.Path import org.knora.webapi.messages.store.sipimessages.* -import org.knora.webapi.messages.v2.responder.SuccessResponseV2 import org.knora.webapi.slice.admin.api.model.MaintenanceRequests.AssetId import org.knora.webapi.slice.admin.domain.model.KnoraProject.Shortcode import org.knora.webapi.slice.admin.domain.model.User @@ -70,16 +69,6 @@ trait SipiService { */ def getFileMetadataFromDspIngest(shortcode: Shortcode, assetId: AssetId): Task[FileMetadataSipiResponse] - /** - * Asks Sipi to move a file from temporary storage to permanent storage. - * - * @param moveTemporaryFileToPermanentStorageRequestV2 the request. - * @return a [[SuccessResponseV2]]. - */ - def moveTemporaryFileToPermanentStorage( - moveTemporaryFileToPermanentStorageRequestV2: MoveTemporaryFileToPermanentStorageRequest, - ): Task[SuccessResponseV2] - /** * Asks Sipi for a text file used internally by Knora. * diff --git a/webapi/src/main/scala/org/knora/webapi/store/iiif/impl/SipiServiceLive.scala b/webapi/src/main/scala/org/knora/webapi/store/iiif/impl/SipiServiceLive.scala index 5b5797fe0d..1bf6e14850 100644 --- a/webapi/src/main/scala/org/knora/webapi/store/iiif/impl/SipiServiceLive.scala +++ b/webapi/src/main/scala/org/knora/webapi/store/iiif/impl/SipiServiceLive.scala @@ -11,7 +11,6 @@ import sttp.client3.* import sttp.client3.SttpBackend import sttp.client3.httpclient.zio.HttpClientZioBackend import zio.* -import zio.json.ast.Json import zio.nio.file.Path import java.net.URI @@ -20,7 +19,6 @@ import dsp.errors.BadRequestException import dsp.errors.NotFoundException import org.knora.webapi.config.Sipi import org.knora.webapi.messages.store.sipimessages.* -import org.knora.webapi.messages.v2.responder.SuccessResponseV2 import org.knora.webapi.slice.admin.api.model.MaintenanceRequests.AssetId import org.knora.webapi.slice.admin.domain.model.KnoraProject.Shortcode import org.knora.webapi.slice.admin.domain.model.User @@ -64,38 +62,6 @@ final case class SipiServiceLive( response.fps.map(BigDecimal(_)), ) - /** - * Asks Sipi to move a file from temporary storage to permanent storage. - * - * @param moveTemporaryFileToPermanentStorageRequestV2 the request. - * @return a [[SuccessResponseV2]]. - */ - def moveTemporaryFileToPermanentStorage( - moveTemporaryFileToPermanentStorageRequestV2: MoveTemporaryFileToPermanentStorageRequest, - ): Task[SuccessResponseV2] = { - val user = moveTemporaryFileToPermanentStorageRequestV2.requestingUser - val params = Map( - ("filename" -> moveTemporaryFileToPermanentStorageRequestV2.internalFilename), - ("prefix" -> moveTemporaryFileToPermanentStorageRequestV2.prefix), - ) - for { - scope <- scopeResolver.resolve(user) - token <- jwtService.createJwt( - user.userIri, - scope, - Map( - "knora-data" -> Json.Obj( - "permission" -> Json.Str("StoreFile"), - "filename" -> Json.Str(moveTemporaryFileToPermanentStorageRequestV2.internalFilename), - "prefix" -> Json.Str(moveTemporaryFileToPermanentStorageRequestV2.prefix), - ), - ), - ) - url = uri"${sipiConfig.internalBaseUrl}/${sipiConfig.moveFileRoute}?token=${token.jwtString}" - _ <- doSipiRequest(quickRequest.post(url).body(params)) - } yield SuccessResponseV2("Moved file to permanent storage.") - } - /** * Asks Sipi for a text file used internally by Knora. * diff --git a/webapi/src/main/scala/org/knora/webapi/store/iiif/impl/SipiServiceMock.scala b/webapi/src/main/scala/org/knora/webapi/store/iiif/impl/SipiServiceMock.scala index 5dd3a47717..1d52c16357 100644 --- a/webapi/src/main/scala/org/knora/webapi/store/iiif/impl/SipiServiceMock.scala +++ b/webapi/src/main/scala/org/knora/webapi/store/iiif/impl/SipiServiceMock.scala @@ -9,7 +9,6 @@ import zio.* import zio.nio.file.Path import org.knora.webapi.messages.store.sipimessages.* -import org.knora.webapi.messages.v2.responder.SuccessResponseV2 import org.knora.webapi.slice.admin.api.model.MaintenanceRequests.AssetId import org.knora.webapi.slice.admin.domain.model.KnoraProject import org.knora.webapi.slice.admin.domain.model.KnoraProject.Shortcode @@ -27,11 +26,6 @@ import org.knora.webapi.store.iiif.impl.SipiServiceMock.SipiMockMethodName.* */ case class SipiServiceMock(ref: Ref[Map[SipiMockMethodName, Task[Object]]]) extends SipiService { - /** - * A request with this filename will always cause a Sipi error. - */ - private val FAILURE_FILENAME: String = "failure.jp2" - private def getReturnValue[T](method: SipiMockMethodName): Task[T] = ref.get.flatMap( _.getOrElse( @@ -48,15 +42,6 @@ case class SipiServiceMock(ref: Ref[Map[SipiMockMethodName, Task[Object]]]) exte ref.set(SipiMockMethodName.values.map(_ -> fail).toMap) } - def moveTemporaryFileToPermanentStorage( - moveTemporaryFileToPermanentStorageRequestV2: MoveTemporaryFileToPermanentStorageRequest, - ): Task[SuccessResponseV2] = - if (moveTemporaryFileToPermanentStorageRequestV2.internalFilename == FAILURE_FILENAME) { - ZIO.fail(SipiException("Sipi failed to move file to permanent storage")) - } else { - ZIO.succeed(SuccessResponseV2("Moved file to permanent storage")) - } - override def getTextFileRequest(textFileRequest: SipiGetTextFileRequest): Task[SipiGetTextFileResponse] = getReturnValue(GetTextFileRequest) diff --git a/webapi/src/test/scala/org/knora/webapi/messages/v2/responder/valuemessages/ValueContentV2Spec.scala b/webapi/src/test/scala/org/knora/webapi/messages/v2/responder/valuemessages/ValueContentV2Spec.scala index a2f1543a9d..c8bf7b3de5 100644 --- a/webapi/src/test/scala/org/knora/webapi/messages/v2/responder/valuemessages/ValueContentV2Spec.scala +++ b/webapi/src/test/scala/org/knora/webapi/messages/v2/responder/valuemessages/ValueContentV2Spec.scala @@ -13,11 +13,9 @@ import zio.test.Spec import zio.test.ZIOSpecDefault import zio.test.assertTrue -import org.knora.webapi.messages.store.sipimessages.MoveTemporaryFileToPermanentStorageRequest import org.knora.webapi.messages.store.sipimessages.SipiGetTextFileRequest import org.knora.webapi.messages.store.sipimessages.SipiGetTextFileResponse import org.knora.webapi.messages.util.rdf.JsonLDUtil -import org.knora.webapi.messages.v2.responder.SuccessResponseV2 import org.knora.webapi.slice.admin.api.model.MaintenanceRequests.AssetId import org.knora.webapi.slice.admin.domain.model.KnoraProject import org.knora.webapi.slice.admin.domain.model.User @@ -55,10 +53,6 @@ object ValueContentV2Spec extends ZIOSpecDefault { ZIO.succeed(expected) // The following are unsupported operations because they are not used in the test - def moveTemporaryFileToPermanentStorage( - moveTemporaryFileToPermanentStorageRequestV2: MoveTemporaryFileToPermanentStorageRequest, - ): Task[SuccessResponseV2] = - ZIO.dieMessage("unsupported operation") def getTextFileRequest(textFileRequest: SipiGetTextFileRequest): Task[SipiGetTextFileResponse] = ZIO.dieMessage("unsupported operation") def downloadAsset(asset: Asset, targetDir: Path, user: User): Task[Option[Path]] =