Skip to content

Commit

Permalink
Fix duplicate route for Editable Mapping annotations (#6446)
Browse files Browse the repository at this point in the history
* [WIP] some enhancements for editable mappings

* Implement duplicate for volume tracings with editable mapping

* changelog
  • Loading branch information
fm3 authored Sep 12, 2022
1 parent 4f32e6f commit 387a22f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released

### Fixed
- Fixed sharing button for users who are currently visiting a dataset or annotation which was shared with them. [#6438](https://github.com/scalableminds/webknossos/pull/6438)
- Fixed the duplicate function for annotations with an editable mapping (a.k.a. supervoxel proofreading) layer. [#6446](https://github.com/scalableminds/webknossos/pull/6446)

### Removed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,23 +181,28 @@ class VolumeTracingController @Inject()(
boundingBox: Option[String]): Action[AnyContent] = Action.async { implicit request =>
log() {
logTime(slackNotificationService.noticeSlowRequest) {
accessTokenService.validateAccess(UserAccessRequest.webknossos, urlOrHeaderToken(token, request)) {
val userToken = urlOrHeaderToken(token, request)
accessTokenService.validateAccess(UserAccessRequest.webknossos, userToken) {
for {
tracing <- tracingService.find(tracingId) ?~> Messages("tracing.notFound")
_ <- bool2Fox(!tracing.getMappingIsEditable) ?~> "Duplicate is not yet implemented for editable mapping annotations"
dataSetBoundingBox = request.body.asJson.flatMap(_.validateOpt[BoundingBox].asOpt.flatten)
resolutionRestrictions = ResolutionRestrictions(minResolution, maxResolution)
editPositionParsed <- Fox.runOptional(editPosition)(Vec3Int.fromUriLiteral)
editRotationParsed <- Fox.runOptional(editRotation)(Vec3Double.fromUriLiteral)
boundingBoxParsed <- Fox.runOptional(boundingBox)(BoundingBox.fromLiteral)
(newId, newTracing) <- tracingService.duplicate(tracingId,
tracing,
fromTask.getOrElse(false),
dataSetBoundingBox,
resolutionRestrictions,
editPositionParsed,
editRotationParsed,
boundingBoxParsed)
newEditableMappingId <- Fox.runIf(tracing.mappingIsEditable.contains(true))(
editableMappingService.duplicate(tracing.mappingName, tracing, userToken))
(newId, newTracing) <- tracingService.duplicate(
tracingId,
tracing,
fromTask.getOrElse(false),
dataSetBoundingBox,
resolutionRestrictions,
editPositionParsed,
editRotationParsed,
boundingBoxParsed,
newEditableMappingId
)
_ <- Fox.runIfOptionTrue(downsample)(tracingService.downsample(newId, newTracing))
} yield Ok(Json.toJson(newId))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class EditableMappingService @Inject()(
"mappingName" -> editableMappingId,
"version" -> version,
"tracingId" -> tracingId,
"baseMappingName" -> editableMapping.baseMappingName,
"createdTimestamp" -> editableMapping.createdTimestamp
)

Expand All @@ -147,6 +148,15 @@ class EditableMappingService @Inject()(
emptyFallback = Some(-1L))
} yield versionOrMinusOne >= 0

def duplicate(editableMappingIdOpt: Option[String], tracing: VolumeTracing, userToken: Option[String]): Fox[String] =
for {
editableMappingId <- editableMappingIdOpt ?~> "duplicate on editable mapping without id"
remoteFallbackLayer <- RemoteFallbackLayer.fromVolumeTracing(tracing)
editableMapping <- get(editableMappingId, remoteFallbackLayer, userToken)
newId = generateId
_ <- tracingDataStore.editableMappings.put(newId, 0L, toProtoBytes(editableMapping.toProto))
} yield newId

def updateActionLog(editableMappingId: String): Fox[JsValue] = {
def versionedTupleToJson(tuple: (Long, List[EditableMappingUpdateAction])): JsObject =
Json.obj(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,16 @@ class VolumeTracingService @Inject()(
resolutionRestrictions: ResolutionRestrictions,
editPosition: Option[Vec3Int],
editRotation: Option[Vec3Double],
boundingBox: Option[BoundingBox]): Fox[(String, VolumeTracing)] = {
boundingBox: Option[BoundingBox],
mappingName: Option[String]): Fox[(String, VolumeTracing)] = {
val tracingWithBB = addBoundingBoxFromTaskIfRequired(sourceTracing, fromTask, dataSetBoundingBox)
val tracingWithResolutionRestrictions = restrictMagList(tracingWithBB, resolutionRestrictions)
val newTracing = tracingWithResolutionRestrictions.copy(
createdTimestamp = System.currentTimeMillis(),
editPosition = editPosition.map(vec3IntToProto).getOrElse(tracingWithResolutionRestrictions.editPosition),
editRotation = editRotation.map(vec3DoubleToProto).getOrElse(tracingWithResolutionRestrictions.editRotation),
boundingBox = boundingBoxOptToProto(boundingBox).getOrElse(tracingWithResolutionRestrictions.boundingBox),
mappingName = mappingName.orElse(tracingWithResolutionRestrictions.mappingName),
version = 0
)
for {
Expand Down

0 comments on commit 387a22f

Please sign in to comment.