1 package CXGN
::BreedersToolbox
::SoilData
;
6 CXGN::BreedersToolbox::SoilData - a class to manage soil data
10 The projectprop of type "soil_data_json" is stored as JSON.
14 my $soil_data = CXGN::BreedersToolbox::SoilData->new( { schema => $schema});
18 Titima Tantikanjana <tt15@cornell.edu>
25 extends
'CXGN::JSONProp';
29 use SGN
::Model
::Cvterm
;
32 has
'description' => (isa
=> 'Str', is
=> 'rw');
34 has
'date' => (isa
=> 'Maybe[Str]', is
=> 'rw');
36 has
'gps' => (isa
=> 'Maybe[Str]', is
=> 'rw');
38 has
'type_of_sampling' => (isa
=> 'Str', is
=> 'rw');
40 has
'data_type_order' => (isa
=> 'ArrayRef', is
=> 'rw');
42 has
'soil_data_details' => (isa
=> 'HashRef', is
=> 'rw');
49 $self->prop_table('projectprop');
50 $self->prop_namespace('Project::Projectprop');
51 $self->prop_primary_key('projectprop_id');
52 $self->prop_type('soil_data_json');
53 $self->cv_name('project_property');
54 $self->allowed_fields([ qw
| description date gps type_of_sampling data_type_order soil_data_details
| ]);
55 $self->parent_table('project');
56 $self->parent_primary_key('project_id');
62 sub get_all_soil_data
{
64 my $schema = $self->bcs_schema();
65 my $project_id = $self->parent_id();
66 my $type_id = $self->_prop_type_id();
68 my $soil_data_rs = $schema->resultset("Project::Projectprop")->search({ project_id
=> $project_id, type_id
=> $type_id }, { order_by
=> {-asc
=> 'projectprop_id'} });
70 while (my $r = $soil_data_rs->next()){
71 my $prop_id = $r->projectprop_id();
72 my $soil_data_json = $r->value();
73 my $soil_data_hash = JSON
::Any
->jsonToObj($soil_data_json);
74 my $description = $soil_data_hash->{'description'};
75 my $date = $soil_data_hash->{'date'};
76 my $gps = $soil_data_hash->{'gps'};
77 my $type_of_sampling = $soil_data_hash->{'type_of_sampling'};
78 my $data_type_order = $soil_data_hash->{'data_type_order'};
79 my $soil_data_details = $soil_data_hash->{'soil_data_details'};
81 push @soil_data_list, [$prop_id, $description, $date, $gps, $type_of_sampling, $data_type_order, $soil_data_details, $project_id];
84 return \
@soil_data_list;
90 my $schema = $self->bcs_schema();
91 my $project_id = $self->parent_id();
92 my $projectprop_id = $self->prop_id();
93 my $type = $self->prop_type();
94 my $type_id = $self->_prop_type_id();
95 my $key_ref = $self->allowed_fields();
96 my @fields = @
$key_ref;
98 my $soil_data_rs = $schema->resultset("Project::Projectprop")->find({ project_id
=> $project_id, projectprop_id
=> $projectprop_id, type_id
=> $type_id }, { order_by
=> {-asc
=> 'projectprop_id'} });
99 my $soil_data_json = $soil_data_rs->value();
100 my $soil_data_hash = JSON
::Any
->jsonToObj($soil_data_json);
103 foreach my $field (@fields) {
104 push @soil_data_info, $soil_data_hash->{$field};
107 return \
@soil_data_info;
111 sub delete_soil_data
{
113 my $schema = $self->bcs_schema();
114 my $dbh = $schema->storage()->dbh();
115 my $project_id = $self->parent_id();
116 my $projectprop_id = $self->prop_id();
117 my $type = $self->prop_type();
118 my $type_id = $self->_prop_type_id();
123 my $q = "DELETE FROM projectprop WHERE projectprop_id = ? AND project_id = ? AND type_id = ?";
124 my $h = $dbh->prepare($q);
126 $h->execute($projectprop_id, $project_id, $type_id);
130 print STDERR
"An error occurred while deleting soil data "."$@\n";