4 SGN::Controller::AJAX::BrAPIAndroidApp - a REST controller class to provide additional functionality required for Android app
11 Nicolas Morales <nm529@cornell.edu>
15 package SGN
::Controller
::AJAX
::BrAPIAndroidApp
;
20 use CXGN
::People
::Login
;
21 use CXGN
::DB
::Connection
;
23 BEGIN { extends
'Catalyst::Controller::REST' }
26 default => 'application/json',
28 map => { 'application/json' => 'JSON', 'text/html' => 'JSON' },
31 sub new_database
: Path
('/brapiapp/new_database') : ActionClass
('REST') { }
33 sub new_database_GET
: Args
(0) {
36 my $name = $c->req->param('databaseName');
37 my $url = $c->req->param('databaseURL');
38 my $session_id = $c->req->param('accessToken');
39 my $bcs_schema = $c->dbic_schema('Bio::Chado::Schema', 'sgn_chado');
41 my $previous_name_search = $bcs_schema->resultset('General::Db')->search({name
=>$name});
42 if ($previous_name_search->count > 0){
43 $c->stash->{rest
} = {error
=> "The given database name already exists and cannot be added!"};
46 my $previous_url_search = $bcs_schema->resultset('General::Db')->search({url
=>$url});
47 if ($previous_url_search->count > 0){
48 $c->stash->{rest
} = {error
=> "The given database URL already exists and cannot be added!"};
52 my $dbh = $c->dbc->dbh;
53 my $cookie_info = CXGN
::Login
->new($dbh)->query_from_cookie($session_id);
56 my $new_entry = $bcs_schema->resultset('General::Db')->create({
59 description
=>'BrAPI_App_Database_Display'
61 if ($new_entry->db_id){
62 $c->stash->{rest
} = {success
=> 1};
64 $c->stash->{rest
} = {error
=> 'The new database entry was not saved!'};
67 $c->stash->{rest
} = {error
=> "User Not Logged In"};
72 sub list_databases
: Path
('/brapiapp/list_databases') : ActionClass
('REST') { }
74 sub list_databases_GET
: Args
(0) {
77 my $bcs_schema = $c->dbic_schema('Bio::Chado::Schema', 'sgn_chado');
80 my $db_rs = $bcs_schema->resultset('General::Db')->search({description
=>'BrAPI_App_Database_Display'}, {order_by
=>{'-asc'=>'db_id'}});
81 while(my $r = $db_rs->next()){
82 push @db_list, [$r->name, $r->url];
84 $c->stash->{rest
} = {database_list
=>\
@db_list};
87 sub remove_database
: Path
('/brapiapp/remove_database') : ActionClass
('REST') { }
89 sub remove_database_POST
: Args
(0) {
92 my $session_id = $c->req->param('accessToken');
93 my $database_name = $c->req->param('databaseName');
94 my $bcs_schema = $c->dbic_schema('Bio::Chado::Schema', 'sgn_chado');
96 my $dbh = $c->dbc->dbh;
97 my $cookie_info = CXGN
::Login
->new($dbh)->query_from_cookie($session_id);
99 my $db = $bcs_schema->resultset('General::Db')->find({description
=>'BrAPI_App_Database_Display', name
=>$database_name});
101 $c->stash->{rest
} = {success
=> 1};
103 $c->stash->{rest
} = {error
=> "User Not Logged In"};
107 sub register
: Path
('/brapiapp/register') : ActionClass
('REST') { }
109 sub register_POST
: Args
(0) {
112 my $dbh = CXGN
::DB
::Connection
->new();
113 my $username = $c->req->param('username');
114 my $password = $c->req->param('password');
115 my $email = $c->req->param('email');
116 my $organization = $c->req->param('organization');
117 my $first_name = $c->req->param('first_name');
118 my $last_name = $c->req->param('last_name');
120 my $new_user = CXGN
::People
::Login
->new($dbh);
121 $new_user -> set_username
($username);
122 $new_user -> set_password
($password);
123 $new_user -> set_pending_email
($email);
124 $new_user -> set_private_email
($email);
125 $new_user -> set_confirm_code
("ConfirmedByBrAPIApp");
126 #$new_user -> set_disabled("x");
127 $new_user -> set_organization
($organization);
128 $new_user -> store
();
130 #this is being added because the person object still uses two different objects, despite the fact that we've merged the tables
131 my $person_id=$new_user->get_sp_person_id();
132 my $new_person=CXGN
::People
::Person
->new($dbh,$person_id);
133 $new_person->set_first_name($first_name);
134 $new_person->set_last_name($last_name);
135 $new_person->store();
137 $c->stash->{rest
} = {success
=> 1};
140 sub search_parameters
: Path
('/brapiapp/searchparameters') : ActionClass
('REST') { }
142 sub search_parameters_GET
: Args
(0) {
145 my $bcs_schema = $c->dbic_schema('Bio::Chado::Schema', 'sgn_chado');
146 my $current_call = $c->req->param('call');
147 my $cv_id = $bcs_schema->resultset('Cv::Cv')->find({name
=>'BrAPIParameters'})->cv_id();
148 my $brapi_search_params = $bcs_schema->resultset('Cv::Cvterm')->find({cv_id
=>$cv_id, name
=>$current_call})->definition();
149 my @search_params = split ',', $brapi_search_params;
150 $c->stash->{rest
} = {
152 parameters
=> \
@search_params