Skip to content

Commit 7e8daab

Browse files
committed
make headers consistent and check for correctness of headers, fix typos, adapt test files to new headers.
1 parent c21f423 commit 7e8daab

File tree

6 files changed

+42
-32
lines changed

6 files changed

+42
-32
lines changed

js/source/legacy/CXGN/BreedersToolbox/UploadRenameAccessions.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,14 @@ jQuery(document).ready(function ($) {
105105
else {
106106
//alert("RESPONSE: "+JSON.stringify(response));
107107
jQuery('#rename_accessions_upload_success_dialog_message').modal('show');
108-
jQuery('#list_of_uploaded_rename_accessions').val(response.renamed_accessions);
108+
var renamed_accessions_html = response.renamed_accessions.join("<br />");
109+
jQuery('#list_of_uploaded_rename_accessions').html(renamed_accessions_html);
109110
//jQuery('#list_of_already_uploaded_rename_accessions').val(response.grafts_already_present);
110111
}
111112
},
112113
error: function(response) {
113114
jQuery('#working_modal').modal('hide');
114-
jQuery('#list_of_rename_accessions_with_problems').html(response.list_of_grafts_with_problems);
115-
alert('An error occurred storing the accession data. None were renamed.'+response.responseText);
115+
alert('An error occurred storing the accession data. None were renamed.'+response.responseText);
116116
}
117117
});
118118
});

