@@ -2,6 +2,7 @@ package controllers
22
33import play .silhouette .api .{LoginInfo , Silhouette }
44import com .scalableminds .util .accesscontext .GlobalAccessContext
5+ import com .scalableminds .util .geometry .{BoundingBox , Vec3Double , Vec3Int }
56import com .scalableminds .util .objectid .ObjectId
67import com .scalableminds .util .time .Instant
78import com .scalableminds .util .tools .{Fox , FoxImplicits }
@@ -15,6 +16,17 @@ import models.task.{TaskType, TaskTypeDAO}
1516import models .team ._
1617import models .user ._
1718import com .scalableminds .util .tools .Full
19+ import com .scalableminds .webknossos .datastore .dataformats .MagLocator
20+ import com .scalableminds .webknossos .datastore .helpers .UPath
21+ import com .scalableminds .webknossos .datastore .models .{LengthUnit , VoxelSize }
22+ import com .scalableminds .webknossos .datastore .models .datasource .{
23+ DataFormat ,
24+ DataSourceId ,
25+ ElementClass ,
26+ StaticColorLayer ,
27+ StaticSegmentationLayer ,
28+ UsableDataSource
29+ }
1830import play .api .libs .json .{JsArray , Json }
1931import utils .{StoreModules , WkConf }
2032
@@ -39,6 +51,8 @@ class InitialDataController @Inject()(initialDataService: InitialDataService, si
3951
4052class InitialDataService @ Inject ()(userService : UserService ,
4153 userDAO : UserDAO ,
54+ datasetDAO : DatasetDAO ,
55+ datasetLayerDAO : DatasetLayerDAO ,
4256 multiUserDAO : MultiUserDAO ,
4357 userExperiencesDAO : UserExperiencesDAO ,
4458 taskTypeDAO : TaskTypeDAO ,
@@ -156,6 +170,95 @@ Samplecountry
156170 Some (" Works if model files are manually placed at binaryData/sample_organization/66544a56d20000af0e42ba0f/" ),
157171 Some (AiModelCategory .em_neurons)
158172 )
173+ private val defaultDataSource = UsableDataSource (
174+ id = DataSourceId (" l4_sample_remote" , defaultOrganization._id),
175+ dataLayers = List (
176+ StaticColorLayer (
177+ name = " color" ,
178+ dataFormat = DataFormat .zarr3,
179+ boundingBox = BoundingBox (Vec3Int (3072 , 3072 , 512 ), 1024 , 1024 , 1024 ),
180+ elementClass = ElementClass .uint8,
181+ mags = List (
182+ MagLocator (
183+ mag = Vec3Int (1 , 1 , 1 ),
184+ path = Some (UPath .fromStringUnsafe(" https://static.webknossos.org/data/zarr_v3/l4_sample/color/1" ))
185+ ),
186+ MagLocator (
187+ mag = Vec3Int (2 , 2 , 1 ),
188+ path = Some (UPath .fromStringUnsafe(" https://static.webknossos.org/data/zarr_v3/l4_sample/color/2-2-1" ))
189+ ),
190+ MagLocator (
191+ mag = Vec3Int (4 , 4 , 1 ),
192+ path = Some (UPath .fromStringUnsafe(" https://static.webknossos.org/data/zarr_v3/l4_sample/color/4-4-1" ))
193+ ),
194+ MagLocator (
195+ mag = Vec3Int (8 , 8 , 2 ),
196+ path = Some (UPath .fromStringUnsafe(" https://static.webknossos.org/data/zarr_v3/l4_sample/color/8-8-2" ))
197+ ),
198+ MagLocator (
199+ mag = Vec3Int (16 , 16 , 4 ),
200+ path = Some (UPath .fromStringUnsafe(" https://static.webknossos.org/data/zarr_v3/l4_sample/color/16-16-4" ))
201+ )
202+ )
203+ ),
204+ StaticSegmentationLayer (
205+ name = " segmentation" ,
206+ dataFormat = DataFormat .zarr3,
207+ boundingBox = BoundingBox (Vec3Int (3072 , 3072 , 512 ), 1024 , 1024 , 1024 ),
208+ elementClass = ElementClass .uint32,
209+ mags = List (
210+ MagLocator (
211+ mag = Vec3Int (1 , 1 , 1 ),
212+ path = Some (UPath .fromStringUnsafe(" https://static.webknossos.org/data/zarr_v3/l4_sample/segmentation/1" ))
213+ ),
214+ MagLocator (
215+ mag = Vec3Int (2 , 2 , 1 ),
216+ path =
217+ Some (UPath .fromStringUnsafe(" https://static.webknossos.org/data/zarr_v3/l4_sample/segmentation/2-2-1" ))
218+ ),
219+ MagLocator (
220+ mag = Vec3Int (4 , 4 , 1 ),
221+ path =
222+ Some (UPath .fromStringUnsafe(" https://static.webknossos.org/data/zarr_v3/l4_sample/segmentation/4-4-1" ))
223+ ),
224+ MagLocator (
225+ mag = Vec3Int (8 , 8 , 2 ),
226+ path =
227+ Some (UPath .fromStringUnsafe(" https://static.webknossos.org/data/zarr_v3/l4_sample/segmentation/8-8-2" ))
228+ ),
229+ MagLocator (
230+ mag = Vec3Int (16 , 16 , 4 ),
231+ path =
232+ Some (UPath .fromStringUnsafe(" https://static.webknossos.org/data/zarr_v3/l4_sample/segmentation/16-16-4" ))
233+ )
234+ ),
235+ largestSegmentId = Some (2504697 ),
236+ )
237+ ),
238+ scale = VoxelSize (Vec3Double (11.239999771118164 , 11.239999771118164 , 28 ), LengthUnit .nanometer)
239+ )
240+
241+ private val defaultDataset = Dataset (
242+ _id = ObjectId (" 68b80290d4000090f8f4aa62" ),
243+ _dataStore = defaultDataStore.name,
244+ _organization = defaultOrganization._id,
245+ _publication = Some (defaultPublication._id),
246+ _uploader = Some (defaultUser._id),
247+ _folder = defaultOrganization._rootFolder,
248+ inboxSourceHash = Some (defaultDataSource.hashCode()),
249+ defaultViewConfiguration = None ,
250+ adminViewConfiguration = None ,
251+ description = None ,
252+ directoryName = defaultDataSource.id.directoryName,
253+ isPublic = false ,
254+ isUsable = true ,
255+ isVirtual = true ,
256+ name = " l4_sample_remote" ,
257+ voxelSize = Some (defaultDataSource.scale),
258+ sharingToken = None ,
259+ status = " " ,
260+ logoUrl = None ,
261+ )
159262
160263 def insert : Fox [Unit ] =
161264 for {
@@ -175,6 +278,7 @@ Samplecountry
175278 _ <- insertTaskType()
176279 _ <- insertProject()
177280 _ <- insertPublication()
281+ _ <- insertDataset()
178282 _ <- insertAiModel()
179283 } yield ()
180284
@@ -276,6 +380,15 @@ Samplecountry
276380 } else Fox .successful(())
277381 }
278382
383+ private def insertDataset (): Fox [Unit ] = datasetDAO.findOne(defaultDataset._id).shiftBox.flatMap { maybeDataset =>
384+ if (maybeDataset.isEmpty) {
385+ for {
386+ _ <- datasetDAO.insertOne(defaultDataset)
387+ _ <- datasetLayerDAO.updateLayers(defaultDataset._id, defaultDataSource)
388+ } yield ()
389+ } else Fox .successful(())
390+ }
391+
279392 private def insertAiModel (): Fox [Unit ] = aiModelDAO.findAll.flatMap { aiModels =>
280393 if (aiModels.isEmpty) {
281394 aiModelDAO.insertOne(defaultAiModel)
0 commit comments