<commit_before>package controllers.api

import controllers.DelvingController
import play.api.mvc.Action
import core.HubServices
import play.api.i18n.Messages
import models.{DataSet, Visibility}

/**
 * Organization API
 *
 * @author <NAME> <<EMAIL>>
 */

object Organization extends DelvingController {

  def providers(orgId: String) = Root {
    Action {
      implicit request =>
        if (HubServices.organizationService.exists(orgId)) {

          val providers = getFactAlternatives(orgId, "provider")

          val xmlResponse =
            <providers>
              {for (p <- providers) yield
              <provider>
                <id>
                  {toIdentifier(p)}
                </id>
                <name>
                  {p}
                </name>
              </provider>}
            </providers>

          DOk(xmlResponse, List("providers"))

        } else {
          NotFound(Messages("organizations.organization.orgNotFound", orgId))
        }
    }
  }

  def dataProviders(orgId: String) = Root {
    Action {
      implicit request =>
        if (HubServices.organizationService.exists(orgId)) {

          val dataProviders = getFactAlternatives(orgId, "dataProvider")

          val xmlResponse =
            <dataProviders>
              {for (p <- dataProviders) yield
              <dataProvider>
                <id>
                  {toIdentifier(p)}
                </id>
                <name>
                  {p}
                </name>
              </dataProvider>}
            </dataProviders>

          DOk(xmlResponse, List("dataProviders"))

        } else {
          NotFound(Messages("organizations.organization.orgNotFound", orgId))
        }
    }
  }

  def collections(orgId: String) = Root {
    Action {
      implicit request =>
        if (HubServices.organizationService.exists(orgId)) {
          val collections = models.DataSet.findAllByOrgId(orgId).filter(_.visibility == Visibility.PUBLIC)

          val xmlResponse =
            <collections>
              {for (c <- collections) yield
              <collection>
                <id>
                  {toIdentifier(c.spec)}
                </id>
                <name>
                  {c.name}
                </name>
              </collection>}
            </collections>

          DOk(xmlResponse, List("collection"))

        } else {
          NotFound(Messages("organizations.organization.orgNotFound", orgId))
        }
    }
  }

  private def getFactAlternatives(orgId: String, fact: String) = DataSet.findAll(orgId).map(ds => ds.details.facts.get(fact)).filterNot(_ == null).map(_.toString).toList.distinct

  private def toIdentifier(name: String) = name.replaceAll(" ", "_")


}<commit_msg>Removing whitespaces<commit_after>package controllers.api

import controllers.DelvingController
import play.api.mvc.Action
import core.HubServices
import play.api.i18n.Messages
import models.{DataSet, Visibility}

/**
 * Organization API
 *
 * @author <NAME> <<EMAIL>>
 */

object Organization extends DelvingController {

  def providers(orgId: String) = Root {
    Action {
      implicit request =>
        if (HubServices.organizationService.exists(orgId)) {

          val providers = getFactAlternatives(orgId, "provider")

          val xmlResponse =
            <providers>
              {for (p <- providers) yield
              <provider>
                <id>{toIdentifier(p)}</id>
                <name>{p}</name>
              </provider>}
            </providers>

          DOk(xmlResponse, List("providers"))

        } else {
          NotFound(Messages("organizations.organization.orgNotFound", orgId))
        }
    }
  }

  def dataProviders(orgId: String) = Root {
    Action {
      implicit request =>
        if (HubServices.organizationService.exists(orgId)) {

          val dataProviders = getFactAlternatives(orgId, "dataProvider")

          val xmlResponse =
            <dataProviders>
              {for (p <- dataProviders) yield
              <dataProvider>
                <id>{toIdentifier(p)}</id>
                <name>{p}</name>
              </dataProvider>}
            </dataProviders>

          DOk(xmlResponse, List("dataProviders"))

        } else {
          NotFound(Messages("organizations.organization.orgNotFound", orgId))
        }
    }
  }

  def collections(orgId: String) = Root {
    Action {
      implicit request =>
        if (HubServices.organizationService.exists(orgId)) {
          val collections = models.DataSet.findAllByOrgId(orgId).filter(_.visibility == Visibility.PUBLIC)

          val xmlResponse =
            <collections>
              {for (c <- collections) yield
              <collection>
                <id>{toIdentifier(c.spec)}</id>
                <name>{c.name}</name>
              </collection>}
            </collections>

          DOk(xmlResponse, List("collection"))

        } else {
          NotFound(Messages("organizations.organization.orgNotFound", orgId))
        }
    }
  }

  private def getFactAlternatives(orgId: String, fact: String) = DataSet.findAll(orgId).map(ds => ds.details.facts.get(fact)).filterNot(_ == null).map(_.toString).toList.distinct

  private def toIdentifier(name: String) = name.replaceAll(" ", "_")


}
{'fraction_non_alphanumeric': 0.11695462312511866, 'fraction_numerical': 0.0007594456047085627, 'mean_word_length': 1.8849945235487404, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, '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': '7233737', 'n_tokens_mistral': 1487, 'n_tokens_neox': 1393, 'n_words': 265}