lib/SGN/Controller/AJAX/Accessions/Rename.pm

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -187,36 +187,36 @@ sub upload_rename_accessions_store : Path('/ajax/rename_accessions/upload_store'
187187
my $schema = $c->dbic_schema("Bio::Chado::Schema");
188188

189189
my ($header, $rename) = $self->_get_rename_accessions_from_file($c, $archived_filename);
190-
190+
191191
my $info = $self->validate_rename_accessions($c, $header, $rename);
192192

193193
print STDERR "FILE CONTENTS: ".Dumper($rename);
194194

195195
my @renamed_accessions;
196196
my @accessions_already_present;
197197
my @error_accessions;
198-
198+
199199
if (exists($info->{accessions_already_present}) && defined($info->{accessions_already_present})) {
200200
@accessions_already_present = @{$info->{accessions_already_present}};
201201
}
202202
my $error;
203203

204204
foreach my $g (@$rename) {
205205
my ($old_accession_name, $new_accession_name) = @$g;
206-
207-
206+
207+
208208
my $stock = CXGN::Stock->new( { schema => $schema, uniquename => $old_accession_name });
209-
209+
210210
$stock->uniquename($new_accession_name);
211-
211+
212212
if ($store_old_name_as_synonym eq "on") {
213213
print STDERR "Storing old name ($old_accession_name) as synonym for $new_accession_name.\n";
214214
$stock->add_synonym($old_accession_name);
215215
}
216216
else {
217217
print STDERR "Synonym storing not requested. \n";
218218
}
219-
219+
220220
$stock->store();
221221

222222
if (exists($info->{errors}) && defined($info->{error}) && $info->{error} ne ''){
@@ -228,7 +228,7 @@ sub upload_rename_accessions_store : Path('/ajax/rename_accessions/upload_store'
228228
}
229229

230230
if (@error_accessions){
231-
$c->stash->{rest} = { error => join(", ",@error_accessions) };
231+
$c->stash->{rest} = { error => join(", ",@error_accessions) };
232232
$c->detach();
233233
}
234234
$c->stash->{rest} = { success => 1, renamed_accession_count => \@renamed_accessions, renamed_accessions => $rename };
@@ -243,9 +243,9 @@ sub _get_rename_accessions_from_file {
243243
my $header = <$F>;
244244
$header =~ s/\r//g;
245245
chomp($header);
246-
246+
247247
my @header = split/\t/, $header;
248-
248+
249249
foreach my $h (@header) {
250250
$h =~ s/^\s+|\s+$//g
251251
}
@@ -261,39 +261,48 @@ sub _get_rename_accessions_from_file {
261261
$new_accession_name =~ s/^\s+|\s+$//g; # trim also
262262
push @rename, [ $old_accession_name, $new_accession_name ];
263263
}
264-
265-
return \@header, \@rename;
264+
265+
return (\@header, \@rename);
266266
}
267267

268+
268269
sub validate_rename_accessions {
269270
my $self = shift;
270271
my $c = shift;
271272
my $header = shift;
272273
my $rename = shift;
273-
274+
275+
my $error = "";
276+
277+
if ($header->[0] ne "old_name") {
278+
$error = "Column 1 header must be old_name. ";
279+
}
280+
if ($header->[1] ne "new_name") {
281+
$error .= "Column 2 header must be new_name. ";
282+
}
283+
274284
my @must_exist = map { $_->[0] } @$rename;
275-
285+
276286
my @must_not_exist = map { $_->[1] } @$rename;
277-
287+
278288
$self->schema( $c->dbic_schema("Bio::Chado::Schema") );
279289
print STDERR "INPUT MUST EXIST: ".Dumper(\@must_exist);
280290
print STDERR "INPUT MUST NOT EXIST: ".Dumper(\@must_not_exist);
281291
my $list_validate = CXGN::List::Validate->new();
282292

283-
284293
my $must_exist_data = $list_validate->validate( $self->schema, 'accessions', \@must_exist );
285-
294+
286295
print STDERR "MUST EXIST: ".Dumper($must_exist_data);
287-
296+
288297
my $must_not_exist_data = $list_validate->validate( $self->schema, 'accessions', \@must_not_exist );
289-
298+
290299
my @missing = ();
291300
if (ref($must_not_exist_data->{missing})) {
292301
@missing = @{$must_not_exist_data->{missing}};
293302
}
294-
303+
295304
print STDERR "MUST NOT EXIST MISSING: ".Dumper(\@missing);
296-
305+
297306
my @must_not_exist_but_present = ();
298307
foreach my $m (@must_not_exist) {
299308
print STDERR "checking $m...\n";
@@ -302,10 +311,10 @@ sub validate_rename_accessions {
302311
push @must_not_exist_but_present, $m;
303312
}
304313
}
305-
314+
306315
print STDERR "MUST NOT EXIST BUT PRESENT: ".Dumper(\@must_not_exist_but_present);
307316

308-
return { must_exist_missing => $must_exist_data->{missing}, must_not_exist_present => \@must_not_exist_but_present };
317+
return { error => $error, must_exist_missing => $must_exist_data->{missing}, must_not_exist_present => \@must_not_exist_but_present };
309318
}
310319

311320

mason/breeders_toolbox/upload_accession_rename_dialog.mas

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
<h2>The accession renaming list upload was successful.</h2>
3939

4040
Successfully renamed:<br />
41-
<div id="list_of_uploaded_rename_accessions">
41+
<div class="bg-success" id="list_of_uploaded_rename_accessions">
42+
[loading...]
4243
</div>
4344
<br />
4445

@@ -113,8 +114,8 @@
113114

114115
<h4>Required fields:</h4>
115116
<ul>
116-
<li>old accession name (exact name MUST exist in the database)</li>
117-
<li>new accession name (must NOT exist in the database)</li>
117+
<li>old_name (exact name MUST exist in the database)</li>
118+
<li>new_name (must NOT exist in the database)</li>
118119
</ul>
119120
</div>
120121
</div>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
old name new name
1+
old_name new_name
22
test_accession1 test_accession100
33
test_accession2 test_accession200
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
old name new name
1+
old_name new_name
22
test_accession100 test_accession1
33
test_accession200 test_accession2
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
old name new name
1+
old_name new_name
22
test_accession227 test_accession228
33
test_accession2 test_accession3

0 commit comments

Comments
 (0)