Unverified Commit daca005c authored by Sebastian Schüpbach's avatar Sebastian Schüpbach
Browse files

ignore resources without binary


Signed-off-by: Sebastian Schüpbach's avatarSebastian Schüpbach <sebastian.schuepbach@unibas.ch>
parent a88abca7
Pipeline #11916 passed with stages
in 10 minutes and 40 seconds
......@@ -60,6 +60,7 @@ class RecordProcessor(fileHandler: DisseminationCopyHandler, fedoraClientWrapper
case (id, event, ft, _) =>
ProcessFailure(id, ft, event.toString, new Exception)
}).recover {
case e: ResourceWithoutBinary => ProcessIgnore(record.key(), e.getMessage)
case e: Exception => ProcessFailure(record.key(), UnknownFileType, "", e)
}
}.get
......
......@@ -49,7 +49,10 @@ object BinaryResourceMetadata {
*/
def build(msg: String, externalBaseUrl: String): Try[BinaryResourceMetadata] = Try {
val jsonldGraph = ujson.read(msg).obj("@graph").arr
buildKafkaMessage(jsonldGraph, externalBaseUrl)
buildKafkaMessage(jsonldGraph, externalBaseUrl) match {
case Some(km) => km
case None => throw new ResourceWithoutBinary("Resource contains no binary object")
}
}
private def setEventType(eventAsString: String): Event = eventAsString match {
......@@ -58,7 +61,7 @@ object BinaryResourceMetadata {
case "Delete" => Delete
}
private def buildKafkaMessage(jsonldGraph: ArrayBuffer[Value], baseUrl: String): BinaryResourceMetadata = {
private def buildKafkaMessage(jsonldGraph: ArrayBuffer[Value], baseUrl: String): Option[BinaryResourceMetadata] = {
jsonldGraph.value
.withFilter(v => isDigitalBinaryObject(v.obj, baseUrl))
.map { o =>
......@@ -68,7 +71,7 @@ object BinaryResourceMetadata {
o("hasMimeType").str,
setEventType(o("eventType").str))
}
.head
.headOption
}
private def isDigitalBinaryObject(obj: ujson.Obj, internalBaseUrl: String): Boolean = {
......
......@@ -25,3 +25,5 @@ package ch.memobase.models
*/
//noinspection ScalaFileName
class UnmanageableMediaFileType(msg: String) extends Exception(msg)
class ResourceWithoutBinary(msg: String) extends Exception(msg)
\ No newline at end of file
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