From f41f4ae37e1d045b7707a85ebffd976e1e9c8b33 Mon Sep 17 00:00:00 2001 From: Florian M Date: Wed, 12 May 2021 08:10:25 +0200 Subject: [PATCH] Relabel too-high tree ids in backend (#5484) * [WIP] relabel too-high tree ids in backend * return skeleton with new trees --- CHANGELOG.unreleased.md | 1 + app/models/annotation/TracingStoreRpcClient.scala | 2 +- .../controllers/SkeletonTracingController.scala | 7 ++++--- .../webknossos/tracingstore/tracings/TracingService.scala | 2 ++ .../tracings/skeleton/SkeletonTracingService.scala | 7 +++++++ 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index b6476dcacb7..168849e010c 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -20,6 +20,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released ### Fixed - Fixed that the row selection in the user table wasn't properly preserved when filtering the table and (un)selecting rows. [#5486](https://github.com/scalableminds/webknossos/pull/5486) - Fixed a bug where histograms generation failed for tiny datasets. [#5458](https://github.com/scalableminds/webknossos/pull/5458) +- Fixed a bug where NMLs with huge tree IDs uploaded via back-end produced broken annotations. [#5484](https://github.com/scalableminds/webknossos/pull/5484) - Fixed a bug where the upload of multiple NMLs failed if some of them have an organization attribute and others don’t. [#5483](https://github.com/scalableminds/webknossos/pull/5483) ### Removed diff --git a/app/models/annotation/TracingStoreRpcClient.scala b/app/models/annotation/TracingStoreRpcClient.scala index 1fd8690066f..0c77c6ff136 100644 --- a/app/models/annotation/TracingStoreRpcClient.scala +++ b/app/models/annotation/TracingStoreRpcClient.scala @@ -27,7 +27,7 @@ object TracingStoreRpcClient { class TracingStoreRpcClient(tracingStore: TracingStore, dataSet: DataSet, rpc: RPC)(implicit ec: ExecutionContext) extends LazyLogging { - def baseInfo = s"Dataset: ${dataSet.name} Tracingstore: ${tracingStore.url}" + def baseInfo = s" Dataset: ${dataSet.name} Tracingstore: ${tracingStore.url}" def getSkeletonTracing(tracingId: String, version: Option[Long]): Fox[SkeletonTracing] = { logger.debug("Called to get SkeletonTracing." + baseInfo) diff --git a/webknossos-tracingstore/app/com/scalableminds/webknossos/tracingstore/controllers/SkeletonTracingController.scala b/webknossos-tracingstore/app/com/scalableminds/webknossos/tracingstore/controllers/SkeletonTracingController.scala index 92a81eed0fb..a60f207d4ed 100644 --- a/webknossos-tracingstore/app/com/scalableminds/webknossos/tracingstore/controllers/SkeletonTracingController.scala +++ b/webknossos-tracingstore/app/com/scalableminds/webknossos/tracingstore/controllers/SkeletonTracingController.scala @@ -38,9 +38,10 @@ class SkeletonTracingController @Inject()(val tracingService: SkeletonTracingSer AllowRemoteOrigin { val tracings: List[Option[SkeletonTracing]] = request.body val mergedTracing = tracingService.merge(tracings.flatten) - tracingService.save(mergedTracing, None, mergedTracing.version, toCache = !persist).map { newId => - Ok(Json.toJson(newId)) - } + val processedTracing = tracingService.remapTooLargeTreeIds(mergedTracing) + for { + newId <- tracingService.save(processedTracing, None, processedTracing.version, toCache = !persist) + } yield Ok(Json.toJson(newId)) } } } diff --git a/webknossos-tracingstore/app/com/scalableminds/webknossos/tracingstore/tracings/TracingService.scala b/webknossos-tracingstore/app/com/scalableminds/webknossos/tracingstore/tracings/TracingService.scala index 07551a26e70..efd5ccfd356 100644 --- a/webknossos-tracingstore/app/com/scalableminds/webknossos/tracingstore/tracings/TracingService.scala +++ b/webknossos-tracingstore/app/com/scalableminds/webknossos/tracingstore/tracings/TracingService.scala @@ -172,6 +172,8 @@ trait TracingService[T <: GeneratedMessage with Message[T]] def merge(tracings: Seq[T]): T + def remapTooLargeTreeIds(tracing: T): T = tracing + def mergeVolumeData(tracingSelectors: Seq[TracingSelector], tracings: Seq[T], newId: String, diff --git a/webknossos-tracingstore/app/com/scalableminds/webknossos/tracingstore/tracings/skeleton/SkeletonTracingService.scala b/webknossos-tracingstore/app/com/scalableminds/webknossos/tracingstore/tracings/skeleton/SkeletonTracingService.scala index ec73f2bcd99..93423ca0d24 100644 --- a/webknossos-tracingstore/app/com/scalableminds/webknossos/tracingstore/tracings/skeleton/SkeletonTracingService.scala +++ b/webknossos-tracingstore/app/com/scalableminds/webknossos/tracingstore/tracings/skeleton/SkeletonTracingService.scala @@ -176,6 +176,13 @@ class SkeletonTracingService @Inject()(tracingDataStore: TracingDataStore, ) } + // Can be removed again when https://github.com/scalableminds/webknossos/issues/5009 is fixed + override def remapTooLargeTreeIds(skeletonTracing: SkeletonTracing): SkeletonTracing = + if (skeletonTracing.trees.exists(_.treeId > 1048576)) { + val newTrees = for ((tree, index) <- skeletonTracing.trees.zipWithIndex) yield tree.withTreeId(index + 1) + skeletonTracing.withTrees(newTrees) + } else skeletonTracing + def mergeVolumeData(tracingSelectors: Seq[TracingSelector], tracings: Seq[SkeletonTracing], newId: String,