Skip to content

Commit

Permalink
rename AnnotationSQL to Annotation. etc. (#2979)
Browse files Browse the repository at this point in the history
  • Loading branch information
fm3 authored Jul 30, 2018
1 parent 31ad990 commit 3b71b12
Show file tree
Hide file tree
Showing 66 changed files with 717 additions and 721 deletions.
4 changes: 2 additions & 2 deletions app/Global.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.scalableminds.util.accesscontext.GlobalAccessContext
import com.typesafe.config.Config
import com.typesafe.scalalogging.LazyLogging
import controllers.InitialDataService
import models.annotation.AnnotationSQLDAO
import models.annotation.AnnotationDAO
import net.liftweb.common.{Failure, Full}
import oxalis.cleanup.CleanUpService
import oxalis.security.WebknossosSilhouette
Expand Down Expand Up @@ -45,7 +45,7 @@ object Global extends GlobalSettings with LazyLogging{
}

CleanUpService.register("deletion of old annotations in initializing state", 1 day) {
AnnotationSQLDAO.deleteOldInitializingAnnotations
AnnotationDAO.deleteOldInitializingAnnotations
}

super.onStart(app)
Expand Down
28 changes: 14 additions & 14 deletions app/controllers/AnnotationController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import com.scalableminds.util.accesscontext.{DBAccessContext, GlobalAccessContex
import com.scalableminds.util.tools.{Fox, FoxImplicits}
import com.scalableminds.webknossos.datastore.tracings.TracingType
import models.annotation._
import models.binary.{DataSetSQL, DataSetSQLDAO}
import models.task.TaskSQLDAO
import models.binary.{DataSet, DataSetDAO}
import models.task.TaskDAO
import models.user.time._
import models.user.{UserSQL, UserSQLDAO}
import models.user.{User, UserDAO}
import oxalis.security.WebknossosSilhouette.{SecuredAction, SecuredRequest, UserAwareAction}
import play.api.i18n.{Messages, MessagesApi}
import play.api.libs.json.{JsArray, _}
Expand Down Expand Up @@ -59,7 +59,7 @@ class AnnotationController @Inject()(val messagesApi: MessagesApi)
mergedAnnotation <- AnnotationMerger.mergeTwoByIds(identifierA, identifierB, true)
restrictions = AnnotationRestrictions.defaultAnnotationRestrictions(mergedAnnotation)
_ <- restrictions.allowAccess(request.identity) ?~> Messages("notAllowed") ~> BAD_REQUEST
_ <- AnnotationSQLDAO.insertOne(mergedAnnotation)
_ <- AnnotationDAO.insertOne(mergedAnnotation)
js <- mergedAnnotation.publicWrites(Some(request.identity), Some(restrictions))
} yield {
JsonOk(js, Messages("annotation.merge.success"))
Expand All @@ -72,7 +72,7 @@ class AnnotationController @Inject()(val messagesApi: MessagesApi)
annotation <- provideAnnotation(typ, id)(securedRequestToUserAwareRequest)
restrictions <- restrictionsFor(typ, id)(securedRequestToUserAwareRequest)
_ <- restrictions.allowAccess(request.identity) ?~> Messages("notAllowed") ~> BAD_REQUEST
loggedTimeAsMap <- TimeSpanService.loggedTimeOfAnnotation(annotation._id, TimeSpanSQL.groupByMonth)
loggedTimeAsMap <- TimeSpanService.loggedTimeOfAnnotation(annotation._id, TimeSpan.groupByMonth)
} yield {
Ok(Json.arr(
loggedTimeAsMap.map {
Expand All @@ -92,7 +92,7 @@ class AnnotationController @Inject()(val messagesApi: MessagesApi)
dataSet <- annotation.dataSet
dataStoreHandler <- dataSet.dataStoreHandler
newTracingReference <- dataStoreHandler.duplicateSkeletonTracing(annotation.tracing, Some(version.toString))
_ <- AnnotationSQLDAO.updateTracingReference(annotation._id, newTracingReference)
_ <- AnnotationDAO.updateTracingReference(annotation._id, newTracingReference)
} yield {
logger.info(s"REVERTED [$typ - $id, $version]")
JsonOk("annotation.reverted")
Expand All @@ -112,7 +112,7 @@ class AnnotationController @Inject()(val messagesApi: MessagesApi)
}

def reopen(typ: String, id: String) = SecuredAction.async { implicit request =>
def isReopenAllowed(user: UserSQL, annotation: AnnotationSQL) = for {
def isReopenAllowed(user: User, annotation: Annotation) = for {
isAdminOrTeamManager <- user.isTeamManagerOrAdminOf(annotation._team)
} yield (annotation._user == user._id || isAdminOrTeamManager)

Expand All @@ -135,7 +135,7 @@ class AnnotationController @Inject()(val messagesApi: MessagesApi)
def createExplorational(dataSetName: String) =
SecuredAction.async(validateJson[CreateExplorationalParameters]) { implicit request =>
for {
dataSetSQL <- DataSetSQLDAO.findOneByName(dataSetName) ?~> Messages("dataSet.notFound", dataSetName)
dataSetSQL <- DataSetDAO.findOneByName(dataSetName) ?~> Messages("dataSet.notFound", dataSetName)
tracingType <- TracingType.values.find(_.toString == request.body.typ).toFox
annotation <- AnnotationService.createExplorationalFor(request.identity, dataSetSQL._id, tracingType, request.body.withFallback.getOrElse(true)) ?~> Messages("annotation.create.failed")
json <- annotation.publicWrites(Some(request.identity))
Expand All @@ -144,7 +144,7 @@ class AnnotationController @Inject()(val messagesApi: MessagesApi)
}
}

private def finishAnnotation(typ: String, id: String, user: UserSQL)(implicit request: SecuredRequest[_]): Fox[(AnnotationSQL, String)] = {
private def finishAnnotation(typ: String, id: String, user: User)(implicit request: SecuredRequest[_]): Fox[(Annotation, String)] = {
for {
annotation <- provideAnnotation(typ, id)(securedRequestToUserAwareRequest)
restrictions <- restrictionsFor(typ, id)(securedRequestToUserAwareRequest)
Expand Down Expand Up @@ -194,7 +194,7 @@ class AnnotationController @Inject()(val messagesApi: MessagesApi)
def annotationsForTask(taskId: String) = SecuredAction.async { implicit request =>
for {
taskIdValidated <- ObjectId.parse(taskId)
task <- TaskSQLDAO.findOne(taskIdValidated) ?~> Messages("task.notFound")
task <- TaskDAO.findOne(taskIdValidated) ?~> Messages("task.notFound")
project <- task.project
_ <- ensureTeamAdministration(request.identity, project._team)
annotations <- task.annotations
Expand All @@ -206,7 +206,7 @@ class AnnotationController @Inject()(val messagesApi: MessagesApi)


def cancel(typ: String, id: String) = SecuredAction.async { implicit request =>
def tryToCancel(annotation: AnnotationSQL) = {
def tryToCancel(annotation: Annotation) = {
annotation match {
case t if t.typ == AnnotationTypeSQL.Task =>
annotation.muta.cancel.map { _ =>
Expand All @@ -231,7 +231,7 @@ class AnnotationController @Inject()(val messagesApi: MessagesApi)
_ <- restrictions.allowFinish(request.identity) ?~> Messages("notAllowed")
newUserId <- (request.body \ "userId").asOpt[String].toFox
newUserIdValidated <- ObjectId.parse(newUserId)
newUser <- UserSQLDAO.findOne(newUserIdValidated) ?~> Messages("user.notFound")
newUser <- UserDAO.findOne(newUserIdValidated) ?~> Messages("user.notFound")
_ <- annotation.muta.transferToUser(newUser)
updated <- provideAnnotation(typ, id)(securedRequestToUserAwareRequest)
json <- updated.publicWrites(Some(request.identity), Some(restrictions))
Expand All @@ -251,9 +251,9 @@ class AnnotationController @Inject()(val messagesApi: MessagesApi)
}
}

private def duplicateAnnotation(annotation: AnnotationSQL, user: UserSQL)(implicit ctx: DBAccessContext): Fox[AnnotationSQL] = {
private def duplicateAnnotation(annotation: Annotation, user: User)(implicit ctx: DBAccessContext): Fox[Annotation] = {
for {
dataSet: DataSetSQL <- annotation.dataSet
dataSet: DataSet <- annotation.dataSet
oldTracingReference = annotation.tracing
_ <- bool2Fox(dataSet.isUsable) ?~> "DataSet is not imported."
dataStoreHandler <- dataSet.dataStoreHandler
Expand Down
38 changes: 19 additions & 19 deletions app/controllers/AnnotationIOController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import com.typesafe.scalalogging.LazyLogging
import models.annotation.AnnotationState._
import models.annotation.nml.{NmlService, NmlWriter}
import models.annotation._
import models.binary.{DataSetSQL, DataSetSQLDAO}
import models.project.ProjectSQLDAO
import models.binary.{DataSet, DataSetDAO}
import models.project.ProjectDAO
import models.task._
import models.user._
import oxalis.security.WebknossosSilhouette.{SecuredAction, UserAwareRequest}
Expand Down Expand Up @@ -56,7 +56,7 @@ class AnnotationIOController @Inject()(val messagesApi: MessagesApi)
}
}

def storeMergedSkeletonTracing(tracings: List[SkeletonTracing], dataSet: DataSetSQL): Fox[TracingReference] = {
def storeMergedSkeletonTracing(tracings: List[SkeletonTracing], dataSet: DataSet): Fox[TracingReference] = {
for {
dataStoreHandler <- dataSet.dataStoreHandler
newTracingReference <- dataStoreHandler.mergeSkeletonTracingsByContents(SkeletonTracings(tracings), persistTracing=true)
Expand All @@ -80,7 +80,7 @@ class AnnotationIOController @Inject()(val messagesApi: MessagesApi)
val description = descriptionForNMLs(parseSuccess.map(_.description))
if (volumeTracings.nonEmpty) {
for {
dataSet <- DataSetSQLDAO.findOneByName(volumeTracings.head._1.dataSetName).toFox ?~> Messages("dataSet.notFound", volumeTracings.head._1.dataSetName)
dataSet <- DataSetDAO.findOneByName(volumeTracings.head._1.dataSetName).toFox ?~> Messages("dataSet.notFound", volumeTracings.head._1.dataSetName)
dataStoreHandler <- dataSet.dataStoreHandler
tracingReference <- dataStoreHandler.saveVolumeTracing(volumeTracings.head._1, parsedFiles.otherFiles.get(volumeTracings.head._2).map(_.file))
annotation <- AnnotationService.createFrom(
Expand All @@ -91,7 +91,7 @@ class AnnotationIOController @Inject()(val messagesApi: MessagesApi)
)
} else if (skeletonTracings.nonEmpty) {
for {
dataSet <- DataSetSQLDAO.findOneByName(skeletonTracings.head.dataSetName).toFox ?~> Messages("dataSet.notFound", skeletonTracings.head.dataSetName)
dataSet <- DataSetDAO.findOneByName(skeletonTracings.head.dataSetName).toFox ?~> Messages("dataSet.notFound", skeletonTracings.head.dataSetName)
mergedTracingReference <- storeMergedSkeletonTracing(skeletonTracings, dataSet)
annotation <- AnnotationService.createFrom(
request.identity, dataSet, mergedTracingReference, AnnotationTypeSQL.Explorational, name, description)
Expand Down Expand Up @@ -121,9 +121,9 @@ class AnnotationIOController @Inject()(val messagesApi: MessagesApi)
} yield result
}

def downloadExplorational(annotationId: String, typ: String, user: UserSQL)(implicit request: UserAwareRequest[_]) = {
def downloadExplorational(annotationId: String, typ: String, user: User)(implicit request: UserAwareRequest[_]) = {

def skeletonToDownloadStream(dataSet: DataSetSQL, annotation: AnnotationSQL, name: String) = {
def skeletonToDownloadStream(dataSet: DataSet, annotation: Annotation, name: String) = {
for {
dataStoreHandler <- dataSet.dataStoreHandler
tracing <- dataStoreHandler.getSkeletonTracing(annotation.tracing)
Expand All @@ -132,7 +132,7 @@ class AnnotationIOController @Inject()(val messagesApi: MessagesApi)
}
}

def volumeToDownloadStream(dataSet: DataSetSQL, annotation: AnnotationSQL, name: String) = {
def volumeToDownloadStream(dataSet: DataSet, annotation: Annotation, name: String) = {
for {
dataStoreHandler <- dataSet.dataStoreHandler
(tracing, data) <- dataStoreHandler.getVolumeTracing(annotation.tracing)
Expand All @@ -147,7 +147,7 @@ class AnnotationIOController @Inject()(val messagesApi: MessagesApi)
}
}

def tracingToDownloadStream(dataSet: DataSetSQL, annotation: AnnotationSQL, name: String) = {
def tracingToDownloadStream(dataSet: DataSet, annotation: Annotation, name: String) = {
annotation.tracing.typ match {
case TracingType.skeleton =>
skeletonToDownloadStream(dataSet, annotation, name)
Expand All @@ -172,44 +172,44 @@ class AnnotationIOController @Inject()(val messagesApi: MessagesApi)
}
}

def downloadProject(projectId: String, user: UserSQL)(implicit ctx: DBAccessContext) = {
def downloadProject(projectId: String, user: User)(implicit ctx: DBAccessContext) = {
for {
projectIdValidated <- ObjectId.parse(projectId)
project <- ProjectSQLDAO.findOne(projectIdValidated) ?~> Messages("project.notFound", projectId)
project <- ProjectDAO.findOne(projectIdValidated) ?~> Messages("project.notFound", projectId)
_ <- Fox.assertTrue(user.isTeamManagerOrAdminOf(project._team))
annotations <- AnnotationSQLDAO.findAllFinishedForProject(projectIdValidated)
annotations <- AnnotationDAO.findAllFinishedForProject(projectIdValidated)
zip <- AnnotationService.zipAnnotations(annotations, project.name + "_nmls.zip")
} yield {
Ok.sendFile(zip.file)
}
}

def downloadTask(taskId: String, user: UserSQL)(implicit ctx: DBAccessContext) = {
def createTaskZip(task: TaskSQL): Fox[TemporaryFile] = task.annotations.flatMap { annotations =>
def downloadTask(taskId: String, user: User)(implicit ctx: DBAccessContext) = {
def createTaskZip(task: Task): Fox[TemporaryFile] = task.annotations.flatMap { annotations =>
val finished = annotations.filter(_.state == Finished)
AnnotationService.zipAnnotations(finished, task._id.toString + "_nmls.zip")
}

for {
task <- TaskSQLDAO.findOne(ObjectId(taskId)).toFox ?~> Messages("task.notFound")
task <- TaskDAO.findOne(ObjectId(taskId)).toFox ?~> Messages("task.notFound")
project <- task.project ?~> Messages("project.notFound")
_ <- ensureTeamAdministration(user, project._team) ?~> Messages("notAllowed")
zip <- createTaskZip(task)
} yield Ok.sendFile(zip.file)
}

def downloadTaskType(taskTypeId: String, user: UserSQL)(implicit ctx: DBAccessContext) = {
def createTaskTypeZip(taskType: TaskTypeSQL) =
def downloadTaskType(taskTypeId: String, user: User)(implicit ctx: DBAccessContext) = {
def createTaskTypeZip(taskType: TaskType) =
for {
tasks <- TaskSQLDAO.findAllByTaskType(taskType._id)
tasks <- TaskDAO.findAllByTaskType(taskType._id)
annotations <- Fox.serialCombined(tasks)(_.annotations).map(_.flatten).toFox
finishedAnnotations = annotations.filter(_.state == Finished)
zip <- AnnotationService.zipAnnotations(finishedAnnotations, taskType.summary + "_nmls.zip")
} yield zip

for {
taskTypeIdValidated <- ObjectId.parse(taskTypeId)
tasktype <- TaskTypeSQLDAO.findOne(taskTypeIdValidated) ?~> Messages("taskType.notFound")
tasktype <- TaskTypeDAO.findOne(taskTypeIdValidated) ?~> Messages("taskType.notFound")
_ <- ensureTeamAdministration(user, tasktype._team) ?~> Messages("notAllowed")
zip <- createTaskTypeZip(tasktype)
} yield Ok.sendFile(zip.file)
Expand Down
10 changes: 5 additions & 5 deletions app/controllers/Application.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.scalableminds.util.tools.{Fox, FoxImplicits}
import javax.inject.Inject
import com.typesafe.config.ConfigRenderOptions
import oxalis.security.WebknossosSilhouette.UserAwareAction
import models.analytics.{AnalyticsEntrySQL, AnalyticsSQLDAO}
import models.analytics.{AnalyticsEntry, AnalyticsSQL}
import models.binary.DataStoreHandlingStrategy
import play.api.i18n.MessagesApi
import play.api.Play.current
Expand All @@ -21,7 +21,7 @@ class Application @Inject()(val messagesApi: MessagesApi) extends Controller {
if (user.isSuperUser) Some(DataStoreHandlingStrategy.webKnossosToken) else None
}
for {
schemaVersion <- ReleaseInformationSQLDAO.getSchemaVersion.futureBox
schemaVersion <- ReleaseInformationDAO.getSchemaVersion.futureBox
} yield {
Ok(Json.obj(
"webknossos" -> webknossos.BuildInfo.toMap.mapValues(_.toString),
Expand All @@ -33,8 +33,8 @@ class Application @Inject()(val messagesApi: MessagesApi) extends Controller {
}

def analytics(namespace: String) = UserAwareAction(parse.json(1024 * 1024)) { implicit request =>
AnalyticsSQLDAO.insertOne(
AnalyticsEntrySQL(
AnalyticsSQL.insertOne(
AnalyticsEntry(
ObjectId.generate,
request.identity.map(_._id),
namespace,
Expand All @@ -49,7 +49,7 @@ class Application @Inject()(val messagesApi: MessagesApi) extends Controller {
}


object ReleaseInformationSQLDAO extends SimpleSQLDAO with FoxImplicits {
object ReleaseInformationDAO extends SimpleSQLDAO with FoxImplicits {
def getSchemaVersion = {
for {
rList <- run(sql"select schemaVersion from webknossos.releaseInformation".as[Int])
Expand Down
20 changes: 10 additions & 10 deletions app/controllers/Authentication.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import com.scalableminds.util.mail._
import com.scalableminds.util.accesscontext.GlobalAccessContext
import com.scalableminds.util.rpc.RPC
import com.scalableminds.util.tools.{Fox, FoxImplicits}
import models.binary.{DataStoreSQL, DataStoreSQLDAO}
import models.binary.{DataStore, DataStoreDAO}
import models.team._
import models.user.UserService.{Mailer => _, _}
import models.user._
Expand Down Expand Up @@ -162,7 +162,7 @@ class Authentication @Inject()(
Fox.successful(BadRequest(Json.obj("messages" -> Json.toJson(errors.map(t => Json.obj("error" -> t))))))
} else {
for {
organization <- OrganizationSQLDAO.findOneByName(signUpData.organization)(GlobalAccessContext)
organization <- OrganizationDAO.findOneByName(signUpData.organization)(GlobalAccessContext)
user <- UserService.insert(organization._id, email, firstName, lastName, signUpData.password, automaticUserActivation, roleOnRegistration,
loginInfo, passwordHasher.hash(signUpData.password))
brainDBResult <- BrainTracing.registerIfNeeded(user).toFox
Expand Down Expand Up @@ -254,7 +254,7 @@ class Authentication @Inject()(
bearerTokenAuthenticatorService.userForToken(passwords.token.trim)(GlobalAccessContext).futureBox.flatMap {
case Full(user) =>
for {
_ <- UserSQLDAO.updatePasswordInfo(user._id, passwordHasher.hash(passwords.password1))(GlobalAccessContext)
_ <- UserDAO.updatePasswordInfo(user._id, passwordHasher.hash(passwords.password1))(GlobalAccessContext)
_ <- bearerTokenAuthenticatorService.remove(passwords.token.trim)
} yield Ok
case _ =>
Expand Down Expand Up @@ -406,7 +406,7 @@ class Authentication @Inject()(
)
}

private def creatingOrganizationsIsAllowed(requestingUser: Option[UserSQL]) = {
private def creatingOrganizationsIsAllowed(requestingUser: Option[User]) = {
val noOrganizationPresent = InitialDataService.assertNoOrganizationsPresent
val configurationFlagSet = Play.configuration.getBoolean("application.allowOrganzationCreation").getOrElse(false) ?~> "allowOrganzationCreation.notEnabled"
val userIsSuperUser = requestingUser.exists(_.isSuperUser).toFox
Expand All @@ -417,26 +417,26 @@ class Authentication @Inject()(
private def createOrganization(organizationDisplayName: String) =
for {
organizationName <- normalizeName(organizationDisplayName).toFox ?~> "invalid organization name"
organization = OrganizationSQL(ObjectId.generate, organizationName.replaceAll(" ", "_"), "", "", organizationDisplayName)
organizationTeam = TeamSQL(ObjectId.generate, organization._id, organization.name, isOrganizationTeam = true)
_ <- OrganizationSQLDAO.insertOne(organization)(GlobalAccessContext)
_ <- TeamSQLDAO.insertOne(organizationTeam)(GlobalAccessContext)
organization = Organization(ObjectId.generate, organizationName.replaceAll(" ", "_"), "", "", organizationDisplayName)
organizationTeam = Team(ObjectId.generate, organization._id, organization.name, isOrganizationTeam = true)
_ <- OrganizationDAO.insertOne(organization)(GlobalAccessContext)
_ <- TeamDAO.insertOne(organizationTeam)(GlobalAccessContext)
_ <- InitialDataService.insertLocalDataStoreIfEnabled
} yield {
organization
}


private def createOrganizationFolder(organizationName: String, loginInfo: LoginInfo)(implicit request: RequestHeader) = {
def sendRPCToDataStore(dataStore: DataStoreSQL, token: String) = {
def sendRPCToDataStore(dataStore: DataStore, token: String) = {
RPC(s"${dataStore.url}/data/triggers/newOrganizationFolder")
.withQueryString("token" -> token, "organizationName" -> organizationName)
.get
}

for {
token <- env.combinedAuthenticatorService.tokenAuthenticatorService.createAndInit(loginInfo, TokenType.DataStore, deleteOld = false).toFox
datastores <- DataStoreSQLDAO.findAll(GlobalAccessContext)
datastores <- DataStoreDAO.findAll(GlobalAccessContext)
_ <- Fox.combined(datastores.map(sendRPCToDataStore(_, token)))
} yield Full(())

Expand Down
Loading

0 comments on commit 3b71b12

Please sign in to comment.