def handleVidispineItemNeedsArchive()

in online_archive/src/main/scala/VidispineMessageProcessor.scala [195:236]


  def handleVidispineItemNeedsArchive(mediaItemOnly: VidispineMediaIngested): Future[Either[String, MessageProcessorReturnValue]] = {
  logger.debug(s"Received message content needing backup $mediaItemOnly")

    mediaItemOnly.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 {
          originalShape <- findOriginalShape(vidispineCommunicator.listItemShapes(itemId))
          shapeVersion <- Future(originalShape.flatMap(_.essenceVersion))
          shapeFileInfo <- Future(originalShape.flatMap(_.getLikelyFile))
          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, Some(itemId), shapeVersion, "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 {
                val enhancedItem = vsMediaIngestedWithVersion(itemId, shapeVersion)
                getRelativePath(absPath, None /* just assume it's NOT pluto-deliverables */) match {
                  case Left(err) =>
                    logger.error(s"Could not relativize file path $absPath: $err. Uploading to $absPath")
                    vidispineFunctions.uploadIfRequiredAndNotExists(absPath, absPath, enhancedItem)
                  case Right(relativePath) =>
                    vidispineFunctions.uploadIfRequiredAndNotExists(absPath, relativePath.toString, enhancedItem)
                }
              }
            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 with backup of item")
        Future.failed(new RuntimeException(s"No source file ID parameter"))
    }
  }