@@ -5,6 +5,8 @@ import com.scalableminds.util.geometry.{BoundingBox, Vec3Double, Vec3Int}
5
5
import com .scalableminds .util .objectid .ObjectId
6
6
import com .scalableminds .util .time .Instant
7
7
import com .scalableminds .util .tools .{Fox , JsonHelper }
8
+ import com .scalableminds .webknossos .datastore .dataformats .MagLocator
9
+ import com .scalableminds .webknossos .datastore .datareaders .AxisOrder
8
10
import com .scalableminds .webknossos .datastore .helpers .DataSourceMagInfo
9
11
import com .scalableminds .webknossos .datastore .models .{LengthUnit , VoxelSize }
10
12
import com .scalableminds .webknossos .datastore .models .datasource .DatasetViewConfiguration .DatasetViewConfiguration
@@ -17,19 +19,23 @@ import com.scalableminds.webknossos.datastore.models.datasource.{
17
19
Category ,
18
20
CoordinateTransformation ,
19
21
CoordinateTransformationType ,
22
+ DataFormat ,
20
23
DataSourceId ,
21
24
ElementClass ,
22
25
LayerAttachment ,
26
+ LayerAttachmentDataformat ,
23
27
LayerAttachmentType ,
24
28
ThinPlateSplineCorrespondences ,
25
- DataLayerLike => DataLayer
29
+ DataLayerLike => DataLayer ,
30
+ DatasetLayerAttachments => AttachmentWrapper
26
31
}
27
32
import com .scalableminds .webknossos .datastore .services .MagPathInfo
28
33
import com .scalableminds .webknossos .schema .Tables ._
29
34
import controllers .DatasetUpdateParameters
30
35
31
36
import javax .inject .Inject
32
37
import models .organization .OrganizationDAO
38
+ import net .liftweb .common .Box .tryo
33
39
import play .api .i18n .{Messages , MessagesProvider }
34
40
import play .api .libs .json ._
35
41
import slick .dbio .DBIO
@@ -40,6 +46,7 @@ import slick.lifted.Rep
40
46
import slick .sql .SqlAction
41
47
import utils .sql .{SQLDAO , SimpleSQLDAO , SqlClient , SqlToken }
42
48
49
+ import java .net .URI
43
50
import scala .concurrent .ExecutionContext
44
51
45
52
case class Dataset (_id : ObjectId ,
@@ -841,6 +848,30 @@ class DatasetMagsDAO @Inject()(sqlClient: SqlClient)(implicit ec: ExecutionConte
841
848
magInfos <- rowsToMagInfos(rows)
842
849
} yield magInfos
843
850
851
+ def parseMagLocator (row : DatasetMagsRow ): Fox [MagLocator ] =
852
+ for {
853
+ mag <- parseMag(row.mag)
854
+ axisOrderParsed = row.axisorder match {
855
+ case Some (axisOrder) => JsonHelper .parseAs[AxisOrder ](axisOrder).toOption
856
+ case None => None
857
+ }
858
+ } yield
859
+ MagLocator (
860
+ mag,
861
+ row.path,
862
+ None ,
863
+ axisOrderParsed,
864
+ row.channelindex,
865
+ row.credentialid
866
+ )
867
+
868
+ def findAllByDatasetId (datasetId : ObjectId ): Fox [Seq [(String , MagLocator )]] =
869
+ for {
870
+ // We assume non-WKW Datasets here (WKW Resolutions are not handled)
871
+ rows <- run(q """ SELECT * FROM webknossos.dataset_mags WHERE _dataset = $datasetId""" .as[DatasetMagsRow ])
872
+ mags <- Fox .combined(rows.map(parseMagLocator))
873
+ } yield rows.map(r => r.datalayername).zip(mags)
874
+
844
875
}
845
876
846
877
class DatasetLayerDAO @ Inject ()(sqlClient : SqlClient ,
@@ -855,7 +886,7 @@ class DatasetLayerDAO @Inject()(sqlClient: SqlClient,
855
886
category <- Category .fromString(row.category).toFox ?~> " Could not parse Layer Category"
856
887
boundingBox <- BoundingBox
857
888
.fromSQL(parseArrayLiteral(row.boundingbox).map(_.toInt))
858
- .toFox ?~> " Could not parse boundingbox "
889
+ .toFox ?~> " Could not parse bounding box "
859
890
elementClass <- ElementClass .fromString(row.elementclass).toFox ?~> " Could not parse Layer ElementClass"
860
891
mags <- datasetMagsDAO.findMagForLayer(datasetId, row.name) ?~> " Could not find mag for layer"
861
892
defaultViewConfigurationOpt <- Fox .runOptional(row.defaultviewconfiguration)(
@@ -867,6 +898,10 @@ class DatasetLayerDAO @Inject()(sqlClient: SqlClient,
867
898
coordinateTransformationsOpt = if (coordinateTransformations.isEmpty) None else Some (coordinateTransformations)
868
899
additionalAxes <- datasetLayerAdditionalAxesDAO.findAllForDatasetAndDataLayerName(datasetId, row.name)
869
900
additionalAxesOpt = if (additionalAxes.isEmpty) None else Some (additionalAxes)
901
+ attachments <- datasetLayerAttachmentsDAO.findAllForDatasetAndDataLayerName(datasetId, row.name)
902
+ attachmentsOpt = if (attachments.isEmpty) None else Some (attachments)
903
+
904
+ dataFormat = row.dataformat.flatMap(df => DataFormat .fromString(df))
870
905
} yield {
871
906
category match {
872
907
case Category .segmentation =>
@@ -883,7 +918,10 @@ class DatasetLayerDAO @Inject()(sqlClient: SqlClient,
883
918
defaultViewConfigurationOpt,
884
919
adminViewConfigurationOpt,
885
920
coordinateTransformationsOpt,
886
- additionalAxesOpt
921
+ additionalAxesOpt,
922
+ numChannels = row.numchannels,
923
+ dataFormat = dataFormat,
924
+ attachments = attachmentsOpt
887
925
))
888
926
case Category .color =>
889
927
Fox .successful(
@@ -896,7 +934,10 @@ class DatasetLayerDAO @Inject()(sqlClient: SqlClient,
896
934
defaultViewConfigurationOpt,
897
935
adminViewConfigurationOpt,
898
936
coordinateTransformationsOpt,
899
- additionalAxesOpt
937
+ additionalAxesOpt,
938
+ numChannels = row.numchannels,
939
+ dataFormat = dataFormat,
940
+ attachments = attachmentsOpt
900
941
))
901
942
case _ => Fox .failure(s " Could not match dataset layer with category $category" )
902
943
}
@@ -907,7 +948,7 @@ class DatasetLayerDAO @Inject()(sqlClient: SqlClient,
907
948
def findAllForDataset (datasetId : ObjectId ): Fox [List [DataLayer ]] =
908
949
for {
909
950
rows <- run(q """ SELECT _dataset, name, category, elementClass, boundingBox, largestSegmentId, mappings,
910
- defaultViewConfiguration, adminViewConfiguration
951
+ defaultViewConfiguration, adminViewConfiguration, numChannels, dataFormat
911
952
FROM webknossos.dataset_layers
912
953
WHERE _dataset = $datasetId
913
954
ORDER BY name """ .as[DatasetLayersRow ])
@@ -1015,6 +1056,39 @@ class DatasetLastUsedTimesDAO @Inject()(sqlClient: SqlClient)(implicit ec: Execu
1015
1056
1016
1057
class DatasetLayerAttachmentsDAO @ Inject ()(sqlClient : SqlClient )(implicit ec : ExecutionContext )
1017
1058
extends SimpleSQLDAO (sqlClient) {
1059
+
1060
+ def parseRow (row : DatasetLayerAttachmentsRow ): Fox [LayerAttachment ] =
1061
+ for {
1062
+ dataFormat <- LayerAttachmentDataformat .fromString(row.dataformat).toFox ?~> " Could not parse data format"
1063
+ uri <- tryo(new URI (row.path)).toFox
1064
+ } yield LayerAttachment (row.name, uri, dataFormat)
1065
+
1066
+ def parseAttachments (rows : List [DatasetLayerAttachmentsRow ]): Fox [AttachmentWrapper ] =
1067
+ for {
1068
+ meshFiles <- Fox .serialCombined(rows.filter(_.`type` == LayerAttachmentType .mesh.toString))(parseRow)
1069
+ agglomerateFiles <- Fox .serialCombined(rows.filter(_.`type` == LayerAttachmentType .agglomerate.toString))(
1070
+ parseRow)
1071
+ connectomeFiles <- Fox .serialCombined(rows.filter(_.`type` == LayerAttachmentType .connectome.toString))(parseRow)
1072
+ segmentIndexFiles <- Fox .serialCombined(rows.filter(_.`type` == LayerAttachmentType .segmentIndex.toString))(
1073
+ parseRow)
1074
+ cumsumFiles <- Fox .serialCombined(rows.filter(_.`type` == LayerAttachmentType .cumsum.toString))(parseRow)
1075
+ } yield
1076
+ AttachmentWrapper (
1077
+ agglomerates = agglomerateFiles,
1078
+ connectomes = connectomeFiles,
1079
+ segmentIndex = segmentIndexFiles.headOption,
1080
+ meshes = meshFiles,
1081
+ cumsum = cumsumFiles.headOption
1082
+ )
1083
+
1084
+ def findAllForDatasetAndDataLayerName (datasetId : ObjectId , layerName : String ): Fox [AttachmentWrapper ] =
1085
+ for {
1086
+ rows <- run(q """ SELECT _dataset, layerName, name, path, type, dataFormat
1087
+ FROM webknossos.dataset_layer_attachments
1088
+ WHERE _dataset = $datasetId AND layerName = $layerName""" .as[DatasetLayerAttachmentsRow ])
1089
+ attachments <- parseAttachments(rows.toList) ?~> " Could not parse attachments"
1090
+ } yield attachments
1091
+
1018
1092
def updateAttachments (datasetId : ObjectId , dataLayersOpt : Option [List [DataLayer ]]): Fox [Unit ] = {
1019
1093
def insertQuery (attachment : LayerAttachment , layerName : String , fileType : String ) =
1020
1094
q """ INSERT INTO webknossos.dataset_layer_attachments(_dataset, layerName, name, path, type, dataFormat)
0 commit comments