<commit_before>use strict;
use warnings;

package CXGN::Phenome::Stock::StockForm;
my $stock_form = CXGN::Phenome::Stock::StockForm->new();

use base qw/CXGN::Page::Form::AjaxFormPage  /;


use CXGN::Tools::Organism;
use Bio::Chado::Schema;
use CXGN::Chado::Stock;

use CXGN::People::Person;
use CXGN::Contact;


use Try::Tiny;

use JSON;
use CatalystX::GlobalContext qw( $c );


sub new {
    my $class  = shift;
    my $self   = $class->SUPER::new(@_);
    return $self;
}

sub define_object {
    my $self = shift;
    my %args      = $self->get_args();
    my $stock_id  = $args{stock_id} || $args{object_id};
    my $user_type = $self->get_user()->get_user_type();
    my %json_hash= $self->get_json_hash();

    my $schema   = $c->dbic_schema( 'Bio::Chado::Schema', 'sgn_chado' );

    $self->set_object_id($stock_id);
    $self->set_object_name('Stock'); #this is useful for email messages
    $self->set_object( CXGN::Chado::Stock->new($schema, $stock_id) );

    if ( $self->get_object()->get_is_obsolete() == 1 && $user_type ne 'curator' )
    {
        $json_hash{error}="Stock $stock_id is obsolete!";
    }
    unless ( ( $stock_id =~ m /^\d+$/ || !$stock_id  )  ) {
        $json_hash{error}="No stock exists for identifier $stock_id";
    }
    $self->set_json_hash(%json_hash);
    $self->set_primary_key("stock_id");
    my @owners;
    #my @owners = $self->get_object()->search_related("stockprops", {
    #type_id => $sp_person_cvterm_id } );

    $self->set_owners( @owners );

    $self->print_json() if $json_hash{error};
}


sub store {
    my $self=shift;

    my $stock    = $self->get_object();
    my $stock_id = $self->get_object_id();
    my $bcs_stock = $stock->get_object_row();
    my %args     = $self->get_args();
    my %json_hash = $self->get_json_hash();
    my $initial_stock_id = $stock_id;

    my $error;
    $stock->set_organism_id($args{organism_id});
    $stock->set_type_id($args{type_id});
    $stock->set_name($args{name});
    $stock->set_uniquename($args{uniquename});
    $stock->set_description($args{description});


    my ($message) ;
    my $message = $stock->exists_in_database();
    my $validate;
    if ($message) {
        $error = " Stock $args{uniquename}  already exists in the database ";
    }else {
        try{
            $self->SUPER::store(); #this sets $json_hash{validate} if the form validation failed.
            $stock_id = $stock->get_stock_id() ;
        } catch {
            $error = " An error occurred. Cannot store to the database\n An  email message has been sent to the SGN development team";
            CXGN::Contact::send_email('stock_ajax_form.pl died', $error . "\n" . $_ , '<EMAIL>');
        };
    }
    #the validate field is false is validation passed for all fields, true if did not pass and the form is re-printed

    %json_hash= $self->get_json_hash();
    $validate= $json_hash{validate};
    $json_hash{error} = $error if $error;

    my $refering_page="/phenome/stock.pl?stock_id=$stock_id";
    $self->send_form_email({subject=>"[New stock details stored] stock $stock_id", mailing_list=>'sgn-<EMAIL>', refering_page=>"www.solgenomics.net".$refering_page}) if (!$validate && !$json_hash{error});
    $json_hash{refering_page}=$refering_page if !$initial_stock_id && !$validate && !$error;

    $self->set_json_hash(%json_hash);

    $self->print_json();
}
<commit_msg>remove redundant var declaration, making a compile warning<commit_after>use strict;
use warnings;

package CXGN::Phenome::Stock::StockForm;
my $stock_form = CXGN::Phenome::Stock::StockForm->new();

use base qw/CXGN::Page::Form::AjaxFormPage  /;


use CXGN::Tools::Organism;
use Bio::Chado::Schema;
use CXGN::Chado::Stock;

use CXGN::People::Person;
use CXGN::Contact;


use Try::Tiny;

use JSON;
use CatalystX::GlobalContext qw( $c );


sub new {
    my $class  = shift;
    my $self   = $class->SUPER::new(@_);
    return $self;
}

sub define_object {
    my $self = shift;
    my %args      = $self->get_args();
    my $stock_id  = $args{stock_id} || $args{object_id};
    my $user_type = $self->get_user()->get_user_type();
    my %json_hash= $self->get_json_hash();

    my $schema   = $c->dbic_schema( 'Bio::Chado::Schema', 'sgn_chado' );

    $self->set_object_id($stock_id);
    $self->set_object_name('Stock'); #this is useful for email messages
    $self->set_object( CXGN::Chado::Stock->new($schema, $stock_id) );

    if ( $self->get_object()->get_is_obsolete() == 1 && $user_type ne 'curator' )
    {
        $json_hash{error}="Stock $stock_id is obsolete!";
    }
    unless ( ( $stock_id =~ m /^\d+$/ || !$stock_id  )  ) {
        $json_hash{error}="No stock exists for identifier $stock_id";
    }
    $self->set_json_hash(%json_hash);
    $self->set_primary_key("stock_id");
    my @owners;
    #my @owners = $self->get_object()->search_related("stockprops", {
    #type_id => $sp_person_cvterm_id } );

    $self->set_owners( @owners );

    $self->print_json() if $json_hash{error};
}


sub store {
    my $self=shift;

    my $stock    = $self->get_object();
    my $stock_id = $self->get_object_id();
    my $bcs_stock = $stock->get_object_row();
    my %args     = $self->get_args();
    my %json_hash = $self->get_json_hash();
    my $initial_stock_id = $stock_id;

    my $error;
    $stock->set_organism_id($args{organism_id});
    $stock->set_type_id($args{type_id});
    $stock->set_name($args{name});
    $stock->set_uniquename($args{uniquename});
    $stock->set_description($args{description});


    my $message = $stock->exists_in_database();
    my $validate;
    if ($message) {
        $error = " Stock $args{uniquename}  already exists in the database ";
    }else {
        try{
            $self->SUPER::store(); #this sets $json_hash{validate} if the form validation failed.
            $stock_id = $stock->get_stock_id() ;
        } catch {
            $error = " An error occurred. Cannot store to the database\n An  email message has been sent to the SGN development team";
            CXGN::Contact::send_email('stock_ajax_form.pl died', $error . "\n" . $_ , '<EMAIL>');
        };
    }
    #the validate field is false is validation passed for all fields, true if did not pass and the form is re-printed

    %json_hash= $self->get_json_hash();
    $validate= $json_hash{validate};
    $json_hash{error} = $error if $error;

    my $refering_page="/phenome/stock.pl?stock_id=$stock_id";
    $self->send_form_email({subject=>"[New stock details stored] stock $stock_id", mailing_list=>'<EMAIL>', refering_page=>"www.solgenomics.net".$refering_page}) if (!$validate && !$json_hash{error});
    $json_hash{refering_page}=$refering_page if !$initial_stock_id && !$validate && !$error;

    $self->set_json_hash(%json_hash);

    $self->print_json();
}

{'fraction_non_alphanumeric': 0.17004288037853024, 'fraction_numerical': 0.0002957267484844004, 'mean_word_length': 3.6972222222222224, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 87, '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': '1069918', 'n_tokens_mistral': 2457, 'n_tokens_neox': 2370, 'n_words': 493}