aggregate and update data
[sgn.git] / lib / CXGN / Transformation / AddTransformationProject.pm
blobced9e68f7b88ed04763782e14050463043bed082
1 =head1 NAME
3 CXGN::Transformation::AddTransformationProject - a module for adding transformation project
5 =cut
8 package CXGN::Transformation::AddTransformationProject;
10 use Moose;
11 use MooseX::FollowPBP;
12 use Moose::Util::TypeConstraints;
13 use Try::Tiny;
14 use CXGN::Location::LocationLookup;
15 use CXGN::Trial;
16 use SGN::Model::Cvterm;
17 use Data::Dumper;
19 has 'chado_schema' => (isa => 'DBIx::Class::Schema',
20 is => 'rw',
21 required => 1,
24 has 'dbh' => (
25 is => 'rw',
26 required => 1,
29 has 'breeding_program_id' => (isa =>'Int',
30 is => 'rw',
31 required => 1,
34 has 'year' => (isa => 'Str',
35 is => 'rw',
36 required => 1,
39 has 'project_description' => (isa => 'Str',
40 is => 'rw',
41 required => 1,
44 has 'nd_geolocation_id' => (isa => 'Int|Undef',
45 is => 'rw',
46 required => 1,
49 has 'transformation_project_name' => (isa => 'Str',
50 is => 'rw',
51 required => 1,
54 has 'owner_id' => (isa => 'Int',
55 is => 'rw',
59 sub existing_transformation_project {
60 my $self = shift;
61 my $transformation_project_name = $self->get_transformation_project_name();
62 my $schema = $self->get_chado_schema();
63 if($schema->resultset('Project::Project')->find({name=>$transformation_project_name})){
64 return 1;
66 else{
67 return;
72 sub save_transformation_project {
73 my $self = shift;
74 my $schema = $self->get_chado_schema();
76 if ($self->existing_transformation_project()){
77 return {error => "Transformation project not saved: Project name already exists"};
80 if (!$self->get_breeding_program_id()){
81 return {error => "Transformation project not saved: Breeding program does not exist"};
84 my $project_year_cvterm = SGN::Model::Cvterm->get_cvterm_row($schema,'project year', 'project_property');
85 my $project_type_cvterm_id = SGN::Model::Cvterm->get_cvterm_row($schema, 'transformation_project', 'project_type')->cvterm_id();
87 my $project = $schema->resultset('Project::Project')
88 ->create({
89 name => $self->get_transformation_project_name(),
90 description => $self->get_project_description(),
91 });
93 my $transformation_project = CXGN::Trial->new({
94 bcs_schema => $schema,
95 trial_id => $project->project_id()
96 });
98 if ($self->get_nd_geolocation_id()){
99 $transformation_project->set_location($self->get_nd_geolocation_id());
102 $transformation_project->set_project_type($project_type_cvterm_id);
103 $transformation_project->set_year($self->get_year());
104 $transformation_project->set_breeding_program($self->get_breeding_program_id);
105 $transformation_project->set_trial_owner($self->get_owner_id);
107 return {success=>1, project_id=>$transformation_project->get_trial_id};
112 #########
114 #########