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

fix reporting

parent 45d7bf78
Pipeline #43092 passed with stages
in 6 minutes and 1 second
......@@ -94,19 +94,23 @@ class RecordProcessor(fileHandler: DisseminationCopyHandler,
createOutcome(res, id, DigitalObject, destFile)
case mT: ImageFile if resource == DigitalObject =>
val destFile = imageFileRootPath(id, mT)
createImageAndThumbnail(id, data, destFile, mT)
case mT: ImageFile if resource == Thumbnail =>
createImageAndThumbnail(id, data, destFile, mT, DigitalObject)
case mT: ImageFile if resource == VideoThumbnail =>
val destFile = videoPosterPath(id, mT)
createImageAndThumbnail(id, data, destFile, mT)
createImageAndThumbnail(id, data, destFile, mT, VideoThumbnail)
}
private def createImageAndThumbnail(id: String, data: ByteArrayOutputStream, destImageFile: String, mimeType: MimeType): List[ProcessOutcome] = {
private def createImageAndThumbnail(id: String,
data: ByteArrayOutputStream,
destImageFile: String,
mimeType: MimeType,
memobaseResource: MemobaseResource): List[ProcessOutcome] = {
val resMediaFile = fileHandler.createImageCopy(data, destImageFile, mimeType)
val outcomeMediaFile = createOutcome(resMediaFile, id, DigitalObject, destImageFile)
val outcomeMediaFile = createOutcome(resMediaFile, id, memobaseResource, destImageFile)
val destPreviewFile = cachedImageFilePath(id, mimeType)
val (width, height) = getThumbnailDimensions
val resThumbnail = fileHandler.createImageThumbnail(destImageFile, destPreviewFile, width, height)
val outcomeThumbnail = createOutcome(resThumbnail, id, DigitalObject, destImageFile)
val outcomeThumbnail = createOutcome(resThumbnail, id, ImageThumbnail, destImageFile)
outcomeMediaFile ++ outcomeThumbnail
}
......
......@@ -38,7 +38,7 @@ trait RecordUtils {
protected def isPreviewImage(obj: ujson.Obj): Boolean = {
hasKeyValue(obj, "type") {
MemobaseResource(_) == Thumbnail
MemobaseResource(_) == VideoThumbnail
}
}
......
......@@ -59,7 +59,7 @@ object BinaryResourceMetadata extends RecordUtils {
resourceType match {
case DigitalObject =>
s"${distributorHost.stripSuffix("/")}/media/$fileName"
case Thumbnail =>
case VideoThumbnail =>
s"${distributorHost.stripSuffix("/")}/thumbnail/$fileName"
case _ =>
""
......
......@@ -35,9 +35,14 @@ case object DigitalObject extends MemobaseResource
case object PhysicalObject extends MemobaseResource
/**
* Represents a thumbnail / preview image / poster
* Represents a video thumbnail
*/
case object Thumbnail extends MemobaseResource
case object VideoThumbnail extends MemobaseResource
/**
* Represents an image thumbnail
*/
case object ImageThumbnail extends MemobaseResource
/**
* Represents a record
......@@ -64,7 +69,7 @@ case object UnknownResource extends MemobaseResource
object MemobaseResource {
def apply(i: String): MemobaseResource = i match {
case "digitalObject" => DigitalObject
case "thumbnail" => Thumbnail
case "thumbnail" => VideoThumbnail
case "physicalObject" => PhysicalObject
case _ => UnknownResource
}
......
......@@ -46,8 +46,9 @@ case object ProcessingFatal extends ProcessingStatus {
case class ReportingObject(id: String,
digitalObject: Option[(ProcessingStatus, String)] = None,
poster: Option[(ProcessingStatus, String)] = None,
audioSnippet: Option[(ProcessingStatus, String)] = None) {
videoThumbnail: Option[(ProcessingStatus, String)] = None,
audioSnippet: Option[(ProcessingStatus, String)] = None,
imageThumbnail: Option[(ProcessingStatus, String)] = None) {
import ReportingObject._
......@@ -57,8 +58,8 @@ case class ReportingObject(id: String,
("step", "09.01-media-converter"),
("timestamp", createTimestamp),
("id", id),
("status", mergeStatus(digitalObject, poster, audioSnippet)),
("message", mergeMessages(digitalObject, poster, audioSnippet))
("status", mergeStatus(digitalObject, videoThumbnail, audioSnippet, imageThumbnail)),
("message", mergeMessages(digitalObject, videoThumbnail, audioSnippet, imageThumbnail))
)
)
}
......@@ -69,9 +70,10 @@ object ReportingObject {
def createTimestamp: String = dateFormatter.format(Calendar.getInstance().getTime)
def mergeStatus(digitalObject: Option[(ProcessingStatus, String)],
poster: Option[(ProcessingStatus, String)],
audioSnippet: Option[(ProcessingStatus, String)]): String = {
val processStatus = List(digitalObject, poster, audioSnippet)
videoThumbnail: Option[(ProcessingStatus, String)],
audioSnippet: Option[(ProcessingStatus, String)],
imageThumbnail: Option[(ProcessingStatus, String)]): String = {
val processStatus = List(digitalObject, videoThumbnail, audioSnippet, imageThumbnail)
.flatMap(obj => obj.flatMap(o => Some(o._1)))
if (processStatus.contains(ProcessingFatal)) {
ProcessingFatal.value
......@@ -85,17 +87,20 @@ object ReportingObject {
}
def mergeMessages(digitalObject: Option[(ProcessingStatus, String)],
poster: Option[(ProcessingStatus, String)],
audioSnippet: Option[(ProcessingStatus, String)]): String =
videoThumbnail: Option[(ProcessingStatus, String)],
audioSnippet: Option[(ProcessingStatus, String)],
imageThumbnail: Option[(ProcessingStatus, String)]): String =
s"""DIGITAL OBJECT: ${digitalObject.flatMap(dO => Some(dO._2)).getOrElse("not available")}
| -- POSTER: ${poster.flatMap(p => Some(p._2)).getOrElse("not available")}
| -- AUDIO SNIPPET:${audioSnippet.flatMap(aS => Some(aS._2)).getOrElse("not available")}""".stripMargin
| -- VIDEO THUMBNAIL: ${videoThumbnail.flatMap(p => Some(p._2)).getOrElse("not available")}
| -- AUDIO SNIPPET:${audioSnippet.flatMap(aS => Some(aS._2)).getOrElse("not available")}
| -- IMAGE THUMBNAIL: ${imageThumbnail.flatMap(iT => Some(iT._2)).getOrElse("not available")}""".stripMargin
def addResourceOutcome(report: ReportingObject, resource: (MemobaseResource, String), status: ProcessingStatus): ReportingObject =
resource._1 match {
case DigitalObject => report.copy(digitalObject = Some(status, resource._2))
case Thumbnail => report.copy(poster = Some(status, resource._2))
case VideoThumbnail => report.copy(videoThumbnail = Some(status, resource._2))
case AudioSnippet => report.copy(audioSnippet = Some(status, resource._2))
case ImageThumbnail => report.copy(imageThumbnail = Some(status, resource._2))
case _ => report
}
}
Supports Markdown
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