protected def internalCheckFile()

in online_archive/src/main/scala/VidispineFunctions.scala [197:254]


  protected def internalCheckFile(filePath:Path) = Files.exists(filePath)

  /**
   * uploads the proxy shape for the given item to S3 using the provided proxyFileUploader
   * @param fileInfo VSShapeFile representing the proxy file
   * @param archivedRecord ArchivedRecord representing the item that needs to get
   * @param shapeDoc ShapeDocument representing the proxy's shape
   * @return a Future, with a tuple of the uploaded filename and file size. On error, the future will fail.
   */
  private def doUploadShape(fileInfo:VSShapeFile, archivedRecord: ArchivedRecord, shapeDoc:ShapeDocument) = {
    val uploadKey = VidispineFunctions.uploadKeyForProxy(archivedRecord, fileInfo)

    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 =>
        logger.error(s"${fileInfo} is a placeholder or has no original media")
        Future.failed(new RuntimeException(s"${fileInfo} is a placeholder or has no original media"))
      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)=>
              logger.info(s"Starting upload of $filePath to s3://${proxyFileUploader.bucketName}/$uploadKey")
              proxyFileUploader.copyFileToS3(filePath.toFile, Some(uploadKey))
            case None=>
              logger.error(s"Could not find path for URI ${fileInfo.uri} on-disk")
              Future.failed(new RuntimeException(s"File $fileInfo could not be found"))
          }
        }
    }
  }