From 20f3afe45fbbfc637816acb79c908930908ebca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20B=C3=BC=C3=9Femeyer?= Date: Thu, 5 Dec 2024 14:33:48 +0100 Subject: [PATCH 1/3] fix legacy support for outdated displayName field of datasets --- app/controllers/DatasetController.scala | 2 +- app/controllers/LegacyApiController.scala | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/controllers/DatasetController.scala b/app/controllers/DatasetController.scala index cf90bdfa10..277fd359ee 100755 --- a/app/controllers/DatasetController.scala +++ b/app/controllers/DatasetController.scala @@ -339,7 +339,7 @@ class DatasetController @Inject()(userService: UserService, sil.SecuredAction.async(parse.json) { implicit request => withJsonBodyUsing(datasetPublicReads) { case (description, datasetName, legacyDatasetDisplayName, sortingKey, isPublic, tags, metadata, folderId) => { - val name = if (datasetName.isDefined) datasetName else legacyDatasetDisplayName + val name = if (legacyDatasetDisplayName.isDefined) legacyDatasetDisplayName else datasetName for { datasetIdValidated <- ObjectId.fromString(datasetId) dataset <- datasetDAO.findOne(datasetIdValidated) ?~> notFoundMessage(datasetIdValidated.toString) ~> NOT_FOUND diff --git a/app/controllers/LegacyApiController.scala b/app/controllers/LegacyApiController.scala index e92e686bdc..3389e868f3 100644 --- a/app/controllers/LegacyApiController.scala +++ b/app/controllers/LegacyApiController.scala @@ -72,7 +72,8 @@ class LegacyApiController @Inject()(annotationController: AnnotationController, for { dataset <- datasetDAO.findOneByNameAndOrganization(datasetName, organizationId) result <- datasetController.read(dataset._id.toString, sharingToken)(request) - } yield result + adaptedResult <- replaceInResult(migrateDatasetJsonToOldFormat)(result) + } yield adaptedResult } def updateDatasetV8(organizationId: String, datasetName: String): Action[JsValue] = @@ -81,7 +82,8 @@ class LegacyApiController @Inject()(annotationController: AnnotationController, _ <- Fox.successful(logVersioned(request)) dataset <- datasetDAO.findOneByNameAndOrganization(datasetName, organizationId) result <- datasetController.update(dataset._id.toString)(request) - } yield result + adaptedResult <- replaceInResult(migrateDatasetJsonToOldFormat)(result) + } yield adaptedResult } def updateDatasetTeamsV8(organizationId: String, datasetName: String): Action[List[ObjectId]] = @@ -241,6 +243,19 @@ class LegacyApiController @Inject()(annotationController: AnnotationController, /* private helper methods for legacy adaptation */ + private def migrateDatasetJsonToOldFormat(jsResult: JsObject): Fox[JsObject] = { + val datasetName = (jsResult \ "name").asOpt[String] + val directoryName = (jsResult \ "directoryName").asOpt[String] + datasetName.zip(directoryName) match { + case Some((name, dirName)) => + for { + dsWithOldNameField <- tryo(jsResult - "name" + ("name" -> Json.toJson(dirName))).toFox + dsWithOldDisplayNameField <- tryo(dsWithOldNameField - "displayName" + ("displayName" -> Json.toJson(name))).toFox + } yield dsWithOldDisplayNameField + case _ => Fox.successful(jsResult) + } + } + private def addDataSetToTaskInAnnotation(jsResult: JsObject): Fox[JsObject] = { val taskObjectOpt = (jsResult \ "task").asOpt[JsObject] taskObjectOpt From cc72de19d6a5655029e44ff6e9ad353c7b90c59b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20B=C3=BC=C3=9Femeyer?= Date: Thu, 5 Dec 2024 14:48:19 +0100 Subject: [PATCH 2/3] add changelog entry --- CHANGELOG.unreleased.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index 752cda3287..3abef3313f 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -32,6 +32,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released - Fixed a bug where changing the color of a segment via the menu in the segments tab would update the segment color of the previous segment, on which the context menu was opened. [#8225](https://github.com/scalableminds/webknossos/pull/8225) - Fixed a bug where in the add remote dataset view the dataset name setting was not in sync with the datasource setting of the advanced tab making the form not submittable. [#8245](https://github.com/scalableminds/webknossos/pull/8245) - Fixed a bug when importing an NML with groups when only groups but no trees exist in an annotation. [#8176](https://github.com/scalableminds/webknossos/pull/8176) +- Fix read and update dataset route for versions 8 and lower. [#8263](https://github.com/scalableminds/webknossos/pull/8263) - Added missing legacy support for `isValidNewName` route. [#8252](https://github.com/scalableminds/webknossos/pull/8252) - Fixed a bug where trying to delete a non-existing node (via the API, for example) would delete the whole active tree. [#8176](https://github.com/scalableminds/webknossos/pull/8176) - Fixed a bug where dataset uploads would fail if the organization directory on disk is missing. [#8230](https://github.com/scalableminds/webknossos/pull/8230) From 3207ef83b6841fe49ec7100d644a34b031cbadbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20B=C3=BC=C3=9Femeyer?= Date: Thu, 5 Dec 2024 14:52:32 +0100 Subject: [PATCH 3/3] remove directoryName from serialized dataset json format in legacy routes --- app/controllers/LegacyApiController.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/LegacyApiController.scala b/app/controllers/LegacyApiController.scala index 3389e868f3..cb8d983285 100644 --- a/app/controllers/LegacyApiController.scala +++ b/app/controllers/LegacyApiController.scala @@ -249,8 +249,8 @@ class LegacyApiController @Inject()(annotationController: AnnotationController, datasetName.zip(directoryName) match { case Some((name, dirName)) => for { - dsWithOldNameField <- tryo(jsResult - "name" + ("name" -> Json.toJson(dirName))).toFox - dsWithOldDisplayNameField <- tryo(dsWithOldNameField - "displayName" + ("displayName" -> Json.toJson(name))).toFox + dsWithOldNameField <- tryo(jsResult - "directoryName" + ("name" -> Json.toJson(dirName))).toFox + dsWithOldDisplayNameField <- tryo(dsWithOldNameField + ("displayName" -> Json.toJson(name))).toFox } yield dsWithOldDisplayNameField case _ => Fox.successful(jsResult) }