<commit_before>package io.stored.server.ext.storage


import io.stored.server.common.{Record, IndexStorage}
import org.json.JSONObject


class HttpIndexStorage(host: String) extends IndexStorage
{
  def init()
  {}

  def shutdown()
  {}

  def purge()
  {}

  def query(nodeIds: Set[Int], sql: String) = null

  def add(nodeIds: Set[Int], datum: Record)
  {}

  def addAll(nodeIds: Set[Int], data: List[Record])
  {}

  def remove(nodeIds: Set[Int], id: String)
  {}
}


object HttpIndexStorage
{
  def create(host: String) : HttpIndexStorage = {
    val indexStorage = new HttpIndexStorage(host)
    indexStorage.init
    indexStorage
  }<commit_msg>initial draft of http client<commit_after>package io.stored.server.ext.storage


import io.stored.server.common.{Record, IndexStorage}
import com.ning.http.client.AsyncHttpClient
import org.json.JSONObject
import collection.mutable.ListBuffer


class HttpIndexStorage(host: String) extends IndexStorage
{
  def init()
  {}

  def shutdown()
  {}

  def purge()
  {}

  def query(nodeIds: Set[Int], sql: String) : List[Record] = {
    val asyncHttpClient = new AsyncHttpClient()
    val f = asyncHttpClient.preparePost("%s/records/queries".format(host)).addParameter("sql",sql).execute
    val response = f.get
    val jsonResponse = new JSONObject(response.getResponseBody)
    val elements = jsonResponse.getJSONArray("elements")

    val results = new ListBuffer[Record]
    (0 until elements.length()).foreach(i => results.append(Record.create(elements.getJSONObject(i))))
    results.toList
  }

  def add(nodeIds: Set[Int], record: Record)
  {
    val asyncHttpClient = new AsyncHttpClient()
    val f = asyncHttpClient.preparePost("%s/records".format(host)).addParameter("record",record.rawData.toString).execute
    val response = f.get
    val jsonResponse = new JSONObject(response.getResponseBody)
    val id = jsonResponse.getString("id")
  }

  def addAll(nodeIds: Set[Int], records: List[Record])
  {
    records.foreach(add(null, _))
  }

  def remove(nodeIds: Set[Int], id: String)
  {}
}


object HttpIndexStorage
{
  def create(host: String) : HttpIndexStorage = {
    val indexStorage = new HttpIndexStorage(host)
    indexStorage.init
    indexStorage
  }
{'fraction_non_alphanumeric': 0.12264150943396226, 'fraction_numerical': 0.0004492362982929021, 'mean_word_length': 4.227699530516432, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '3835242', 'n_tokens_mistral': 712, 'n_tokens_neox': 688, 'n_words': 154}