1 package SGN
::Controller
::AJAX
::Transformation
;
6 use CXGN
::People
::Person
;
8 use CXGN
::Stock
::StockLookup
;
9 use CXGN
::Location
::LocationLookup
;
10 use SGN
::Model
::Cvterm
;
11 use CXGN
::List
::Validate
;
13 use CXGN
::Transformation
::AddTransformationProject
;
14 use CXGN
::Transformation
::AddTransformationIdentifier
;
15 use List
::MoreUtils qw
/any /;
18 BEGIN { extends
'Catalyst::Controller::REST' }
21 default => 'application/json',
23 map => { 'application/json' => 'JSON', 'text/html' => 'JSON' },
27 sub add_transformation_project
: Path
('/ajax/transformation/add_transformation_project') : ActionClass
('REST') {}
29 sub add_transformation_project_POST
:Args
(0){
31 my $schema = $c->dbic_schema('Bio::Chado::Schema', 'sgn_chado');
32 my $dbh = $c->dbc->dbh;
33 my $project_name = $c->req->param('project_name');
34 my $breeding_program_id = $c->req->param('project_program_id');
35 my $location = $c->req->param('project_location');
36 my $year = $c->req->param('year');
37 my $project_description = $c->req->param('project_description');
38 $project_name =~ s/^\s+|\s+$//g;
40 print STDERR
"PROJECT NAME =".Dumper
($project_name)."\n";
42 $c->stash->{rest
} = {error
=> "You need to be logged in to add a transformation project."};
46 if (!any
{ $_ eq "curator" || $_ eq "submitter" } ($c->user()->roles)){
47 $c->stash->{rest
} = {error
=> "you have insufficient privileges to add a transformation project." };
51 my $user_id = $c->user()->get_object()->get_sp_person_id();
53 my $geolocation_lookup = CXGN
::Location
::LocationLookup
->new(schema
=>$schema);
54 $geolocation_lookup->set_location_name($location);
55 if(!$geolocation_lookup->get_geolocation()){
56 $c->stash->{rest
}={error
=> "Location not found"};
62 my $add_transformation_project = CXGN
::Transformation
::AddTransformationProject
->new({
63 chado_schema
=> $schema,
65 breeding_program_id
=> $breeding_program_id,
67 project_description
=> $project_description,
68 transformation_project_name
=> $project_name,
69 nd_geolocation_id
=> $geolocation_lookup->get_geolocation()->nd_geolocation_id(),
73 my $return = $add_transformation_project->save_transformation_project();
74 if ($return->{error
}){
75 $error = $return->{error
};
80 $c->stash->{rest
} = {error
=> $@
};
85 $c->stash->{rest
} = {error
=> $error};
87 $c->stash->{rest
} = {success
=> 1};
93 sub add_transformation_identifier
: Path
('/ajax/transformation/add_transformation_identifier') : ActionClass
('REST') {}
95 sub add_transformation_identifier_POST
:Args
(0){
97 my $schema = $c->dbic_schema('Bio::Chado::Schema', 'sgn_chado');
98 my $phenome_schema = $c->dbic_schema("CXGN::Phenome::Schema");
99 my $dbh = $c->dbc->dbh;
100 my $transformation_identifier = $c->req->param('transformation_identifier');
101 my $plant_material = $c->req->param('plant_material');
102 my $vector_construct = $c->req->param('vector_construct');
103 my $notes = $c->req->param('notes');
104 my $transformation_project_id = $c->req->param('transformation_project_id');
105 $transformation_identifier =~ s/^\s+|\s+$//g;
107 print STDERR
"TRANSFORMATION IDENTIFIER =".Dumper
($transformation_identifier)."\n";
110 $c->stash->{rest
} = {error
=> "You need to be logged in to add a transformation transformation identifier."};
114 if (!any
{ $_ eq "curator" || $_ eq "submitter" } ($c->user()->roles)){
115 $c->stash->{rest
} = {error
=> "you have insufficient privileges to add a transformation identifier." };
119 my $user_id = $c->user()->get_object()->get_sp_person_id();
121 my $accession_cvterm_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema,'accession', 'stock_type')->cvterm_id();
122 my $vector_construct_cvterm_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema,'vector_construct', 'stock_type')->cvterm_id();
124 if ($schema->resultset("Stock::Stock")->find({uniquename
=> $transformation_identifier})){
125 $c->stash->{rest
} = {error
=> "Transformation identifier already exists." };
129 if (! $schema->resultset("Stock::Stock")->find({uniquename
=> $plant_material, type_id
=> $accession_cvterm_id })){
130 $c->stash->{rest
} = {error
=> "Plant material does not exist or does not exist as accession uniquename." };
134 if (! $schema->resultset("Stock::Stock")->find({uniquename
=> $vector_construct, type_id
=> $vector_construct_cvterm_id })){
135 $c->stash->{rest
} = {error
=> "vector construct does not exist or does not exist as vector construct uniquename." };
140 my $add_transformation = CXGN
::Transformation
::AddTransformationIdentifier
->new({
141 chado_schema
=> $schema,
142 phenome_schema
=> $phenome_schema,
144 transformation_project_id
=> $transformation_project_id,
145 transformation_identifier
=> $transformation_identifier,
146 plant_material
=> $plant_material,
147 vector_construct
=> $vector_construct,
149 owner_id
=> $user_id,
152 $add_transformation->add_transformation_identifier();
156 $c->stash->{rest
} = { error
=> "An error occurred: $@"};