<commit_before>package org.supler.demo

import akka.actor.ActorSystem
import org.joda.time.DateTime
import org.json4s.JValue
import org.json4s.JsonAST.{JField, JObject, JString}
import org.supler.errors.ValidationMode
import spray.http.MediaTypes
import spray.http.StatusCodes._
import spray.httpx.Json4sSupport
import spray.routing.{Route, SimpleRoutingApp}

object DemoServer extends App with SimpleRoutingApp with Json4sSupport {
  implicit val actorSystem = ActorSystem()
  implicit val json4sFormats = org.json4s.DefaultFormats

  var person = Person("Adam", "", new DateTime(), 10, None, None, null, None, None,
    Set("red", "blue"), likesBroccoli = false,
    List(
      Car("Ford", 1990),
      Car("Toyota", 2004)),
    List(
      LegoSet("Motorcycle", "Technic", 1924, 31),
      LegoSet("Arctic Supply Plane", "City", 60064, 0),
      LegoSet("Princess and Horse", "Duplo", 4825, 7)),
    new DateTime(2012, 2, 19, 0, 0))

  def getJson(route: Route) = get { respondWithMediaType(MediaTypes.`application/json`) { route } }

  val (port, suplerJsDirective, sourceMapDirective) = if (System.getProperty("supler.demo.production") != null) {
    (8195, getFromResourceDirectory(""), getFromResourceDirectory(""))
  } else {
    (8080, getFromDirectory("./supler-js/app/scripts/compiled"), getFromDirectory("./supler-js/app/scripts"))
    // compiled by grunt
  }

  startServer(interface = "localhost", port = port) {
    path("rest" / "form1.json") {
      getJson {
        complete {
          PersonForm.personForm(person).generateJSON
        }
      } ~
      post {
        entity(as[JValue]) { jvalue =>
          complete {
            val validated = PersonForm.personForm(person)
              .applyJSONValues(jvalue)
              .doValidate()

            if (validated.hasErrors) {
              validated.generateJSON
            } else {
              person = validated.obj
              println(s"Persisted: $person")

              JObject(
                JField("msg", JString("Persisted: " + person)))
            }
          }
        }
      } ~
      put {
        entity(as[JValue]) { jvalue =>
          complete {
            PersonForm.personForm(person).refresh
          }
        }
      }
    } ~
    pathSuffixTest(".+\\.ts".r) { id =><commit_msg>Special refresh function for ajax refreshes<commit_after>package org.supler.demo

import akka.actor.ActorSystem
import org.joda.time.DateTime
import org.json4s.JValue
import org.json4s.JsonAST.{JField, JObject, JString}
import org.supler.errors.ValidationMode
import spray.http.MediaTypes
import spray.http.StatusCodes._
import spray.httpx.Json4sSupport
import spray.routing.{Route, SimpleRoutingApp}

object DemoServer extends App with SimpleRoutingApp with Json4sSupport {
  implicit val actorSystem = ActorSystem()
  implicit val json4sFormats = org.json4s.DefaultFormats

  var person = Person("Adam", "", new DateTime(), 10, None, None, null, None, None,
    Set("red", "blue"), likesBroccoli = false,
    List(
      Car("Ford", 1990),
      Car("Toyota", 2004)),
    List(
      LegoSet("Motorcycle", "Technic", 1924, 31),
      LegoSet("Arctic Supply Plane", "City", 60064, 0),
      LegoSet("Princess and Horse", "Duplo", 4825, 7)),
    new DateTime(2012, 2, 19, 0, 0))

  def getJson(route: Route) = get { respondWithMediaType(MediaTypes.`application/json`) { route } }

  val (port, suplerJsDirective, sourceMapDirective) = if (System.getProperty("supler.demo.production") != null) {
    (8195, getFromResourceDirectory(""), getFromResourceDirectory(""))
  } else {
    (8080, getFromDirectory("./supler-js/app/scripts/compiled"), getFromDirectory("./supler-js/app/scripts"))
    // compiled by grunt
  }

  startServer(interface = "localhost", port = port) {
    path("rest" / "form1.json") {
      getJson {
        complete {
          PersonForm.personForm(person).generateJSON
        }
      } ~
      post {
        entity(as[JValue]) { jvalue =>
          complete {
            val validated = PersonForm.personForm(person)
              .applyJSONValues(jvalue)
              .doValidate()

            if (validated.hasErrors) {
              validated.generateJSON
            } else {
              person = validated.obj
              println(s"Persisted: $person")

              JObject(
                JField("msg", JString("Persisted: " + person)))
            }
          }
        }
      } ~
      put {
        entity(as[JValue]) { jvalue =>
          complete {
            PersonForm.personForm(person).refresh(jvalue)
          }
        }
      }
    } ~
    pathSuffixTest(".+\\.ts".r) { id =>
{'fraction_non_alphanumeric': 0.13056636402939906, 'fraction_numerical': 0.02204928664072633, 'mean_word_length': 2.570216049382716, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '1458922', 'n_tokens_mistral': 1492, 'n_tokens_neox': 1394, 'n_words': 289}