seedlot upload with accession synonyms. seedlot upload works to update existing seedlots
[sgn.git] / lib / SGN / Controller / AJAX / VectorConstruct.pm
blob2f16d4567c41637732216a04992e3ec9a360be0e
1 =head1 NAME
3 SGN::Controller::AJAX::VectorConstruct - a REST controller class for Vector Constructs.
5 =head1 DESCRIPTION
7 Synchronizes vector constructs into the database from the ETHZ CASS database.
9 =head1 AUTHOR
11 Nicolas Morales <nm529@cornell.edu>
13 =cut
15 package SGN::Controller::AJAX::VectorConstruct;
17 use Moose;
18 use JSON -support_by_pp;
19 use List::MoreUtils qw /any /;
20 use Data::Dumper;
21 use JSON;
22 use SGN::Model::Cvterm;
25 BEGIN { extends 'Catalyst::Controller::REST' }
27 __PACKAGE__->config(
28 default => 'application/json',
29 stash_key => 'rest',
30 map => { 'application/json' => 'JSON', 'text/html' => 'JSON' },
33 sub sync_cass_constructs : Path('/ajax/cass_vector_construct/sync') Args(0) ActionClass('REST') { }
35 sub sync_cass_constructs_POST {
36 my $self = shift;
37 my $c = shift;
38 my $status = '';
39 my $schema = $c->dbic_schema("Bio::Chado::Schema");
41 my $construct_names = decode_json($c->req->param("data"));
42 my %construct_hash = %$construct_names;
43 my $constructs = $construct_hash{construct};
44 my @construct_array = @$constructs;
46 my $stock_type_id = SGN::Model::Cvterm->get_cvterm_row($schema, 'vector_construct', 'stock_type')->cvterm_id();
48 my $create_db = $schema->resultset("General::Db")->find_or_create({
49 name => 'ETHZ_CASS',
50 description => 'Internal ETHZ CASS DB',
51 urlprefix => '',
52 url => 'https://cass.pb.ethz.ch'
53 });
55 foreach (@construct_array) {
56 #print STDERR $_->{construct};
57 #print STDERR $_->{construct_id};
58 #print STDERR $_->{level};
60 my $create_stock = $schema->resultset("Stock::Stock")->find_or_create({
61 uniquename => $_->{construct},
62 name => $_->{construct},
63 type_id => $stock_type_id,
64 });
66 my $create_dbxref = $schema->resultset("General::Dbxref")->find_or_create({
67 db_id => $create_db->db_id(),
68 accession => $_->{construct_id},
69 version => 'vector_construct',
70 description => 'ETHZ_CASS vector_construct id'
71 });
73 my $create_stock_dbxref = $schema->resultset("Stock::StockDbxref")->find_or_create({
74 stock_id => $create_stock->stock_id(),
75 dbxref_id => $create_dbxref->dbxref_id()
76 });
79 #print STDERR Dumper $constructs;
80 #print STDERR $status;
82 $c->stash->{rest} = {response=>$status};