Skip to content

Commit

Permalink
Use nml name rather than zip name when creating tasks from zip (#4277)
Browse files Browse the repository at this point in the history
* Do not use zipfile name when creating tasks
* changelog
* Merge branch 'master' into tasks-use-nml-name
  • Loading branch information
fm3 authored and bulldozer-boy[bot] committed Sep 5, 2019
1 parent af3ff6b commit 800c3a3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/AnnotationIOController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/TaskController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down
13 changes: 7 additions & 6 deletions app/models/annotation/nml/NmlService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 800c3a3

Please sign in to comment.