in online_nearline/src/main/scala/VidispineMessageProcessor.scala [242:286]
def getFilePathForShape(shapeDoc: ShapeDocument, itemId: String, shapeId: String): Future[Either[String,Path]] = {
def filePathsForShape(f:VSShapeFile) = f.uri match {
case None=>Seq()
case Some(uriList)=>
uriList.map(u=>Try { URI.create(u) }.toOption).collect({case Some(uri)=>uri})
}
/**
* checks the paths in the list using `internalCheckFile` and returns the first one that passes the check, or None
* if there are no results
* @param paths a list of paths to check
* @return either a checked, working Path or None
*/
def firstCheckedFilepath(paths:Seq[Path]) = paths.foldLeft[Option[Path]](None)((result, filePath)=>{
result match {
case existingResult@Some(_)=>existingResult
case None=>
if (internalCheckFile(filePath)) {
logger.info(s"Found filePath for Vidispine shape $filePath")
Some(filePath)
} else {
result
}
}
})
shapeDoc.getLikelyFile match {
case None =>
Future(Left(s"No file exists on shape $shapeId for item $itemId yet"))
case Some(fileInfo) =>
val uriList = filePathsForShape(fileInfo)
if(uriList.isEmpty) {
logger.error(s"Either ${fileInfo.uri} is empty or it does not contain a valid URI")
Future.failed(new RuntimeException(s"Fileinfo $fileInfo has no valid URI"))
} else {
val filePaths = uriList.map(Paths.get)
firstCheckedFilepath(filePaths) match {
case Some(filePath)=>
Future(Right(filePath))
case None=>
logger.error(s"Could not find path for any of URI ${fileInfo.uri} on-disk")
Future.failed(new RuntimeException(s"File any of URI ${fileInfo.uri} for Vidispine shape could not be found"))
}
}
}
}