protected def newCorrelationId: String = UUID.randomUUID()

in online_nearline/src/main/scala/VidispineMessageProcessor.scala [69:118]


  protected def newCorrelationId: String = UUID.randomUUID().toString

  /**
   * performs a search on the given vault looking for a matching file (i.e. one with the same file name AND size).
   * If one exists, it will create a NearlineRecord linking that file to the given name, save it to the database and return it.
   * Intended for use if no record exists already but a file may exist on the storage.
   * @param vault vault to check
   * @param filePath absolute path to the file on-disk
   * @param mediaIngested VidispineMediaIngested object representing the incoming message. This function will always
   *                      return None if the file size is not set here.
   * @param shouldSave if set to false, then don't write the record to the database before returning. Defaults to `true`.
   * @return a Future, containing the newly saved NearlineRecord if a record is found or None if not.
   */
  def checkForPreExistingFiles(vault:Vault, filePath:Path, mediaIngested: QueryableItem, shouldSave:Boolean=true) = {
    val fileSizeFut = (mediaIngested.fileSize, mediaIngested.itemId) match {
      case (Some(fileSize), _) => Future(Some(fileSize))
      case (None, Some(itemId))=>
        logger.info(s"No file size provided in incoming message, looking based on file ID")
        vidispineCommunicator.findItemFile(itemId, "original").map(_.map(_.size))
      case (None,None)=>
        logger.error("Could not check for pre-existing files as neither file size nor item ID was provided")
        Future(None)
    }

    fileSizeFut.flatMap({
      case Some(fileSize) =>
        fileCopier
          .findMatchingFilesOnNearline(vault, filePath, fileSize)
          .flatMap(matches => {
            if (matches.isEmpty) {
              logger.info(s"Found no pre-existing archived files for $filePath")
              Future(None)
            } else {
              logger.info(s"Found ${matches.length} archived files for $filePath: ${matches.map(_.pathOrFilename).mkString(",")}")
              val newRec = NearlineRecord(
                objectId = matches.head.oid,
                originalFilePath = filePath.toString,
                correlationId = newCorrelationId
              )
              if (shouldSave) {
                nearlineRecordDAO.writeRecord(newRec).map(newId => Some(newRec.copy(id = Some(newId))))
              } else {
                Future(Some(newRec))
              }
            }
          })
      case None=>
        Future(None)
    })
  }