<commit_before>=head1 LICENSE

Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
Copyright [2016-2022] EMBL-European Bioinformatics Institute

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.

=cut

package EnsEMBL::Web::Object::IDMapper;

use strict;
use warnings;

use Bio::EnsEMBL::Registry;
use Bio::EnsEMBL::DBSQL::DBAdaptor;
use EnsEMBL::Web::DBSQL::ArchiveAdaptor;
use EnsEMBL::Web::Utils::FileHandler qw(file_get_contents);

use parent qw(EnsEMBL::Web::Object::Tools);

sub get_edit_jobs_data {
  ## Abstract method implementation
  my $self        = shift;
  my $hub         = $self->hub;
  my $ticket      = $self->get_requested_ticket   or return [];
  my $job         = shift @{ $ticket->job || [] } or return [];
  my $job_data    = $job->job_data->raw;
  my $input       = delete $job_data->{'input'};

  if ($input->{'type'} eq 'text') {
    $job_data->{'text'} = file_get_contents(sprintf '%s/%s', $job->job_dir, delete $job_data->{'input_file'});
  } else {
    $input->{'type'} eq $_ and $job_data->{$_} = $input->{$_} for qw(url file);
  }

  return [ $job_data ];
}

sub species_list {
  ## Returns a list of species
  ## @return Arrayref of hashes with each hash having species specific info
  my $self = shift;

  if (!$self->{'_species_list'}) {
    my $hub = $self->hub;
    my $sd  = $hub->species_defs;

    my @species;

    for ($self->valid_species) {

      push @species, {
        'value'       => $_,
        'caption'     => $sd->species_label($_, 1),
        'assembly'    => $sd->get_config($_, 'ASSEMBLY_NAME')
      };
    }

    @species = sort { $a->{'caption'} cmp $b->{'caption'} } @species;

    $self->{'_species_list'} = \@species;
  }

  return $self->{'_species_list'};
}

sub handle_download {
  ## Method reached by url ensembl.org/Download/IDMapper/<commit_msg>Check for stable_id_event records in core db - ENSWEB-6538<commit_after>=head1 LICENSE

Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
Copyright [2016-2022] EMBL-European Bioinformatics Institute

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.

=cut

package EnsEMBL::Web::Object::IDMapper;

use strict;
use warnings;

use Bio::EnsEMBL::Registry;
use Bio::EnsEMBL::DBSQL::DBAdaptor;
use EnsEMBL::Web::DBSQL::ArchiveAdaptor;
use EnsEMBL::Web::Utils::FileHandler qw(file_get_contents);

use parent qw(EnsEMBL::Web::Object::Tools);

sub get_edit_jobs_data {
  ## Abstract method implementation
  my $self        = shift;
  my $hub         = $self->hub;
  my $ticket      = $self->get_requested_ticket   or return [];
  my $job         = shift @{ $ticket->job || [] } or return [];
  my $job_data    = $job->job_data->raw;
  my $input       = delete $job_data->{'input'};

  if ($input->{'type'} eq 'text') {
    $job_data->{'text'} = file_get_contents(sprintf '%s/%s', $job->job_dir, delete $job_data->{'input_file'});
  } else {
    $input->{'type'} eq $_ and $job_data->{$_} = $input->{$_} for qw(url file);
  }

  return [ $job_data ];
}

sub species_list {
  ## Returns a list of species
  ## @return Arrayref of hashes with each hash having species specific info
  my $self = shift;

  if (!$self->{'_species_list'}) {
    my $hub = $self->hub;
    my $sd  = $hub->species_defs;

    my @species;

    for ($self->valid_species) {

      ## Do we have data for this species?
      my $history = $sd->table_info_other($_, 'core', 'stable_id_event');

      push @species, {
        'value'       => $_,
        'caption'     => $sd->species_label($_, 1),
        'assembly'    => $sd->get_config($_, 'ASSEMBLY_NAME')
      } if $history->{'rows'};
    }

    @species = sort { $a->{'caption'} cmp $b->{'caption'} } @species;

    $self->{'_species_list'} = \@species;
  }

  return $self->{'_species_list'};
}

sub handle_download {
  ## Method reached by url ensembl.org/Download/IDMapper/
{'fraction_non_alphanumeric': 0.14256325858876776, 'fraction_numerical': 0.009874511417403826, 'mean_word_length': 3.6481835564053537, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '360860', 'n_tokens_mistral': 1675, 'n_tokens_neox': 1561, 'n_words': 468}