-
Notifications
You must be signed in to change notification settings - Fork 24
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
Add option to lock explorative annotations #7801
Changes from all commits
75ddb36
aec1293
d25b004
47b5b0c
0a48511
be6a02e
0a65e05
85d31ab
2007f5e
81a01c3
70935a4
51993d6
61fbf22
1980d35
730c6d3
d77d856
4b91dd3
5950da0
6e593ba
f3c4893
79cd978
95535b8
c20baf6
581099d
073f941
c05b825
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ import models.annotation.AnnotationType.AnnotationType | |
import play.api.libs.json._ | ||
import slick.jdbc.GetResult._ | ||
import slick.jdbc.PostgresProfile.api._ | ||
import slick.jdbc.GetResult | ||
import slick.jdbc.TransactionIsolation.Serializable | ||
import slick.lifted.Rep | ||
import slick.sql.SqlAction | ||
|
@@ -33,6 +34,7 @@ case class Annotation( | |
name: String = "", | ||
viewConfiguration: Option[JsObject] = None, | ||
state: AnnotationState.Value = Active, | ||
isLockedByOwner: Boolean = false, | ||
tags: Set[String] = Set.empty, | ||
tracingTime: Option[Long] = None, | ||
typ: AnnotationType.Value = AnnotationType.Explorational, | ||
|
@@ -84,6 +86,7 @@ case class AnnotationCompactInfo(id: ObjectId, | |
modified: Instant, | ||
tags: Set[String], | ||
state: AnnotationState.Value = Active, | ||
isLockedByOwner: Boolean, | ||
dataSetName: String, | ||
visibility: AnnotationVisibility.Value = AnnotationVisibility.Internal, | ||
tracingTime: Option[Long] = None, | ||
|
@@ -93,10 +96,6 @@ case class AnnotationCompactInfo(id: ObjectId, | |
annotationLayerTypes: Seq[String], | ||
annotationLayerStatistics: Seq[JsObject]) | ||
|
||
object AnnotationCompactInfo { | ||
implicit val jsonFormat: Format[AnnotationCompactInfo] = Json.format[AnnotationCompactInfo] | ||
} | ||
|
||
Comment on lines
-96
to
-99
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was not needed |
||
class AnnotationLayerDAO @Inject()(SQLClient: SqlClient)(implicit ec: ExecutionContext) | ||
extends SimpleSQLDAO(SQLClient) { | ||
|
||
|
@@ -218,6 +217,7 @@ class AnnotationDAO @Inject()(sqlClient: SqlClient, annotationLayerDAO: Annotati | |
r.name, | ||
viewconfigurationOpt, | ||
state, | ||
r.islockedbyowner, | ||
parseArrayLiteral(r.tags).toSet, | ||
r.tracingtime, | ||
typ, | ||
|
@@ -322,6 +322,43 @@ class AnnotationDAO @Inject()(sqlClient: SqlClient, annotationLayerDAO: Annotati | |
} yield parsed | ||
} | ||
|
||
// Necessary since a tuple can only have 22 elements | ||
implicit def GetResultAnnotationCompactInfo: GetResult[AnnotationCompactInfo] = GetResult { prs => | ||
import prs._ | ||
|
||
val id = <<[ObjectId] | ||
val name = <<[String] | ||
val description = <<[String] | ||
val ownerId = <<[ObjectId] | ||
val ownerFirstName = <<[String] | ||
val ownerLastName = <<[String] | ||
val othersMayEdit = <<[Boolean] | ||
val teamIds = parseArrayLiteral(<<[String]).map(ObjectId(_)) | ||
val teamNames = parseArrayLiteral(<<[String]) | ||
val teamOrganizationIds = parseArrayLiteral(<<[String]).map(ObjectId(_)) | ||
val modified = <<[Instant] | ||
val tags = parseArrayLiteral(<<[String]).toSet | ||
val state = AnnotationState.fromString(<<[String]).getOrElse(AnnotationState.Active) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While we’re here, could you try out if this and the other enums also work without the String detour, with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i tried bug failed 🙈: I changed to val state = <<[AnnotationState]
val isLockedByOwner = <<[Boolean]
val dataSetName = <<[String]
val typ = <<[AnnotationType]
val visibility = <<[AnnotationVisibility] But scala could not find the matching implicit def GetResultAnnotationCompactInfo(implicit
e0: GetResult[AnnotationState],
e1: GetResult[AnnotationType],
e2: GetResult[AnnotationVisibility]
): GetResult[AnnotationCompactInfo] = GetResult { prs => But then the call => I'd say no to the question / suggestion or we need to define the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, thanks for experimenting! Then let’s do this another time. Feel free to go via the string route as is :) |
||
val isLockedByOwner = <<[Boolean] | ||
val dataSetName = <<[String] | ||
val typ = AnnotationType.fromString(<<[String]).getOrElse(AnnotationType.Explorational) | ||
val visibility = AnnotationVisibility.fromString(<<[String]).getOrElse(AnnotationVisibility.Internal) | ||
val tracingTime = Option(<<[Long]) | ||
val organizationName = <<[String] | ||
val tracingIds = parseArrayLiteral(<<[String]) | ||
val annotationLayerNames = parseArrayLiteral(<<[String]) | ||
val annotationLayerTypes = parseArrayLiteral(<<[String]) | ||
val annotationLayerStatistics = | ||
parseArrayLiteral(<<[String]).map(layerStats => Json.parse(layerStats).validate[JsObject].getOrElse(Json.obj())) | ||
|
||
// format: off | ||
AnnotationCompactInfo(id, typ, name,description,ownerId,ownerFirstName,ownerLastName, othersMayEdit,teamIds, | ||
teamNames,teamOrganizationIds,modified,tags,state,isLockedByOwner,dataSetName,visibility,tracingTime, | ||
organizationName,tracingIds,annotationLayerNames,annotationLayerTypes,annotationLayerStatistics | ||
) | ||
// format: on | ||
} | ||
|
||
def findAllListableExplorationals( | ||
isFinished: Option[Boolean], | ||
forUser: Option[ObjectId], | ||
|
@@ -366,6 +403,7 @@ class AnnotationDAO @Inject()(sqlClient: SqlClient, annotationLayerDAO: Annotati | |
a.modified, | ||
a.tags, | ||
a.state, | ||
a.isLockedByOwner, | ||
d.name, | ||
a.typ, | ||
a.visibility, | ||
|
@@ -384,67 +422,15 @@ class AnnotationDAO @Inject()(sqlClient: SqlClient, annotationLayerDAO: Annotati | |
WHERE $stateQuery AND $accessQuery AND $userQuery AND $typQuery | ||
GROUP BY | ||
a._id, a.name, a.description, a._user, a.othersmayedit, a.modified, | ||
a.tags, a.state, a.typ, a.visibility, a.tracingtime, | ||
a.tags, a.state, a.islockedbyowner, a.typ, a.visibility, a.tracingtime, | ||
u.firstname, u.lastname, | ||
teams_agg.team_ids, teams_agg.team_names, teams_agg.team_organization_ids, | ||
d.name, o.name | ||
ORDER BY a._id DESC | ||
LIMIT $limit | ||
OFFSET ${pageNumber * limit}""" | ||
rows <- run( | ||
query.as[ | ||
(ObjectId, | ||
String, | ||
String, | ||
ObjectId, | ||
String, | ||
String, | ||
Boolean, | ||
String, | ||
String, | ||
String, | ||
Instant, | ||
String, | ||
String, | ||
String, | ||
String, | ||
String, | ||
Long, | ||
String, | ||
String, | ||
String, | ||
String, | ||
String)]) | ||
} yield | ||
rows.toList.map( | ||
r => { | ||
AnnotationCompactInfo( | ||
id = r._1, | ||
name = r._2, | ||
description = r._3, | ||
ownerId = r._4, | ||
ownerFirstName = r._5, | ||
ownerLastName = r._6, | ||
othersMayEdit = r._7, | ||
teamIds = parseArrayLiteral(r._8).map(ObjectId(_)), | ||
teamNames = parseArrayLiteral(r._9), | ||
teamOrganizationIds = parseArrayLiteral(r._10).map(ObjectId(_)), | ||
modified = r._11, | ||
tags = parseArrayLiteral(r._12).toSet, | ||
state = AnnotationState.fromString(r._13).getOrElse(AnnotationState.Active), | ||
dataSetName = r._14, | ||
typ = AnnotationType.fromString(r._15).getOrElse(AnnotationType.Explorational), | ||
visibility = AnnotationVisibility.fromString(r._16).getOrElse(AnnotationVisibility.Internal), | ||
tracingTime = Option(r._17), | ||
organizationName = r._18, | ||
tracingIds = parseArrayLiteral(r._19), | ||
annotationLayerNames = parseArrayLiteral(r._20), | ||
annotationLayerTypes = parseArrayLiteral(r._21), | ||
annotationLayerStatistics = parseArrayLiteral(r._22).map(layerStats => | ||
Json.parse(layerStats).validate[JsObject].getOrElse(Json.obj())) | ||
) | ||
} | ||
) | ||
rows <- run(query.as[AnnotationCompactInfo]) | ||
} yield rows.toList | ||
|
||
def countAllListableExplorationals(isFinished: Option[Boolean])(implicit ctx: DBAccessContext): Fox[Long] = { | ||
val stateQuery = getStateQuery(isFinished) | ||
|
@@ -692,6 +678,18 @@ class AnnotationDAO @Inject()(sqlClient: SqlClient, annotationLayerDAO: Annotati | |
_ = logger.info(s"Updated state of Annotation $id to $state, access context: ${ctx.toStringAnonymous}") | ||
} yield () | ||
|
||
def updateLockedState(id: ObjectId, isLocked: Boolean)(implicit ctx: DBAccessContext): Fox[Unit] = | ||
for { | ||
_ <- assertUpdateAccess(id) ?~> "FAILED: AnnotationSQLDAO.assertUpdateAccess" | ||
query = q"UPDATE webknossos.annotations SET isLockedByOwner = $isLocked WHERE _id = $id".asUpdate | ||
_ <- run( | ||
query.withTransactionIsolation(Serializable), | ||
retryCount = 50, | ||
retryIfErrorContains = List(transactionSerializationError)) ?~> "FAILED: run in AnnotationSQLDAO.updateState" | ||
_ = logger.info( | ||
s"Updated isLockedByOwner of Annotation $id to $isLocked, access context: ${ctx.toStringAnonymous}") | ||
} yield () | ||
|
||
def updateDescription(id: ObjectId, description: String)(implicit ctx: DBAccessContext): Fox[Unit] = | ||
for { | ||
_ <- assertUpdateAccess(id) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
START TRANSACTION; | ||
|
||
do $$ begin ASSERT (select schemaVersion from webknossos.releaseInformation) = 114, 'Previous schema version mismatch'; end; $$ LANGUAGE plpgsql; | ||
|
||
DROP VIEW webknossos.annotations_; | ||
ALTER TABLE webknossos.annotations ADD isLockedByOwner BOOLEAN NOT NULL DEFAULT FALSE; | ||
CREATE VIEW webknossos.annotations_ as SELECT * FROM webknossos.annotations WHERE NOT isDeleted; | ||
|
||
UPDATE webknossos.releaseInformation SET schemaVersion = 115; | ||
|
||
COMMIT TRANSACTION; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
START TRANSACTION; | ||
|
||
do $$ begin ASSERT (select schemaVersion from webknossos.releaseInformation) = 115, 'Previous schema version mismatch'; end; $$ LANGUAGE plpgsql; | ||
|
||
DROP VIEW webknossos.annotations_; | ||
ALTER TABLE webknossos.annotations DROP COLUMN isLockedByOwner; | ||
CREATE VIEW webknossos.annotations_ as SELECT * FROM webknossos.annotations WHERE NOT isDeleted; | ||
|
||
UPDATE webknossos.releaseInformation SET schemaVersion = 114; | ||
|
||
COMMIT TRANSACTION; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was unused