<commit_before>package models.annotation.handler

import com.scalableminds.util.reactivemongo.DBAccessContext
import com.scalableminds.util.tools.{Fox, FoxImplicits}
import models.annotation._
import models.project.{Project, ProjectDAO}
import models.task.TaskDAO
import models.team.Role
import models.user.User
import reactivemongo.bson.BSONObjectID

import scala.concurrent.ExecutionContext.Implicits.global

object ProjectInformationHandler extends AnnotationInformationHandler with FoxImplicits {

  //TODO: rocksDB test this
  def provideAnnotation(projectName: String, user: Option[User])(implicit ctx: DBAccessContext): Fox[Annotation] =
  {
    for {
      project <- ProjectDAO.findOneByName(projectName) ?~> "project.notFound"
      tasks <- TaskDAO.findAllByProject(project.name)
      annotations <- Fox.serialSequence(tasks)(_.annotations).map(_.flatten).toFox
      finishedAnnotations = annotations.filter(_.state.isFinished)
      _ <- assertAllOnSameDataset(annotations)
      dataSetName = finishedAnnotations.head.dataSetName
      mergedAnnotation <- AnnotationMerger.mergeN(BSONObjectID(project.name), persistTracing=false, user.map(_._id),
        dataSetName, project.team, AnnotationType.CompoundProject, annotations) ?~> "project.noAnnotation"
    } yield mergedAnnotation
  }

  override def restrictionsFor(projectName: String)(implicit ctx: DBAccessContext) =
    for {
      project <- ProjectDAO.findOneByName(projectName)
    } yield {
      new AnnotationRestrictions {
        override def allowAccess(user: Option[User]) =
          user.flatMap(_.roleInTeam(project.team)).contains(Role.Admin)
      }
    }
}<commit_msg>fix: CompoundProject annotation: use project.id instead of (invalid) project.name<commit_after>package models.annotation.handler

import com.scalableminds.util.reactivemongo.DBAccessContext
import com.scalableminds.util.tools.{Fox, FoxImplicits}
import models.annotation._
import models.project.{Project, ProjectDAO}
import models.task.TaskDAO
import models.team.Role
import models.user.User
import reactivemongo.bson.BSONObjectID

import scala.concurrent.ExecutionContext.Implicits.global

object ProjectInformationHandler extends AnnotationInformationHandler with FoxImplicits {

  def provideAnnotation(projectName: String, user: Option[User])(implicit ctx: DBAccessContext): Fox[Annotation] =
  {
    for {
      project <- ProjectDAO.findOneByName(projectName) ?~> "project.notFound"
      tasks <- TaskDAO.findAllByProject(project.name)
      annotations <- Fox.serialSequence(tasks)(_.annotations).map(_.flatten).toFox
      finishedAnnotations = annotations.filter(_.state.isFinished)
      _ <- assertAllOnSameDataset(annotations)
      dataSetName = finishedAnnotations.head.dataSetName
      mergedAnnotation <- AnnotationMerger.mergeN(BSONObjectID(project.id), persistTracing=false, user.map(_._id),
        dataSetName, project.team, AnnotationType.CompoundProject, annotations) ?~> "project.noAnnotation"
    } yield mergedAnnotation
  }

  override def restrictionsFor(projectName: String)(implicit ctx: DBAccessContext) =
    for {
      project <- ProjectDAO.findOneByName(projectName)
    } yield {
      new AnnotationRestrictions {
        override def allowAccess(user: Option[User]) =
          user.flatMap(_.roleInTeam(project.team)).contains(Role.Admin)
      }
    }
}
{'fraction_non_alphanumeric': 0.0982089552238806, 'fraction_numerical': 0.0, 'mean_word_length': 4.787564766839378, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '255736', 'n_tokens_mistral': 980, 'n_tokens_neox': 954, 'n_words': 166}