From ec8c7faee8f1f6bf3aac33b6f26fce25a1c1ffe7 Mon Sep 17 00:00:00 2001 From: titima15 Date: Sat, 13 Aug 2022 01:14:26 +0000 Subject: [PATCH] improve validation --- .../Plugin/GenotypeTrialCoordinateTemplate.pm | 44 +++++++++++++++------- .../Trial/ParseUpload/Plugin/GenotypeTrialXLS.pm | 15 ++++++++ 2 files changed, 46 insertions(+), 13 deletions(-) diff --git a/lib/CXGN/Trial/ParseUpload/Plugin/GenotypeTrialCoordinateTemplate.pm b/lib/CXGN/Trial/ParseUpload/Plugin/GenotypeTrialCoordinateTemplate.pm index ace480d63..0a296dc37 100644 --- a/lib/CXGN/Trial/ParseUpload/Plugin/GenotypeTrialCoordinateTemplate.pm +++ b/lib/CXGN/Trial/ParseUpload/Plugin/GenotypeTrialCoordinateTemplate.pm @@ -60,26 +60,44 @@ sub _validate_with_plugin { } } + my $value_header = $columns[0]; + $value_header =~ s/^\s+|\s+$//g; + my $column_header = $columns[1]; + $column_header =~ s/^\s+|\s+$//g; + my $row_header = $columns[2]; + $row_header =~ s/^\s+|\s+$//g; + my $identification_header = $columns[3]; + $identification_header =~ s/^\s+|\s+$//g; + my $person_header = $columns[4]; + $person_header =~ s/^\s+|\s+$//g; + my $date_header = $columns[5]; + $date_header =~ s/^\s+|\s+$//g; + my $facility_identifier_header; if ($include_facility_identifiers) { - if ($columns[0] ne "Value" || - $columns[1] ne "Column" || - $columns[2] ne "Row" || - $columns[3] ne "Identification" || - $columns[4] ne "Person" || - $columns[5] ne "Date" || - $columns[6] ne "Facility Identifier") { + $facility_identifier_header = $columns[6]; + $facility_identifier_header =~ s/^\s+|\s+$//g; + } + + if ($include_facility_identifiers) { + if ($value_header ne "Value" || + $column_header ne "Column" || + $row_header ne "Row" || + $identification_header ne "Identification" || + $person_header ne "Person" || + $date_header ne "Date" || + $facility_identifier_header ne "Facility Identifier") { push @error_messages, 'File contents incorrect. Header row must contain: "Value","Column","Row","Identification","Person","Date", Facility Identifier'; $errors{'error_messages'} = \@error_messages; $self->_set_parse_errors(\%errors); return; } } else { - if ($columns[0] ne "Value" || - $columns[1] ne "Column" || - $columns[2] ne "Row" || - $columns[3] ne "Identification" || - $columns[4] ne "Person" || - $columns[5] ne "Date" ) { + if ($value_header ne "Value" || + $column_header ne "Column" || + $row_header ne "Row" || + $identification_header ne "Identification" || + $person_header ne "Person" || + $date_header ne "Date" ) { push @error_messages, 'File contents incorrect. Header row must contain: "Value","Column","Row","Identification","Person","Date"'; $errors{'error_messages'} = \@error_messages; $self->_set_parse_errors(\%errors); diff --git a/lib/CXGN/Trial/ParseUpload/Plugin/GenotypeTrialXLS.pm b/lib/CXGN/Trial/ParseUpload/Plugin/GenotypeTrialXLS.pm index 531703dc5..196902822 100644 --- a/lib/CXGN/Trial/ParseUpload/Plugin/GenotypeTrialXLS.pm +++ b/lib/CXGN/Trial/ParseUpload/Plugin/GenotypeTrialXLS.pm @@ -64,49 +64,64 @@ sub _validate_with_plugin { if ($worksheet->get_cell(0,0)) { $date_head = $worksheet->get_cell(0,0)->value(); + $date_head =~ s/^\s+|\s+$//g; } if ($worksheet->get_cell(0,1)) { $sample_id_head = $worksheet->get_cell(0,1)->value(); + $sample_id_head =~ s/^\s+|\s+$//g; } if ($worksheet->get_cell(0,2)) { $well_A01_head = $worksheet->get_cell(0,2)->value(); + $well_A01_head =~ s/^\s+|\s+$//g; } if ($worksheet->get_cell(0,3)) { $row_head = $worksheet->get_cell(0,3)->value(); + $row_head =~ s/^\s+|\s+$//g; } if ($worksheet->get_cell(0,4)) { $column_head = $worksheet->get_cell(0,4)->value(); + $column_head =~ s/^\s+|\s+$//g; } if ($worksheet->get_cell(0,5)) { $source_observation_unit_name_head = $worksheet->get_cell(0,5)->value(); + $source_observation_unit_name_head =~ s/^\s+|\s+$//g; } if ($worksheet->get_cell(0,6)) { $ncbi_taxonomy_id_head = $worksheet->get_cell(0,6)->value(); + $ncbi_taxonomy_id_head =~ s/^\s+|\s+$//g; } if ($worksheet->get_cell(0,7)) { $dna_person_head = $worksheet->get_cell(0,7)->value(); + $dna_person_head =~ s/^\s+|\s+$//g; } if ($worksheet->get_cell(0,8)) { $notes_head = $worksheet->get_cell(0,8)->value(); + $notes_head =~ s/^\s+|\s+$//g; } if ($worksheet->get_cell(0,9)) { $tissue_type_head = $worksheet->get_cell(0,9)->value(); + $tissue_type_head =~ s/^\s+|\s+$//g; } if ($worksheet->get_cell(0,10)) { $extraction_head = $worksheet->get_cell(0,10)->value(); + $extraction_head =~ s/^\s+|\s+$//g; } if ($worksheet->get_cell(0,11)) { $concentration_head = $worksheet->get_cell(0,11)->value(); + $concentration_head =~ s/^\s+|\s+$//g; } if ($worksheet->get_cell(0,12)) { $volume_head = $worksheet->get_cell(0,12)->value(); + $volumn_head =~ s/^\s+|\s+$//g; } if ($worksheet->get_cell(0,13)) { $is_blank_head = $worksheet->get_cell(0,13)->value(); + $is_blank_head =~ s/^\s+|\s+$//g; } if ($include_facility_identifiers){ if ($worksheet->get_cell(0,14)) { $facility_identifier_head = $worksheet->get_cell(0,14)->value(); + $facility_identifier_head =~ s/^\s+|\s+$//g; } } -- 2.11.4.GIT