<commit_before>package models

import play.api.libs.json.Json
import library.{Benchmark, Dress, Redis}
import org.apache.commons.lang3.{StringUtils, RandomStringUtils}

import play.api.data._
import play.api.data.Forms._
import play.api.templates.HtmlFormat
import org.joda.time.{DateTime, Instant}
import play.api.i18n.Messages

/**
 * Proposal is the main and maybe the most important object for a CFP.
 *
 * Author: <NAME>
 * Created: 12/10/2013 15:19
 */
case class ProposalType(id: String, label: String)

object ProposalType {
  implicit val proposalTypeFormat = Json.format[ProposalType]

  val UNKNOWN = ProposalType(id="unknown", label="unknown.label")

  def allAsId = ConferenceDescriptor.ConferenceProposalTypes.ALL.map(a => (a.id, a.label)).toSeq.sorted

  def allForCombos = {
    val allProposalTypes = ConferenceDescriptor.ConferenceProposalTypes.ALL
    val onlyThoseThatShouldBeDisplayed = allProposalTypes.filter(pt=>ConferenceDescriptor.ConferenceProposalTypes.ALL.exists(pc=>pc.id==pt.id))
    val finalFormat=onlyThoseThatShouldBeDisplayed.map(a => (a.id, a.label)).toSeq.sorted
    finalFormat
  }

  def allIDsOnly = allAsId.map(_._1)


  def parse(proposalType: String): ProposalType = {
    ConferenceDescriptor.ConferenceProposalTypes.ALL.find(p => p.id == proposalType).getOrElse(UNKNOWN)
  }

  val audienceLevels:Seq[(String,String)]={
    List(
      ("l1","level1.label")
      , ("l2","level2.label")
      , ("l3","level3.label")
    )
  }.toSeq

  val demoLevels:Seq[(String,String)]={
    List(
      ("d1","demoLevel1.label")
      , ("d2","demoLevel2.label")
      , ("d3","demoLevel3.label"))
  }.toSeq
}

case class ProposalState(code: String)

object ProposalState {

  implicit val proposalStateFormat = Json.format[ProposalState]

  val DRAFT = ProposalState("draft")
  val SUBMITTED = ProposalState("submitted")
  val DELETED = ProposalState("deleted")
  val APPROVED = ProposalState("approved")
  val REJECTED = ProposalState("rejected")
  val ACCEPTED = ProposalState("accepted")
  val DECLINED = ProposalState("declined")
  val BACKUP = ProposalState("backup")
  val UNKNOWN = ProposalState("unknown")


  val all = List(
    DRAFT,
    SUBMITTED,
    DELETED,
    APPROVED,
    REJECTED,
    ACCEPTED,
    DECLINED,
    BACKUP,
    UNKNOWN
  )

  val allButDeleted = List(
    DRAFT,
    SUBMITTED,
    APPROVED,
    REJECTED,
    ACCEPTED,
    DECLINED,
    BACKUP
  )

  val allAsCode = all.map(_.code)

  def parse(state: String): ProposalState = {
    state match {
      case "draft" => DRAFT
      case "submitted" => SUBMITTED
      case "deleted" => DELETED
      case "approved" => APPROVED
      case "rejected" => REJECTED
      case "accepted" => ACCEPTED
      case "declined" => DECLINED
      case "backup" => BACKUP
      case other => UNKNOWN
    }
  }
}


import com.github.rjeschke.txtmark._

// A proposal
case class Proposal(id: String,
                    event: String,
                    lang: String,
                    title: String,
                    mainSpeaker: String,
                    secondarySpeaker: Option[String],
                    otherSpeakers: List[String],
                    talkType: ProposalType,
                    audienceLevel: String,
                    summary: String,
                    privateMessage: String,
                    state: ProposalState,
                    sponsorTalk: Boolean = false,
                    track: Track,
                    demoLevel: String,
                    userGroup:Boolean,
                    wishlisted:Option[Boolean]=None) {

  def allSpeakerUUIDs: List[String] = {
    mainSpeaker :: (secondarySpeaker.toList ++ otherSpeakers)
  }

  def allSpeakers:List[Speaker]={
    allSpeakerUUIDs.flatMap{uuid=>
      Speaker.findByUUID(uuid)
    }
  }

  def allSpeakersGravatar:List[String]={
    allSpeakers.flatMap(_.avatarUrl)
  }

  lazy val summaryAsHtml: String = {
    val escapedHtml = HtmlFormat.escape(summary).body // escape HTML code and JS
    val processedMarkdownTest = Processor.process(StringUtils.trimToEmpty(escapedHtml).trim()) // Then do markdown processing
    processedMarkdownTest
  }

  lazy val privateMessageAsHtml: String = {
    val escapedHtml = HtmlFormat.escape(privateMessage).body // escape HTML code and JS
    val processedMarkdownTest = Processor.process(StringUtils.trimToEmpty(escapedHtml).trim()) // Then do markdown processing
    processedMarkdownTest
  }
}

