Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix duplicate route for Editable Mapping annotations #6446

Merged
merged 5 commits into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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