<commit_before>/**
 *  Copyright 2013 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.mooo.nilewapps.bokbytarappen.server

import scala.concurrent.duration._
import akka.actor.Actor

import spray.routing._
import spray.routing.authentication._
import spray.http._
import spray.httpx.marshalling._
import spray.httpx.SprayJsonSupport

import spray.json.DefaultJsonProtocol
import SprayJsonSupport._
import MediaTypes._

import scala.slick.driver.H2Driver.simple._
import Database.threadLocalSession

import TokenJsonProtocol._

import scala.language.postfixOps

/**
 * Actor that runs the service
 */
class ServiceActor extends Actor with Service {

  def actorRefFactory = context

  def receive = runRoute(routes ~
    /**
     * Stops the server. Can only be accessed from localhost.
     */
    path("stop") {
      host("localhost") {
        get {
          complete {
            context.system.scheduler.scheduleOnce(1.second) { context.system.shutdown() }
            "shutdown"
          }
        }
      }
    })

}

/**
 * Provides all functionality of the server
 */
trait Service extends HttpService with DB with Authenticator {

  val routes =
    path("") {
      get {
        respondWithMediaType(`text/html`) {
          complete {
            <html>
              <body>
                <h1>Say hello to <i>Bokbytarappen's server</i>!</h1>
              </body>
            </html>
          }
        }
      }
    } ~
    /**
     * Returns json array of all universities in a given country.
     */
    path("universities" / IntNumber) { countryCode =>
      get {
        respondWithMediaType(`application/json`) {<commit_msg>Added validation test service<commit_after>/**
 *  Copyright 2013 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.mooo.nilewapps.bokbytarappen.server

import scala.concurrent.duration._
import akka.actor.Actor

import spray.routing._
import spray.routing.authentication._
import spray.http._
import spray.httpx.marshalling._
import spray.httpx.SprayJsonSupport
import spray.util.LoggingContext

import spray.json.DefaultJsonProtocol
import SprayJsonSupport._
import MediaTypes._

import scala.slick.driver.H2Driver.simple._
import Database.threadLocalSession

import TokenJsonProtocol._

import scala.language.postfixOps

  object SuperSpecialException extends Exception

/**
 * Actor that runs the service
 */
class ServiceActor extends Actor with Service {

  def actorRefFactory = context

  implicit def exceptionHandler(implicit log: LoggingContext) =
    ExceptionHandler.fromPF {
      case SuperSpecialException => ctx =>
        log.warning("{} encountered while handling request: {}", ctx.request)
        ctx.complete(489, "Super special error!")
    }

  def receive = runRoute(routes ~
    /**
     * Stops the server. Can only be accessed from localhost.
     */
    path("stop") {
      host("localhost") {
        get {
          complete {
            context.system.scheduler.scheduleOnce(1.second) { context.system.shutdown() }
            "shutdown"
          }
        }
      }
    })

}

/**
 * Provides all functionality of the server
 */
trait Service extends HttpService with DB with Authenticator {

  val routes =
    path("") {
      get {
        respondWithMediaType(`text/html`) {
          complete {
            <html>
              <body>
                <h1>Say hello to <i>Bokbytarappen's server</i>!</h1>
              </body>
            </html>
          }
        }
      }
    } ~
    path("special") {
      get {
        validate(1 > 2, "1 must be greater than 2") {
          complete {
            throw SuperSpecialException
          }
        }
      }
    } ~
    /**
     * Returns json array of all universities in a given country.
     */
    path("universities" / IntNumber) { countryCode =>
      get {
        respondWithMediaType(`application/json`) {
{'fraction_non_alphanumeric': 0.09251728344855632, 'fraction_numerical': 0.0063033753558357055, 'mean_word_length': 2.56966618287373, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 26, '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': '5528197', 'n_tokens_mistral': 1363, 'n_tokens_neox': 1338, 'n_words': 419}