Verified Commit c916f79c authored by Sebastian Schüpbach's avatar Sebastian Schüpbach
Browse files

use file name as binary object identifier

parent 65fdc8e9
Pipeline #35331 passed with stages
in 8 minutes and 18 seconds
......@@ -55,19 +55,14 @@ object BinaryResourceMetadata extends RecordUtils {
extractBinaryResourceMetadata(jsonldGraph, externalBaseUrl, distributorHost)
}
private def buildDistributorUrl(longId: String, baseUrl: String, distributorHost: String, resourceType: MemobaseResource): String = {
val pattern = raw"""${baseUrl.stripSuffix("/")}/digital/([^/]+)-1""".r
pattern.findFirstMatchIn(longId) match {
case Some(m) =>
resourceType match {
case DigitalObject =>
s"${distributorHost.stripSuffix("/")}/media/${m.group(1)}"
case Thumbnail =>
s"${distributorHost.stripSuffix("/")}/thumbnail/${m.group(1)}"
case _ =>
""
}
case None => ""
private def buildDistributorUrl(fileName: String, distributorHost: String, resourceType: MemobaseResource): String = {
resourceType match {
case DigitalObject =>
s"${distributorHost.stripSuffix("/")}/media/$fileName"
case Thumbnail =>
s"${distributorHost.stripSuffix("/")}/thumbnail/$fileName"
case _ =>
""
}
}
......@@ -77,25 +72,27 @@ object BinaryResourceMetadata extends RecordUtils {
.withFilter {
v => isDigitalObject(v.obj) || isPreviewImage(v.obj)
}
.map { v => {
val id = v.obj.getOrElse("@id", Value("<unknown id>")).str
Try(
v.obj match {
case v if isLocalRecord(v) && isProcessableMimeType(v) =>
val instantiation = MemobaseResource(v("type").str)
BinaryResourceMetadata(
v("@id").str.substring(s"$baseUrl/digital/".length - 1),
buildDistributorUrl(v("@id").str, baseUrl, distributorHost, instantiation),
Conversions.getMediaFileType(v("hasMimeType").str).get,
instantiation)
case v if isLocalRecord(v) =>
val resource = MemobaseResource(v("type").str)
throw new UnmanageableMediaFileType(s"Media file type for $id unknown", resource)
case v =>
val resource = MemobaseResource(v("type").str)
throw new NoLocalBinary(id, resource)
}
)
}
.map {
v => {
val resourceId = v.obj.getOrElse("@id", Value("<unknown id>")).str
Try(
v.obj match {
case v if isLocalRecord(v) && isProcessableMimeType(v) =>
val instantiation = MemobaseResource(v("type").str)
val locator = v("locator").str.split("/").last.replaceAll(" ", "_")
BinaryResourceMetadata(
v("@id").str.substring(s"$baseUrl/digital/".length - 1),
buildDistributorUrl(locator, distributorHost, instantiation),
Conversions.getMediaFileType(v("hasMimeType").str).get,
instantiation)
case v if isLocalRecord(v) =>
val resource = MemobaseResource(v("type").str)
throw new UnmanageableMediaFileType(s"Media file type for $resourceId unknown", resource)
case v =>
val resource = MemobaseResource(v("type").str)
throw new NoLocalBinary(resourceId, resource)
}
)
}
}.toList
}
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