Due to a scheduled upgrade to version 14.10, GitLab will be unavailabe on Monday 30.05., from 19:00 until 20:00.

Commit f99da3db authored by Thomas Bernhart's avatar Thomas Bernhart
Browse files

MEMO-669: Make sure the mimetype of the correct resource is returned

parent 8a81e9e0
......@@ -90,10 +90,8 @@ class Ingester(
it.second.let { path ->
if (path != null) {
sftpClient.open(File(path)).use { stream ->
val binaryUri = "${it.first}/${Service.BINARY_FILE_URI_PATH}"
val mimeType = rdfHandler.getMimeType().first { mT ->
mT.first == digitalInstantiationUrl
}.second
val binaryUri = "$digitalInstantiationUrl/${Service.BINARY_FILE_URI_PATH}"
val mimeType = rdfHandler.getMimeType(digitalInstantiationUrl)
log.info("Ingesting binary $binaryUri with mime type $mimeType.")
transaction.createOrUpdateBinaryResource(URI(binaryUri), stream, mimeType)
}
......
......@@ -9,6 +9,7 @@ import org.apache.jena.rdf.model.impl.StatementImpl
import org.apache.jena.riot.Lang
import org.apache.jena.riot.RDFDataMgr
import org.apache.log4j.LogManager
import org.memobase.exceptions.MissingMimeTypeException
import org.memobase.rdf.EBUCORE
import org.memobase.rdf.RDF
import org.memobase.rdf.RICO
......@@ -109,11 +110,14 @@ class RdfHandler(data: String, private val externalBaseUrl: String) {
}.toList()
}
fun getMimeType(): List<Pair<String, String?>> {
return model.listSubjectsWithProperty(RICO.type, Service.DIGITAL_OBJECT_TYPE).filterKeep {
it.hasProperty(EBUCORE.hasMimeType)
}.mapWith {
Pair(it.uri, it.getProperty(EBUCORE.hasMimeType).`object`.asLiteral().string)
fun getMimeType(uri: String): String {
val mimeTypes = model.getResource(uri).listProperties(EBUCORE.hasMimeType).mapWith {
it.`object`.asLiteral().string
}.toList()
if (mimeTypes.size == 1) {
return mimeTypes[0]
} else {
throw MissingMimeTypeException("No MimeType found for resource $uri")
}
}
}
package org.memobase.exceptions
class MissingMimeTypeException(message: String) : Exception(message)
......@@ -127,7 +127,8 @@ class TestRdfHandler {
@Test
fun `test mime type extraction for binaries`() {
val rdfHandler = RdfHandler(readFile("input.nt"), "https://memobase.ch/")
assertThat(rdfHandler.getMimeType().first().second).isEqualTo("video/mpeg")
val mimeType = rdfHandler.getMimeType("https://memobase.ch/instantiation/digital/AFZ-IB_Becker_Audiovisuals_63-1")
assertThat(mimeType).isEqualTo("video/mpeg")
}
private val uris2 = listOf(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment