Skip to content

Commit 6a7f8f1

Browse files
authored
Include AttachmentType in proxy routes (#9433)
Previously, proxyAttachment only worked if attachment name was unique across attachment types in the layer Note that the libs use the paths from the proxy datasource-properties.json route, so this isn’t a breaking change (unless someone used the routes manually) ### Steps to test: - check that /data/datasets/:datasetId/proxy/datasource-properties.json lists correct attachment paths - check that they work ### Issues: - fixes #9431 ------ - [x] Added changelog entry (create a `$PR_NUMBER.md` file in `unreleased_changes` or use `./tools/create-changelog-entry.py`) - [x] Removed dev-only changes like prints and application.conf edits - [x] Considered [common edge cases](../blob/master/.github/common_edge_cases.md) - [x] Needs datastore update after deployment
1 parent 9e3b60a commit 6a7f8f1

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

webknossos-datastore/app/com/scalableminds/webknossos/datastore/controllers/DataProxyController.scala

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import com.scalableminds.webknossos.datastore.dataformats.MagLocator
88
import com.scalableminds.webknossos.datastore.datavault.{ByteRange, Encoding}
99
import com.scalableminds.webknossos.datastore.datavault.Encoding.Encoding
1010
import com.scalableminds.webknossos.datastore.helpers.UPath
11-
import com.scalableminds.webknossos.datastore.models.datasource.{DataLayerAttachments, UsableDataSource}
11+
import com.scalableminds.webknossos.datastore.models.datasource.{
12+
DataLayerAttachments,
13+
LayerAttachmentType,
14+
UsableDataSource
15+
}
1216
import com.scalableminds.webknossos.datastore.services.{DataStoreAccessTokenService, DatasetCache, UserAccessRequest}
1317
import com.scalableminds.webknossos.datastore.storage.DataVaultService
1418
import play.api.http.Writeable
@@ -55,17 +59,18 @@ class DataProxyController @Inject()(accessTokenService: DataStoreAccessTokenServ
5559

5660
def proxyAttachment(datasetId: ObjectId,
5761
dataLayerName: String,
62+
attachmentType: String,
5863
attachmentName: String,
5964
path: String): Action[AnyContent] = Action.async { implicit request =>
6065
accessTokenService.validateAccessFromTokenContext(UserAccessRequest.readDataset(datasetId)) {
6166
for {
6267
_ <- validatePath(path)
6368
(_, dataLayer) <- datasetCache.getWithLayer(datasetId, dataLayerName) ?~> Messages("dataLayer.notFound",
6469
dataLayerName) ~> NOT_FOUND
65-
attachment <- dataLayer.allAttachments.find(_.name == attachmentName).toFox ?~> Messages(
66-
"dataLayer.wrongAttachment",
67-
dataLayerName,
68-
attachmentName) ~> NOT_FOUND
70+
attachmentTypeValidated <- LayerAttachmentType.fromString(attachmentType).toFox
71+
attachment <- dataLayer.attachments
72+
.flatMap(_.getByTypeAndName(attachmentTypeValidated, attachmentName))
73+
.toFox ?~> Messages("dataLayer.wrongAttachment", dataLayerName, attachmentName) ~> NOT_FOUND
6974
attachmentPath <- dataVaultService.vaultPathFor(attachment)
7075
requestedPath = attachmentPath / path
7176
byteRange <- ByteRange.fromRequest(request)
@@ -97,10 +102,10 @@ class DataProxyController @Inject()(accessTokenService: DataStoreAccessTokenServ
97102
path = Some(UPath.fromStringUnsafe(s"./layers/$layerName/mags/${mag.mag.toMagLiteral(allowScalar = true)}")))
98103

99104
private def adaptPathsForAttachments(attachments: DataLayerAttachments, layerName: String): DataLayerAttachments =
100-
attachments.mapped(
101-
attachment =>
105+
attachments.mappedWithType(
106+
(attachment, attachmentType) =>
102107
attachment.copy(
103-
path = UPath.fromStringUnsafe(s"./layers/$layerName/attachments/${attachment.name}")
108+
path = UPath.fromStringUnsafe(s"./layers/$layerName/attachments/$attachmentType/${attachment.name}")
104109
))
105110

106111
private def validatePath(path: String): Fox[Unit] =

webknossos-datastore/app/com/scalableminds/webknossos/datastore/models/datasource/DataLayerAttachments.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@ case class DataLayerAttachments(
7070
cumsum = cumsum.map(attachmentMapping(_))
7171
)
7272

73+
def mappedWithType(
74+
attachmentMapping: (LayerAttachment, LayerAttachmentType) => LayerAttachment): DataLayerAttachments =
75+
DataLayerAttachments(
76+
meshes = meshes.map(attachmentMapping(_, LayerAttachmentType.mesh)),
77+
agglomerates = agglomerates.map(attachmentMapping(_, LayerAttachmentType.agglomerate)),
78+
segmentIndex = segmentIndex.map(attachmentMapping(_, LayerAttachmentType.segmentIndex)),
79+
connectomes = connectomes.map(attachmentMapping(_, LayerAttachmentType.connectome)),
80+
cumsum = cumsum.map(attachmentMapping(_, LayerAttachmentType.cumsum)),
81+
)
82+
7383
def renameByMap(renamingMap: Map[(LayerAttachmentType, String), String]): DataLayerAttachments =
7484
DataLayerAttachments(
7585
meshes = meshes.map(a => a.copy(name = renamingMap.getOrElse((LayerAttachmentType.mesh, a.name), a.name))),

webknossos-datastore/conf/datastore.latest.routes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ GET /datasets/:datasetId/layers/:dataLayerName/histogram
1313

1414
# Read mag and attachment data via proxy
1515
GET /datasets/:datasetId/proxy/layers/:dataLayerName/mags/:mag/*path @com.scalableminds.webknossos.datastore.controllers.DataProxyController.proxyMag(datasetId: ObjectId, dataLayerName: String, mag: String, path: String)
16-
GET /datasets/:datasetId/proxy/layers/:dataLayerName/attachments/:attachmentName/*path @com.scalableminds.webknossos.datastore.controllers.DataProxyController.proxyAttachment(datasetId: ObjectId, dataLayerName: String, attachmentName: String, path: String)
16+
GET /datasets/:datasetId/proxy/layers/:dataLayerName/attachments/:attachmentType/:attachmentName/*path @com.scalableminds.webknossos.datastore.controllers.DataProxyController.proxyAttachment(datasetId: ObjectId, dataLayerName: String, attachmentType: String, attachmentName: String, path: String)
1717
GET /datasets/:datasetId/proxy/datasource-properties.json @com.scalableminds.webknossos.datastore.controllers.DataProxyController.proxyDatasource(datasetId: ObjectId)
1818

1919
# Knossos compatible routes

0 commit comments

Comments
 (0)