object Proposal {

  implicit val proposalFormat = Json.format[Proposal]

  val langs = Seq(("en", "English"), ("fr", "Français"))

  val audienceLevels = Seq(("novice", "Novice"), ("intermediate", "Intermediate"), ("expert", "Expert"))

  val ProposalIDRegExp = "([A-Z][A-Z][A-Z]-\\d\\d\\d)".r

  val HttpUrl = "((([A-Za-z]{3,9}:(?:\\/\\/)?)(?:[-;:&=\\+\\$,\\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\\+\\$,\\w]+@)[A-Za-z0-9.-]+)((?:\\/[\\+~%\\/.\\w-_]*)?\\??(?:[-\\+=&;%@.\\w_]*)#?(?:[\\w]*))?)".r

  def isSpeaker(proposalId: String, uuid: String): Boolean = Redis.pool.withClient {
    implicit client =>
      client.sismember("Proposals:ByAuthor:" + uuid, proposalId)
  }

  def save(authorUUID: String, proposal: Proposal, proposalState: ProposalState) = Redis.pool.withClient {
    client =>
    // If it's a sponsor talk, we force it to be a conference
    // We also enforce the user id, for security reason<commit_msg>bug(review proposal): Fixed bug in automated parsing of proposal IDs<commit_after>package models

import play.api.libs.json.Json
import library.{Benchmark, Dress, Redis}
import org.apache.commons.lang3.{StringUtils, RandomStringUtils}

import play.api.data._
import play.api.data.Forms._
import play.api.templates.HtmlFormat
import org.joda.time.{DateTime, Instant}
import play.api.i18n.Messages

/**
 * Proposal is the main and maybe the most important object for a CFP.
 *
 * Author: <NAME>
 * Created: 12/10/2013 15:19
 */
case class ProposalType(id: String, label: String)

object ProposalType {
  implicit val proposalTypeFormat = Json.format[ProposalType]

  val UNKNOWN = ProposalType(id="unknown", label="unknown.label")

  def allAsId = ConferenceDescriptor.ConferenceProposalTypes.ALL.map(a => (a.id, a.label)).toSeq.sorted

  def allForCombos = {
    val allProposalTypes = ConferenceDescriptor.ConferenceProposalTypes.ALL
    val onlyThoseThatShouldBeDisplayed = allProposalTypes.filter(pt=>ConferenceDescriptor.ConferenceProposalTypes.ALL.exists(pc=>pc.id==pt.id))
    val finalFormat=onlyThoseThatShouldBeDisplayed.map(a => (a.id, a.label)).toSeq.sorted
    finalFormat
  }

  def allIDsOnly = allAsId.map(_._1)


  def parse(proposalType: String): ProposalType = {
    ConferenceDescriptor.ConferenceProposalTypes.ALL.find(p => p.id == proposalType).getOrElse(UNKNOWN)
  }

  val audienceLevels:Seq[(String,String)]={
    List(
      ("l1","level1.label")
      , ("l2","level2.label")
      , ("l3","level3.label")
    )
  }.toSeq

  val demoLevels:Seq[(String,String)]={
    List(
      ("d1","demoLevel1.label")
      , ("d2","demoLevel2.label")
      , ("d3","demoLevel3.label"))
  }.toSeq
}

case class ProposalState(code: String)

object ProposalState {

  implicit val proposalStateFormat = Json.format[ProposalState]

  val DRAFT = ProposalState("draft")
  val SUBMITTED = ProposalState("submitted")
  val DELETED = ProposalState("deleted")
  val APPROVED = ProposalState("approved")
  val REJECTED = ProposalState("rejected")
  val ACCEPTED = ProposalState("accepted")
  val DECLINED = ProposalState("declined")
  val BACKUP = ProposalState("backup")
  val UNKNOWN = ProposalState("unknown")


  val all = List(
    DRAFT,
    SUBMITTED,
    DELETED,
    APPROVED,
    REJECTED,
    ACCEPTED,
    DECLINED,
    BACKUP,
    UNKNOWN
  )

  val allButDeleted = List(
    DRAFT,
    SUBMITTED,
    APPROVED,
    REJECTED,
    ACCEPTED,
    DECLINED,
    BACKUP
  )

  val allAsCode = all.map(_.code)

  def parse(state: String): ProposalState = {
    state match {
      case "draft" => DRAFT
      case "submitted" => SUBMITTED
      case "deleted" => DELETED
      case "approved" => APPROVED
      case "rejected" => REJECTED
      case "accepted" => ACCEPTED
      case "declined" => DECLINED
      case "backup" => BACKUP
      case other => UNKNOWN
    }
  }
}


import com.github.rjeschke.txtmark._

// A proposal
case class Proposal(id: String,
                    event: String,
                    lang: String,
                    title: String,
                    mainSpeaker: String,
                    secondarySpeaker: Option[String],
                    otherSpeakers: List[String],
                    talkType: ProposalType,
                    audienceLevel: String,
                    summary: String,
                    privateMessage: String,
                    state: ProposalState,
                    sponsorTalk: Boolean = false,
                    track: Track,
                    demoLevel: String,
                    userGroup:Boolean,
                    wishlisted:Option[Boolean]=None) {

  def allSpeakerUUIDs: List[String] = {
    mainSpeaker :: (secondarySpeaker.toList ++ otherSpeakers)
  }

  def allSpeakers:List[Speaker]={
    allSpeakerUUIDs.flatMap{uuid=>
      Speaker.findByUUID(uuid)
    }
  }

  def allSpeakersGravatar:List[String]={
    allSpeakers.flatMap(_.avatarUrl)
  }

  lazy val summaryAsHtml: String = {
    val escapedHtml = HtmlFormat.escape(summary).body // escape HTML code and JS
    val processedMarkdownTest = Processor.process(StringUtils.trimToEmpty(escapedHtml).trim()) // Then do markdown processing
    processedMarkdownTest
  }

  lazy val privateMessageAsHtml: String = {
    val escapedHtml = HtmlFormat.escape(privateMessage).body // escape HTML code and JS
    val processedMarkdownTest = Processor.process(StringUtils.trimToEmpty(escapedHtml).trim()) // Then do markdown processing
    processedMarkdownTest
  }
}

object Proposal {

  implicit val proposalFormat = Json.format[Proposal]

  val langs = Seq(("en", "English"), ("fr", "Français"))

  val audienceLevels = Seq(("novice", "Novice"), ("intermediate", "Intermediate"), ("expert", "Expert"))

  val ProposalIDRegExp = "([A-Z][A-Z][A-Z]-\\d\\d\\d\\d)".r

  val HttpUrl = "((([A-Za-z]{3,9}:(?:\\/\\/)?)(?:[-;:&=\\+\\$,\\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\\+\\$,\\w]+@)[A-Za-z0-9.-]+)((?:\\/[\\+~%\\/.\\w-_]*)?\\??(?:[-\\+=&;%@.\\w_]*)#?(?:[\\w]*))?)".r

  def isSpeaker(proposalId: String, uuid: String): Boolean = Redis.pool.withClient {
    implicit client =>
      client.sismember("Proposals:ByAuthor:" + uuid, proposalId)
  }

  def save(authorUUID: String, proposal: Proposal, proposalState: ProposalState) = Redis.pool.withClient {
    client =>
    // If it's a sponsor talk, we force it to be a conference
    // We also enforce the user id, for security reason
{'fraction_non_alphanumeric': 0.1395112016293279, 'fraction_numerical': 0.006295130531383078, 'mean_word_length': 2.9892909896602657, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7428064', 'n_tokens_mistral': 3632, 'n_tokens_neox': 3498, 'n_words': 714}