From 800c3a3167fe7fa74d66f5315485b8ea7b356c3c Mon Sep 17 00:00:00 2001 From: Florian M Date: Thu, 5 Sep 2019 14:56:49 +0200 Subject: [PATCH] Use nml name rather than zip name when creating tasks from zip (#4277) * Do not use zipfile name when creating tasks * changelog * Merge branch 'master' into tasks-use-nml-name --- CHANGELOG.md | 1 + app/controllers/AnnotationIOController.scala | 2 +- app/controllers/TaskController.scala | 2 +- app/models/annotation/nml/NmlService.scala | 13 +++++++------ 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e6a1843d50..4b3cb726d1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.md). - Renamed "Expected Time" to "Time Limit" in the project table. [#4278](https://github.com/scalableminds/webknossos/pull/4278) ### Fixed +- When creating tasks from zip, the individual nml names are used again, rather than the zip name. [#4277](https://github.com/scalableminds/webknossos/pull/4277) ## [19.09.0](https://github.com/scalableminds/webknossos/releases/tag/19.09.0) - 2019-08-28 diff --git a/app/controllers/AnnotationIOController.scala b/app/controllers/AnnotationIOController.scala index cd3a5cfd392..59ecc0c6cc0 100755 --- a/app/controllers/AnnotationIOController.scala +++ b/app/controllers/AnnotationIOController.scala @@ -101,7 +101,7 @@ class AnnotationIOController @Inject()(nmlWriter: NmlWriter, val parsedFiles = request.body.files.foldLeft(NmlResults.ZipParseResult()) { case (acc, next) => val file = new File(next.ref.path.toString) - acc.combineWith(nmlService.extractFromFile(file, next.filename)) + acc.combineWith(nmlService.extractFromFile(file, next.filename, useZipName = true)) } val tracingsProcessed = diff --git a/app/controllers/TaskController.scala b/app/controllers/TaskController.scala index cb5ac525af8..71174617b3a 100755 --- a/app/controllers/TaskController.scala +++ b/app/controllers/TaskController.scala @@ -159,7 +159,7 @@ class TaskController @Inject()(annotationService: AnnotationService, .findOneByName(params.projectName) ?~> Messages("project.notFound", params.projectName) ~> NOT_FOUND _ <- Fox.assertTrue(userService.isTeamManagerOrAdminOf(request.identity, project._team)) parseResults: List[NmlParseResult] = nmlService - .extractFromFiles(inputFiles.map(f => (new File(f.ref.path.toString), f.filename))) + .extractFromFiles(inputFiles.map(f => (new File(f.ref.path.toString), f.filename)), useZipName = false) .parseResults skeletonSuccesses <- Fox.serialCombined(parseResults)(_.toSkeletonSuccessFox) ?~> "task.create.failed" result <- createTasks(skeletonSuccesses.map(s => diff --git a/app/models/annotation/nml/NmlService.scala b/app/models/annotation/nml/NmlService.scala index f8365f17fca..495cb26b5df 100644 --- a/app/models/annotation/nml/NmlService.scala +++ b/app/models/annotation/nml/NmlService.scala @@ -35,14 +35,15 @@ class NmlService @Inject()(temporaryFileCreator: TemporaryFileCreator)(implicit case Empty => NmlParseEmpty(name) } - def extractFromZip(file: File, zipFileName: Option[String] = None)(implicit m: MessagesProvider): ZipParseResult = { + def extractFromZip(file: File, zipFileName: Option[String] = None, useZipName: Boolean)( + implicit m: MessagesProvider): ZipParseResult = { val name = zipFileName getOrElse file.getName var otherFiles = Map.empty[String, TemporaryFile] var parseResults = List.empty[NmlParseResult] ZipIO.withUnziped(file, includeHiddenFiles = false) { (filename, file) => if (filename.toString.endsWith(".nml")) { val result = extractFromNml(file, filename.toString) - parseResults ::= result.withName(name) + parseResults ::= (if (useZipName) result.withName(name) else result) } else { val tempFile = temporaryFileCreator.create(filename.toString) Files.copy(file, tempFile.path, StandardCopyOption.REPLACE_EXISTING) @@ -98,15 +99,15 @@ class NmlService @Inject()(temporaryFileCreator: TemporaryFileCreator)(implicit } } - def extractFromFiles(files: Seq[(File, String)])(implicit m: MessagesProvider): ZipParseResult = + def extractFromFiles(files: Seq[(File, String)], useZipName: Boolean)(implicit m: MessagesProvider): ZipParseResult = files.foldLeft(NmlResults.ZipParseResult()) { - case (acc, next) => acc.combineWith(extractFromFile(next._1, next._2)) + case (acc, next) => acc.combineWith(extractFromFile(next._1, next._2, useZipName)) } - def extractFromFile(file: File, fileName: String)(implicit m: MessagesProvider): ZipParseResult = + def extractFromFile(file: File, fileName: String, useZipName: Boolean)(implicit m: MessagesProvider): ZipParseResult = if (fileName.endsWith(".zip")) { logger.trace("Extracting from Zip file") - extractFromZip(file, Some(fileName)) + extractFromZip(file, Some(fileName), useZipName) } else { logger.trace("Extracting from Nml file") val parseResult = extractFromNml(file, fileName)