<commit_before>package app.services

import scala.collection.mutable

import com.typesafe.config.ConfigFactory
import com.unboundid.ldap.sdk._

trait LDAPService {

  val configuration = ConfigFactory.load
  val host = configuration.getString("ldap.host")
  val port = configuration.getInt("ldap.port")
  val ldaps = configuration.getBoolean("ldap.ldaps")
  val baseDN = configuration.getString("ldap.baseDN")
  val bindDN = configuration.getString("ldap.bindDN")
  val password = configuration.getString("ldap.password")
  val uidAttributeName = configuration.getString("ldap.uidAttributeName")
  val initialConnextions = configuration.getInt("ldap.initialConnextions")
  val maxConnections = configuration.getInt("ldap.maxConnections")

  //TODO: Create connection options

  case class UserConnection(
    dn: String,
    connection: LDAPConnection
  //TODO: Add user's role.
  )

  /**
   * Create connection using by config user.
   */
  protected val defaultConnection = new LDAPConnection(host, port, bindDN, password)

  /**
   * The connections store by user.
   */
  protected val connections: mutable.HashMap[String, UserConnection] = mutable.HashMap()

  /**
   * Create connection by users and store it.
   */
  def createConnectionByUser(uid: String, dn: String, password: String): Unit = {
    val connection = UserConnection(dn, new LDAPConnection(host, port, dn, password))
    connections += (uid -> connection)
  }

  /**
   * Remove & close connection from connections store by User.
   */
  def removeConnectionByUser(uid: String): Unit = {
    //TODO: Release connection certainly.
    connections.get(uid) match {
      case Some(uc) => {
        uc.connection.close
        connections -= uid
      }
      case None => None
    }
  }

  /**
   * Get Connection by uid.
   */
  def getConnectionByUser(uid: String): Option[UserConnection] = {
    connections.get(uid)
  }

  /*
  val connectionPool: LDAPConnectionPool = {
    if (ldaps) {
      //TODO: Have to change create over TLS connection.
      new LDAPConnectionPool(connection, initialConnextions, maxConnections)
    } else {
      new LDAPConnectionPool(connection, initialConnextions, maxConnections)
    }
  }
  */

}<commit_msg>Add TODO comment<commit_after>package app.services

import scala.collection.mutable

import com.typesafe.config.ConfigFactory
import com.unboundid.ldap.sdk._

trait LDAPService {

  val configuration = ConfigFactory.load
  val host = configuration.getString("ldap.host")
  val port = configuration.getInt("ldap.port")
  val ldaps = configuration.getBoolean("ldap.ldaps")
  val baseDN = configuration.getString("ldap.baseDN")
  val bindDN = configuration.getString("ldap.bindDN")
  val password = configuration.getString("ldap.password")
  val uidAttributeName = configuration.getString("ldap.uidAttributeName")
  val initialConnextions = configuration.getInt("ldap.initialConnextions")
  val maxConnections = configuration.getInt("ldap.maxConnections")

  //TODO: Create connection options

  case class UserConnection(
    dn: String,
    connection: LDAPConnection
  //TODO: Add user's role.
  )

  /**
   * Create connection using by config user.
   * TODO: Support LDAPS
   */
  protected val defaultConnection = new LDAPConnection(host, port, bindDN, password)

  /**
   * The connections store by user.
   */
  protected val connections: mutable.HashMap[String, UserConnection] = mutable.HashMap()

  /**
   * Create connection by users and store it.
   * TODO: Support LDAPS
   */
  def createConnectionByUser(uid: String, dn: String, password: String): Unit = {
    val connection = UserConnection(dn, new LDAPConnection(host, port, dn, password))
    connections += (uid -> connection)
  }

  /**
   * Remove & close connection from connections store by User.
   */
  def removeConnectionByUser(uid: String): Unit = {
    //TODO: Release connection certainly.
    connections.get(uid) match {
      case Some(uc) => {
        uc.connection.close
        connections -= uid
      }
      case None => None
    }
  }

  /**
   * Get Connection by uid.
   */
  def getConnectionByUser(uid: String): Option[UserConnection] = {
    connections.get(uid)
  }

  /*
  val connectionPool: LDAPConnectionPool = {
    if (ldaps) {
      //TODO: Have to change create over TLS connection.
      new LDAPConnectionPool(connection, initialConnextions, maxConnections)
    } else {
      new LDAPConnectionPool(connection, initialConnextions, maxConnections)
    }
  }
  */

}
{'fraction_non_alphanumeric': 0.1060842433697348, 'fraction_numerical': 0.0, 'mean_word_length': 3.5287588294651866, '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': '7563796', 'n_tokens_mistral': 1309, 'n_tokens_neox': 1289, 'n_words': 334}