in online_archive/src/main/scala/VidispineMessageProcessor.scala [148:193]
def handleIngestedMedia(mediaIngested: VidispineMediaIngested): Future[Either[String, MessageProcessorReturnValue]] = {
val status = mediaIngested.status
val itemId = mediaIngested.itemId
logger.debug(s"Received message content $mediaIngested")
if (status.contains("FAILED") || itemId.isEmpty) {
logger.error(s"Import status not in correct state for archive $status itemId=${itemId}")
Future.failed(SilentDropMessage(Some(s"Import status not in correct state for archive $status itemId=$itemId")))
} else {
mediaIngested.itemId match {
case Some(itemId)=> //unfortunately we can't accurately determine the _original_ file from an essence_version message so we need to go back to the item
//and query that
logger.debug(s"Got ingested item ID $itemId from the message")
for {
shapeFileInfo <- vidispineCommunicator.findItemFile(itemId, "original")
absPath <- Future(shapeFileInfo.flatMap(_.getAbsolutePath))
maybeProject <- absPath.map(Paths.get(_)).map(asLookup.assetFolderProjectLookup).getOrElse(Future(None))
result <- (absPath, maybeProject) match {
case (None, _)=>
logger.error(s"Could not get absolute filepath for item $itemId")
Future.failed(new RuntimeException(s"Could not get absolute filepath for file $itemId"))
case (Some(absPath), Some(projectInfo)) =>
if(projectInfo.deletable.contains(true) || projectInfo.sensitive.contains(true)) {
setIgnoredRecord(absPath, mediaIngested.itemId, mediaIngested.essenceVersion, "Project was either deletable or sensitive")
.flatMap(_=>
Future.failed(SilentDropMessage(Some(s"$absPath is from project ${projectInfo.id} which is either deletable or sensitive")))
)
} else {
getRelativePath(absPath, mediaIngested.importSource) match {
case Left(err) =>
logger.error(s"Could not relativize file path $absPath: $err. Uploading to $absPath")
vidispineFunctions.uploadIfRequiredAndNotExists(absPath, absPath, mediaIngested)
case Right(relativePath) =>
vidispineFunctions.uploadIfRequiredAndNotExists(absPath, relativePath.toString, mediaIngested)
}
}
case (_, None) =>
Future(Left(s"Could not look up a project for itemId $itemId ($absPath)"))
}
} yield result.map(MessageProcessorReturnValue.apply)
case None=>
logger.error(s"The incoming message had no source file ID parameter, can't continue")
Future.failed(new RuntimeException(s"No source file ID parameter"))
}
}
}