Skip to content

Commit

Permalink
remove DeleteTemporaryFileRequest & delete_temp_file.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
siers committed Nov 25, 2024
1 parent ef64f38 commit 0134b9c
Show file tree
Hide file tree
Showing 8 changed files with 0 additions and 189 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import zio.ULayer
import zio.ZLayer
import zio.nio.file.Path

import org.knora.webapi.messages.store.sipimessages.DeleteTemporaryFileRequest
import org.knora.webapi.messages.store.sipimessages.MoveTemporaryFileToPermanentStorageRequest
import org.knora.webapi.messages.store.sipimessages.SipiGetTextFileRequest
import org.knora.webapi.messages.store.sipimessages.SipiGetTextFileResponse
Expand Down Expand Up @@ -69,15 +68,6 @@ case class SipiServiceTestDelegator(
): Task[SuccessResponseV2] =
sipiService.moveTemporaryFileToPermanentStorage(moveTemporaryFileToPermanentStorageRequestV2)

/**
* Asks Sipi to delete a temporary file.
*
* @param deleteTemporaryFileRequestV2 the request.
* @return a [[SuccessResponseV2]].
*/
override def deleteTemporaryFile(deleteTemporaryFileRequestV2: DeleteTemporaryFileRequest): Task[SuccessResponseV2] =
sipiService.deleteTemporaryFile(deleteTemporaryFileRequestV2)

/**
* Asks Sipi for a text file used internally by Knora.
*
Expand Down
122 changes: 0 additions & 122 deletions sipi/scripts/delete_temp_file.lua

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@ sealed trait SipiRequest extends IIIFRequest
case class MoveTemporaryFileToPermanentStorageRequest(internalFilename: String, prefix: String, requestingUser: User)
extends SipiRequest

/**
* Asks Sipi to delete a temporary file.
*
* @param internalFilename the name of the file.
* @param requestingUser the user making the request.
*/
case class DeleteTemporaryFileRequest(internalFilename: 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 @@ -10,7 +10,6 @@ import zio.*
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.DeleteTemporaryFileRequest
import org.knora.webapi.messages.store.sipimessages.IIIFRequest
import org.knora.webapi.messages.store.sipimessages.MoveTemporaryFileToPermanentStorageRequest
import org.knora.webapi.messages.store.sipimessages.SipiGetTextFileRequest
Expand All @@ -25,7 +24,6 @@ final case class IIIFRequestMessageHandlerLive(iiifService: SipiService) extends

override def handle(message: ResponderRequest): Task[Any] = message match {
case req: MoveTemporaryFileToPermanentStorageRequest => iiifService.moveTemporaryFileToPermanentStorage(req)
case req: DeleteTemporaryFileRequest => iiifService.deleteTemporaryFile(req)
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 @@ -80,14 +80,6 @@ trait SipiService {
moveTemporaryFileToPermanentStorageRequestV2: MoveTemporaryFileToPermanentStorageRequest,
): Task[SuccessResponseV2]

/**
* Asks Sipi to delete a temporary file.
*
* @param deleteTemporaryFileRequestV2 the request.
* @return a [[SuccessResponseV2]].
*/
def deleteTemporaryFile(deleteTemporaryFileRequestV2: DeleteTemporaryFileRequest): 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 @@ -10,7 +10,6 @@ import sttp.client3
import sttp.client3.*
import sttp.client3.SttpBackend
import sttp.client3.httpclient.zio.HttpClientZioBackend
import sttp.model.Uri
import zio.*
import zio.json.ast.Json
import zio.nio.file.Path
Expand Down Expand Up @@ -97,32 +96,6 @@ final case class SipiServiceLive(
} yield SuccessResponseV2("Moved file to permanent storage.")
}

/**
* Asks Sipi to delete a temporary file.
*
* @param deleteTemporaryFileRequestV2 the request.
* @return a [[SuccessResponseV2]].
*/
def deleteTemporaryFile(deleteTemporaryFileRequestV2: DeleteTemporaryFileRequest): Task[SuccessResponseV2] = {
val deleteRequestContent =
Map(
"knora-data" -> Json.Obj(
"permission" -> Json.Str("DeleteTempFile"),
"filename" -> Json.Str(deleteTemporaryFileRequestV2.internalFilename),
),
)

val url: String => Uri = s =>
uri"${sipiConfig.internalBaseUrl}/${sipiConfig.deleteTempFileRoute}/${deleteTemporaryFileRequestV2.internalFilename}?token=${s}"

val user = deleteTemporaryFileRequestV2.requestingUser
for {
scope <- scopeResolver.resolve(user)
token <- jwtService.createJwt(user.userIri, scope, deleteRequestContent)
_ <- doSipiRequest(quickRequest.delete(url(token.jwtString)))
} yield SuccessResponseV2("Deleted temporary file.")
}

/**
* Asks Sipi for a text file used internally by Knora.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,6 @@ case class SipiServiceMock(ref: Ref[Map[SipiMockMethodName, Task[Object]]]) exte
ZIO.succeed(SuccessResponseV2("Moved file to permanent storage"))
}

def deleteTemporaryFile(deleteTemporaryFileRequestV2: DeleteTemporaryFileRequest): Task[SuccessResponseV2] =
if (deleteTemporaryFileRequestV2.internalFilename == FAILURE_FILENAME) {
ZIO.fail(SipiException("Sipi failed to delete temporary file"))
} else {
ZIO.succeed(SuccessResponseV2("Deleted temporary file"))
}

override def getTextFileRequest(textFileRequest: SipiGetTextFileRequest): Task[SipiGetTextFileResponse] =
getReturnValue(GetTextFileRequest)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import zio.test.Spec
import zio.test.ZIOSpecDefault
import zio.test.assertTrue

import org.knora.webapi.messages.store.sipimessages.DeleteTemporaryFileRequest
import org.knora.webapi.messages.store.sipimessages.MoveTemporaryFileToPermanentStorageRequest
import org.knora.webapi.messages.store.sipimessages.SipiGetTextFileRequest
import org.knora.webapi.messages.store.sipimessages.SipiGetTextFileResponse
Expand Down Expand Up @@ -60,10 +59,6 @@ object ValueContentV2Spec extends ZIOSpecDefault {
moveTemporaryFileToPermanentStorageRequestV2: MoveTemporaryFileToPermanentStorageRequest,
): Task[SuccessResponseV2] =
ZIO.dieMessage("unsupported operation")
def deleteTemporaryFile(
deleteTemporaryFileRequestV2: DeleteTemporaryFileRequest,
): 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 0134b9c

Please sign in to comment.