<commit_before>/*
 * Copyright 2020 Global Biodiversity Information Facility (GBIF)
 *
 * 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 org.gbif.registry.service;

import org.gbif.api.annotation.NullToNotFound;
import org.gbif.api.model.Constants;
import org.gbif.api.model.common.DOI;
import org.gbif.api.model.common.paging.PagingRequest;
import org.gbif.api.model.common.paging.PagingResponse;
import org.gbif.api.model.registry.Citation;
import org.gbif.api.model.registry.Dataset;
import org.gbif.api.model.registry.Metadata;
import org.gbif.api.model.registry.Organization;
import org.gbif.api.vocabulary.MetadataType;
import org.gbif.registry.doi.util.RegistryDoiUtils;
import org.gbif.registry.domain.ws.CitationDatasetUsage;
import org.gbif.registry.metadata.CitationGenerator;
import org.gbif.registry.metadata.parse.DatasetParser;
import org.gbif.registry.persistence.mapper.DatasetMapper;
import org.gbif.registry.persistence.mapper.MetadataMapper;
import org.gbif.registry.persistence.mapper.OrganizationMapper;
import org.gbif.registry.persistence.mapper.handler.ByteArrayWrapper;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import javax.annotation.Nullable;

import org.apache.commons.collections.CollectionUtils;
import org.owasp.html.HtmlPolicyBuilder;
import org.owasp.html.PolicyFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.google.common.base.Strings;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.Lists;

@SuppressWarnings("UnstableApiUsage")
@Service
public class RegistryDatasetServiceImpl implements RegistryDatasetService {

  private static final Logger LOG = LoggerFactory.getLogger(RegistryDatasetServiceImpl.class);

  private static final UUID IUCN_DATASET_KEY = UUID.fromString("<KEY>");

  // HTML sanitizer policy for paragraph
  private static final PolicyFactory PARAGRAPH_HTML_SANITIZER =
      new HtmlPolicyBuilder()
          .allowCommonBlockElements() // "p", "div", "h1", ...
          .allowCommonInlineFormattingElements() // "b", "i" ...
          .allowElements("a")
          .allowUrlProtocols("https", "http")
          .allowAttributes("href")
          .onElements("a")
          .toFactory();

  private final DatasetMapper datasetMapper;
  private final MetadataMapper metadataMapper;<commit_msg>Google Java Format<commit_after>/*
 * Copyright 2020 Global Biodiversity Information Facility (GBIF)
 *
 * 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 org.gbif.registry.service;

import org.gbif.api.annotation.NullToNotFound;
import org.gbif.api.model.Constants;
import org.gbif.api.model.common.DOI;
import org.gbif.api.model.common.paging.PagingRequest;
import org.gbif.api.model.common.paging.PagingResponse;
import org.gbif.api.model.registry.Citation;
import org.gbif.api.model.registry.Dataset;
import org.gbif.api.model.registry.Metadata;
import org.gbif.api.model.registry.Organization;
import org.gbif.api.vocabulary.MetadataType;
import org.gbif.registry.doi.util.RegistryDoiUtils;
import org.gbif.registry.domain.ws.CitationDatasetUsage;
import org.gbif.registry.metadata.CitationGenerator;
import org.gbif.registry.metadata.parse.DatasetParser;
import org.gbif.registry.persistence.mapper.DatasetMapper;
import org.gbif.registry.persistence.mapper.MetadataMapper;
import org.gbif.registry.persistence.mapper.OrganizationMapper;
import org.gbif.registry.persistence.mapper.handler.ByteArrayWrapper;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import javax.annotation.Nullable;

import org.apache.commons.collections.CollectionUtils;
import org.owasp.html.HtmlPolicyBuilder;
import org.owasp.html.PolicyFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.google.common.base.Strings;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.Lists;

@SuppressWarnings("UnstableApiUsage")
@Service
public class RegistryDatasetServiceImpl implements RegistryDatasetService {

  private static final Logger LOG = LoggerFactory.getLogger(RegistryDatasetServiceImpl.class);

  private static final UUID IUCN_DATASET_KEY =
      UUID.fromString("<KEY>");

  // HTML sanitizer policy for paragraph
  private static final PolicyFactory PARAGRAPH_HTML_SANITIZER =
      new HtmlPolicyBuilder()
          .allowCommonBlockElements() // "p", "div", "h1", ...
          .allowCommonInlineFormattingElements() // "b", "i" ...
          .allowElements("a")
          .allowUrlProtocols("https", "http")
          .allowAttributes("href")
          .onElements("a")
          .toFactory();

  private final DatasetMapper datasetMapper;
  private final MetadataMapper metadataMapper;
{'fraction_non_alphanumeric': 0.10157117917790827, 'fraction_numerical': 0.0034915092842405966, 'mean_word_length': 4.797608095676173, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2566214', 'n_tokens_mistral': 1835, 'n_tokens_neox': 1825, 'n_words': 433}