in app/controllers/ImportController.scala [90:136]
def importFromPath = IsAuthenticatedAsync(circe.json(2048)) { uid=> request=>
request.body.as[SpecificImportRequest] match {
case Left(err)=>
Future(BadRequest(GenericErrorResponse("bad_request",err.toString()).asJson))
case Right(importRequest)=>
scanTargetDAO.targetForBucket(importRequest.collectionName).flatMap({
case None=>
Future(BadRequest(GenericErrorResponse("not_found", "The given collection does not exist").asJson))
case Some(Left(err))=>
logger.error(s"Could not look up scan target for bucket: $err")
Future(InternalServerError(GenericErrorResponse("db_error","Could not look up scan target").asJson))
case Some(Right(scanTarget))=>
if(scanTarget.enabled) {
implicit val s3client:S3Client = s3ClientMgr.getClient(awsProfile)
if(s3client.doesObjectExist(scanTarget.bucketName, importRequest.itemPath).get) {
val entry = ArchiveEntry.fromS3Sync(scanTarget.bucketName, importRequest.itemPath, None, scanTarget.region) //importing from path => take latest version
indexer.indexSingleItem(entry).flatMap({
case Left(err)=>
logger.error(s"Could not index new item $entry: $err")
Future(InternalServerError(GenericErrorResponse("index_error","Could not index new item, see server logs").asJson))
case Right(newId)=>
logger.info(s"Registered new item with ID $newId, adding to path cache")
ingestProxyQueue ! IngestProxyQueue.CheckRegisteredProxy
ingestProxyQueue ! IngestProxyQueue.CheckRegisteredThumb
ingestProxyQueue ! IngestProxyQueue.StartAnalyse
addToPathCache(importRequest).map(_=>{
Ok(ObjectCreatedResponse("ok","item",newId).asJson)
}).recover({
case err:Throwable=>
logger.error(s"Could not add to path cache, but did create item: $err")
Ok(ObjectCreatedResponse("ok","item",newId).asJson)
})
})
} else {
Future(NotFound(GenericErrorResponse("not_found","The given file does not exist").asJson))
}
} else {
Future(BadRequest(GenericErrorResponse("disabled","This scan target is disabled").asJson))
}
}).recover({
case err:Throwable=>
logger.error(s"Specific import request crashed: ${err.getMessage}", err)
InternalServerError(GenericErrorResponse("error","The import process failed, please see server logs for details").asJson)
})
}
}