Skip to content
Permalink
Browse files
feat(resource): add support for 7z files in ArchiveRepresentation (DE…
  • Loading branch information
BalduinLandolt committed Jan 13, 2022
1 parent a3d2f8c commit 729689c7111bc907f1b108242475ae2fe342b2a7
@@ -41,6 +41,7 @@ local APPLICATION_ZIP = "application/zip"
local APPLICATION_TAR = "application/x-tar"
local APPLICATION_ISO = "application/x-iso9660-image"
local APPLICATION_GZIP = "application/gzip"
local APPLICATION_7Z = "application/x-7z-compressed"
local VIDEO_MP4 = "video/mp4"


@@ -80,7 +81,8 @@ local document_mime_types = {
local archive_mime_types = {
APPLICATION_TAR,
APPLICATION_ZIP,
APPLICATION_GZIP
APPLICATION_GZIP,
APPLICATION_7Z
}

local video_mime_types = {
@@ -115,7 +117,8 @@ local document_extensions = {
local archive_extensions = {
"zip",
"tar",
"gz"
"gz",
"7z"
}

local video_extensions = {
Binary file not shown.
@@ -401,7 +401,8 @@ app {
archive-mime-types = [
"application/zip",
"application/x-tar",
"application/gzip"
"application/gzip",
"application/x-7z-compressed"
]
}

@@ -101,6 +101,9 @@ class KnoraSipiIntegrationV2ITSpec
private val testZipOriginalFilename = "test.zip"
private val pathToTestZip = s"test_data/test_route/files/$testZipOriginalFilename"

private val test7zOriginalFilename = "test.7z"
private val pathToTest7z = s"test_data/test_route/files/$test7zOriginalFilename"

private val minimalWavOriginalFilename = "minimal.wav"
private val pathToMinimalWav = s"test_data/test_route/files/$minimalWavOriginalFilename"
private val minimalWavDuration = BigDecimal("0.0")
@@ -1104,6 +1107,66 @@ class KnoraSipiIntegrationV2ITSpec
checkResponseOK(sipiGetFileRequest)
}

"create a resource of type ArchiveRepresentation with a 7z file" in {
// Upload the file to Sipi.
val sipiUploadResponse: SipiUploadResponse = uploadToSipi(
loginToken = loginToken,
filesToUpload = Seq(FileToUpload(path = pathToTest7z, mimeType = MediaTypes.`application/x-7z-compressed`))
)

val uploadedFile: SipiUploadResponseEntry = sipiUploadResponse.uploadedFiles.head
uploadedFile.originalFilename should ===(test7zOriginalFilename)

// Create the resource in the API.

val jsonLdEntity = UploadFileRequest
.make(fileType = FileType.ArchiveFile, internalFilename = uploadedFile.internalFilename)
.toJsonLd

val request = Post(
s"$baseApiUrl/v2/resources",
HttpEntity(RdfMediaTypes.`application/ld+json`, jsonLdEntity)
) ~> addCredentials(BasicHttpCredentials(anythingUserEmail, password))
val responseJsonDoc: JsonLDDocument = getResponseJsonLD(request)
zipResourceIri.set(responseJsonDoc.body.requireIDAsKnoraDataIri.toString)

// Get the resource from Knora.
val knoraGetRequest = Get(s"$baseApiUrl/v2/resources/${URLEncoder.encode(zipResourceIri.get, "UTF-8")}")
val resource: JsonLDDocument = getResponseJsonLD(knoraGetRequest)

resource.requireTypeAsKnoraTypeIri.toString should equal(
OntologyConstants.KnoraApiV2Complex.ArchiveRepresentation
)

// Get the new file value from the resource.

val savedValues: JsonLDArray = getValuesFromResource(
resource = resource,
propertyIriInResult = OntologyConstants.KnoraApiV2Complex.HasArchiveFileValue.toSmartIri
)

val savedValue: JsonLDValue = if (savedValues.value.size == 1) {
savedValues.value.head
} else {
throw AssertionException(s"Expected one file value, got ${savedValues.value.size}")
}

val savedValueObj: JsonLDObject = savedValue match {
case jsonLDObject: JsonLDObject => jsonLDObject
case other => throw AssertionException(s"Invalid value object: $other")
}

zipValueIri.set(savedValueObj.requireIDAsKnoraDataIri.toString)

val savedDocument: SavedDocument = savedValueToSavedDocument(savedValueObj)
assert(savedDocument.internalFilename == uploadedFile.internalFilename)
assert(savedDocument.pageCount.isEmpty)

// Request the permanently stored file from Sipi.
val sipiGetFileRequest = Get(savedDocument.url.replace("http://0.0.0.0:1024", baseInternalSipiUrl))
checkResponseOK(sipiGetFileRequest)
}

"create a resource with a WAV file" in {
// Upload the file to Sipi.
val sipiUploadResponse: SipiUploadResponse = uploadToSipi(

0 comments on commit 729689c

Please sign in to comment.