Skip to content

Commit

Permalink
Add recommended configuration to TaskTypes (backend only) (#3415)
Browse files Browse the repository at this point in the history
* add recommended configuration to tasktype schema

* add recommendedConfiguration field to TaskType api

* update migrations.md

* new snapshots
  • Loading branch information
fm3 authored Nov 1, 2018
1 parent e352545 commit 57a21ba
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 9 deletions.
2 changes: 2 additions & 0 deletions MIGRATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ User-facing changes are documented in the [changelog](CHANGELOG.md).

## Unreleased
-
### Postgres Evolutions:
- [033-tasktype-recommendedConfiguration.sql](033-tasktype-recommendedConfiguration.sql)


## [18.11.0](https://github.com/scalableminds/webknossos/releases/tag/18.11.0) - 2018-10-29
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,7 @@ Generated by [AVA](https://ava.li).
type: {
description: 'Check those cells out!',
id: '570b9f4c2a7c0e4c008da6ff',
recommendedConfiguration: null,
settings: {
allowedModes: [
'orthogonal',
Expand Down Expand Up @@ -1236,6 +1237,7 @@ Generated by [AVA](https://ava.li).
type: {
description: 'Check those cells out!',
id: '570b9f4c2a7c0e4c008da6ee',
recommendedConfiguration: null,
settings: {
allowedModes: [
'orthogonal',
Expand Down Expand Up @@ -1362,6 +1364,7 @@ Generated by [AVA](https://ava.li).
type: {
description: 'Check those cells out!',
id: '570b9f4c2a7c0e4c008da6ff',
recommendedConfiguration: null,
settings: {
allowedModes: [
'orthogonal',
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Generated by [AVA](https://ava.li).
type: {
description: 'Check those cells out!',
id: 'id',
recommendedConfiguration: null,
settings: {
allowedModes: [
'orthogonal',
Expand Down Expand Up @@ -130,6 +131,7 @@ Generated by [AVA](https://ava.li).
type: {
description: 'Check those cells out!',
id: 'id',
recommendedConfiguration: null,
settings: {
allowedModes: [
'orthogonal',
Expand Down Expand Up @@ -252,6 +254,7 @@ Generated by [AVA](https://ava.li).
type: {
description: 'Check those cells out!',
id: '570b9f4c2a7c0e4c008da6ee',
recommendedConfiguration: null,
settings: {
allowedModes: [
'orthogonal',
Expand Down Expand Up @@ -339,6 +342,7 @@ Generated by [AVA](https://ava.li).
type: {
description: 'Check those cells out!',
id: '570b9f4c2a7c0e4c008da6ee',
recommendedConfiguration: null,
settings: {
allowedModes: [
'orthogonal',
Expand Down Expand Up @@ -391,6 +395,7 @@ Generated by [AVA](https://ava.li).
type: {
description: 'Check those cells out!',
id: '570b9f4c2a7c0e4c008da6ee',
recommendedConfiguration: null,
settings: {
allowedModes: [
'orthogonal',
Expand Down Expand Up @@ -439,6 +444,7 @@ Generated by [AVA](https://ava.li).
type: {
description: 'Check those cells out!',
id: '570b9f4c2a7c0e4c008da6ee',
recommendedConfiguration: null,
settings: {
allowedModes: [
'orthogonal',
Expand Down Expand Up @@ -487,6 +493,7 @@ Generated by [AVA](https://ava.li).
type: {
description: 'Check those cells out!',
id: '570b9f4c2a7c0e4c008da6ff',
recommendedConfiguration: null,
settings: {
allowedModes: [
'orthogonal',
Expand Down Expand Up @@ -540,6 +547,7 @@ Generated by [AVA](https://ava.li).
type: {
description: 'Check those cells out!',
id: '570b9f4c2a7c0e4c008da6ee',
recommendedConfiguration: null,
settings: {
allowedModes: [
'orthogonal',
Expand Down Expand Up @@ -588,6 +596,7 @@ Generated by [AVA](https://ava.li).
type: {
description: 'Check those cells out!',
id: '570b9f4c2a7c0e4c008da6ee',
recommendedConfiguration: null,
settings: {
allowedModes: [
'orthogonal',
Expand Down Expand Up @@ -639,6 +648,7 @@ Generated by [AVA](https://ava.li).
type: {
description: 'Check those cells out!',
id: '570b9f4c2a7c0e4c008da6ee',
recommendedConfiguration: null,
settings: {
allowedModes: [
'orthogonal',
Expand Down Expand Up @@ -695,6 +705,7 @@ Generated by [AVA](https://ava.li).
type: {
description: 'Check those cells out!',
id: '570b9f4c2a7c0e4c008da6ee',
recommendedConfiguration: null,
settings: {
allowedModes: [
'orthogonal',
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Generated by [AVA](https://ava.li).
{
description: 'description',
id: 'fixed-id',
recommendedConfiguration: null,
settings: {
allowedModes: [
'orthogonal',
Expand Down Expand Up @@ -36,6 +37,7 @@ Generated by [AVA](https://ava.li).
{
description: 'Check those cells out!',
id: '570b9f4c2a7c0e4c008da6ee',
recommendedConfiguration: null,
settings: {
allowedModes: [
'orthogonal',
Expand All @@ -56,6 +58,7 @@ Generated by [AVA](https://ava.li).
{
description: 'Check those cells out!',
id: '570b9f4c2a7c0e4c008da6ee',
recommendedConfiguration: null,
settings: {
allowedModes: [
'orthogonal',
Expand All @@ -72,6 +75,7 @@ Generated by [AVA](https://ava.li).
{
description: 'Check those cells out!',
id: '570b9f4c2a7c0e4c008da6ff',
recommendedConfiguration: null,
settings: {
allowedModes: [
'orthogonal',
Expand All @@ -97,6 +101,7 @@ Generated by [AVA](https://ava.li).
success: 'Task type successfully edited',
},
],
recommendedConfiguration: null,
settings: {
allowedModes: [
'orthogonal',
Expand All @@ -121,6 +126,7 @@ Generated by [AVA](https://ava.li).
success: 'Task type successfully edited',
},
],
recommendedConfiguration: null,
settings: {
allowedModes: [
'orthogonal',
Expand Down
Binary file not shown.
3 changes: 2 additions & 1 deletion app/controllers/TaskTypeController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class TaskTypeController @Inject()(taskTypeDAO: TaskTypeDAO,
((__ \ 'summary).read[String](minLength[String](2) or maxLength[String](50)) and
(__ \ 'description).read[String] and
(__ \ 'teamId).read[String] (ObjectId.stringObjectIdReads("teamId")) and
(__ \ 'settings).read[AnnotationSettings]) (taskTypeService.fromForm _)
(__ \ 'settings).read[AnnotationSettings] and
(__ \ 'recommendedConfiguration).readNullable[JsValue]) (taskTypeService.fromForm _)

def create = sil.SecuredAction.async(parse.json) { implicit request =>
withJsonBodyUsing(taskTypePublicReads) { taskType =>
Expand Down
19 changes: 14 additions & 5 deletions app/models/task/TaskType.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import models.annotation.AnnotationSettings
import models.team.TeamDAO
import play.api.libs.json._
import slick.jdbc.PostgresProfile.api._
import play.api.libs.json._
import slick.lifted.Rep
import utils.{ObjectId, SQLClient, SQLDAO}

Expand All @@ -20,6 +21,7 @@ case class TaskType(
summary: String,
description: String,
settings: AnnotationSettings = AnnotationSettings.defaultFor(TracingType.skeleton),
recommendedConfiguration: Option[JsValue] = None,
created: Long = System.currentTimeMillis(),
isDeleted: Boolean = false
) extends FoxImplicits {
Expand All @@ -32,13 +34,16 @@ class TaskTypeService @Inject()(teamDAO: TeamDAO)(implicit ec: ExecutionContext)
summary: String,
description: String,
team: String,
settings: AnnotationSettings) = {
settings: AnnotationSettings,
recommendedConfiguration: Option[JsValue]
) = {
TaskType(
ObjectId.generate,
ObjectId(team),
summary,
description,
settings)
settings,
recommendedConfiguration)
}

def publicWrites(taskType: TaskType)(implicit ctx: DBAccessContext) = {
Expand All @@ -50,7 +55,8 @@ class TaskTypeService @Inject()(teamDAO: TeamDAO)(implicit ec: ExecutionContext)
"description" -> taskType.description,
"teamId" -> team._id.toString,
"teamName" -> team.name,
"settings" -> Json.toJson(taskType.settings)
"settings" -> Json.toJson(taskType.settings),
"recommendedConfiguration" -> taskType.recommendedConfiguration
)
}
}
Expand All @@ -73,6 +79,7 @@ class TaskTypeDAO @Inject()(sqlClient: SQLClient)(implicit ec: ExecutionContext)
r.settingsBranchpointsallowed,
r.settingsSomaclickingallowed
),
r.recommendedconfiguration.map(Json.parse),
r.created.getTime,
r.isdeleted
))
Expand Down Expand Up @@ -107,9 +114,10 @@ class TaskTypeDAO @Inject()(sqlClient: SQLClient)(implicit ec: ExecutionContext)
val allowedModes = writeArrayTuple(t.settings.allowedModes)
for {
_ <- run(sqlu"""insert into webknossos.taskTypes(_id, _team, summary, description, settings_allowedModes, settings_preferredMode,
settings_branchPointsAllowed, settings_somaClickingAllowed, created, isDeleted)
settings_branchPointsAllowed, settings_somaClickingAllowed, recommendedConfiguration, created, isDeleted)
values(${t._id.id}, ${t._team.id}, ${t.summary}, ${t.description}, '#${sanitize(writeArrayTuple(t.settings.allowedModes))}', #${optionLiteral(t.settings.preferredMode.map(sanitize(_)))},
${t.settings.branchPointsAllowed}, ${t.settings.somaClickingAllowed}, ${new java.sql.Timestamp(t.created)}, ${t.isDeleted})""")
${t.settings.branchPointsAllowed}, ${t.settings.somaClickingAllowed}, #${optionLiteral(t.recommendedConfiguration.map(c => sanitize(Json.toJson(c).toString)))},
${new java.sql.Timestamp(t.created)}, ${t.isDeleted})""")
} yield ()
}

Expand All @@ -126,6 +134,7 @@ class TaskTypeDAO @Inject()(sqlClient: SQLClient)(implicit ec: ExecutionContext)
settings_preferredMode = #${optionLiteral(t.settings.preferredMode.map(sanitize(_)))},
settings_branchPointsAllowed = ${t.settings.branchPointsAllowed},
settings_somaClickingAllowed = ${t.settings.somaClickingAllowed},
recommendedConfiguration = #${optionLiteral(t.recommendedConfiguration.map(c => sanitize(Json.toJson(c).toString)))},
isDeleted = ${t.isDeleted}
where _id = ${t._id.id}""")
} yield ()
Expand Down
13 changes: 13 additions & 0 deletions conf/evolutions/033-tasktype-recommendedConfiguration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- https://github.com/scalableminds/webknossos/pull/TODO

START TRANSACTION;

DROP VIEW webknossos.taskTypes_;
ALTER TABLE webknossos.taskTypes ADD COLUMN recommendedConfiguration JSONB;


CREATE VIEW webknossos.taskTypes_ AS SELECT * FROM webknossos.taskTypes WHERE NOT isDeleted;

UPDATE webknossos.releaseInformation SET schemaVersion = 33;

COMMIT TRANSACTION;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
START TRANSACTION;

DROP VIEW webknossos.taskTypes_;
ALTER TABLE webknossos.taskTypes DROP COLUMN recommendedConfiguration JSONB;


CREATE VIEW webknossos.taskTypes_ AS SELECT * FROM webknossos.taskTypes WHERE NOT isDeleted;

UPDATE webknossos.releaseInformation SET schemaVersion = 32;

COMMIT TRANSACTION;
4 changes: 2 additions & 2 deletions test/db/taskTypes.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
_id,_team,summary,description,settings_allowedModes,settings_preferredMode,settings_branchPointsAllowed,settings_somaClickingAllowed,created,isDeleted
'570b9f4c2a7c0e4c008da6ee','570b9f4b2a7c0e3b008da6ec','ek_0563_BipolarCells','Check those cells out!','{orthogonal,oblique,flight}',,t,t,'2016-04-11T12:57:48.000Z',f
'570b9f4c2a7c0e4c008da6ff','69882b370d889b84020efd4f','ek_0674_BipolarCells','Check those cells out!','{orthogonal,oblique,flight}',,t,t,'2016-04-11T12:57:48.000Z',f
'570b9f4c2a7c0e4c008da6ee','570b9f4b2a7c0e3b008da6ec','ek_0563_BipolarCells','Check those cells out!','{orthogonal,oblique,flight}',,t,t,,'2016-04-11T12:57:48.000Z',f
'570b9f4c2a7c0e4c008da6ff','69882b370d889b84020efd4f','ek_0674_BipolarCells','Check those cells out!','{orthogonal,oblique,flight}',,t,t,,'2016-04-11T12:57:48.000Z',f
3 changes: 2 additions & 1 deletion tools/postgres/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ START TRANSACTION;
CREATE TABLE webknossos.releaseInformation (
schemaVersion BIGINT NOT NULL
);
INSERT INTO webknossos.releaseInformation(schemaVersion) values(32);
INSERT INTO webknossos.releaseInformation(schemaVersion) values(33);
COMMIT TRANSACTION;

CREATE TABLE webknossos.analytics(
Expand Down Expand Up @@ -160,6 +160,7 @@ CREATE TABLE webknossos.taskTypes(
settings_preferredMode webknossos.TASKTYPE_MODES DEFAULT 'orthogonal',
settings_branchPointsAllowed BOOLEAN NOT NULL,
settings_somaClickingAllowed BOOLEAN NOT NULL,
recommendedConfiguration JSONB,
created TIMESTAMPTZ NOT NULL DEFAULT NOW(),
isDeleted BOOLEAN NOT NULL DEFAULT false
);
Expand Down

0 comments on commit 57a21ba

Please sign in to comment.