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

Make mappings field in datasource optional #4532

Merged
merged 4 commits into from
Apr 9, 2020
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.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.md).
- Users can now input floating point numbers into the rotation field in flight and oblique mode. These values will get rounded internally. [#4507](https://github.com/scalableminds/webknossos/pull/4507)
- Deleting an empty tree group in the `Trees` tab no longer prompts for user confirmation. [#4506](https://github.com/scalableminds/webknossos/pull/4506)
- Toggling the "Render missing data black" option now automatically reloads all layers making it unnecessary to reload the whole page. [#4516](https://github.com/scalableminds/webknossos/pull/4516)
- The "mappings" attribute of segmentation layers in datasource jsons can now be omitted. [#4532](https://github.com/scalableminds/webknossos/pull/4532)

### Fixed
- Users only get tasks of datasets that they can access. [#4488](https://github.com/scalableminds/webknossos/pull/4488)
Expand Down
6 changes: 4 additions & 2 deletions app/models/binary/DataSet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ class DataSetDataLayerDAO @Inject()(sqlClient: SQLClient, dataSetResolutionsDAO:
} yield {
(row.largestsegmentid, row.mappings) match {
case (Some(segmentId), Some(mappings)) =>
val mappingsAsSet = parseArrayTuple(mappings).toSet
Fox.successful(
AbstractSegmentationLayer(
row.name,
Expand All @@ -377,7 +378,7 @@ class DataSetDataLayerDAO @Inject()(sqlClient: SQLClient, dataSetResolutionsDAO:
resolutions.sortBy(_.maxDim),
elementClass,
segmentId,
parseArrayTuple(mappings).toSet,
if (mappingsAsSet.isEmpty) None else Some(mappingsAsSet),
defaultViewConfigurationOpt.map(SegmentationLayerViewConfiguration.from)
))
case (None, None) =>
Expand Down Expand Up @@ -419,10 +420,11 @@ class DataSetDataLayerDAO @Inject()(sqlClient: SQLClient, dataSetResolutionsDAO:
def insertLayerQuery(_dataSet: ObjectId, layer: DataLayer) =
layer match {
case s: AbstractSegmentationLayer => {
val mappings = s.mappings.getOrElse(Set())
sqlu"""insert into webknossos.dataset_layers(_dataSet, name, category, elementClass, boundingBox, largestSegmentId, mappings, defaultViewConfiguration)
values(${_dataSet.id}, ${s.name}, '#${s.category.toString}', '#${s.elementClass.toString}',
'#${writeStructTuple(s.boundingBox.toSql.map(_.toString))}', ${s.largestSegmentId}, '#${writeArrayTuple(
s.mappings.map(sanitize(_)).toList)}', #${optionLiteral(
mappings.map(sanitize(_)).toList)}', #${optionLiteral(
s.defaultViewConfiguration.map(d => Json.toJson(d).toString))})"""
}
case d: AbstractDataLayer => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/javascripts/libs/datasource.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
"largestSegmentId": { "type": "number", "minimum": 1 },
"mappings": { "type": "array", "items": { "type": "string" } }
},
"required": ["category", "largestSegmentId", "mappings"]
"required": ["category", "largestSegmentId"]
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ Generated by [AVA](https://ava.li).
category: 'segmentation',
elementClass: 'uint16',
largestSegmentId: 10000,
mappings: [],
name: 'segmentation',
resolutions: [],
},
Expand Down Expand Up @@ -495,7 +494,6 @@ Generated by [AVA](https://ava.li).
category: 'segmentation',
elementClass: 'uint16',
largestSegmentId: 10000,
mappings: [],
name: 'segmentation',
resolutions: [],
},
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ object MappingProvider {

val mappingFileExtension = "json"

def exploreMappings(layerDir: Path): Set[String] =
PathUtils
def exploreMappings(layerDir: Path): Option[Set[String]] = {
val mappingSet = PathUtils
.listFiles(layerDir.resolve(MappingProvider.mappingsDir),
PathUtils.fileExtensionFilter(MappingProvider.mappingFileExtension))
.map { paths =>
paths.map(path => FilenameUtils.removeExtension(path.getFileName.toString))
}
.getOrElse(Nil)
.toSet
if (mappingSet.isEmpty) None else Some(mappingSet)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ case class KnossosSegmentationLayer(
name: String,
sections: List[KnossosSection],
elementClass: ElementClass.Value,
mappings: Set[String],
mappings: Option[Set[String]],
largestSegmentId: Long,
defaultViewConfiguration: Option[SegmentationLayerViewConfiguration] = None
) extends SegmentationLayer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ case class WKWSegmentationLayer(
boundingBox: BoundingBox,
wkwResolutions: List[WKWResolution],
elementClass: ElementClass.Value,
mappings: Set[String],
mappings: Option[Set[String]],
largestSegmentId: Long,
defaultViewConfiguration: Option[SegmentationLayerViewConfiguration] = None
) extends SegmentationLayer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ trait SegmentationLayerLike extends DataLayerLike {

def largestSegmentId: Long

def mappings: Set[String]
def mappings: Option[Set[String]]

def defaultViewConfiguration: Option[SegmentationLayerViewConfiguration]
}
Expand Down Expand Up @@ -261,7 +261,7 @@ case class AbstractSegmentationLayer(
resolutions: List[Point3D],
elementClass: ElementClass.Value,
largestSegmentId: Long,
mappings: Set[String],
mappings: Option[Set[String]],
defaultViewConfiguration: Option[SegmentationLayerViewConfiguration] = None
) extends SegmentationLayerLike

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,6 @@ trait DataSourceImporter {
case Right(point) => point.maxDim
}

protected def exploreMappings(baseDir: Path): Set[String] = MappingProvider.exploreMappings(baseDir)
protected def exploreMappings(baseDir: Path): Option[Set[String]] = MappingProvider.exploreMappings(baseDir)

}
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ class DataSourceService @Inject()(
}

def exploreMappings(organizationName: String, dataSetName: String, dataLayerName: String): Set[String] =
MappingProvider.exploreMappings(dataBaseDir.resolve(organizationName).resolve(dataSetName).resolve(dataLayerName))
MappingProvider
.exploreMappings(dataBaseDir.resolve(organizationName).resolve(dataSetName).resolve(dataLayerName))
.getOrElse(Set())

private def validateDataSource(dataSource: DataSource): Box[Unit] = {
def Check(expression: Boolean, msg: String): Option[String] = if (!expression) Some(msg) else None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class FallbackLayerAdapter(primary: SegmentationLayer, fallback: SegmentationLay

val largestSegmentId: Long = math.max(primary.largestSegmentId, fallback.largestSegmentId)

val mappings: Set[String] = primary.mappings
val mappings: Option[Set[String]] = primary.mappings

lazy val bucketProvider: BucketProvider = new FallbackBucketProvider(primary, fallback)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ case class VolumeTracingLayer(

val bucketProvider: BucketProvider = volumeBucketProvider

val mappings: Set[String] = Set.empty
val mappings: Option[Set[String]] = None

val resolutions: List[Point3D] = List(Point3D(1, 1, 1))
}