def processFileAndProject()

in online_archive/src/main/scala/AssetSweeperMessageProcessor.scala [105:141]


  def processFileAndProject(fullPath:Path, maybeProject: Option[ProjectRecord]):Future[Either[String, MessageProcessorReturnValue]] = {
    val ignoreReason = maybeProject match {
      case Some(project)=>
        if(project.deletable.getOrElse(false)) {  //If the project is marked as “deletable”, record to datastore as “ignored”
          logger.info(s"Not archiving '$fullPath' as it belongs to '${project.title}' (${project.id.map(i=>s"project id $i").getOrElse("no project id")}) which is marked as deletable")
          Some(s"project ${project.id.getOrElse(-1)} is deletable")
        } else if(project.sensitive.getOrElse(false)) {
          logger.info(s"Not archiving '$fullPath' as it belongs to '${project.title}' (${project.id.map(i=>s"project id $i").getOrElse("no project id")}) which is marked as sensitive")
          Some(s"project ${project.id.getOrElse(-1)} is sensitive")
        } else {
          None
        }
      case None=>
        logger.warn(s"No project could be found that is associated with $fullPath, assuming that it does need external archive")
        None
    }

    ignoreReason match {
      case None=> //no reason to ignore - we should archive
        asLookup.relativizeFilePath(fullPath) match {
          case Left(err)=>
            logger.error(s"Could not relativize file path $fullPath: $err. Uploading to $fullPath")
            callUpload(fullPath, fullPath)
          case Right(relativePath)=>
            callUpload(fullPath, relativePath)
        }

      case Some(reason)=>
        val rec = IgnoredRecord(None, fullPath.toString, reason, None, None)
        //record the fact we ignored the file to the database. This should not raise duplicate record errors.
        ignoredRecordDAO
          .writeRecord(rec)
          .map(recId=> {
            Right(rec.copy(id=Some(recId)).asJson)
          })
    }
  }