1 package CXGN
::Transformation
::AddAutogeneratedNameInfo
;
5 CXGN::Transformation::AddAutogeneratedNameInfo - a module to add autogenerated name metadata.
15 Titima Tantikanjana (tt15@cornell.edu)
20 use MooseX
::FollowPBP
;
21 use Moose
::Util
::TypeConstraints
;
23 use SGN
::Model
::Cvterm
;
30 isa
=> 'DBIx::Class::Schema',
31 predicate
=> 'has_schema',
37 predicate
=> 'has_dbh',
41 has
'breeding_program_id' => (
44 predicate
=> 'has_breeding_program_id',
51 predicate
=> 'has_prefix',
55 has
'current_serial_number' => (
58 predicate
=> 'has_prefix',
62 has
'number_of_digits' => (
65 predicate
=> 'has_number_of_digits',
68 has
'description' => (
71 predicate
=> 'has_description',
77 predicate
=> 'has_added_by',
84 predicate
=> 'has_date',
91 my $schema = $self->get_schema();
92 my $breeding_program_id = $self->get_breeding_program_id();
93 my $prefix = $self->get_prefix();
94 my $current_serial_number = $self->get_current_serial_number();
95 my $number_of_digits = $self->get_number_of_digits();
96 my $description = $self->get_description();
97 my $added_by = $self->get_added_by();;
98 my $date = $self->get_date();;
99 my $transaction_error;
103 my $name_metadata_cvterm = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'autogenerated_name_metadata', 'project_property');
105 $name_metadata{'current_serial_number'} = $current_serial_number;
106 $name_metadata{'number_of_digits'} = $number_of_digits;
107 $name_metadata{'description'} = $description;
108 $name_metadata{'added_by'} = $added_by;
109 $name_metadata{'date'} = $date;
111 my $stored_name_metadata_string;
112 my $new_name_metadata_string;
113 my $name_metadata_hash = {};
114 my $program = $schema->resultset('Project::Project')->find({ project_id
=> $breeding_program_id});
116 print STDERR
"Breeding Program not found!\n";
119 my $metadata_projectprop_rs = $program->projectprops({type_id
=> $name_metadata_cvterm->cvterm_id});
120 if ($metadata_projectprop_rs->count == 1){
121 $stored_name_metadata_string = $metadata_projectprop_rs->first->value();
122 $name_metadata_hash = decode_json
$stored_name_metadata_string;
123 print STDERR
"PREVIOUS METADATA =".Dumper
($name_metadata_hash)."\n";
124 $name_metadata_hash->{$prefix} = \
%name_metadata;
125 $new_name_metadata_string = encode_json
$name_metadata_hash;
126 print STDERR
"UPDATED METADATA =".Dumper
($name_metadata_hash)."\n";
128 $metadata_projectprop_rs->first->update({value
=>$new_name_metadata_string});
129 } elsif ($metadata_projectprop_rs->count > 1) {
130 print STDERR
"More than one found!\n";
133 $name_metadata_hash->{$prefix} = \
%name_metadata;
134 $new_name_metadata_string = encode_json
$name_metadata_hash;
135 print STDERR
"NEW METADATA =".Dumper
($name_metadata_hash)."\n";
137 $program->create_projectprops({$name_metadata_cvterm->name() => $new_name_metadata_string});
142 $schema->txn_do($coderef);
144 $transaction_error = $_;
147 if ($transaction_error) {
148 print STDERR
"Transaction error adding autogenerated name metadata: $transaction_error\n";