Skip to content

Commit

Permalink
remove moveTemporaryFileToPermanentStorage and serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
siers committed Nov 25, 2024
1 parent ae7aad3 commit 3708cb6
Show file tree
Hide file tree
Showing 7 changed files with 2 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]] =
Expand Down

0 comments on commit 3708cb6

Please sign in to comment.