def redoRestore()

in app/controllers/LightboxController.scala [416:453]


  def redoRestore(user:String, fileId:String) = IsAuthenticatedAsync { claims=> request=>
    targetUserProfile(request, user).flatMap({
      case None=>Future(BadRequest(GenericErrorResponse("session_error","no session present").asJson))
      case Some(Left(err))=>
        logger.error(s"Session is corrupted: ${err.toString}")
        Future(InternalServerError(GenericErrorResponse("session_error","session is corrupted, log out and log in again").asJson))
      case Some(Right(profile))=>
        Future.sequence(Seq(
          lightboxEntryDAO.get(profile.userEmail, fileId),
          indexer.getById(fileId))).flatMap(results=>{
          val archiveEntry = results(1).asInstanceOf[ArchiveEntry]
          val lbEntryResponse = results.head.asInstanceOf[Option[Either[DynamoReadError, LightboxEntry]]]

          lbEntryResponse match {
            case Some(Right(lbEntry)) =>
              if (profile.perRestoreQuota.isDefined && (archiveEntry.size/1048576L) < profile.perRestoreQuota.get)
                (glacierRestoreActor ? GlacierRestoreActor.InitiateRestore(archiveEntry, lbEntry, None)).mapTo[GRMsg].map({
                  case GlacierRestoreActor.RestoreSuccess =>
                    Ok(GenericErrorResponse("ok", "restore initiaited").asJson)
                  case GlacierRestoreActor.RestoreFailure(err) =>
                    logger.error(s"Could not redo restore for $archiveEntry", err)
                    InternalServerError(GenericErrorResponse("error", err.toString).asJson)
                })
              else {
                profile.perRestoreQuota match {
                  case Some(userQuota)=>logger.warn(s"Can't restore $fileId: user's quota of $userQuota Mb is less than file size of ${archiveEntry.size/1048576L}Mb")
                  case None=>logger.warn(s"Can't restore $fileId: user has no quota")
                }
                Future(Forbidden(GenericErrorResponse("quota_exceeded", "This restore would exceed your quota").asJson))
              }
            case Some(Left(error)) =>
              Future(InternalServerError(GenericErrorResponse("db_error", error.toString).asJson))
            case None =>
              Future(InternalServerError(GenericErrorResponse("integrity_error", s"No lightbox entry available for file $fileId").asJson))
          }
        })
    })
  }