3 CXGN::Transformation::AddTransformationProject - a module for adding transformation project
8 package CXGN
::Transformation
::AddTransformationProject
;
11 use MooseX
::FollowPBP
;
12 use Moose
::Util
::TypeConstraints
;
14 use CXGN
::Location
::LocationLookup
;
16 use SGN
::Model
::Cvterm
;
19 has
'chado_schema' => (isa
=> 'DBIx::Class::Schema',
29 has
'breeding_program_id' => (isa
=>'Int',
34 has
'year' => (isa
=> 'Str',
39 has
'project_description' => (isa
=> 'Str',
44 has
'nd_geolocation_id' => (isa
=> 'Int|Undef',
49 has
'transformation_project_name' => (isa
=> 'Str',
54 has
'owner_id' => (isa
=> 'Int',
59 sub existing_transformation_project
{
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})){
72 sub save_transformation_project
{
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')
89 name
=> $self->get_transformation_project_name(),
90 description
=> $self->get_project_description(),
93 my $transformation_project = CXGN
::Trial
->new({
94 bcs_schema
=> $schema,
95 trial_id
=> $project->project_id()
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};