replace access token example with ... so that lint is happy (this is in the POD and...
[sgn.git] / lib / SGN / Controller / AJAX / BrAPI.pm
blob4dc04fdc925ed9e42c7d14a1b260930d2bfc5973
2 package SGN::Controller::AJAX::BrAPI;
4 use Moose;
5 use JSON::Any;
6 use Data::Dumper;
8 use POSIX;
9 use CXGN::BreedersToolbox::Projects;
10 use CXGN::Trial;
11 use CXGN::Trial::TrialLayout;
12 use CXGN::Stock;
13 use CXGN::Login;
14 use CXGN::Trial::TrialCreate;
15 use CXGN::Trial::Search;
16 use CXGN::Location::LocationLookup;
17 use JSON;
18 use JSON qw( decode_json );
19 use Data::Dumper;
20 use Digest::MD5;
21 use Try::Tiny;
22 use File::Slurp qw | read_file |;
23 use Spreadsheet::WriteExcel;
24 use Time::Piece;
26 use CXGN::BrAPI;
28 BEGIN { extends 'Catalyst::Controller::REST' };
30 __PACKAGE__->config(
31 # Leaving default Content-Type to not break everything. If data is passed that is not parsable as json, and the
32 # data type is not handled in the map below, we get a catalyst error with a 200 response which is not ideal.
33 default => 'application/json',
34 stash_key => 'rest',
35 map => { 'application/json' => 'JSON',
36 # would be nice if we could do image/* instead of explicitly listing each type
37 # also should see if a single list of image types can be used for this and for _get_extension in Images.pm
38 'image/_*' => [ 'Callback', { deserialize => \&deserialize_image, serialize => \&serialize_image } ],
39 'image/jpeg' => [ 'Callback', { deserialize => \&deserialize_image, serialize => \&serialize_image } ],
40 'image/png' => [ 'Callback', { deserialize => \&deserialize_image, serialize => \&serialize_image } ],
41 'image/gif' => [ 'Callback', { deserialize => \&deserialize_image, serialize => \&serialize_image } ],
42 'image/svg+xml' => [ 'Callback', { deserialize => \&deserialize_image, serialize => \&serialize_image } ],
43 'application/pdf' => [ 'Callback', { deserialize => \&deserialize_image, serialize => \&serialize_image } ],
44 'application/postscript' => [ 'Callback', { deserialize => \&deserialize_image, serialize => \&serialize_image } ],
48 has 'brapi_module' => (
49 isa => 'CXGN::BrAPI',
50 is => 'rw',
53 has 'bcs_schema' => (
54 isa => 'Bio::Chado::Schema',
55 is => 'rw',
58 my $DEFAULT_PAGE_SIZE=10;
60 # don't do anything, let catalyst handle putting body into a temp file
61 sub deserialize_image {
62 my ( $self, $data, $c ) = @_;
63 # want $c->request->data to be undefined so that parsing in brapi sub skips it
64 return;
67 # have to serialize the json because using the callbacks in the config map
68 sub serialize_image {
69 my ( $self, $data, $c ) = @_;
70 my $json = JSON->new->allow_nonref;
71 $json->allow_tags;
72 $json->allow_blessed;
73 $json->convert_blessed;
74 my $json_text = $json->encode( $c->stash->{rest} );
76 $c->response->content_type('application/json');
77 return $json_text;
80 sub brapi : Chained('/') PathPart('brapi') CaptureArgs(1) {
81 my $self = shift;
82 my $c = shift;
83 my $version = shift;
84 my @status;
86 my $page = $c->req->param("page") || 0;
87 my $page_size = $c->req->param("pageSize") || $DEFAULT_PAGE_SIZE;
88 my $authorization_token = $c->req->headers->header("Authorization");
89 my $bearer_token = undef;
91 if (defined $authorization_token) {
92 my @bearer = split(/\s/, $authorization_token);
93 if (scalar @bearer == 2) {
94 if ($bearer[0] eq "Bearer") {
95 $bearer_token = $bearer[1];
100 my $session_token = $c->req->headers->header("access_token") || $bearer_token;
102 if (defined $c->request->data){
103 my $data_type = ref $c->request->data;
104 my $current_page;
105 $current_page = $c->request->data->{"page"} if ($data_type ne 'ARRAY');
106 my $current_page_size;
107 $current_page_size = $c->request->data->{"pageSize"} if ($data_type ne 'ARRAY');
108 my $current_session_token;
109 $current_session_token = $c->request->data->{"access_token"} if ($data_type ne 'ARRAY');
110 $page = $current_page || $page || 0;
111 $page_size = $current_page_size || $page_size || $DEFAULT_PAGE_SIZE;
112 $session_token = $current_session_token|| $session_token;
114 my $bcs_schema = $c->dbic_schema('Bio::Chado::Schema', 'sgn_chado');
115 my $metadata_schema = $c->dbic_schema("CXGN::Metadata::Schema");
116 my $phenome_schema = $c->dbic_schema("CXGN::Phenome::Schema");
117 my $people_schema = $c->dbic_schema("CXGN::People::Schema");
118 push @status, { 'INFO' => "BrAPI base call found with page=$page, pageSize=$page_size" };
120 my $brapi = CXGN::BrAPI->new({
121 version => $version,
122 brapi_module_inst => {
123 context => $c,
124 bcs_schema => $bcs_schema,
125 metadata_schema => $metadata_schema,
126 phenome_schema => $phenome_schema,
127 people_schema => $people_schema,
128 page_size => $page_size,
129 page => $page,
130 status => \@status
133 $self->brapi_module($brapi);
134 $self->bcs_schema($bcs_schema);
136 $c->response->headers->header( "Access-Control-Allow-Origin" => '*' );
137 $c->response->headers->header( "Access-Control-Allow-Methods" => "POST, GET, PUT, DELETE" );
138 $c->response->headers->header( 'Access-Control-Allow-Headers' => 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range,Authorization');
139 $c->stash->{session_token} = $session_token;
141 if (defined $c->request->data){
142 # All POST requests accept for search methods require a json array body
143 if ($c->request->method eq "POST" && index($c->request->env->{REQUEST_URI}, "search") == -1){
144 if (ref $c->request->data ne 'ARRAY') {
145 my $response = CXGN::BrAPI::JSONResponse->return_error($c->stash->{status}, 'JSON array body required', 400);
146 _standard_response_construction($c, $response);
148 $c->stash->{clean_inputs} = _clean_inputs($c->req->params,$c->request->data);
149 } elsif ($c->request->method eq "PUT") {
150 if (ref $c->request->data eq 'ARRAY') {
151 my $response = CXGN::BrAPI::JSONResponse->return_error($c->stash->{status}, 'JSON hash body required', 400);
152 _standard_response_construction($c, $response);
154 $c->stash->{clean_inputs} = $c->request->data;
155 } else {
156 $c->stash->{clean_inputs} = $c->request->data;
159 else {
160 $c->stash->{clean_inputs} = _clean_inputs($c->req->params);
164 #useful because javascript can pass 'undef' as an empty value, and also standardizes all inputs as arrayrefs
165 sub _clean_inputs {
166 no warnings 'uninitialized';
167 my $params = shift;
168 my $alldata = shift;
170 if($alldata){
171 my %data = ref $alldata eq 'ARRAY' ? map { $_ => $_} @{$alldata} : %{$alldata};
172 %$params = $params ? (%data, %$params) : %data;
175 foreach (keys %$params){
176 my $values = $params->{$_};
177 my $ret_val;
178 if (ref \$values eq 'SCALAR' || ref $values eq 'ARRAY'){
180 if (ref \$values eq 'SCALAR') {
181 push @$ret_val, $values;
182 } elsif (ref $values eq 'ARRAY'){
183 $ret_val = $values;
186 @$ret_val = grep {$_ ne undef} @$ret_val;
187 @$ret_val = grep {$_ ne ''} @$ret_val;
188 $_ =~ s/\[\]$//; #ajax POST with arrays adds [] to the end of the name e.g. germplasmName[]. since all inputs are arrays now we can remove the [].
189 $params->{$_} = $ret_val;
191 elsif (ref $values eq 'HASH') {
192 $params->{$_} = $values;
194 else {
195 die "Input $_ is not a scalar, arrayref, or a single level hash\n";
199 return $params;
202 sub _validate_request {
203 my $c = shift;
204 my $data_type = shift;
205 my $data = shift;
206 my $required_fields = shift;
207 my $required_field_prefix = shift;
209 if ($required_fields) {
210 # Validate each array element
211 if ($data_type eq 'ARRAY') {
212 foreach my $object (values %{$data}) {
213 # Ignore the query params if they were passed in. Their included in the body
214 if (ref($object) eq 'HASH') {
215 _validate_request($c, 'HASH', $object, $required_fields);
220 # Check all of our fields
221 foreach my $required_field (@{$required_fields}) {
222 # Check if the required field has another level or not
223 if (ref($required_field) eq 'HASH') {
224 # Check the field keys and recurse
225 foreach my $sub_req_field (keys %{$required_field}) {
226 if ($data_type eq 'HASH') {
227 if (!$data->{$sub_req_field}) {
228 _missing_field_response($c, $sub_req_field, $required_field_prefix);
229 } else {
230 my $sub_data = $data->{$sub_req_field};
231 _validate_request($c, 'HASH', $sub_data, $required_field->{$sub_req_field},
232 $required_field_prefix ? sprintf("%s.%s", $required_field_prefix, $sub_req_field): $sub_req_field);
236 next;
239 if ($data_type eq 'HASH') {
240 if (!$data->{$required_field}) {
241 _missing_field_response($c, $required_field, $required_field_prefix);
248 sub _missing_field_response {
249 my $c = shift;
250 my $field_name = shift;
251 my $prefix = shift;
252 my $response = CXGN::BrAPI::JSONResponse->return_error($c->stash->{status}, $prefix ? sprintf("%s.%s required", $prefix, $field_name) : sprintf("%s required", $field_name), 400);
253 _standard_response_construction($c, $response);
256 sub _authenticate_user {
257 my $c = shift;
258 my $force_authenticate = shift;
259 my $status = $c->stash->{status};
260 my $user_id;
261 my $user_type;
262 my $user_pref;
263 my $expired;
264 my $wildcard = 'any';
266 print STDERR "AUTHENTICATING USER status: $status\n";
267 my %server_permission;
268 my $rc = eval{
269 print STDERR "SERVER PERMISSION CHECK...\n";
270 my $server_permission = $c->config->{"brapi_" . $c->request->method};
271 my @server_permission = split ',', $server_permission;
272 %server_permission = map { $_ => 1 } @server_permission;
273 1; };
275 if(!$rc && !%server_permission){
276 $server_permission{$wildcard} = 1;
279 print STDERR "SERVER CHECK DONE...\n";
280 # Check if there is a config for default brapi user. This will be overwritten if a token is passed.
281 # Will still throw error if auth is required
282 if ($c->config->{brapi_default_user} && $c->config->{brapi_require_login} == 0) {
283 print STDERR "BRAPI DEFAULT USER CHECK...\n";
284 $user_id = CXGN::People::Person->get_person_by_username($c->dbc->dbh, $c->config->{brapi_default_user});
285 $user_type = $c->config->{brapi_default_user_role};
286 if (! defined $user_id) {
287 my $brapi_package_result = CXGN::BrAPI::JSONResponse->return_error($status, 'Default brapi user was not found');
288 _standard_response_construction($c, $brapi_package_result, 500);
292 # If our brapi config is set to authenticate or the controller calling this asks for forcing of
293 # authentication or serverinfo call method request auth, we authenticate.
294 my $login = CXGN::Login->new($c->dbc->dbh);
295 if ($c->config->{brapi_require_login} == 1 || $force_authenticate || !exists($server_permission{$wildcard})){
296 print STDERR "REQUIRE LOGIN... logging in user\n";
297 print STDERR "SESSION TOKEN: ".$c->stash->{session_token}."\n";
298 if ($c->stash->{session_token}) {
299 ($user_id, $user_type, $user_pref, $expired) = $login->query_from_cookie($c->stash->{session_token});
300 print STDERR "LOGGING IN USER: ".$user_id." : ".$user_type." : ".$expired;
302 else {
303 print STDERR "GET USER ID FROM LOGIN...\n";
304 if ($c->user) {
305 $user_id = $c->user->get_object->get_sp_person_id();
306 ($user_type) = $c->user->get_object->get_user_type();
308 my $cookie_string = $login->get_login_cookie();
309 print STDERR "USER ID: $user_id, EXPIRED: $expired, USER TYPE: $user_type\n";
310 $c->stash->{session_token} = $login->get_login_cookie();
314 if (!$user_id || $expired || !$user_type || (!exists($server_permission{$user_type}) && !exists($server_permission{$wildcard}))) {
315 my $brapi_package_result = CXGN::BrAPI::JSONResponse->return_error($status, 'You must login and have permission to access this BrAPI call.');
317 _standard_response_construction($c, $brapi_package_result, 401);
321 return (1, $user_id, $user_type, $user_pref, $expired);
324 sub _standard_response_construction {
325 my $c = shift;
326 my $brapi_package_result = shift;
327 my $return_status = shift;
328 my $status = $brapi_package_result->{status};
329 my $pagination = $brapi_package_result->{pagination};
330 my $result = $brapi_package_result->{result};
331 my $datafiles = $brapi_package_result->{datafiles};
333 # some older brapi stuff uses parameter, could refactor at some point
334 if (!$return_status) { $return_status = $brapi_package_result->{http_code} };
336 my %metadata = (pagination=>$pagination, status=>$status, datafiles=>$datafiles);
337 my %response = (metadata=>\%metadata, result=>$result);
338 $c->stash->{rest} = \%response;
339 $c->response->status((!$return_status) ? 200 : $return_status);
340 $c->detach;
343 =head2 /brapi/v1/token
345 Usage: For logging a user in and loggin a user out through the API
346 Desc:
348 For Logging In
349 POST Request:
351 "grant_type" : "password", //(optional, text, `password`) ... The grant type, only allowed value is password, but can be ignored
352 "username" : "user38", // (required, text, `thepoweruser`) ... The username
353 "password" : "secretpw", // (optional, text, `mylittlesecret`) ... The password
354 "client_id" : "blabla" // (optional, text, `blabla`) ... The client id, currently ignored.
357 POST Response:
359 "metadata": {
360 "pagination": {},
361 "status": {},
362 "datafiles": []
364 "userDisplayName": "John Smith",
365 "access_token": "..."
366 "expires_in": "The lifetime in seconds of the access token"
369 For Logging out
370 DELETE Request:
373 "access_token" : "..." // (optional, text, `R6gKDBRxM4HLj6eGi4u5HkQjYoIBTPfvtZzUD8TUzg4`) ... The user access token. Default: current user token.
376 DELETE Response:
378 "metadata": {
379 "pagination" : {},
380 "status" : { "message" : "User has been logged out successfully."},
381 "datafiles": []
383 "result" : {}
386 =cut
388 sub authenticate_token : Chained('brapi') PathPart('token') Args(0) : ActionClass('REST') { }
390 sub authenticate_token_DELETE {
391 my $self = shift;
392 my $c = shift;
393 my $brapi = $self->brapi_module;
394 my $brapi_module = $brapi->brapi_wrapper('Authentication');
395 my $brapi_package_result = $brapi_module->logout();
396 _standard_response_construction($c, $brapi_package_result);
399 sub authenticate_token_GET {
400 my $self = shift;
401 my $c = shift;
402 process_authenticate_token($self,$c);
405 sub authenticate_token_POST {
406 my $self = shift;
407 my $c = shift;
408 process_authenticate_token($self,$c);
411 sub process_authenticate_token {
412 my $self = shift;
413 my $c = shift;
414 my $clean_inputs = $c->stash->{clean_inputs};
415 my $brapi = $self->brapi_module;
416 my $brapi_module = $brapi->brapi_wrapper('Authentication');
417 my $brapi_package_result = $brapi_module->login(
418 $clean_inputs->{grant_type}->[0],
419 $clean_inputs->{password}->[0],
420 $clean_inputs->{username}->[0],
421 $clean_inputs->{client_id}->[0],
424 my $status = $brapi_package_result->{status};
425 my $pagination = $brapi_package_result->{pagination};
426 my $result = $brapi_package_result->{result};
427 my $datafiles = $brapi_package_result->{datafiles};
429 my %metadata = (pagination=>$pagination, status=>$status, datafiles=>$datafiles);
430 my %response = (metadata=>\%metadata, access_token=>$result->{access_token}, userDisplayName=>$result->{userDisplayName}, expires_in=>$CXGN::Login::LOGIN_TIMEOUT);
431 $c->stash->{rest} = \%response;
432 $c->detach();
435 =head2 /brapi/v1/calls
437 Usage: For determining which calls have been implemented and with which datafile types and methods
438 Desc:
440 GET Request:
442 GET Response:
444 "metadata": {
445 "pagination": {
446 "pageSize": 3,
447 "currentPage": 0,
448 "totalCount": 3,
449 "totalPages": 1
451 "status": {},
452 "datafiles": []
454 "result": {
455 "data": [
457 "call": "allelematrix",
458 "datatypes": [
459 "json",
460 "tsv"
462 "methods": [
463 "GET",
464 "POST"
468 "call": "germplasm/id/mcpd",
469 "datatypes": [
470 "json"
472 "methods": [
473 "GET"
477 "call": "doesntexistyet",
478 "datatypes": [
479 "png",
480 "jpg"
482 "methods": [
483 "GET"
490 =cut
492 sub calls : Chained('brapi') PathPart('calls') Args(0) : ActionClass('REST') { }
494 sub calls_GET {
495 my $self = shift;
496 my $c = shift;
497 my ($auth) = _authenticate_user($c);
498 my $clean_inputs = $c->stash->{clean_inputs};
499 my $brapi = $self->brapi_module;
500 my $brapi_module = $brapi->brapi_wrapper('Calls');
501 my $brapi_package_result = $brapi_module->search(
502 $clean_inputs
504 _standard_response_construction($c, $brapi_package_result);
507 =head2 /brapi/v2/serverinfo
509 Usage: For determining which endpoints have been implemented and with which datafile types and methods
510 Desc:
512 GET Request:
514 GET Response:
516 "metadata": {
517 "pagination": {
518 "pageSize": 3,
519 "currentPage": 0,
520 "totalCount": 3,
521 "totalPages": 1
523 "status": {},
524 "datafiles": []
526 "result": {
527 "data": [
529 "call": "allelematrix",
530 "datatypes": [
531 "json",
532 "tsv"
534 "methods": [
535 "GET",
536 "POST"
540 "call": "germplasm/id/mcpd",
541 "datatypes": [
542 "json"
544 "methods": [
545 "GET"
549 "call": "doesntexistyet",
550 "datatypes": [
551 "png",
552 "jpg"
554 "methods": [
555 "GET"
562 =cut
564 sub serverinfo : Chained('brapi') PathPart('serverinfo') Args(0) : ActionClass('REST') { }
566 sub serverinfo_GET {
567 my $self = shift;
568 my $c = shift;
569 my ($auth) = _authenticate_user($c);
570 my $clean_inputs = $c->stash->{clean_inputs};
571 my $brapi = $self->brapi_module;
572 my $brapi_module = $brapi->brapi_wrapper('ServerInfo');
573 my $brapi_package_result = $brapi_module->search($c,$clean_inputs);
574 _standard_response_construction($c, $brapi_package_result);
577 sub crops : Chained('brapi') PathPart('crops') Args(0) : ActionClass('REST') { }
579 sub crops_GET {
580 my $self = shift;
581 my $c = shift;
582 my $supported_crop = $c->config->{'supportedCrop'};
583 my $brapi = $self->brapi_module;
584 my $brapi_module = $brapi->brapi_wrapper('Crops');
585 my $brapi_package_result = $brapi_module->crops($supported_crop);
586 _standard_response_construction($c, $brapi_package_result);
589 sub commoncropnames : Chained('brapi') PathPart('commoncropnames') Args(0) : ActionClass('REST') { }
591 sub commoncropnames_GET {
592 my $self = shift;
593 my $c = shift;
594 my $supported_crop = $c->config->{'supportedCrop'};
595 my $brapi = $self->brapi_module;
596 my $brapi_module = $brapi->brapi_wrapper('CommonCropNames');
597 my $brapi_package_result = $brapi_module->crops($supported_crop);
598 _standard_response_construction($c, $brapi_package_result);
601 sub observation_levels : Chained('brapi') PathPart('observationlevels') Args(0) : ActionClass('REST') { }
603 sub observation_levels_GET {
604 my $self = shift;
605 my $c = shift;
606 my $brapi = $self->brapi_module;
607 my $brapi_module = $brapi->brapi_wrapper('ObservationVariables');
608 my $brapi_package_result = $brapi_module->observation_levels();
609 _standard_response_construction($c, $brapi_package_result);
612 sub seasons : Chained('brapi') PathPart('seasons') Args(0) : ActionClass('REST') { }
614 sub seasons_POST {
615 my $self = shift;
616 my $c = shift;
617 my ($auth, $user_id) = _authenticate_user($c);
618 my $clean_inputs = $c->stash->{clean_inputs};
619 my $postedData = $clean_inputs;
620 my @data;
621 foreach my $season (values %{$postedData}) {
622 push @data, {
623 seasonDbId=>$season->{year},
624 season=>undef,
625 year=>$season->{year}
628 my $pagination = CXGN::BrAPI::Pagination->pagination_response(scalar(@data), scalar(@data), 1);
629 my %result = (data=>\@data);
630 my @data_files;
631 my $status;
632 _standard_response_construction($c, CXGN::BrAPI::JSONResponse->return_success(\%result, $pagination, \@data_files, $status, "Season created successfully"));
635 sub seasons_GET {
636 my $self = shift;
637 my $c = shift;
638 seasons_process($self, $c);
641 sub seasons_process {
642 my $self = shift;
643 my $c = shift;
644 my ($auth) = _authenticate_user($c);
645 my $clean_inputs = $c->stash->{clean_inputs};
646 my $brapi = $self->brapi_module;
647 my $brapi_module = $brapi->brapi_wrapper('Studies');
648 my $brapi_package_result = $brapi_module->seasons(
649 $clean_inputs->{year}->[0],
651 _standard_response_construction($c, $brapi_package_result);
654 sub season_single : Chained('brapi') PathPart('seasons') CaptureArgs(1) {
655 my $self = shift;
656 my $c = shift;
657 my $id = shift;
658 $c->stash->{seasonDbId} = $id;
661 sub season_fetch : Chained('season_single') PathPart('') Args(0) : ActionClass('REST') { }
664 sub season_fetch_GET {
665 my $self = shift;
666 my $c = shift;
667 my ($auth) = _authenticate_user($c);
668 my $clean_inputs = $c->stash->{clean_inputs};
669 my $brapi = $self->brapi_module;
670 my $brapi_module = $brapi->brapi_wrapper('Seasons');
671 my $brapi_package_result = $brapi_module->detail($c->stash->{seasonDbId});
672 _standard_response_construction($c, $brapi_package_result);
675 sub season_search : Chained('brapi') PathPart('search/seasons') Args(0) : ActionClass('REST') { }
677 sub season_search_POST {
678 my $self = shift;
679 my $c = shift;
680 save_results($self,$c,$c->stash->{clean_inputs},'Seasons');
683 sub season_search_retrieve : Chained('brapi') PathPart('search/seasons') Args(1) {
684 my $self = shift;
685 my $c = shift;
686 my $search_id = shift;
687 retrieve_results($self, $c, $search_id, 'Seasons');
691 =head2 brapi/v1/studyTypes
693 Usage: To retrieve a list of programs being worked onthe various study types
694 Desc:
695 Return JSON example:
697 "metadata" : {
698 "pagination": {
699 "pageSize": 10,
700 "currentPage": 1,
701 "totalCount": 10,
702 "totalPages": 1
704 "status": []
706 "result" : {
707 "data" : [
709 "name": "Nursery",
710 "description": "Description for Nursery study type"
713 "name": "Trial",
714 "description": "Description for Nursery study type"
719 Args:
720 Side Effects:
722 =cut
724 sub study_types : Chained('brapi') PathPart('studytypes') Args(0) : ActionClass('REST') { }
726 sub study_types_POST {
727 my $self = shift;
728 my $c = shift;
729 study_types_process($self, $c);
732 sub study_types_GET {
733 my $self = shift;
734 my $c = shift;
735 study_types_process($self, $c);
738 sub study_types_process {
739 my $self = shift;
740 my $c = shift;
741 my ($auth) = _authenticate_user($c);
742 my $brapi = $self->brapi_module;
743 my $brapi_module = $brapi->brapi_wrapper('Studies');
744 my $brapi_package_result = $brapi_module->study_types();
745 _standard_response_construction($c, $brapi_package_result);
751 =head2 /brapi/v1/germplasm-search?germplasmName=&germplasmGenus=&germplasmSubTaxa=&germplasmDbId&germplasmPUI=http://data.inra.fr/accession/234Col342&germplasmSpecies=Triticum&panel=diversitypanel1&collection=none&pageSize=pageSize&page=page
753 Usage: For searching a germplasm by name. Allows for exact and wildcard match methods. http://docs.brapi.apiary.io/#germplasm
754 Desc:
756 POST Request:
759 "germplasmPUI" : "http://...", // (optional, text, `http://data.inra.fr/accession/234Col342`) ... The name or synonym of external genebank accession identifier
760 "germplasmDbId" : 986, // (optional, text, `986`) ... The name or synonym of external genebank accession identifier
761 "germplasmSpecies" : "tomato", // (optional, text, `aestivum`) ... The name or synonym of genus or species ( merge with below ?)
762 "germplasmGenus" : "Solanum lycopersicum", //(optional, text, `Triticum, Hordeum`) ... The name or synonym of genus or species
763 "germplasmName" : "XYZ1", // (optional, text, `Triticum, Hordeum`) ... The name or synonym of the accession
764 "accessionNumber" : "ITC1234" // optional
765 "pageSize" : 100, // (optional, integer, `1000`) ... The size of the pages to be returned. Default is `1000`.
766 "page": 1 (optional, integer, `10`) ... Which result page is requested
770 POST Response:
772 "metadata": {
773 "status": {},
774 "datafiles": [],
775 "pagination": {
776 "pageSize": 10,
777 "currentPage": 1,
778 "totalCount": 2,
779 "totalPages": 1
782 "result": {
783 "data":[
785 "germplasmDbId": "01BEL084609",
786 "defaultDisplayName": "Pahang",
787 "accessionNumber": "ITC0609",
788 "germplasmName": "Pahang",
789 "germplasmPUI": "http://www.crop-diversity.org/mgis/accession/01BEL084609",
790 "pedigree": "TOBA97/SW90.1057",
791 "germplasmSeedSource": "Female GID:4/Male GID:4",
792 "synonyms": [ ],
793 "commonCropName": "banana",
794 "instituteCode": "01BEL084",
795 "instituteName": "ITC",
796 "biologicalStatusOfAccessionCode": 412,
797 "countryOfOriginCode": "UNK",
798 "typeOfGermplasmStorageCode": 10,
799 "genus": "Musa",
800 "species": "acuminata",
801 "speciesAuthority": "",
802 "subtaxa": "sp malaccensis var pahang",
803 "subtaxaAuthority": "",
804 "donors":
807 "donorAccessionNumber": "",
808 "donorInstituteCode": "",
809 "germplasmPUI": ""
812 "acquisitionDate": "19470131"
818 =cut
820 sub germplasm_search_old : Chained('brapi') PathPart('germplasm-search') Args(0) : ActionClass('REST') { }
822 sub germplasm_search_old_GET {
823 my $self = shift;
824 my $c = shift;
825 my ($auth) = _authenticate_user($c);
826 my $clean_inputs = $c->stash->{clean_inputs};
827 my $brapi = $self->brapi_module;
828 my $brapi_module = $brapi->brapi_wrapper('Germplasm');
829 my $brapi_package_result = $brapi_module->search({
830 germplasmName => $clean_inputs->{germplasmName},
831 accessionNumber => $clean_inputs->{accessionNumber},
832 germplasmGenus => $clean_inputs->{germplasmGenus},
833 germplasmSubTaxa => $clean_inputs->{germplasmSubTaxa},
834 germplasmSpecies => $clean_inputs->{germplasmSpecies},
835 germplasmDbId => $clean_inputs->{germplasmDbId},
836 germplasmPUI => $clean_inputs->{germplasmPUI},
837 matchMethod => $clean_inputs->{matchMethod},
839 _standard_response_construction($c, $brapi_package_result);
842 sub germplasm_search_old_POST {
843 my $self = shift;
844 my $c = shift;
845 # my ($auth) = _authenticate_user($c);
846 my $clean_inputs = $c->stash->{clean_inputs};
847 my $brapi = $self->brapi_module;
848 my $brapi_module = $brapi->brapi_wrapper('Germplasm');
849 my $brapi_package_result = $brapi_module->search({
850 germplasmName => $clean_inputs->{germplasmNames},
851 accessionNumber => $clean_inputs->{accessionNumbers},
852 germplasmGenus => $clean_inputs->{germplasmGenus},
853 germplasmSubTaxa => $clean_inputs->{germplasmSubTaxa},
854 germplasmSpecies => $clean_inputs->{germplasmSpecies},
855 germplasmDbId => $clean_inputs->{germplasmDbIds},
856 germplasmPUI => $clean_inputs->{germplasmPUIs},
857 matchMethod => $clean_inputs->{matchMethod},
859 _standard_response_construction($c, $brapi_package_result);
862 sub germplasm : Chained('brapi') PathPart('germplasm') Args(0) : ActionClass('REST') { }
864 sub germplasm_GET {
865 my $self = shift;
866 my $c = shift;
867 my $auth = _authenticate_user($c);
868 my $clean_inputs = $c->stash->{clean_inputs};
869 my $brapi = $self->brapi_module;
870 my $brapi_module = $brapi->brapi_wrapper('Germplasm');
871 my $brapi_package_result = $brapi_module->search($clean_inputs,$c);
873 _standard_response_construction($c, $brapi_package_result);
876 sub germplasm_POST {
877 my $self = shift;
878 my $c = shift;
879 my ($auth,$user_id) = _authenticate_user($c);
880 my $clean_inputs = $c->stash->{clean_inputs};
881 my $data = $clean_inputs;
882 my @all_germplasm;
883 foreach my $germplasm (values %{$data}) {
884 push @all_germplasm, $germplasm;
886 my $brapi = $self->brapi_module;
887 my $brapi_module = $brapi->brapi_wrapper('Germplasm');
888 my $brapi_package_result = $brapi_module->store(\@all_germplasm,$user_id,$c);
890 _standard_response_construction($c, $brapi_package_result);
893 sub germplasm_search_save : Chained('brapi') PathPart('search/germplasm') Args(0) : ActionClass('REST') { }
895 sub germplasm_search_save_POST {
896 my $self = shift;
897 my $c = shift;
898 save_results($self,$c,$c->stash->{clean_inputs},'Germplasm');
901 sub germplasm_search_retrieve : Chained('brapi') PathPart('search/germplasm') Args(1) {
902 my $self = shift;
903 my $c = shift;
904 my $search_id = shift;
905 retrieve_results($self, $c, $search_id, 'Germplasm');
908 =head2 brapi/v1/germplasm/{id}
910 Usage: To retrieve details for a single germplasm
911 Desc:
912 Return JSON example:
914 "metadata": {
915 "status": [],
916 "pagination": {}
918 "result": {
919 "germplasmDbId": "01BEL084609",
920 "defaultDisplayName": "Pahang",
921 "germplasmName": "Pahang",
922 "accessionNumber": "ITC0609",
923 "germplasmPUI": "http://www.crop-diversity.org/mgis/accession/01BEL084609",
924 "pedigree": "TOBA97/SW90.1057",
925 "seedSource": "Female GID:4/Male GID:4",
926 "synonyms": ["Pahanga","Pahange"],
929 Args:
930 Side Effects:
932 =cut
934 sub germplasm_single : Chained('brapi') PathPart('germplasm') CaptureArgs(1) {
935 my $self = shift;
936 my $c = shift;
937 my $stock_id = shift;
939 $c->stash->{stock_id} = $stock_id;
943 sub germplasm_detail : Chained('germplasm_single') PathPart('') Args(0) : ActionClass('REST') { }
945 sub germplasm_detail_GET {
946 my $self = shift;
947 my $c = shift;
948 my ($auth) = _authenticate_user($c);
949 my $clean_inputs = $c->stash->{clean_inputs};
950 my $brapi = $self->brapi_module;
951 my $brapi_module = $brapi->brapi_wrapper('Germplasm');
952 my $brapi_package_result = $brapi_module->germplasm_detail(
953 $c->stash->{stock_id},$c
955 _standard_response_construction($c, $brapi_package_result);
958 sub germplasm_detail_PUT {
959 my $self = shift;
960 my $c = shift;
961 my ($auth,$user_id) = _authenticate_user($c);
962 my $clean_inputs = $c->stash->{clean_inputs};
963 my $data = $clean_inputs;
964 my @all_germplasm;
965 push @all_germplasm, $data;
966 my $brapi = $self->brapi_module;
967 my $brapi_module = $brapi->brapi_wrapper('Germplasm');
968 my $brapi_package_result = $brapi_module->update($c->stash->{stock_id},\@all_germplasm,$user_id,$c);
970 _standard_response_construction($c, $brapi_package_result);
973 =head2 brapi/v1/germplasm/{id}/MCPD
975 MCPD CALL NO LONGER IN BRAPI SPEC
977 Usage: To retrieve multi crop passport descriptor for a single germplasm
978 Desc:
979 Return JSON example:
981 "metadata": {
982 "status": [],
983 "pagination": {}
985 "result": {
986 "germplasmDbId": "01BEL084609",
987 "defaultDisplayName": "Pahang",
988 "accessionNumber": "ITC0609",
989 "germplasmName": "Pahang",
990 "germplasmPUI": "http://www.crop-diversity.org/mgis/accession/01BEL084609",
991 "pedigree": "TOBA97/SW90.1057",
992 "germplasmSeedSource": "Female GID:4/Male GID:4",
993 "synonyms": [ ],
994 "commonCropName": "banana",
995 "instituteCode": "01BEL084",
996 "instituteName": "ITC",
997 "biologicalStatusOfAccessionCode": 412,
998 "countryOfOriginCode": "UNK",
999 "typeOfGermplasmStorageCode": 10,
1000 "genus": "Musa",
1001 "species": "acuminata",
1002 "speciesAuthority": "",
1003 "subtaxa": "sp malaccensis var pahang",
1004 "subtaxaAuthority": "",
1005 "donors":
1008 "donorAccessionNumber": "",
1009 "donorInstituteCode": "",
1010 "germplasmPUI": ""
1013 "acquisitionDate": "19470131"
1015 Args:
1016 Side Effects:
1018 =cut
1020 sub germplasm_mcpd : Chained('germplasm_single') PathPart('mcpd') Args(0) : ActionClass('REST') { }
1022 sub germplasm_mcpd_GET {
1023 my $self = shift;
1024 my $c = shift;
1025 my ($auth) = _authenticate_user($c);
1026 my $clean_inputs = $c->stash->{clean_inputs};
1027 my $brapi = $self->brapi_module;
1028 my $brapi_module = $brapi->brapi_wrapper('Germplasm');
1029 my $brapi_package_result = $brapi_module->germplasm_mcpd(
1030 $c->stash->{stock_id}
1032 _standard_response_construction($c, $brapi_package_result);
1036 #BrAPI Trials are modeled as Folders
1037 sub trials_list : Chained('brapi') PathPart('trials') Args(0) : ActionClass('REST') { }
1039 sub trials_list_GET {
1040 my $self = shift;
1041 my $c = shift;
1042 trials_search_process($self, $c);
1045 sub trials_list_POST {
1046 my $self = shift;
1047 my $c = shift;
1048 my ($auth,$user_id) = _authenticate_user($c);
1049 my $clean_inputs = $c->stash->{clean_inputs};
1050 my $data = $clean_inputs;
1051 my @all_trials;
1052 foreach my $trials (values %{$data}) {
1053 push @all_trials, $trials;
1055 my $brapi = $self->brapi_module;
1056 my $brapi_module = $brapi->brapi_wrapper('Trials');
1057 my $brapi_package_result = $brapi_module->store(\@all_trials,$user_id);
1058 _standard_response_construction($c, $brapi_package_result);
1061 sub trials_search_process {
1062 my $self = shift;
1063 my $c = shift;
1064 my ($auth) = _authenticate_user($c);
1065 my $clean_inputs = $c->stash->{clean_inputs};
1066 my $brapi = $self->brapi_module;
1067 my $brapi_module = $brapi->brapi_wrapper('Trials');
1068 my $brapi_package_result = $brapi_module->search({
1069 crop => $c->config->{supportedCrop},
1070 contactDbIds => $clean_inputs->{contactDbId},
1071 searchDateRangeStart => $clean_inputs->{searchDateRangeStart},
1072 searchDateRangeEnd => $clean_inputs->{searchDateRangeEnd},
1073 trialPUIs => $clean_inputs->{trialPUI},
1074 externalReferenceIDs => $clean_inputs->{externalReferenceID},
1075 externalReferenceIds => $clean_inputs->{externalReferenceId},
1076 externalReferenceSources => $clean_inputs->{externalReferenceSource},
1077 active => $clean_inputs->{active},
1078 commonCropNames => $clean_inputs->{commonCropName},
1079 programDbIds => $clean_inputs->{programDbId},
1080 locationDbIds => $clean_inputs->{locationDbId},
1081 studyDbIds => $clean_inputs->{studyDbId},
1082 trialDbIds => $clean_inputs->{trialDbId},
1083 trialNames => $clean_inputs->{trialName},
1086 _standard_response_construction($c, $brapi_package_result);
1090 sub trials_single : Chained('brapi') PathPart('trials') CaptureArgs(1) {
1091 my $self = shift;
1092 my $c = shift;
1093 my $folder_id = shift;
1095 $c->stash->{trial_id} = $folder_id;
1099 sub trials_detail : Chained('trials_single') PathPart('') Args(0) : ActionClass('REST') { }
1101 sub trials_detail_PUT {
1102 my $self = shift;
1103 my $c = shift;
1104 my ($auth,$user_id) = _authenticate_user($c);
1105 my $clean_inputs = $c->stash->{clean_inputs};
1106 my $data = $clean_inputs;
1107 $data->{trialDbId} = $c->stash->{trial_id};
1108 my $brapi = $self->brapi_module;
1109 my $brapi_module = $brapi->brapi_wrapper('Trials');
1110 my $brapi_package_result = $brapi_module->update($data,$user_id,$c->config->{supportedCrop});
1111 _standard_response_construction($c, $brapi_package_result);
1114 sub trials_detail_GET {
1115 my $self = shift;
1116 my $c = shift;
1117 my ($auth) = _authenticate_user($c);
1118 my $clean_inputs = $c->stash->{clean_inputs};
1119 my $brapi = $self->brapi_module;
1120 my $brapi_module = $brapi->brapi_wrapper('Trials');
1121 my $brapi_package_result = $brapi_module->details(
1122 $c->stash->{trial_id},
1123 $c->config->{supportedCrop}
1125 _standard_response_construction($c, $brapi_package_result);
1128 sub trials_search_save : Chained('brapi') PathPart('search/trials') Args(0) : ActionClass('REST') { }
1130 sub trials_search_save_POST {
1131 my $self = shift;
1132 my $c = shift;
1133 save_results($self,$c,$c->stash->{clean_inputs},'Trials');
1136 sub trials_search_retrieve : Chained('brapi') PathPart('search/trials') Args(1) {
1137 my $self = shift;
1138 my $c = shift;
1139 my $search_id = shift;
1140 retrieve_results($self, $c, $search_id, 'Trials');
1144 =head2 brapi/v1/germplasm/{id}/pedigree?notation=purdy
1146 Usage: To retrieve pedigree information for a single germplasm
1147 Desc:
1148 Return JSON example:
1150 "metadata": {
1151 "status": [],
1152 "pagination": {}
1154 "result": {
1155 "germplasmDbId": "382",
1156 "pedigree": "TOBA97/SW90.1057",
1157 "parent1Id": "23",
1158 "parent2Id": "55"
1161 Args:
1162 Side Effects:
1164 =cut
1166 sub germplasm_pedigree : Chained('germplasm_single') PathPart('pedigree') Args(0) : ActionClass('REST') { }
1168 sub germplasm_pedigree_POST {
1169 my $self = shift;
1170 my $c = shift;
1171 #my $auth = _authenticate_user($c);
1174 sub germplasm_pedigree_GET {
1175 my $self = shift;
1176 my $c = shift;
1177 my ($auth) = _authenticate_user($c);
1178 my $clean_inputs = $c->stash->{clean_inputs};
1179 my $brapi = $self->brapi_module;
1180 my $brapi_module = $brapi->brapi_wrapper('Germplasm');
1181 my $brapi_package_result = $brapi_module->germplasm_pedigree({
1182 stock_id => $c->stash->{stock_id},
1183 notation => $clean_inputs->{notation}->[0]
1185 _standard_response_construction($c, $brapi_package_result);
1189 =head2 brapi/v1/germplasm/{id}/progeny?notation=purdy
1191 Usage: To retrieve progeny (direct descendant) information for a single germplasm
1192 Desc:
1193 Return JSON example:
1195 "metadata" : {
1196 "pagination": {},
1197 "status": [],
1198 "datafiles": []
1200 "result" : {
1201 "germplasmDbId": "382",
1202 "defaultDisplayName": "Pahang",
1203 "data" : [{
1204 "progenyGermplasmDbId": "403",
1205 "parentType": "FEMALE"
1206 }, {
1207 "progenyGermplasmDbId": "402",
1208 "parentType": "MALE"
1209 }, {
1210 "progenyGermplasmDbId": "405",
1211 "parentType": "SELF"
1215 Args:
1216 Side Effects:
1218 =cut
1220 sub germplasm_progeny : Chained('germplasm_single') PathPart('progeny') Args(0) : ActionClass('REST') { }
1222 sub germplasm_progeny_POST {
1223 my $self = shift;
1224 my $c = shift;
1227 sub germplasm_progeny_GET {
1228 my $self = shift;
1229 my $c = shift;
1230 my ($auth) = _authenticate_user($c);
1231 my $clean_inputs = $c->stash->{clean_inputs};
1232 my $brapi = $self->brapi_module;
1233 my $brapi_module = $brapi->brapi_wrapper('Germplasm');
1234 my $brapi_package_result = $brapi_module->germplasm_progeny({
1235 stock_id => $c->stash->{stock_id}
1237 _standard_response_construction($c, $brapi_package_result);
1240 sub germplasm_attributes_detail : Chained('germplasm_single') PathPart('attributes') Args(0) : ActionClass('REST') { }
1242 sub germplasm_attributes_detail_GET {
1243 my $self = shift;
1244 my $c = shift;
1245 my ($auth) = _authenticate_user($c);
1246 my $clean_inputs = $c->stash->{clean_inputs};
1247 my $brapi = $self->brapi_module;
1248 my $brapi_module = $brapi->brapi_wrapper('GermplasmAttributes');
1249 my $brapi_package_result = $brapi_module->germplasm_attributes_germplasm_detail({
1250 stock_id => $c->stash->{stock_id},
1251 attribute_dbids => $clean_inputs->{attributeDbId}
1253 _standard_response_construction($c, $brapi_package_result);
1256 =head2 brapi/v1/germplasm/{id}/markerprofiles
1258 Usage: To retrieve markerprofile ids for a single germplasm
1259 Desc:
1260 Return JSON example:
1262 "metadata": {
1263 "status": [],
1264 "pagination": {}
1266 "result": {
1267 "germplasmDbId": "382",
1268 "markerProfiles": [
1269 "123",
1270 "456"
1274 Args:
1275 Side Effects:
1277 =cut
1279 sub germplasm_markerprofile : Chained('germplasm_single') PathPart('markerprofiles') Args(0) : ActionClass('REST') { }
1281 sub germplasm_markerprofile_POST {
1282 my $self = shift;
1283 my $c = shift;
1284 #my $auth = _authenticate_user($c);
1287 sub germplasm_markerprofile_GET {
1288 my $self = shift;
1289 my $c = shift;
1290 my ($auth) = _authenticate_user($c);
1291 my $clean_inputs = $c->stash->{clean_inputs};
1292 my $brapi = $self->brapi_module;
1293 my $brapi_module = $brapi->brapi_wrapper('Germplasm');
1294 my $brapi_package_result = $brapi_module->germplasm_markerprofiles(
1295 $c->stash->{stock_id}
1297 _standard_response_construction($c, $brapi_package_result);
1302 # Germplasm Attributes
1305 sub germplasm_attributes_list : Chained('brapi') PathPart('attributes') Args(0) : ActionClass('REST') { }
1307 sub germplasm_attributes_list_GET {
1308 my $self = shift;
1309 my $c = shift;
1310 germplasm_attributes_process($self, $c);
1313 sub germplasm_attributes_process {
1314 my $self = shift;
1315 my $c = shift;
1316 my ($auth) = _authenticate_user($c);
1317 my $clean_inputs = $c->stash->{clean_inputs};
1318 my $brapi = $self->brapi_module;
1319 my $brapi_module = $brapi->brapi_wrapper('GermplasmAttributes');
1320 my $brapi_package_result = $brapi_module->search($clean_inputs);
1321 _standard_response_construction($c, $brapi_package_result);
1324 sub attribute_single : Chained('brapi') PathPart('attributes') CaptureArgs(1) {
1325 my $self = shift;
1326 my $c = shift;
1327 my $attribute_id = shift;
1329 $c->stash->{attribute_id} = $attribute_id;
1332 sub attribute_detail : Chained('attribute_single') PathPart('') Args(0) : ActionClass('REST') { }
1334 sub attribute_detail_GET {
1335 my $self = shift;
1336 my $c = shift;
1337 my ($auth) = _authenticate_user($c);
1338 my $clean_inputs = $c->stash->{clean_inputs};
1339 my $brapi = $self->brapi_module;
1340 my $brapi_module = $brapi->brapi_wrapper('GermplasmAttributes');
1341 my $brapi_package_result = $brapi_module->detail($c->stash->{attribute_id});
1342 _standard_response_construction($c, $brapi_package_result);
1345 sub germplasm_attribute_categories_list : Chained('brapi') PathPart('attributes/categories') Args(0) : ActionClass('REST') { }
1347 sub germplasm_attribute_categories_list_GET {
1348 my $self = shift;
1349 my $c = shift;
1350 my ($auth) = _authenticate_user($c);
1351 my $brapi = $self->brapi_module;
1352 my $brapi_module = $brapi->brapi_wrapper('GermplasmAttributes');
1353 my $brapi_package_result = $brapi_module->germplasm_attributes_categories_list();
1354 _standard_response_construction($c, $brapi_package_result);
1357 sub attributes_save : Chained('brapi') PathPart('search/attributes') Args(0) : ActionClass('REST') { }
1359 sub attributes_save_POST {
1360 my $self = shift;
1361 my $c = shift;
1362 save_results($self,$c,$c->stash->{clean_inputs},'GermplasmAttributes');
1365 sub attributes_retrieve : Chained('brapi') PathPart('search/attributes') Args(1) {
1366 my $self = shift;
1367 my $c = shift;
1368 my $search_id = shift;
1369 retrieve_results($self, $c, $search_id, 'GermplasmAttributes');
1373 sub germplasm_attributes_values : Chained('brapi') PathPart('attributevalues') Args(0) : ActionClass('REST') { }
1375 sub germplasm_attributes_values_GET {
1376 my $self = shift;
1377 my $c = shift;
1378 my ($auth) = _authenticate_user($c);
1379 my $clean_inputs = $c->stash->{clean_inputs};
1380 my $brapi = $self->brapi_module;
1381 my $brapi_module = $brapi->brapi_wrapper('GermplasmAttributeValues');
1382 my $brapi_package_result = $brapi_module->search($clean_inputs);
1383 _standard_response_construction($c, $brapi_package_result);
1386 sub germplasm_attributes_values_single : Chained('brapi') PathPart('attributevalues') CaptureArgs(1) {
1387 my $self = shift;
1388 my $c = shift;
1389 my $value_id = shift;
1391 $c->stash->{value_id} = $value_id;
1394 sub germplasm_attributes_values_detail : Chained('germplasm_attributes_values_single') PathPart('') Args(0) : ActionClass('REST') { }
1396 sub germplasm_attributes_values_detail_GET {
1397 my $self = shift;
1398 my $c = shift;
1399 my ($auth) = _authenticate_user($c);
1400 my $clean_inputs = $c->stash->{clean_inputs};
1401 $clean_inputs->{attributeValueDbId}=[$c->stash->{value_id}];
1402 my $brapi = $self->brapi_module;
1403 my $brapi_module = $brapi->brapi_wrapper('GermplasmAttributeValues');
1404 my $brapi_package_result = $brapi_module->search($clean_inputs);
1405 _standard_response_construction($c, $brapi_package_result);
1408 sub attributes_values_save : Chained('brapi') PathPart('search/attributevalues') Args(0) : ActionClass('REST') { }
1410 sub attributes_values_save_POST {
1411 my $self = shift;
1412 my $c = shift;
1413 save_results($self,$c,$c->stash->{clean_inputs},'GermplasmAttributeValues');
1416 sub attributes_values_retrieve : Chained('brapi') PathPart('search/attributevalues') Args(1) {
1417 my $self = shift;
1418 my $c = shift;
1419 my $search_id = shift;
1420 retrieve_results($self, $c, $search_id, 'GermplasmAttributeValues');
1423 =head2 brapi/v1/markerprofiles?germplasm=germplasmDbId&extract=extractDbId&method=methodDbId
1425 Usage: To retrieve markerprofile ids for a single germplasm
1426 Desc:
1427 Return JSON example:
1429 "metadata" : {
1430 "pagination": {
1431 "pageSize": 10,
1432 "currentPage": 1,
1433 "totalCount": 10,
1434 "totalPages": 1
1436 "status": []
1438 "result" : {
1439 "data" : [
1441 "markerProfileDbId": "993",
1442 "germplasmDbId" : 2374,
1443 "extractDbId" : 3939,
1444 "analysisMethod": "GoldenGate",
1445 "resultCount": 1470
1448 "markerProfileDbId": "994",
1449 "germplasmDbId" : 2374,
1450 "extractDbId" : 3939,
1451 "analysisMethod": "GBS",
1452 "resultCount": 1470
1457 Args:
1458 Side Effects:
1460 =cut
1462 sub markerprofile_search_process {
1463 my $self = shift;
1464 my $c = shift;
1465 my ($auth) = _authenticate_user($c);
1466 my $default_protocol = $self->bcs_schema->resultset('NaturalDiversity::NdProtocol')->find({name=>$c->config->{default_genotyping_protocol}});
1467 my $default_protocol_id = $default_protocol ? $default_protocol->nd_protocol_id : 0;
1468 my $clean_inputs = $c->stash->{clean_inputs};
1469 my $brapi = $self->brapi_module;
1470 my $brapi_module = $brapi->brapi_wrapper('Markerprofiles');
1471 my $brapi_package_result = $brapi_module->markerprofiles_search({
1472 cache_file_path => $c->config->{cache_file_path},
1473 shared_cluster_dir => $c->config->{cluster_shared_tempdir},
1474 study_ids => $clean_inputs->{studyDbId},
1475 stock_ids => $clean_inputs->{germplasmDbId},
1476 extract_ids => $clean_inputs->{extractDbId},
1477 sample_ids => $clean_inputs->{sampleDbId},
1478 protocol_ids => $clean_inputs->{methodDbId}
1480 _standard_response_construction($c, $brapi_package_result);
1483 sub markerprofiles_list : Chained('brapi') PathPart('markerprofiles') Args(0) : ActionClass('REST') { }
1485 sub markerprofiles_list_POST {
1486 my $self = shift;
1487 my $c = shift;
1488 markerprofile_search_process($self, $c);
1491 sub markerprofiles_list_GET {
1492 my $self = shift;
1493 my $c = shift;
1494 markerprofile_search_process($self, $c);
1498 =head2 brapi/v1/markerprofiles/markerprofilesDbId
1500 Usage: To retrieve data for a single markerprofile
1501 Desc:
1502 Return JSON example:
1504 "metadata" : {
1505 "pagination": {
1506 "pageSize": 10,
1507 "currentPage": 1,
1508 "totalCount": 10,
1509 "totalPages": 1
1511 "status": []
1514 "result": {
1515 "germplasmDbId": 993,
1516 "extractDbId" : 38383,
1517 "markerprofileDbId": 37484,
1518 "analysisMethod": "GBS-Pst1",
1519 "encoding": "AA,BB,AB",
1520 "data" : [ { "marker1": "AA" }, { "marker2":"AB" }, ... ]
1523 Args:
1524 Side Effects:
1526 =cut
1528 sub markerprofiles_single : Chained('brapi') PathPart('markerprofiles') CaptureArgs(1) {
1529 my $self = shift;
1530 my $c = shift;
1531 my $id = shift;
1532 $c->stash->{markerprofile_id} = $id; # this is genotypeprop_id
1535 sub genotype_fetch : Chained('markerprofiles_single') PathPart('') Args(0) : ActionClass('REST') { }
1537 sub genotype_fetch_POST {
1538 my $self = shift;
1539 my $c = shift;
1540 #my $auth = _authenticate_user($c);
1543 sub genotype_fetch_GET {
1544 my $self = shift;
1545 my $c = shift;
1546 my ($auth) = _authenticate_user($c);
1547 my $clean_inputs = $c->stash->{clean_inputs};
1548 my $brapi = $self->brapi_module;
1549 my $brapi_module = $brapi->brapi_wrapper('Markerprofiles');
1550 my $brapi_package_result = $brapi_module->markerprofiles_detail({
1551 cache_file_path => $c->config->{cache_file_path},
1552 shared_cluster_dir => $c->config->{cluster_shared_tempdir},
1553 markerprofile_id => $c->stash->{markerprofile_id},
1554 unknown_string => $clean_inputs->{unknownString}->[0],
1555 sep_phased => $clean_inputs->{sepPhased}->[0],
1556 sep_unphased => $clean_inputs->{sepUnphased}->[0],
1557 expand_homozygotes => $clean_inputs->{expandHomozygotes}->[0],
1559 _standard_response_construction($c, $brapi_package_result);
1563 sub markerprofiles_methods : Chained('brapi') PathPart('markerprofiles/methods') Args(0) {
1564 my $self = shift;
1565 my $c = shift;
1566 my ($auth) = _authenticate_user($c);
1567 my $brapi = $self->brapi_module;
1568 my $brapi_module = $brapi->brapi_wrapper('Markerprofiles');
1569 my $brapi_package_result = $brapi_module->markerprofiles_methods();
1570 _standard_response_construction($c, $brapi_package_result);
1575 =head2 brapi/v1/allelematrices-search?markerprofileDbId=100&markerprofileDbId=101
1577 Usage: Gives a matrix data structure for a given list of markerprofileDbIds
1578 Desc:
1579 Return JSON example:
1581 "metadata": {
1582 "status": [],
1583 "pagination": {
1584 "pageSize": 100,
1585 "currentPage": 1,
1586 "totalCount": 1,
1587 "totalPages": 1
1590 "result" : {
1591 "makerprofileDbIds": ["markerprofileId1","markerprofileId2","markerprofileId3"],
1592 "data" : [
1593 { "markerDbId1":["AB","AA","AA"] },
1594 { "markerDbId2":["AA","AB","AA"] },
1595 { "markerDbId3":["AB","AB","BB"] }
1599 Args:
1600 Side Effects:
1602 =cut
1604 sub allelematrices : Chained('brapi') PathPart('allelematrices-search') Args(0) : ActionClass('REST') { }
1606 sub allelematrices_POST {
1607 my $self = shift;
1608 my $c = shift;
1609 allelematrix_search_process($self, $c);
1612 sub allelematrices_GET {
1613 my $self = shift;
1614 my $c = shift;
1615 allelematrix_search_process($self, $c);
1618 sub allelematrices_new : Chained('brapi') PathPart('allelematrices') Args(0) : ActionClass('REST') { }
1620 sub allelematrices_new_GET {
1621 my $self = shift;
1622 my $c = shift;
1623 allelematrix_search_process($self, $c);
1626 sub allelematrices_cached : Chained('brapi') PathPart('search/allelematrices') Args(0) : ActionClass('REST') { }
1628 sub allelematrices_cached_POST {
1629 my $self = shift;
1630 my $c = shift;
1631 allelematrix_search_process($self, $c);
1634 sub allelematrices_cached_GET {
1635 my $self = shift;
1636 my $c = shift;
1637 allelematrix_search_process($self, $c);
1641 sub allelematrix : Chained('brapi') PathPart('allelematrix-search') Args(0) : ActionClass('REST') { }
1643 sub allelematrix_POST {
1644 my $self = shift;
1645 my $c = shift;
1646 allelematrix_search_process($self, $c);
1649 sub allelematrix_GET {
1650 my $self = shift;
1651 my $c = shift;
1652 allelematrix_search_process($self, $c);
1655 sub allelematrix_search_process {
1656 my $self = shift;
1657 my $c = shift;
1658 # my ($auth) = _authenticate_user($c);
1660 my $clean_inputs = $c->stash->{clean_inputs};
1661 my $format = $clean_inputs->{format}->[0];
1662 my $file_path;
1663 my $uri;
1664 if ($format eq 'tsv' || $format eq 'csv' || $format eq 'xls'){
1665 my $dir = $c->tempfiles_subdir('download');
1666 ($file_path, $uri) = $c->tempfile( TEMPLATE => 'download/allelematrix_'.$format.'_'.'XXXXX');
1668 my $brapi = $self->brapi_module;
1669 my $brapi_module = $brapi->brapi_wrapper('Markerprofiles');
1670 my $brapi_package_result = $brapi_module->markerprofiles_allelematrix({
1671 cache_file_path => $c->config->{cache_file_path},
1672 shared_cluster_dir => $c->config->{cluster_shared_tempdir},
1673 markerprofile_ids => $clean_inputs->{markerprofileDbId},
1674 marker_ids => $clean_inputs->{markerDbId},
1675 unknown_string => $clean_inputs->{unknownString}->[0],
1676 sep_phased => $clean_inputs->{sepPhased}->[0],
1677 sep_unphased => $clean_inputs->{sepUnphased}->[0],
1678 expand_homozygotes => $clean_inputs->{expandHomozygotes}->[0],
1679 format => $format,
1680 main_production_site_url => $c->config->{main_production_site_url},
1681 file_path => $file_path,
1682 file_uri => $uri
1684 _standard_response_construction($c, $brapi_package_result);
1688 =head2 brapi/v2/plates
1690 =cut
1692 sub plates : Chained('brapi') PathPart('plates') Args(0) : ActionClass('REST') { }
1694 sub plates_GET {
1695 my $self = shift;
1696 my $c = shift;
1697 my ($auth,$user_id) = _authenticate_user($c);
1698 my $clean_inputs = $c->stash->{clean_inputs};
1699 my $brapi = $self->brapi_module;
1700 my $brapi_module = $brapi->brapi_wrapper('Plates');
1701 my $brapi_package_result = $brapi_module->search($clean_inputs,$user_id);
1702 _standard_response_construction($c, $brapi_package_result);
1705 sub plates_single : Chained('brapi') PathPart('plates') CaptureArgs(1) {
1706 my $self = shift;
1707 my $c = shift;
1708 my $plate_id = shift;
1710 $c->stash->{plate_id} = $plate_id;
1713 sub plates_detail : Chained('plates_single') PathPart('') Args(0) : ActionClass('REST') { }
1715 sub plates_detail_GET {
1716 my $self = shift;
1717 my $c = shift;
1718 my ($auth,$user_id) = _authenticate_user($c);
1719 my $clean_inputs = $c->stash->{clean_inputs};
1720 my $brapi = $self->brapi_module;
1721 my $brapi_module = $brapi->brapi_wrapper('Plates');
1722 my $brapi_package_result = $brapi_module->detail($c->stash->{plate_id},$user_id);
1723 _standard_response_construction($c, $brapi_package_result);
1726 sub plates_search_save : Chained('brapi') PathPart('search/plates') Args(0) : ActionClass('REST') { }
1728 sub plates_search_save_POST {
1729 my $self = shift;
1730 my $c = shift;
1731 save_results($self,$c,$c->stash->{clean_inputs},'Plates');
1734 sub plates_search_retrieve : Chained('brapi') PathPart('search/Plates') Args(1) {
1735 my $self = shift;
1736 my $c = shift;
1737 my $search_id = shift;
1738 retrieve_results($self, $c, $search_id, 'Plates');
1742 =head2 brapi/v2/lists
1744 =cut
1746 sub lists : Chained('brapi') PathPart('lists') Args(0) : ActionClass('REST') { }
1748 sub lists_GET {
1749 my $self = shift;
1750 my $c = shift;
1751 my ($auth,$user_id) = _authenticate_user($c, $c->config->{brapi_lists_require_login});
1752 my $clean_inputs = $c->stash->{clean_inputs};
1753 my $brapi = $self->brapi_module;
1754 my $brapi_module = $brapi->brapi_wrapper('Lists');
1755 my $brapi_package_result;
1756 if($c->config->{brapi_lists_require_login}) {
1757 $brapi_package_result = $brapi_module->search($clean_inputs, $user_id, 1);
1758 } else {
1759 $brapi_package_result = $brapi_module->search($clean_inputs, undef, 0);
1761 _standard_response_construction($c, $brapi_package_result);
1764 sub lists_POST {
1765 my $self = shift;
1766 my $c = shift;
1767 my ($auth,$user_id) = _authenticate_user($c);
1768 my $clean_inputs = $c->stash->{clean_inputs};
1769 my $data = $clean_inputs;
1770 my @all_lists;
1771 foreach my $list (values %{$data}) {
1772 push @all_lists, $list;
1774 my $brapi = $self->brapi_module;
1775 my $brapi_module = $brapi->brapi_wrapper('Lists');
1776 my $brapi_package_result = $brapi_module->store(\@all_lists,$user_id);
1777 _standard_response_construction($c, $brapi_package_result);
1780 sub list_single : Chained('brapi') PathPart('lists') CaptureArgs(1) {
1781 my $self = shift;
1782 my $c = shift;
1783 my $list_id = shift;
1785 $c->stash->{list_id} = $list_id;
1788 sub list_detail : Chained('list_single') PathPart('') Args(0) : ActionClass('REST') { }
1790 sub list_detail_GET {
1791 my $self = shift;
1792 my $c = shift;
1793 my ($auth,$user_id) = _authenticate_user($c);
1794 my $clean_inputs = $c->stash->{clean_inputs};
1795 my $brapi = $self->brapi_module;
1796 my $brapi_module = $brapi->brapi_wrapper('Lists');
1797 my $brapi_package_result = $brapi_module->detail($c->stash->{list_id},$user_id);
1798 _standard_response_construction($c, $brapi_package_result);
1801 sub list_detail_PUT {
1802 my $self = shift;
1803 my $c = shift;
1804 my ($auth,$user_id) = _authenticate_user($c);
1805 my $clean_inputs = $c->stash->{clean_inputs};
1806 my $data = $clean_inputs;
1807 $data->{listDbId} = $c->stash->{list_id};
1808 my $brapi = $self->brapi_module;
1809 my $brapi_module = $brapi->brapi_wrapper('Lists');
1810 my $brapi_package_result = $brapi_module->update($data,$user_id);
1811 _standard_response_construction($c, $brapi_package_result);
1814 sub list_items : Chained('list_single') PathPart('items') Args(0) : ActionClass('REST') { }
1816 sub list_items_POST {
1817 my $self = shift;
1818 my $c = shift;
1819 my ($auth,$user_id) = _authenticate_user($c);
1820 my $clean_inputs = $c->stash->{clean_inputs};
1821 my $brapi = $self->brapi_module;
1822 my $brapi_module = $brapi->brapi_wrapper('Lists');
1823 my $brapi_package_result = $brapi_module->store_items($c->stash->{list_id},$clean_inputs,$user_id);
1824 _standard_response_construction($c, $brapi_package_result);
1827 sub list_data : Chained('list_single') PathPart('data') Args(0) : ActionClass('REST') { }
1829 sub list_data_POST {
1830 my $self = shift;
1831 my $c = shift;
1832 my ($auth,$user_id) = _authenticate_user($c);
1833 my $clean_inputs = $c->stash->{clean_inputs};
1834 my $brapi = $self->brapi_module;
1835 my $brapi_module = $brapi->brapi_wrapper('Lists');
1836 my $brapi_package_result = $brapi_module->store_items($c->stash->{list_id},$clean_inputs,$user_id);
1837 _standard_response_construction($c, $brapi_package_result);
1841 sub list_search_save : Chained('brapi') PathPart('search/lists') Args(0) : ActionClass('REST') { }
1843 sub list_search_save_POST {
1844 my $self = shift;
1845 my $c = shift;
1846 save_results($self,$c,$c->stash->{clean_inputs},'Lists');
1849 sub list_search_retrieve : Chained('brapi') PathPart('search/lists') Args(1) {
1850 my $self = shift;
1851 my $c = shift;
1852 my $search_id = shift;
1853 retrieve_results($self, $c, $search_id, 'Lists');
1856 =head2 brapi/v2/people
1858 =cut
1860 sub people : Chained('brapi') PathPart('people') Args(0) : ActionClass('REST') { }
1862 sub people_GET {
1863 my $self = shift;
1864 my $c = shift;
1865 my ($auth) = _authenticate_user($c);
1866 my $clean_inputs = $c->stash->{clean_inputs};
1867 my $brapi = $self->brapi_module;
1868 my $brapi_module = $brapi->brapi_wrapper('People');
1869 my $brapi_package_result = $brapi_module->search($clean_inputs,$c);
1870 _standard_response_construction($c, $brapi_package_result);
1873 sub people_single : Chained('brapi') PathPart('people') CaptureArgs(1) {
1874 my $self = shift;
1875 my $c = shift;
1876 my $people_id = shift;
1878 $c->stash->{people_id} = $people_id;
1881 sub people_detail : Chained('people_single') PathPart('') Args(0) : ActionClass('REST') { }
1883 sub people_detail_GET {
1884 my $self = shift;
1885 my $c = shift;
1886 my ($auth) = _authenticate_user($c);
1887 my $clean_inputs = $c->stash->{clean_inputs};
1888 my $brapi = $self->brapi_module;
1889 my $brapi_module = $brapi->brapi_wrapper('People');
1890 my $brapi_package_result = $brapi_module->detail($c->stash->{people_id},$c);
1891 _standard_response_construction($c, $brapi_package_result);
1894 sub people_search_save : Chained('brapi') PathPart('search/people') Args(0) : ActionClass('REST') { }
1896 sub people_search_save_POST {
1897 my $self = shift;
1898 my $c = shift;
1899 save_results($self,$c,$c->stash->{clean_inputs},'People');
1902 sub people_search_retrieve : Chained('brapi') PathPart('search/people') Args(1) {
1903 my $self = shift;
1904 my $c = shift;
1905 my $search_id = shift;
1906 retrieve_results($self, $c, $search_id, 'People');
1909 =head2 brapi/v1/programs
1911 Usage: To retrieve a list of programs being worked on
1912 Desc:
1913 Return JSON example:
1915 "metadata" : {
1916 "pagination": {
1917 "pageSize": 10,
1918 "currentPage": 1,
1919 "totalCount": 10,
1920 "totalPages": 1
1922 "status": []
1924 "result" : {
1925 "data" : [
1927 "programDbid": "123",
1928 "name": "Wheat Resistance Program",
1929 "objective" : "Disease resistance",
1930 "leadPerson" : "Dr. Henry Beachell"
1933 "programDbId": "456",
1934 "name": "Wheat Improvement Program",
1935 "objective" : "Yield improvement",
1936 "leadPerson" : "Dr. Norman Borlaug"
1941 Args:
1942 Side Effects:
1944 =cut
1946 sub programs_list : Chained('brapi') PathPart('programs') Args(0) : ActionClass('REST') { }
1948 sub programs_list_POST {
1949 my $self = shift;
1950 my $c = shift;
1951 my ($auth,$user_id) = _authenticate_user($c);
1952 my $clean_inputs = $c->stash->{clean_inputs};
1953 my $data = $clean_inputs;
1954 my @all_programs;
1955 foreach my $program (values %{$data}) {
1956 push @all_programs, $program;
1958 my $brapi = $self->brapi_module;
1959 my $brapi_module = $brapi->brapi_wrapper('Programs');
1961 my $brapi_package_result = $brapi_module->store(\@all_programs, $user_id);
1962 _standard_response_construction($c, $brapi_package_result);
1965 sub programs_list_GET {
1966 my $self = shift;
1967 my $c = shift;
1968 my ($auth) = _authenticate_user($c);
1969 my $clean_inputs = $c->stash->{clean_inputs};
1970 my $brapi = $self->brapi_module;
1971 my $brapi_module = $brapi->brapi_wrapper('Programs');
1972 my $brapi_package_result = $brapi_module->search({
1973 program_names => $clean_inputs->{programName},
1974 programNames => $clean_inputs->{programName},
1975 abbreviations => $clean_inputs->{abbreviation},
1976 externalReferenceIDs => $clean_inputs->{externalReferenceID},
1977 externalReferenceSources => $clean_inputs->{externalReferenceSource},
1978 commonCropNames => $clean_inputs->{commonCropName},
1979 crop => $c->config->{supportedCrop}
1981 _standard_response_construction($c, $brapi_package_result);
1984 sub programs_single : Chained('brapi') PathPart('programs') CaptureArgs(1) {
1985 my $self = shift;
1986 my $c = shift;
1987 my $program_id = shift;
1989 $c->stash->{program_id} = $program_id;
1992 sub programs_detail : Chained('programs_single') PathPart('') Args(0) : ActionClass('REST') { }
1994 sub programs_detail_GET {
1995 my $self = shift;
1996 my $c = shift;
1997 my ($auth) = _authenticate_user($c);
1998 my $clean_inputs = $c->stash->{clean_inputs};
1999 my $brapi = $self->brapi_module;
2000 my $brapi_module = $brapi->brapi_wrapper('Programs');
2001 my $brapi_package_result = $brapi_module->detail(
2002 $c->stash->{program_id},
2003 $c->config->{supportedCrop}
2005 _standard_response_construction($c, $brapi_package_result);
2008 sub programs_detail_PUT {
2009 my $self = shift;
2010 my $c = shift;
2011 my ($auth,$user_id) = _authenticate_user($c);
2012 my $user_id = undef;
2013 my $clean_inputs = $c->stash->{clean_inputs};
2014 my $data = $clean_inputs;
2015 $data->{programDbId} = $c->stash->{program_id};
2016 my $brapi = $self->brapi_module;
2017 my $brapi_module = $brapi->brapi_wrapper('Programs');
2018 my $brapi_package_result = $brapi_module->update($data,$user_id);
2019 _standard_response_construction($c, $brapi_package_result);
2022 sub programs_search_save : Chained('brapi') PathPart('search/programs') Args(0) : ActionClass('REST') { }
2024 sub programs_search_save_POST {
2025 my $self = shift;
2026 my $c = shift; #print $self;
2027 save_results($self,$c,$c->stash->{clean_inputs},'Programs');
2030 sub programs_search_retrieve : Chained('brapi') PathPart('search/programs') Args(1) {
2031 my $self = shift;
2032 my $c = shift;
2033 my $search_id = shift;
2034 retrieve_results($self, $c, $search_id, 'Programs');
2038 =head2 brapi/v1/studies?programId=programId
2040 Usage: To retrieve studies
2041 Desc:
2042 Return JSON example:
2044 "metadata": {
2045 "pagination": {
2046 "pageSize": 2,
2047 "currentPage": 1,
2048 "totalCount": 100,
2049 "totalPages": 50
2051 "status" : []
2053 "result": {
2054 "data": [
2056 "studyDbId": 35,
2057 "name": "Earlygenerationtesting",
2058 "studyType": "Trial",
2059 "years": ["2005", "2008"],
2060 "locationDbId": 23,
2061 "programDbId": 27,
2062 "optionalInfo" : {
2063 "studyPUI" : "PUI string",
2064 "studyType": "Trial",
2065 "startDate": "2015-06-01",
2066 "endDate" : "2015-12-31",
2071 "studyDbId": 345,
2072 "name": "Earlygenerationtesting",
2073 "seasons": ["2005", "2008"],
2074 "locationDbId": 33,
2075 "programDbId": 58,
2076 "optionalInfo" : {
2077 "studyPUI" : "PUI string",
2078 "studyType": "Trial",
2079 "startDate": "2015-06-01",
2080 "endDate" : "2015-12-31",
2086 Args:
2087 Side Effects:
2089 =cut
2091 sub studies_search : Chained('brapi') PathPart('studies-search') Args(0) : ActionClass('REST') { }
2093 sub studies_search_POST {
2094 my $self = shift;
2095 my $c = shift;
2096 # my ($auth) = _authenticate_user($c);
2097 my $clean_inputs = $c->stash->{clean_inputs};
2098 my $brapi = $self->brapi_module;
2099 my $brapi_module = $brapi->brapi_wrapper('Studies');
2100 my $brapi_package_result = $brapi_module->search({
2101 programDbIds => $clean_inputs->{programDbIds},
2102 programNames => $clean_inputs->{programNames},
2103 studyDbIds => $clean_inputs->{studyDbIds},
2104 studyNames => $clean_inputs->{studyNames},
2105 trialDbIds => $clean_inputs->{trialDbIds},
2106 trialNames => $clean_inputs->{trialNames},
2107 studyLocationDbIds => $clean_inputs->{locationDbIds},
2108 studyLocationNames => $clean_inputs->{studyLocations},
2109 studyTypeName => $clean_inputs->{studyType},
2110 germplasmDbIds => $clean_inputs->{germplasmDbIds},
2111 germplasmNames => $clean_inputs->{germplasmNames},
2112 seasons => $clean_inputs->{seasonDbIds},
2113 observationVariableDbIds => $clean_inputs->{observationVariableDbIds},
2114 observationVariableNames => $clean_inputs->{observationVariableNames},
2115 active => $clean_inputs->{active}->[0],
2116 sortBy => $clean_inputs->{sortBy}->[0],
2117 sortOrder => $clean_inputs->{sortOrder}->[0],
2118 }, $c);
2119 _standard_response_construction($c, $brapi_package_result);
2122 sub studies_search_GET {
2123 my $self = shift;
2124 my $c = shift;
2125 my ($auth) = _authenticate_user($c);
2126 my $clean_inputs = $c->stash->{clean_inputs};
2127 my $brapi = $self->brapi_module;
2128 my $brapi_module = $brapi->brapi_wrapper('Studies');
2129 my $brapi_package_result = $brapi_module->search({
2130 programDbIds => $clean_inputs->{programDbId},
2131 programNames => $clean_inputs->{programName},
2132 studyDbIds => $clean_inputs->{studyDbId},
2133 studyNames => $clean_inputs->{studyName},
2134 trialDbIds => $clean_inputs->{trialDbId},
2135 trialNames => $clean_inputs->{trialName},
2136 studyLocationDbIds => $clean_inputs->{locationDbId},
2137 studyLocationNames => $clean_inputs->{locationName},
2138 seasons => $clean_inputs->{seasonDbId},
2139 studyTypeName => $clean_inputs->{studyType},
2140 germplasmDbIds => $clean_inputs->{germplasmDbId},
2141 germplasmNames => $clean_inputs->{germplasmName},
2142 observationVariableDbIds => $clean_inputs->{observationVariableDbId},
2143 observationVariableNames => $clean_inputs->{observationVariableName},
2144 active => $clean_inputs->{active}->[0],
2145 sortBy => $clean_inputs->{sortBy}->[0],
2146 sortOrder => $clean_inputs->{sortOrder}->[0],
2147 }, $c);
2148 _standard_response_construction($c, $brapi_package_result);
2151 sub studies : Chained('brapi') PathPart('studies') Args(0) : ActionClass('REST') { }
2153 sub studies_GET {
2154 my $self = shift;
2155 my $c = shift;
2156 my $auth = _authenticate_user($c);
2157 my $clean_inputs = $c->stash->{clean_inputs};
2158 my $brapi = $self->brapi_module;
2159 my $brapi_module = $brapi->brapi_wrapper('Studies');
2160 my $brapi_package_result = $brapi_module->search({
2161 programDbIds => $clean_inputs->{programDbId},
2162 programNames => $clean_inputs->{programName},
2163 studyDbIds => $clean_inputs->{studyDbId},
2164 studyNames => $clean_inputs->{studyName},
2165 trialDbIds => $clean_inputs->{trialDbId},
2166 trialNames => $clean_inputs->{trialName},
2167 studyLocationDbIds => $clean_inputs->{locationDbId},
2168 studyLocationNames => $clean_inputs->{locationName},
2169 seasons => $clean_inputs->{seasonDbId},
2170 seasonDbIds => $clean_inputs->{seasonDbId},
2171 studyTypes => $clean_inputs->{studyType},
2172 germplasmDbIds => $clean_inputs->{germplasmDbId},
2173 germplasmNames => $clean_inputs->{germplasmName},
2174 observationVariableDbIds => $clean_inputs->{observationVariableDbId},
2175 observationVariableNames => $clean_inputs->{observationVariableName},
2176 crop => $c->config->{supportedCrop},
2177 active => $clean_inputs->{active}->[0],
2178 sortBy => $clean_inputs->{sortBy}->[0],
2179 sortOrder => $clean_inputs->{sortOrder}->[0],
2180 commonCropNames => $clean_inputs->{commonCropName},
2181 }, $c);
2182 _standard_response_construction($c, $brapi_package_result);
2185 sub studies_POST {
2186 my $self = shift;
2187 my $c = shift;
2188 my ($auth, $user_id) = _authenticate_user($c);
2189 my $clean_inputs = $c->stash->{clean_inputs};
2190 my $data = $clean_inputs;
2191 _validate_request($c, 'ARRAY', $data, ['trialDbId', 'studyName', 'studyType', 'locationDbId', {'experimentalDesign' => ['PUI']}]);
2193 my @all_studies;
2194 foreach my $study (values %{$data}) {
2195 push @all_studies, $study;
2197 my $brapi = $self->brapi_module;
2198 my $brapi_module = $brapi->brapi_wrapper('Studies');
2199 my $brapi_package_result = $brapi_module->store(\@all_studies, $user_id, $c);
2200 _standard_response_construction($c, $brapi_package_result);
2203 sub studies_search_save : Chained('brapi') PathPart('search/studies') Args(0) : ActionClass('REST') { }
2205 sub studies_search_save_POST {
2206 my $self = shift;
2207 my $c = shift;
2208 save_results($self,$c,$c->stash->{clean_inputs},'Studies');
2211 sub studies_search_retrieve : Chained('brapi') PathPart('search/studies') Args(1) {
2212 my $self = shift;
2213 my $c = shift;
2214 my $search_id = shift;
2215 retrieve_results($self, $c, $search_id, 'Studies');
2219 =head2 brapi/v1/studies/{studyId}/germplasm?pageSize=20&page=1
2221 Usage: To retrieve all germplasm used in a study
2222 Desc:
2223 Return JSON example:
2225 "metadata": {
2226 "status": [],
2227 "pagination": {
2228 "pageSize": 1000,
2229 "currentPage": 1,
2230 "totalCount": 1,
2231 "totalPages": 1
2234 "result": {
2235 "studyDbId": 123,
2236 "studyName": "myBestTrial",
2237 "data": [
2239 "germplasmDbId": "382",
2240 "trialEntryNumberId": "1",
2241 "defaultDisplayName": "Pahang",
2242 "germplasmName": "Pahang",
2243 "accessionNumber": "ITC0609",
2244 "germplasmPUI": "http://www.crop-diversity.org/mgis/accession/01BEL084609",
2245 "pedigree": "TOBA97/SW90.1057",
2246 "seedSource": "",
2247 "synonyms": ["01BEL084609"],
2250 "germplasmDbId": "394",
2251 "trialEntryNumberId": "2",
2252 "defaultDisplayName": "Pahang",
2253 "germplasmName": "Pahang",
2254 "accessionNumber": "ITC0727",
2255 "germplasmPUI": "http://www.crop-diversity.org/mgis/accession/01BEL084727",
2256 "pedigree": "TOBA97/SW90.1057",
2257 "seedSource": "",
2258 "synonyms": [ "01BEL084727"],
2263 Args:
2264 Side Effects:
2266 =cut
2268 sub studies_single : Chained('brapi') PathPart('studies') CaptureArgs(1) {
2269 my $self = shift;
2270 my $c = shift;
2271 my $study_id = shift;
2273 $c->stash->{study_id} = $study_id;
2277 sub studies_germplasm : Chained('studies_single') PathPart('germplasm') Args(0) : ActionClass('REST') { }
2279 sub studies_germplasm_POST {
2280 my $self = shift;
2281 my $c = shift;
2282 my ($auth) = _authenticate_user($c);
2284 my $metadata = $c->req->params("metadata");
2285 my $result = $c->req->params("result");
2286 my %metadata_hash = %$metadata;
2287 my %result_hash = %$result;
2289 #print STDERR Dumper($metadata);
2290 #print STDERR Dumper($result);
2292 my $pagintation = $metadata_hash{"pagination"};
2295 sub studies_germplasm_GET {
2296 my $self = shift;
2297 my $c = shift;
2298 my ($auth) = _authenticate_user($c);
2299 my $brapi = $self->brapi_module;
2300 my $brapi_module = $brapi->brapi_wrapper('Studies');
2301 my $brapi_package_result = $brapi_module->studies_germplasm(
2302 $c->stash->{study_id}
2304 _standard_response_construction($c, $brapi_package_result);
2307 sub studies_info : Chained('studies_single') PathPart('') Args(0) : ActionClass('REST') { }
2309 sub studies_info_POST {
2310 my $self = shift;
2311 my $c = shift;
2312 #my $auth = _authenticate_user($c);
2315 sub studies_info_GET {
2316 my $self = shift;
2317 my $c = shift;
2318 my ($auth) = _authenticate_user($c);
2319 my $clean_inputs = $c->stash->{clean_inputs};
2320 my $brapi = $self->brapi_module;
2321 my $brapi_module = $brapi->brapi_wrapper('Studies');
2322 my $brapi_package_result = $brapi_module->detail(
2323 $c->stash->{study_id},
2324 $c->config->{main_production_site_url},
2325 $c->config->{supportedCrop}
2327 _standard_response_construction($c, $brapi_package_result);
2330 sub studies_info_PUT {
2331 my $self = shift;
2332 my $c = shift;
2333 my ($auth,$user_id) = _authenticate_user($c);
2334 my $clean_inputs = $c->stash->{clean_inputs};
2335 my $data = $clean_inputs;
2336 _validate_request($c, 'HASH', $data, ['trialDbId', 'studyName', 'studyType', 'locationDbId', {'experimentalDesign' => ['PUI']}]);
2337 $data->{studyDbId} = $c->stash->{study_id};
2339 my $brapi = $self->brapi_module;
2340 my $brapi_module = $brapi->brapi_wrapper('Studies');
2341 my $brapi_package_result = $brapi_module->update($data,$user_id,$c);
2342 _standard_response_construction($c, $brapi_package_result);
2345 sub studies_observation_variables : Chained('studies_single') PathPart('observationvariables') Args(0) : ActionClass('REST') { }
2347 sub studies_observation_variables_POST {
2348 my $self = shift;
2349 my $c = shift;
2350 #my $auth = _authenticate_user($c);
2353 sub studies_observation_variables_GET {
2354 my $self = shift;
2355 my $c = shift;
2356 my ($auth) = _authenticate_user($c);
2357 my $brapi = $self->brapi_module;
2358 my $brapi_module = $brapi->brapi_wrapper('Studies');
2359 my $brapi_package_result = $brapi_module->studies_observation_variables(
2360 $c->stash->{study_id},
2361 $c->config->{supportedCrop}
2363 _standard_response_construction($c, $brapi_package_result);
2367 sub studies_layout : Chained('studies_single') PathPart('layout') Args(0) : ActionClass('REST') { }
2369 sub studies_layout_POST {
2370 my $self = shift;
2371 my $c = shift;
2372 #my $auth = _authenticate_user($c);
2375 sub studies_layout_GET {
2376 my $self = shift;
2377 my $c = shift;
2378 my $clean_inputs = $c->stash->{clean_inputs};
2379 my ($auth) = _authenticate_user($c);
2380 my $format = $clean_inputs->{format}->[0] || 'json';
2381 my $file_path;
2382 my $uri;
2383 if ($format eq 'tsv' || $format eq 'csv' || $format eq 'xls'){
2384 my $dir = $c->tempfiles_subdir('download');
2385 my $time_stamp = strftime "%Y-%m-%dT%H%M%S", localtime();
2386 my $temp_file_name = $time_stamp . "phenotype_download_$format"."_XXXX";
2387 ($file_path, $uri) = $c->tempfile( TEMPLATE => "download/$temp_file_name");
2390 my $brapi = $self->brapi_module;
2391 my $brapi_module = $brapi->brapi_wrapper('Studies');
2392 my $brapi_package_result = $brapi_module->studies_layout({
2393 study_id => $c->stash->{study_id},
2394 format => $format,
2395 main_production_site_url => $c->config->{main_production_site_url},
2396 file_path => $file_path,
2397 file_uri => $uri
2399 _standard_response_construction($c, $brapi_package_result);
2402 sub studies_layouts : Chained('studies_single') PathPart('layouts') Args(0) : ActionClass('REST') { }
2404 sub studies_layouts_GET {
2405 my $self = shift;
2406 my $c = shift;
2407 my $clean_inputs = $c->stash->{clean_inputs};
2408 my ($auth) = _authenticate_user($c);
2409 my $format = $clean_inputs->{format}->[0] || 'json';
2410 my $file_path;
2411 my $uri;
2412 if ($format eq 'tsv' || $format eq 'csv' || $format eq 'xls'){
2413 my $dir = $c->tempfiles_subdir('download');
2414 my $time_stamp = strftime "%Y-%m-%dT%H%M%S", localtime();
2415 my $temp_file_name = $time_stamp . "phenotype_download_$format"."_XXXX";
2416 ($file_path, $uri) = $c->tempfile( TEMPLATE => "download/$temp_file_name");
2419 my $brapi = $self->brapi_module;
2420 my $brapi_module = $brapi->brapi_wrapper('Studies');
2421 my $brapi_package_result = $brapi_module->studies_layout({
2422 study_id => $c->stash->{study_id},
2423 format => $format,
2424 main_production_site_url => $c->config->{main_production_site_url},
2425 file_path => $file_path,
2426 file_uri => $uri
2428 _standard_response_construction($c, $brapi_package_result);
2432 =head2 brapi/v1/studies/<studyDbId>/observationunits?observationVariableDbId=2
2434 Usage: To retrieve phenotypic values on a the plot level for an entire trial
2435 Desc:
2436 Return JSON example:
2438 "metadata" : "status": [],
2439 "pagination": {
2440 "pageSize": 1,
2441 "currentPage": 1,
2442 "totalCount": 1,
2443 "totalPages": 1
2445 "result" : {
2446 "data" : [
2448 "studyDbId": 1,
2449 "plotDbId": 11,
2450 "observationVariableDbId" : 393939,
2451 "observationVariableName" : "Yield",
2452 "plotName": "ZIPA_68_Ibadan_2014",
2453 "timestamp" : "2015-11-05 15:12",
2454 "uploadedBy" : {dbUserId},
2455 "operator" : "Jane Doe",
2456 "germplasmName": 143,
2457 "value" : 5,
2462 Args:
2463 Side Effects:
2465 =cut
2467 sub studies_observations : Chained('studies_single') PathPart('observationunits') Args(0) : ActionClass('REST') { }
2469 sub studies_observations_GET {
2470 my $self = shift;
2471 my $c = shift;
2472 my $clean_inputs = $c->stash->{clean_inputs};
2473 # my ($auth) = _authenticate_user($c);
2474 my $brapi = $self->brapi_module;
2475 my $brapi_module = $brapi->brapi_wrapper('Studies');
2476 my $brapi_package_result = $brapi_module->observation_units({
2477 study_id => $c->stash->{study_id},
2478 observationVariableDbIds => $clean_inputs->{observationVariableDbId},
2479 data_level => $clean_inputs->{observationLevel}->[0]
2481 _standard_response_construction($c, $brapi_package_result);
2485 =head2 brapi/v1/studies/<studyDbId>/table
2487 Usage: To retrieve phenotypic values for a study, in a manner representative of a table, with headers and data separated
2488 Desc:
2489 Return JSON example:
2491 "metadata": {
2492 "status": [],
2493 "pagination": {
2494 "pageSize": 1,
2495 "currentPage": 1,
2496 "totalCount": 1,
2497 "totalPages": 1
2500 "result" : {
2501 "studyDbId": 1,
2502 "observationVariableDbId": [ '', '', '', '', '', '', '', '', 44444, 55555, 66666...],
2503 "observationVariableName": [ "plotDbId", "plotName", "block", "rep", "germplasmID", "germplasmName", "operator", "timestamp", "Yield", "Color", "Dry Matter"...],
2505 "data" :
2507 [1, "plot1", 1, 1, "CIP1", 41, "user1", "2015-11-05 15:12", 10, "yellow", 9, ...],
2508 [2, "plot2", 1, 1, "CIP2", 42, "user1", "2015-11-05 20:12", 3, "red", 4, ...]
2512 Args:
2513 Side Effects:
2515 =cut
2517 sub studies_table : Chained('studies_single') PathPart('table') Args(0) : ActionClass('REST') { }
2519 sub studies_table_GET {
2520 my $self = shift;
2521 my $c = shift;
2522 my ($auth) = _authenticate_user($c);
2524 my $clean_inputs = $c->stash->{clean_inputs};
2525 my $format = $clean_inputs->{format}->[0];
2526 my $file_path;
2527 my $uri;
2528 if ($format eq 'tsv' || $format eq 'csv' || $format eq 'xls'){
2529 my $dir = $c->tempfiles_subdir('download');
2530 my $time_stamp = strftime "%Y-%m-%dT%H%M%S", localtime();
2531 my $temp_file_name = $time_stamp . "phenotype_download_$format"."_XXXX";
2532 ($file_path, $uri) = $c->tempfile( TEMPLATE => "download/$temp_file_name");
2534 my $brapi = $self->brapi_module;
2535 my $brapi_module = $brapi->brapi_wrapper('Studies');
2536 my $brapi_package_result = $brapi_module->studies_table({
2537 study_id => $c->stash->{study_id},
2538 data_level => $clean_inputs->{observationLevel}->[0],
2539 search_type => $clean_inputs->{search_type}->[0],
2540 exclude_phenotype_outlier => $clean_inputs->{exclude_phenotype_outlier}->[0],
2541 trait_ids => $clean_inputs->{observationVariableDbId},
2542 trial_ids => $clean_inputs->{studyDbId},
2543 format => $format,
2544 main_production_site_url => $c->config->{main_production_site_url},
2545 file_path => $file_path,
2546 file_uri => $uri
2549 _standard_response_construction($c, $brapi_package_result);
2553 =head2 brapi/v1/studies/<studyDbId>/observations?observationVariableDbId=2
2555 Usage: To retrieve phenotypic values on a the plot level for an entire trial
2556 Desc:
2557 Return JSON example:
2559 "metadata" : "status": [],
2560 "pagination": {
2561 "pageSize": 1,
2562 "currentPage": 1,
2563 "totalCount": 1,
2564 "totalPages": 1
2566 "result" : {
2567 "data" : [
2569 "studyDbId": 1,
2570 "plotDbId": 11,
2571 "observationVariableDbId" : 393939,
2572 "observationVariableName" : "Yield",
2573 "plotName": "ZIPA_68_Ibadan_2014",
2574 "timestamp" : "2015-11-05 15:12",
2575 "uploadedBy" : {dbUserId},
2576 "operator" : "Jane Doe",
2577 "germplasmName": 143,
2578 "value" : 5,
2583 Args:
2584 Side Effects:
2586 =cut
2588 sub studies_observations_granular : Chained('studies_single') PathPart('observations') Args(0) : ActionClass('REST') { }
2590 sub studies_observations_granular_PUT {
2591 my $self = shift;
2592 my $c = shift;
2593 my $clean_inputs = $c->stash->{clean_inputs};
2594 my $observations = $clean_inputs->{observations};
2595 #print STDERR "Observations are ". Dumper($observations) . "\n";
2596 save_observation_results($self, $c, $observations, 'v1');
2599 sub studies_observations_granular_GET {
2600 my $self = shift;
2601 my $c = shift;
2602 my $clean_inputs = $c->stash->{clean_inputs};
2603 my ($auth) = _authenticate_user($c);
2604 my $brapi = $self->brapi_module;
2605 my $brapi_module = $brapi->brapi_wrapper('Studies');
2606 my $brapi_package_result = $brapi_module->observation_units_granular({
2607 study_id => $c->stash->{study_id},
2608 observationVariableDbIds => $clean_inputs->{observationVariableDbId},
2609 data_level => $clean_inputs->{observationLevel}->[0],
2610 search_type => $clean_inputs->{search_type}->[0],
2611 exclude_phenotype_outlier => $clean_inputs->{exclude_phenotype_outlier}->[0],
2613 _standard_response_construction($c, $brapi_package_result);
2616 =head2 brapi/v1/phenotypes?observationUnitLevel=plot&studyDbId=876&studyPUI=&studyLocation=&studySet=&studyProject=&treatmentFactor=lowInput&germplasmGenus=&germplasmSubTaxa=&germplasmDbId&germplasmPUI=http://data.inra.fr/accession/234Col342&germplasmSpecies=Triticum&panel=diversitypanel1&collection=none&observationVariables=CO_321:000034,CO_321:000025&location=bergheim&season=2005,2006&pageSize={pageSize}&page={page}
2618 Usage: To retrieve a phenotype dataset
2619 Desc:d
2620 Return JSON example:
2622 "metadata": {
2623 "pagination": {
2624 "pageSize": 10,
2625 "currentPage": 1,
2626 "totalCount": 10,
2627 "totalPages": 1
2629 "status": []
2632 "result" : {
2633 "observationUnitDbId": 20,
2634 "observationUnitPUI": "http://phenome-fppn.fr/maugio/bloc/12/2345",
2635 "studyId": "RIGW1",
2636 "studyDbId": 25,
2637 "studyLocation": "Bergheim",
2638 "studyPUI": "http://phenome-fppn.fr/phenoarch/2014/1",
2639 "studyProject": "Inovine",
2640 "studySet": ["National Network", "Frost suceptibility network"],
2641 "studyPlatform": "Phenome",
2642 "observationUnitLevelTypes" : [ "plant","plot", "bloc"],
2643 "observationUnitLevelLabels": [ "1","26123", "1"],
2644 "germplasmPUI": "http://inra.fr/vassal/41207Col0001E",
2645 "germplasmDbId": 3425,
2646 "germplasmName": "charger",
2647 "treatments":
2650 "factor" : "water regimen" ,
2651 "modality":"water deficit"
2654 "attributes":
2656 {"att1" :"value"},
2657 {"numPot" :"23"}
2659 "X" : "",
2660 "Y" : "",
2661 "XLabel" : "",
2662 "YLabel" : "",
2663 "data": [
2665 "instanceNumber" : 1,
2666 "observationVariableDbId": 35,
2667 "season": "2005",
2668 "observationValue" : "red",
2669 "observationTimeStamp": null,
2670 "quality": "reliability of the observation",
2671 "collectionFacilityLabel": "phenodyne",
2672 "collector" : "John Doe and team"
2675 "instanceNumber" : 1,
2676 "observationVariableDbId": 35,
2677 "season": null,
2678 "observationValue" : 32,
2679 "observationTimeStamp": "2006-07-03::10:00",
2680 "quality": "8",
2681 "collectionFacilityLabel": null,
2682 "collector" : "userURIOrName"
2688 Args:
2689 Side Effects:
2691 =cut
2693 sub phenotypes_search : Chained('brapi') PathPart('phenotypes-search') Args(0) : ActionClass('REST') { }
2695 sub phenotypes_search_POST {
2696 my $self = shift;
2697 my $c = shift;
2698 # my ($auth) = _authenticate_user($c);
2699 my $clean_inputs = $c->stash->{clean_inputs};
2700 my $brapi = $self->brapi_module;
2701 my $brapi_module = $brapi->brapi_wrapper('ObservationUnits');
2702 my $brapi_package_result = $brapi_module->search($c->stash->{clean_inputs});
2703 _standard_response_construction($c, $brapi_package_result);
2706 sub phenotypes_search_GET {
2707 my $self = shift;
2708 my $c = shift;
2709 my ($auth) = _authenticate_user($c);
2710 my $clean_inputs = $c->stash->{clean_inputs};
2711 my $brapi = $self->brapi_module;
2712 my $brapi_module = $brapi->brapi_wrapper('ObservationUnits');
2713 my $brapi_package_result = $brapi_module->search($c->stash->{clean_inputs});
2714 _standard_response_construction($c, $brapi_package_result);
2717 # Observation units
2719 sub observation_units : Chained('brapi') PathPart('observationunits') Args(0) ActionClass('REST') { }
2721 sub observation_units_GET {
2723 my $self = shift;
2724 my $c = shift;
2725 my ($auth) = _authenticate_user($c);
2726 my $clean_inputs = $c->stash->{clean_inputs};
2727 my $brapi = $self->brapi_module;
2728 my $brapi_module = $brapi->brapi_wrapper('ObservationUnits');
2729 my $brapi_package_result = $brapi_module->search($c->stash->{clean_inputs}, $c);
2730 _standard_response_construction($c, $brapi_package_result);
2733 sub observation_units_POST {
2735 my $self = shift;
2736 my $c = shift;
2737 # The observation units need an operator, so login required
2738 my $force_authenticate = $c->config->{brapi_observation_units_require_login};
2739 my ($auth,$user_id) = _authenticate_user($c, $force_authenticate);
2740 my $clean_inputs = $c->stash->{clean_inputs};
2741 my $data = $clean_inputs;
2742 _validate_request($c, 'ARRAY', $data, [
2743 'studyDbId',
2744 'observationUnitName',
2746 'observationUnitPosition' => [
2748 'observationLevel' => ['levelName', 'levelCode'],
2753 my @all_units;
2754 foreach my $unit (values %{$data}) {
2755 push @all_units, $unit;
2757 my $brapi = $self->brapi_module;
2758 my $brapi_module = $brapi->brapi_wrapper('ObservationUnits');
2759 my $brapi_package_result = $brapi_module->observationunits_store(\@all_units,$c,$user_id);
2760 _standard_response_construction($c, $brapi_package_result);
2763 sub observation_units_PUT {
2765 my $self = shift;
2766 my $c = shift;
2767 my $force_authenticate = $c->config->{brapi_observation_units_require_login};
2768 my ($auth,$user_id) = _authenticate_user($c, $force_authenticate);
2769 my $clean_inputs = $c->stash->{clean_inputs};
2770 my %data = %$clean_inputs;
2771 my @all_units;
2772 foreach my $unit (keys %data) {
2773 my $observationUnitDbId = $unit;
2774 my $units = $data{$unit};
2775 $units->{observationUnitDbId} = $observationUnitDbId;
2776 push @all_units, $units;
2778 my $brapi = $self->brapi_module;
2779 my $brapi_module = $brapi->brapi_wrapper('ObservationUnits');
2780 my $brapi_package_result = $brapi_module->observationunits_update(\@all_units,$c,$user_id);
2781 _standard_response_construction($c, $brapi_package_result);
2784 sub observation_units_table : Chained('brapi') PathPart('observationunits/table') Args(0) : ActionClass('REST') { }
2786 sub observation_units_table_GET {
2787 my $self = shift;
2788 my $c = shift;
2789 my ($auth) = _authenticate_user($c);
2790 my $clean_inputs = $c->stash->{clean_inputs};
2791 my $brapi = $self->brapi_module;
2792 my $brapi_module = $brapi->brapi_wrapper('ObservationTables');
2793 my $brapi_package_result = $brapi_module->search_observationunit_tables($c->stash->{clean_inputs});
2794 _standard_response_construction($c, $brapi_package_result);
2797 sub observation_unit_single : Chained('brapi') PathPart('observationunits') Args(1) ActionClass('REST') {
2798 my $self = shift;
2799 my $c = shift;
2800 my $observation_unit_db_id = shift;
2802 $c->stash->{observation_unit_db_id} = $observation_unit_db_id;
2805 sub observation_unit_single_PUT {
2806 my $self = shift;
2807 my $c = shift;
2808 my $observation_unit_db_id = shift;
2809 my $clean_inputs = $c->stash->{clean_inputs};
2810 my ($auth) = _authenticate_user($c);
2811 my $observationUnits = $clean_inputs;
2812 $observationUnits->{observationUnitDbId} = $observation_unit_db_id;
2813 my @all_observations_units;
2814 push @all_observations_units, $observationUnits;
2815 my $brapi = $self->brapi_module;
2816 my $brapi_module = $brapi->brapi_wrapper('ObservationUnits');
2817 my $brapi_package_result = $brapi_module->observationunits_update(\@all_observations_units, $c);
2819 _standard_response_construction($c, $brapi_package_result);
2822 sub observation_unit_single_GET {
2823 my $self = shift;
2824 my $c = shift;
2825 my ($auth) = _authenticate_user($c);
2826 my $clean_inputs = $c->stash->{clean_inputs};
2827 my $brapi = $self->brapi_module;
2828 my $brapi_module = $brapi->brapi_wrapper('ObservationUnits');
2829 my $brapi_package_result = $brapi_module->detail(
2830 $c->stash->{observation_unit_db_id}, $c);
2831 _standard_response_construction($c, $brapi_package_result);
2834 sub observation_units_search_save : Chained('brapi') PathPart('search/observationunits') Args(0) : ActionClass('REST') { }
2836 sub observation_units_search_save_POST {
2837 my $self = shift;
2838 my $c = shift;
2839 save_results($self,$c,$c->stash->{clean_inputs},'ObservationUnits');
2842 sub observation_units_search_retrieve : Chained('brapi') PathPart('search/observationunits') Args(1) {
2843 my $self = shift;
2844 my $c = shift;
2845 my $search_id = shift;
2846 retrieve_results($self, $c, $search_id, 'ObservationUnits');
2850 sub phenotypes_search_table : Chained('brapi') PathPart('phenotypes-search/table') Args(0) : ActionClass('REST') { }
2852 sub phenotypes_search_table_POST {
2853 my $self = shift;
2854 my $c = shift;
2855 process_phenotypes_search_table($self, $c);
2858 sub phenotypes_search_table_GET {
2859 my $self = shift;
2860 my $c = shift;
2861 process_phenotypes_search_table($self, $c);
2864 sub process_phenotypes_search_table {
2865 my $self = shift;
2866 my $c = shift;
2867 # my ($auth) = _authenticate_user($c);
2868 my $clean_inputs = $c->stash->{clean_inputs};
2869 my $brapi = $self->brapi_module;
2870 my $brapi_module = $brapi->brapi_wrapper('ObservationTables');
2871 my $brapi_package_result = $brapi_module->search_table($c->stash->{clean_inputs});
2872 _standard_response_construction($c, $brapi_package_result);
2875 sub observation_tables_search_save : Chained('brapi') PathPart('search/observationtables') Args(0) : ActionClass('REST') { }
2877 sub observation_tables_search_save_POST {
2878 my $self = shift;
2879 my $c = shift;
2880 save_results($self,$c,$c->stash->{clean_inputs},'ObservationTables');
2883 sub observation_tables_search_retrieve : Chained('brapi') PathPart('search/observationtables') Args(1) {
2884 my $self = shift;
2885 my $c = shift;
2886 my $search_id = shift;
2887 retrieve_results($self, $c, $search_id, 'ObservationTables');
2890 sub phenotypes_search_csv : Chained('brapi') PathPart('phenotypes-search/csv') Args(0) : ActionClass('REST') { }
2892 sub phenotypes_search_csv_POST {
2893 my $self = shift;
2894 my $c = shift;
2895 process_phenotypes_search_csv($self, $c);
2898 sub phenotypes_search_csv_GET {
2899 my $self = shift;
2900 my $c = shift;
2901 process_phenotypes_search_csv($self, $c);
2904 sub process_phenotypes_search_csv {
2905 my $self = shift;
2906 my $c = shift;
2907 # my ($auth) = _authenticate_user($c);
2908 my $clean_inputs = $c->stash->{clean_inputs};
2909 my $dir = $c->tempfiles_subdir('download');
2910 my $time_stamp = strftime "%Y-%m-%dT%H%M%S", localtime();
2911 my $temp_file_name = $time_stamp . "phenotype_download_csv"."_XXXX";
2912 my ($file_path, $uri) = $c->tempfile( TEMPLATE => "download/$temp_file_name");
2914 my $brapi = $self->brapi_module;
2915 my $brapi_module = $brapi->brapi_wrapper('Phenotypes');
2916 my $brapi_package_result = $brapi_module->search_table_csv_or_tsv({
2917 trait_ids => $clean_inputs->{observationVariableDbIds},
2918 accession_ids => $clean_inputs->{germplasmDbIds},
2919 study_ids => $clean_inputs->{studyDbIds},
2920 location_ids => $clean_inputs->{locationDbIds},
2921 years => $clean_inputs->{seasonDbIds},
2922 data_level => $clean_inputs->{observationLevel}->[0],
2923 search_type => $clean_inputs->{search_type}->[0],
2924 exclude_phenotype_outlier => $clean_inputs->{exclude_phenotype_outlier}->[0],
2925 format => 'csv',
2926 main_production_site_url => $c->config->{main_production_site_url},
2927 file_path => $file_path,
2928 file_uri => $uri
2930 _standard_response_construction($c, $brapi_package_result);
2933 sub phenotypes_search_tsv : Chained('brapi') PathPart('phenotypes-search/tsv') Args(0) : ActionClass('REST') { }
2935 sub phenotypes_search_tsv_POST {
2936 my $self = shift;
2937 my $c = shift;
2938 process_phenotypes_search_tsv($self, $c);
2941 sub phenotypes_search_tsv_GET {
2942 my $self = shift;
2943 my $c = shift;
2944 process_phenotypes_search_tsv($self, $c);
2947 sub process_phenotypes_search_tsv {
2948 my $self = shift;
2949 my $c = shift;
2950 # my ($auth) = _authenticate_user($c);
2951 my $clean_inputs = $c->stash->{clean_inputs};
2952 my $dir = $c->tempfiles_subdir('download');
2953 my $time_stamp = strftime "%Y-%m-%dT%H%M%S", localtime();
2954 my $temp_file_name = $time_stamp . "phenotype_download_tsv"."_XXXX";
2955 my ($file_path, $uri) = $c->tempfile( TEMPLATE => "download/$temp_file_name");
2957 my $brapi = $self->brapi_module;
2958 my $brapi_module = $brapi->brapi_wrapper('Phenotypes');
2959 my $brapi_package_result = $brapi_module->search_table_csv_or_tsv({
2960 trait_ids => $clean_inputs->{observationVariableDbIds},
2961 accession_ids => $clean_inputs->{germplasmDbIds},
2962 study_ids => $clean_inputs->{studyDbIds},
2963 location_ids => $clean_inputs->{locationDbIds},
2964 years => $clean_inputs->{seasonDbIds},
2965 data_level => $clean_inputs->{observationLevel}->[0],
2966 search_type => $clean_inputs->{search_type}->[0],
2967 exclude_phenotype_outlier => $clean_inputs->{exclude_phenotype_outlier}->[0],
2968 format => 'tsv',
2969 main_production_site_url => $c->config->{main_production_site_url},
2970 file_path => $file_path,
2971 file_uri => $uri
2973 _standard_response_construction($c, $brapi_package_result);
2977 sub traits_list : Chained('brapi') PathPart('traits') Args(0) : ActionClass('REST') { }
2979 sub traits_list_POST {
2980 my $self = shift;
2981 my $c = shift;
2982 #my $auth = _authenticate_user($c);
2985 sub traits_list_GET {
2986 my $self = shift;
2987 my $c = shift;
2988 my ($auth) = _authenticate_user($c);
2989 my $clean_inputs = $c->stash->{clean_inputs};
2990 my $brapi = $self->brapi_module;
2991 my $brapi_module = $brapi->brapi_wrapper('Traits');
2992 my $brapi_package_result = $brapi_module->list({
2993 trait_ids => $clean_inputs->{traitDbIds},
2994 names => $clean_inputs->{names}
2995 }, $c);
2996 _standard_response_construction($c, $brapi_package_result);
3000 sub traits_single : Chained('brapi') PathPart('traits') CaptureArgs(1) {
3001 my $self = shift;
3002 my $c = shift;
3003 my $trait_id = shift;
3005 $c->stash->{trait_id} = $trait_id;
3009 sub trait_detail : Chained('traits_single') PathPart('') Args(0) : ActionClass('REST') { }
3011 sub trait_detail_GET {
3012 my $self = shift;
3013 my $c = shift;
3014 my ($auth) = _authenticate_user($c);
3015 my $clean_inputs = $c->stash->{clean_inputs};
3016 my $brapi = $self->brapi_module;
3017 my $brapi_module = $brapi->brapi_wrapper('Traits');
3018 my $brapi_package_result = $brapi_module->detail(
3019 $c->stash->{trait_id}, $c
3021 _standard_response_construction($c, $brapi_package_result);
3025 =head2 brapi/v1/maps?species=speciesId
3027 Usage: To retrieve a list of all maps available in the database.
3028 Desc:
3029 Return JSON example:
3031 "metadata" : {
3032 "pagination" : {
3033 "pageSize": 30,
3034 "currentPage": 2,
3035 "totalCount": 40,
3036 "totalPages": 2
3038 "status" : []
3040 "result": {
3041 "data" : [
3043 "mapId": 1,
3044 "name": "Some Map",
3045 "species": "Some species",
3046 "type": "Genetic",
3047 "unit": "cM",
3048 "publishedDate": "2008-04-16",
3049 "markerCount": 1000,
3050 "linkageGroupCount": 7,
3051 "comments": "This map contains ..."
3054 "mapId": 2,
3055 "name": "Some Other map",
3056 "species": "Some Species",
3057 "type": "Genetic",
3058 "unit": "cM",
3059 "publishedDate": "2009-01-12",
3060 "markerCount": 1501,
3061 "linkageGroupCount": 7,
3062 "comments": "this is blah blah"
3067 Args:
3068 Side Effects:
3070 =cut
3072 sub maps_list : Chained('brapi') PathPart('maps') Args(0) : ActionClass('REST') { }
3074 sub maps_list_POST {
3075 my $self = shift;
3076 my $c = shift;
3077 #my $auth = _authenticate_user($c);
3080 sub maps_list_GET {
3081 my $self = shift;
3082 my $c = shift;
3083 my ($auth) = _authenticate_user($c);
3084 my $clean_inputs = $c->stash->{clean_inputs};
3085 my $brapi = $self->brapi_module;
3086 my $brapi_module = $brapi->brapi_wrapper('GenomeMaps');
3087 my $brapi_package_result = $brapi_module->list({
3088 config => $c->config,
3089 mapDbId => $clean_inputs->{mapDbId},
3090 commonCropName => $clean_inputs->{commonCropName},
3091 scientificName => $clean_inputs->{scientificName},
3092 type => $clean_inputs->{type},
3095 _standard_response_construction($c, $brapi_package_result);
3100 =head2 brapi/v1/maps/<map_id>
3102 Usage: To retrieve details for a specific map_id
3103 Desc:
3104 Return JSON example:
3106 "metadata" : {
3107 "pagination" : {
3108 "pageSize": 30,
3109 "currentPage": 2,
3110 "totalCount": 40,
3111 "totalPages": 2
3113 "status" : []
3115 "result": {
3116 "mapId": "id",
3117 "name": "Some map",
3118 "type": "Genetic",
3119 "unit": "cM",
3120 "linkageGroups": [
3122 "linkageGroupId": 1,
3123 "numberMarkers": 100000,
3124 "maxPosition": 10000000
3127 "linkageGroupId": 2,
3128 "numberMarkers": 1247,
3129 "maxPostion": 12347889
3134 Args:
3135 Side Effects:
3137 =cut
3139 sub maps_single : Chained('brapi') PathPart('maps') CaptureArgs(1) {
3140 my $self = shift;
3141 my $c = shift;
3142 my $map_id = shift;
3144 $c->stash->{map_id} = $map_id;
3148 sub maps_details : Chained('maps_single') PathPart('') Args(0) : ActionClass('REST') { }
3150 sub maps_details_POST {
3151 my $self = shift;
3152 my $c = shift;
3153 #my $auth = _authenticate_user($c);
3156 sub maps_details_GET {
3157 my $self = shift;
3158 my $c = shift;
3159 my ($auth) = _authenticate_user($c);
3160 my $clean_inputs = $c->stash->{clean_inputs};
3161 my $brapi = $self->brapi_module;
3162 my $brapi_module = $brapi->brapi_wrapper('GenomeMaps');
3163 my $brapi_package_result = $brapi_module->detail(
3164 $c->stash->{map_id}
3166 _standard_response_construction($c, $brapi_package_result);
3170 =head2 brapi/v1/maps/<map_id>/position?linkageGroupIdList=1,2,3
3172 Usage: To retrieve marker position data for a species map_id. Can provide a list of linkage groups (e.g. chromosomes) to narrow result set.
3173 Desc:
3174 Return JSON example:
3176 "metadata" : {
3177 "pagination" : { "pageSize": 30, "currentPage": 2, "totalCount": 40, "totalPages":2 },
3178 "status: []
3180 "result": {
3181 "data" : [
3183 "markerDbId": 1,
3184 "markerName": "marker1",
3185 "location": "1000",
3186 "linkageGroup": "1A"
3187 }, {
3188 "markerDbId": 2,
3189 "markerName": "marker2",
3190 "location": "1001",
3191 "linkageGroup": "1A"
3196 Args:
3197 Side Effects:
3199 =cut
3201 sub maps_marker_detail : Chained('maps_single') PathPart('positions') Args(0) : ActionClass('REST') { }
3203 sub maps_marker_detail_POST {
3204 my $self = shift;
3205 my $c = shift;
3206 #my $auth = _authenticate_user($c);
3209 sub maps_marker_detail_GET {
3210 my $self = shift;
3211 my $c = shift;
3212 my ($auth) = _authenticate_user($c);
3213 my $clean_inputs = $c->stash->{clean_inputs};
3214 my $brapi = $self->brapi_module;
3215 my $brapi_module = $brapi->brapi_wrapper('GenomeMaps');
3216 my $brapi_package_result = $brapi_module->positions({
3217 map_id => $c->stash->{map_id},
3218 linkage_group_ids => $clean_inputs->{linkageGroupId},
3219 min => $clean_inputs->{min}->[0],
3220 max => $clean_inputs->{max}->[0],
3222 _standard_response_construction($c, $brapi_package_result);
3225 sub maps_marker_linkagegroup_detail : Chained('maps_single') PathPart('positions') Args(1) : ActionClass('REST') { }
3227 sub maps_marker_linkagegroup_detail_GET {
3228 my $self = shift;
3229 my $c = shift;
3230 my $linkage_group_id = shift;
3231 my ($auth) = _authenticate_user($c);
3232 my $clean_inputs = $c->stash->{clean_inputs};
3233 my $brapi = $self->brapi_module;
3234 my $brapi_module = $brapi->brapi_wrapper('GenomeMaps');
3235 my $brapi_package_result = $brapi_module->positions({
3236 map_id => $c->stash->{map_id},
3237 linkage_group_ids => [$linkage_group_id],
3238 min => $clean_inputs->{min}->[0],
3239 max => $clean_inputs->{max}->[0],
3241 _standard_response_construction($c, $brapi_package_result);
3244 =head2 brapi/v2/maps/map_id/linkagegroups
3245 =cut
3247 sub maps_marker_detail_lg : Chained('maps_single') PathPart('linkagegroups') Args(0) : ActionClass('REST') { }
3249 sub maps_marker_detail_lg_GET {
3250 my $self = shift;
3251 my $c = shift;
3252 my ($auth) = _authenticate_user($c);
3253 my $clean_inputs = $c->stash->{clean_inputs};
3254 my $brapi = $self->brapi_module;
3255 my $brapi_module = $brapi->brapi_wrapper('GenomeMaps');
3256 my $brapi_package_result = $brapi_module->linkagegroups({
3257 map_id => $c->stash->{map_id},
3258 linkage_group_ids => $clean_inputs->{linkageGroupId},
3259 min => $clean_inputs->{min}->[0],
3260 max => $clean_inputs->{max}->[0],
3262 _standard_response_construction($c, $brapi_package_result);
3265 =head2 brapi/v2/markerpositions
3266 =cut
3268 sub maps_markerpositions : Chained('brapi') PathPart('markerpositions') Args(0) : ActionClass('REST') { }
3270 sub maps_markerpositions_GET {
3271 my $self = shift;
3272 my $c = shift;
3273 my ($auth) = _authenticate_user($c);
3274 my $clean_inputs = $c->stash->{clean_inputs};
3275 my $brapi = $self->brapi_module;
3276 my $brapi_module = $brapi->brapi_wrapper('MarkerPositions');
3277 my $brapi_package_result = $brapi_module->search({
3278 mapDbId => $clean_inputs->{mapDbId},
3279 variantDbId => $clean_inputs->{variantDbId},
3280 linkageGroupName => $clean_inputs->{linkageGroupName},
3281 maxPosition => $clean_inputs->{maxPosition},
3282 minPosition => $clean_inputs->{minPosition},
3283 }, $c );
3284 _standard_response_construction($c, $brapi_package_result);
3287 sub maps_markerpositions_save : Chained('brapi') PathPart('search/markerpositions') Args(0) : ActionClass('REST') { }
3289 sub maps_markerpositions_save_POST {
3290 my $self = shift;
3291 my $c = shift;
3292 save_results($self,$c,$c->stash->{clean_inputs},'MarkerPositions');
3295 sub maps_markerpositions_retrieve : Chained('brapi') PathPart('search/markerpositions') Args(1) {
3296 my $self = shift;
3297 my $c = shift;
3298 my $search_id = shift;
3299 retrieve_results($self, $c, $search_id, 'MarkerPositions');
3302 =head2 brapi/<version>/locations
3304 Usage: To retrieve locations.
3305 Desc:
3306 Return JSON example:
3307 Args:
3308 Side Effects:
3310 =cut
3312 sub locations_list : Chained('brapi') PathPart('locations') Args(0) : ActionClass('REST') { }
3314 sub locations_list_POST {
3315 my $self = shift;
3316 my $c = shift;
3317 my ($auth,$user_id) = _authenticate_user($c);
3318 my $clean_inputs = $c->stash->{clean_inputs};
3319 my $data = $clean_inputs;
3320 my @all_locations;
3321 foreach my $location (values %{$data}) {
3322 push @all_locations, $location;
3324 my $brapi = $self->brapi_module;
3325 my $brapi_module = $brapi->brapi_wrapper('Locations');
3326 my $brapi_package_result = $brapi_module->store(\@all_locations,$user_id);
3327 _standard_response_construction($c, $brapi_package_result);
3330 sub locations_list_GET {
3331 my $self = shift;
3332 my $c = shift;
3333 my ($auth) = _authenticate_user($c);
3334 my $clean_inputs = $c->stash->{clean_inputs};
3335 my $brapi = $self->brapi_module;
3336 my $brapi_module = $brapi->brapi_wrapper('Locations');
3337 my $brapi_package_result = $brapi_module->search($clean_inputs);
3338 _standard_response_construction($c, $brapi_package_result);
3341 sub locations_detail : Chained('brapi') PathPart('locations') Args(1) : ActionClass('REST') { }
3343 sub locations_detail_GET {
3344 my $self = shift;
3345 my $c = shift;
3346 my $location_id = shift;
3347 my ($auth) = _authenticate_user($c);
3348 my $clean_inputs = $c->stash->{clean_inputs};
3349 my $brapi = $self->brapi_module;
3350 my $brapi_module = $brapi->brapi_wrapper('Locations');
3351 my $brapi_package_result = $brapi_module->detail($location_id);
3352 _standard_response_construction($c, $brapi_package_result);
3355 sub locations_detail_PUT {
3356 my $self = shift;
3357 my $c = shift;
3358 my $location_id = shift;
3359 my ($auth,$user_id) = _authenticate_user($c);
3360 my $user_id = undef;
3361 my $clean_inputs = $c->stash->{clean_inputs};
3362 my $data = $clean_inputs;
3363 my @all_locations;
3364 $data->{locationDbId} = $location_id;
3365 push @all_locations, $data;
3366 my $brapi = $self->brapi_module;
3367 my $brapi_module = $brapi->brapi_wrapper('Locations');
3368 my $brapi_package_result = $brapi_module->store(\@all_locations,$user_id);
3369 # Format the response to be single hash
3370 $brapi_package_result->{result} = $brapi_package_result->{result}->{data}[0];
3371 _standard_response_construction($c, $brapi_package_result);
3374 sub locations_search_save : Chained('brapi') PathPart('search/locations') Args(0) : ActionClass('REST') { }
3376 sub locations_search_save_POST {
3377 my $self = shift;
3378 my $c = shift;
3379 save_results($self,$c,$c->stash->{clean_inputs},'Locations');
3382 sub locations_search_retrieve : Chained('brapi') PathPart('search/locations') Args(1) {
3383 my $self = shift;
3384 my $c = shift;
3385 my $search_id = shift;
3386 retrieve_results($self, $c, $search_id, 'Locations');
3389 sub observationvariable_data_type_list : Chained('brapi') PathPart('variables/datatypes') Args(0) : ActionClass('REST') { }
3391 sub observationvariable_data_type_list_POST {
3392 my $self = shift;
3393 my $c = shift;
3394 #my $auth = _authenticate_user($c);
3397 sub observationvariable_data_type_list_GET {
3398 my $self = shift;
3399 my $c = shift;
3400 my ($auth) = _authenticate_user($c);
3401 my $clean_inputs = $c->stash->{clean_inputs};
3402 my $brapi = $self->brapi_module;
3403 my $brapi_module = $brapi->brapi_wrapper('ObservationVariables');
3404 my $brapi_package_result = $brapi_module->observation_variable_data_types();
3405 _standard_response_construction($c, $brapi_package_result);
3408 sub observationvariable_ontologies : Chained('brapi') PathPart('ontologies') Args(0) : ActionClass('REST') { }
3410 sub observationvariable_ontologies_POST {
3411 my $self = shift;
3412 my $c = shift;
3413 #my $auth = _authenticate_user($c);
3416 sub observationvariable_ontologies_GET {
3417 my $self = shift;
3418 my $c = shift;
3419 my ($auth) = _authenticate_user($c);
3421 #Using code pattern found in SGN::Controller::Ontology->onto_browser
3422 my $onto_root_namespaces = $c->config->{onto_root_namespaces};
3423 my @namespaces = split ", ", $onto_root_namespaces;
3424 foreach my $n (@namespaces) {
3425 $n =~ s/\s*(\w+)\s*\(.*\)/$1/g;
3427 #print STDERR Dumper \@namespaces;
3429 my $clean_inputs = $c->stash->{clean_inputs};
3430 my $brapi = $self->brapi_module;
3431 my $brapi_module = $brapi->brapi_wrapper('ObservationVariables');
3432 my $brapi_package_result = $brapi_module->observation_variable_ontologies({
3433 name_spaces => \@namespaces,
3434 ontologyDbId => $clean_inputs->{ontologyDbId}
3436 _standard_response_construction($c, $brapi_package_result);
3439 sub observationvariable_search : Chained('brapi') PathPart('variables-search') Args(0) : ActionClass('REST') { }
3441 sub observationvariable_search_POST {
3442 my $self = shift;
3443 my $c = shift;
3444 _observationvariable_search_process($self, $c);
3447 sub observationvariable_search_GET {
3448 my $self = shift;
3449 my $c = shift;
3450 _observationvariable_search_process($self, $c);
3453 sub _observationvariable_search_process {
3454 my $self = shift;
3455 my $c = shift;
3456 # my ($auth) = _authenticate_user($c);
3458 my $clean_inputs = $c->stash->{clean_inputs};
3459 my $brapi = $self->brapi_module;
3460 my $brapi_module = $brapi->brapi_wrapper('ObservationVariables');
3461 my $brapi_package_result = $brapi_module->search({
3462 observationvariable_db_ids => $clean_inputs->{observationVariableDbId},
3463 ontology_db_names => $clean_inputs->{ontologyXref},
3464 ontology_dbxref_terms => $clean_inputs->{ontologyDbId},
3465 method_db_ids => $clean_inputs->{methodDbId},
3466 scale_db_ids => $clean_inputs->{scaleDbId},
3467 observationvariable_names => $clean_inputs->{name},
3468 observationvariable_datatypes => $clean_inputs->{datatype},
3469 observationvariable_classes => $clean_inputs->{traitClass},
3470 studyDbIds => $clean_inputs->{studyDbId},
3471 }, $c);
3472 _standard_response_construction($c, $brapi_package_result);
3475 sub variables_search_save : Chained('brapi') PathPart('search/variables') Args(0) : ActionClass('REST') { }
3477 sub variables_search_save_POST {
3478 my $self = shift;
3479 my $c = shift;
3480 save_results($self,$c,$c->stash->{clean_inputs},'ObservationVariables');
3483 sub variables_search_retrieve : Chained('brapi') PathPart('search/variables') Args(1) {
3484 my $self = shift;
3485 my $c = shift;
3486 my $search_id = shift;
3487 retrieve_results($self, $c, $search_id, 'ObservationVariables');
3490 sub observationvariable_list : Chained('brapi') PathPart('variables') Args(0) : ActionClass('REST') { }
3492 # Endpoint for POST variables
3493 sub observationvariable_list_POST {
3494 my $self = shift;
3495 my $c = shift;
3497 my $can_post_variables = $c->config->{brapi_post_variables};
3498 if (not $can_post_variables){
3499 my $error = CXGN::BrAPI::JSONResponse->return_error([], "Not configured to post Observation Variables");
3500 _standard_response_construction($c, $error, 404);
3503 my $force_authenticate = $c->config->{brapi_variables_require_login};
3504 my ($auth,$user_id) = _authenticate_user($c, $force_authenticate);
3506 my $clean_inputs = $c->stash->{clean_inputs};
3507 my $data = $clean_inputs;
3508 _validate_request($c, 'ARRAY', $data, [
3509 'observationVariableName',
3510 {'scale' => ['dataType', 'scaleName']},
3511 {'method' => ['methodName', 'methodClass']},
3512 {'trait' => ['traitName', 'status']}
3515 my $response;
3516 try {
3517 my @all_variables;
3518 foreach my $variable (values %{$data}) {
3519 push @all_variables, $variable;
3522 my $brapi = $self->brapi_module;
3523 my $brapi_module = $brapi->brapi_wrapper('ObservationVariables');
3524 $response = $brapi_module->store(\@all_variables, $c);
3525 } catch {
3526 if ($_->isa('CXGN::BrAPI::Exceptions::ConflictException')){
3527 my $error = CXGN::BrAPI::JSONResponse->return_error([], $_->message);
3528 _standard_response_construction($c, $error, 409);
3529 } else {
3530 warn Dumper($_);
3531 my $error = CXGN::BrAPI::JSONResponse->return_error([], "An unknown error has occurred.");
3532 _standard_response_construction($c, $error, 500);
3536 _standard_response_construction($c, $response);
3539 sub observationvariable_list_GET {
3540 my $self = shift;
3541 my $c = shift;
3542 my ($auth) = _authenticate_user($c);
3543 my $clean_inputs = $c->stash->{clean_inputs};
3544 my $supported_crop = $c->config->{'supportedCrop'};
3545 my $brapi = $self->brapi_module;
3546 my $brapi_module = $brapi->brapi_wrapper('ObservationVariables');
3547 my $brapi_package_result = $brapi_module->search({
3548 observationVariableDbIds => $clean_inputs->{observationVariableDbId},
3549 traitClasses => $clean_inputs->{traitClass},
3550 studyDbIds => $clean_inputs->{studyDbId},
3551 externalReferenceIds => $clean_inputs->{externalReferenceId},
3552 externalReferenceSources => $clean_inputs->{externalReferenceSource},
3553 supportedCrop =>$supported_crop,
3554 }, $c);
3555 _standard_response_construction($c, $brapi_package_result);
3558 sub observationvariable_detail : Chained('brapi') PathPart('variables') Args(1) : ActionClass('REST') { }
3560 sub observationvariable_detail_GET {
3561 my $self = shift;
3562 my $c = shift;
3563 my $trait_id = shift;
3564 my ($auth) = _authenticate_user($c);
3565 my $clean_inputs = $c->stash->{clean_inputs};
3566 my $supported_crop = $c->config->{'supportedCrop'};
3567 my $brapi = $self->brapi_module;
3568 my $brapi_module = $brapi->brapi_wrapper('ObservationVariables');
3569 my $brapi_package_result = $brapi_module->detail(
3570 $trait_id,$c
3572 _standard_response_construction($c, $brapi_package_result);
3575 # Endpoint for PUT variables
3576 sub observationvariable_detail_PUT {
3577 my $self = shift;
3578 my $c = shift;
3579 my $variableDbId = shift;
3580 my $force_authenticate = $c->config->{brapi_variables_require_login};
3581 my ($auth,$user_id) = _authenticate_user($c, $force_authenticate);
3583 my $can_put_variables = $c->config->{brapi_put_variables};
3584 if (not $can_put_variables){
3585 my $error = CXGN::BrAPI::JSONResponse->return_error([], "Not configured to update Observation Variables");
3586 _standard_response_construction($c, $error, 404);
3589 my $response;
3590 try {
3591 my $clean_inputs = $c->stash->{clean_inputs};
3592 #TODO: Parse into a trait object to check bad requests
3593 my $data = $clean_inputs;
3594 $data->{observationVariableDbId} = $variableDbId;
3596 my $brapi = $self->brapi_module;
3597 my $brapi_module = $brapi->brapi_wrapper('ObservationVariables');
3598 $response = $brapi_module->update($data,$c);
3599 } catch {
3600 warn Dumper($_);
3601 if ($_->isa('CXGN::BrAPI::Exceptions::NotFoundException')){
3602 my $error = CXGN::BrAPI::JSONResponse->return_error([], $_->message);
3603 _standard_response_construction($c, $error, 404);
3604 } else {
3605 my $error = CXGN::BrAPI::JSONResponse->return_error([], "An unknown error has occurred.");
3606 _standard_response_construction($c, $error, 500);
3610 _standard_response_construction($c, $response);
3614 sub samples_list : Chained('brapi') PathPart('samples-search') Args(0) : ActionClass('REST') { }
3616 sub samples_list_POST {
3617 my $self = shift;
3618 my $c = shift;
3619 _sample_search_process($self, $c);
3622 sub samples_list_GET {
3623 my $self = shift;
3624 my $c = shift;
3625 _sample_search_process($self, $c);
3628 sub _sample_search_process {
3629 my $self = shift;
3630 my $c = shift;
3631 # my ($auth) = _authenticate_user($c);
3632 my $clean_inputs = $c->stash->{clean_inputs};
3633 my $brapi = $self->brapi_module;
3634 my $brapi_module = $brapi->brapi_wrapper('Samples');
3635 my $brapi_package_result = $brapi_module->search({
3636 sampleDbId => $clean_inputs->{sampleDbId},
3637 sampleName => $clean_inputs->{sampleName},
3638 plateDbId => $clean_inputs->{plateDbId},
3639 plateName => $clean_inputs->{plateName},
3640 germplasmDbId => $clean_inputs->{germplasmDbId},
3641 germplasmName => $clean_inputs->{germplasmName},
3642 observationUnitDbId => $clean_inputs->{observationUnitDbId},
3643 observationUnitName => $clean_inputs->{observationUnitName},
3645 _standard_response_construction($c, $brapi_package_result);
3648 sub samples : Chained('brapi') PathPart('samples') Args(0) : ActionClass('REST') { }
3650 sub samples_GET {
3651 my $self = shift;
3652 my $c = shift;
3653 my $auth = _authenticate_user($c);
3654 my $clean_inputs = $c->stash->{clean_inputs};
3655 my $brapi = $self->brapi_module;
3656 my $brapi_module = $brapi->brapi_wrapper('Samples');
3657 my $brapi_package_result = $brapi_module->search($clean_inputs);
3658 _standard_response_construction($c, $brapi_package_result);
3661 sub samples_list_search : Chained('brapi') PathPart('search/samples') Args(0) : ActionClass('REST') { }
3663 sub samples_list_search_POST {
3664 my $self = shift;
3665 my $c = shift;
3666 save_results($self,$c,$c->stash->{clean_inputs},'Samples');
3669 sub samples_list_search_retrieve : Chained('brapi') PathPart('search/samples') Args(1) {
3670 my $self = shift;
3671 my $c = shift;
3672 my $search_id = shift;
3673 retrieve_results($self, $c, $search_id, 'Samples');
3677 =head2 brapi/v1/samples/<sampleDbId>
3679 Usage: To retrieve details for a specific sample
3680 Desc:
3681 Return JSON example:
3683 "metadata": {
3684 "pagination" : {
3685 "pageSize":0,
3686 "currentPage":0,
3687 "totalCount":0,
3688 "totalPages":0
3690 "status" : [],
3691 "datafiles": []
3693 "result": {
3694 "sampleDbId": "Unique-Plant-SampleID",
3695 "observationUnitDbId": "abc123",
3696 "germplasmDbId": "def456",
3697 "studyDbId": "StudyId-123",
3698 "plotDbId": "PlotId-123",
3699 "plantDbId" : "PlantID-123",
3700 "plateDbId": "PlateID-123",
3701 "plateIndex": 0,
3702 "takenBy": "Mr. Technician",
3703 "sampleTimestamp": "2016-07-27T14:43:22+0100",
3704 "sampleType" : "TypeOfSample",
3705 "tissueType" : "TypeOfTissue",
3706 "notes": "Cut from infected leaf",
3709 =cut
3711 sub samples_single : Chained('brapi') PathPart('samples') CaptureArgs(1) {
3712 my $self = shift;
3713 my $c = shift;
3714 my $sample_id = shift;
3716 $c->stash->{sample_id} = $sample_id;
3720 sub sample_details : Chained('samples_single') PathPart('') Args(0) : ActionClass('REST') { }
3722 sub sample_details_POST {
3723 my $self = shift;
3724 my $c = shift;
3725 #my $auth = _authenticate_user($c);
3728 sub sample_details_GET {
3729 my $self = shift;
3730 my $c = shift;
3731 my ($auth) = _authenticate_user($c);
3732 my $clean_inputs = $c->stash->{clean_inputs};
3733 my $brapi = $self->brapi_module;
3734 my $brapi_module = $brapi->brapi_wrapper('Samples');
3735 my $brapi_package_result = $brapi_module->detail(
3736 $c->stash->{sample_id}
3738 _standard_response_construction($c, $brapi_package_result);
3745 sub authenticate : Chained('brapi') PathPart('authenticate/oauth') Args(0) {
3746 my $self = shift;
3747 my $c = shift;
3749 my $host = $c->config->{main_production_site_url};
3750 $c->res->redirect("https://accounts.google.com/o/oauth2/auth?scope=profile&response_type=code&client_id=1068256137120-62dvk8sncnbglglrmiroms0f5d7lg111.apps.googleusercontent.com&redirect_uri=$host/oauth2callback");
3752 $c->stash->{rest} = { success => 1 };
3757 =head2 brapi/v1/phenotypes
3759 Usage: To store phenotypes
3760 Desc:
3761 Request body example:
3763 "data": [
3765 "observationUnitDbId": "observationUnitDbId0",
3766 "observations": [
3768 "collector": "collector0",
3769 "observationDbId": "observationDbId0",
3770 "observationTimeStamp": "2018-01-01T14:47:23-0600",
3771 "observationVariableDbId": "observationVariableDbId0",
3772 "observationVariableName": "observationVariableName0",
3773 "season": "season0",
3774 "value": "value0"
3777 "collector": "collector1",
3778 "observationDbId": "observationDbId1",
3779 "observationTimeStamp": "2018-01-01T14:47:23-0600",
3780 "observationVariableDbId": "observationVariableDbId1",
3781 "observationVariableName": "observationVariableName1",
3782 "season": "season1",
3783 "value": "value1"
3786 "studyDbId": "studyDbId0"
3789 "observationUnitDbId": "observationUnitDbId1",
3790 "observations": [
3792 "collector": "collector0",
3793 "observationDbId": "observationDbId0",
3794 "observationTimeStamp": "2018-01-01T14:47:23-0600",
3795 "observationVariableDbId": "observationVariableDbId0",
3796 "observationVariableName": "observationVariableName0",
3797 "season": "season0",
3798 "value": "value0"
3801 "collector": "collector1",
3802 "observationDbId": "observationDbId1",
3803 "observationTimeStamp": "2018-01-01T14:47:23-0600",
3804 "observationVariableDbId": "observationVariableDbId1",
3805 "observationVariableName": "observationVariableName1",
3806 "season": "season1",
3807 "value": "value1"
3810 "studyDbId": "studyDbId1"
3815 Response JSON example:
3817 "metadata": {
3818 "datafiles": [],
3819 "pagination": {
3820 "currentPage": 0,
3821 "pageSize": 1000,
3822 "totalCount": 2,
3823 "totalPages": 1
3825 "status": []
3827 "result": {
3828 "data": [
3830 "germplasmDbId": "8383",
3831 "germplasmName": "Pahang",
3832 "observationDbId": "12345",
3833 "observationLevel": "plot",
3834 "observationTimestamp": "2015-11-05T15:12:56+01:00",
3835 "observationUnitDbId": "11",
3836 "observationUnitName": "ZIPA_68_Ibadan_2014",
3837 "observationVariableDbId": "CO_334:0100632",
3838 "observationVariableName": "Yield",
3839 "operator": "Jane Doe",
3840 "studyDbId": "35",
3841 "uploadedBy": "dbUserId",
3842 "value": "5"
3847 Args:
3848 Side Effects:
3850 =cut
3852 sub phenotypes : Chained('brapi') PathPart('phenotypes') Args(0) : ActionClass('REST') { }
3854 sub phenotypes_POST {
3855 my $self = shift;
3856 my $c = shift;
3857 my $clean_inputs = $c->stash->{clean_inputs};
3858 my $data = $clean_inputs->{data};
3859 my @all_observations;
3860 foreach my $observationUnit (@{$data}) {
3861 my $observationUnitDbId = $observationUnit->{observationUnitDbId};
3862 my $observations = $observationUnit->{observations};
3863 foreach my $observation (@{$observations}) {
3864 $observation->{observationUnitDbId} = $observationUnitDbId;
3865 push @all_observations, $observation;
3868 save_observation_results($self, $c, \@all_observations, 'v1');
3871 =head2 brapi/v2/observations
3873 Usage: To store observations
3874 Desc:
3875 Request body example:
3877 "observations": [
3879 "collector": "string", //optional
3880 "observationDbId": "string", // if populated then update existing otherwise add new
3881 "observationTimeStamp": "2018-06-19T18:59:45.751Z", //optional
3882 "observationUnitDbId": "string", //required
3883 "observationVariableDbId": "string", //required
3884 "value": "string" //required
3888 Response JSON example:
3890 "metadata": {
3891 "datafiles": [],
3892 "pagination": {
3893 "currentPage": 0,
3894 "pageSize": 1000,
3895 "totalCount": 2,
3896 "totalPages": 1
3898 "status": []
3900 "result": {
3901 "data": [
3903 "germplasmDbId": "8383",
3904 "germplasmName": "Pahang",
3905 "observationDbId": "12345",
3906 "observationLevel": "plot",
3907 "observationTimestamp": "2015-11-05T15:12:56+01:00",
3908 "observationUnitDbId": "11",
3909 "observationUnitName": "ZIPA_68_Ibadan_2014",
3910 "observationVariableDbId": "CO_334:0100632",
3911 "observationVariableName": "Yield",
3912 "operator": "Jane Doe",
3913 "studyDbId": "35",
3914 "uploadedBy": "dbUserId",
3915 "value": "5"
3920 Args:
3921 Side Effects:
3923 =cut
3925 sub observations : Chained('brapi') PathPart('observations') Args(0) : ActionClass('REST') { }
3927 sub observations_PUT {
3928 my $self = shift;
3929 my $c = shift;
3930 my $version = $c->request->captures->[0];
3931 my $brapi_package_result;
3932 if ($version eq 'v2'){
3933 my $force_authenticate = $c->config->{brapi_observations_require_login};
3934 my ($auth,$user_id,$user_type) = _authenticate_user($c,$force_authenticate);
3935 my $clean_inputs = $c->stash->{clean_inputs};
3936 my %observations = %$clean_inputs;
3937 my @all_observations;
3938 foreach my $observation (keys %observations) {
3939 my $observationDbId = $observation;
3940 my $observations = $observations{$observation};
3941 $observations->{observationDbId} = $observationDbId;
3942 push @all_observations, $observations;
3944 my $brapi = $self->brapi_module;
3945 my $brapi_module = $brapi->brapi_wrapper('Observations');
3946 $brapi_package_result = $brapi_module->observations_store({
3947 observations => \@all_observations,
3948 user_id => $user_id,
3949 user_type => $user_type,
3950 overwrite => 1,
3951 },$c);
3952 } elsif ($version eq 'v1'){
3953 my $clean_inputs = $c->stash->{clean_inputs};
3954 my $observations = $clean_inputs->{observations};
3955 save_observation_results($self, $c, $observations, 'v1');
3958 my $status = $brapi_package_result->{status};
3959 my $http_status_code = _get_http_status_code($status);
3961 _standard_response_construction($c, $brapi_package_result, $http_status_code);
3964 sub observations_GET {
3965 my $self = shift;
3966 my $c = shift;
3967 my $auth = _authenticate_user($c);
3968 my $clean_inputs = $c->stash->{clean_inputs};
3969 my $brapi = $self->brapi_module;
3970 my $brapi_module = $brapi->brapi_wrapper('Observations');
3971 my $brapi_package_result = $brapi_module->search({
3972 observationLevel => $clean_inputs->{observationLevel},
3973 seasonDbId => $clean_inputs->{seasonDbId},
3974 locationDbId => $clean_inputs->{locationDbId},
3975 studyDbId => $clean_inputs->{studyDbId},
3976 germplasmDbId => $clean_inputs->{germplasmDbId},
3977 programDbId => $clean_inputs->{programDbId},
3978 observationTimeStampRangeStart => $clean_inputs->{observationTimeStampRangeStart},
3979 observationTimeStampRangeEnd => $clean_inputs->{observationTimeStampRangeEnd},
3980 observationUnitDbId => $clean_inputs->{observationUnitDbId},
3981 observationDbId => $clean_inputs->{observationDbId},
3982 observationVariableDbId => $clean_inputs->{observationVariableDbId}
3985 _standard_response_construction($c, $brapi_package_result);
3988 sub observations_POST {
3989 my $self = shift;
3990 my $c = shift;
3991 my $force_authenticate = $c->config->{brapi_observations_require_login};
3992 my ($auth,$user_id,$user_type) = _authenticate_user($c, $force_authenticate);
3993 my $clean_inputs = $c->stash->{clean_inputs};
3994 my $data = $clean_inputs;
3995 my @all_observations;
3996 foreach my $observation (values %{$data}) {
3997 push @all_observations, $observation;
3999 my $brapi = $self->brapi_module;
4000 my $brapi_module = $brapi->brapi_wrapper('Observations');
4001 my $brapi_package_result = $brapi_module->observations_store({
4002 observations => \@all_observations,
4003 user_id => $user_id,
4004 user_type => $user_type,
4005 overwrite => 0,
4006 },$c);
4008 my $status = $brapi_package_result->{status};
4009 my $http_status_code = _get_http_status_code($status);
4011 _standard_response_construction($c, $brapi_package_result, $http_status_code);
4014 sub observations_table : Chained('brapi') PathPart('observations/table') Args(0) : ActionClass('REST') { }
4016 sub observations_table_GET {
4017 my $self = shift;
4018 my $c = shift;
4019 my ($auth) = _authenticate_user($c);
4020 my $clean_inputs = $c->stash->{clean_inputs};
4021 my $brapi = $self->brapi_module;
4022 my $brapi_module = $brapi->brapi_wrapper('ObservationTables');
4023 my $brapi_package_result = $brapi_module->search($c->stash->{clean_inputs});
4024 _standard_response_construction($c, $brapi_package_result);
4027 sub observations_single : Chained('brapi') PathPart('observations') CaptureArgs(1) {
4028 my $self = shift;
4029 my $c = shift;
4030 print STDERR " Capturing id\n";
4031 $c->stash->{observation_id} = shift;
4034 sub observations_detail : Chained('observations_single') PathPart('') Args(0) ActionClass('REST') { }
4036 sub observations_detail_GET {
4037 my $self = shift;
4038 my $c = shift;
4039 my $clean_inputs = $c->stash->{clean_inputs};
4040 my $brapi = $self->brapi_module;
4041 my $brapi_module = $brapi->brapi_wrapper('Observations');
4042 my $brapi_package_result = $brapi_module->detail({
4043 observationDbId => $c->stash->{observation_id}
4045 _standard_response_construction($c, $brapi_package_result);
4048 sub observations_detail_PUT {
4049 my $self = shift;
4050 my $c = shift;
4051 my ($auth,$user_id,$user_type) = _authenticate_user($c);
4052 my $clean_inputs = $c->stash->{clean_inputs};
4053 my $observations = $clean_inputs;
4054 my @all_observations;
4055 $observations->{observationDbId} = $c->stash->{observation_id};
4056 push @all_observations, $observations;
4058 my $brapi = $self->brapi_module;
4059 my $brapi_module = $brapi->brapi_wrapper('Observations');
4060 my $brapi_package_result = $brapi_module->observations_store({
4061 observations => \@all_observations,
4062 user_id => $user_id,
4063 user_type => $user_type,
4064 overwrite => 1,
4065 },$c);
4068 my $status = $brapi_package_result->{status};
4069 my $http_status_code = _get_http_status_code($status);
4071 _standard_response_construction($c, $brapi_package_result, $http_status_code);
4074 sub observation_search_save : Chained('brapi') PathPart('search/observations') Args(0) : ActionClass('REST') { }
4076 sub observation_search_save_POST {
4077 my $self = shift;
4078 my $c = shift;
4079 save_results($self,$c,$c->stash->{clean_inputs},'Observations');
4082 sub observation_search_retrieve : Chained('brapi') PathPart('search/observations') Args(1) {
4083 my $self = shift;
4084 my $c = shift;
4085 my $search_id = shift;
4086 retrieve_results($self, $c, $search_id, 'Observations');
4089 sub save_observation_results {
4090 my $self = shift;
4091 my $c = shift;
4092 my $observations = shift;
4093 my $version = shift;
4095 # Check that the user is a user. We don't check other permissions for now.
4096 my $force_authenticate = $c->config->{brapi_observations_require_login};
4097 my ($auth_success, $user_id, $user_type, $user_pref, $expired) = _authenticate_user($c, $force_authenticate);
4099 my $dbh = $c->dbc->dbh;
4100 my $p = CXGN::People::Person->new($dbh, $user_id);
4101 my $username = $p->get_username;
4102 my $clean_inputs = $c->stash->{clean_inputs};
4103 my $brapi = $self->brapi_module;
4105 my $dir = $c->tempfiles_subdir('/delete_nd_experiment_ids');
4106 my $temp_file_nd_experiment_id = $c->config->{basepath}."/".$c->tempfile( TEMPLATE => 'delete_nd_experiment_ids/fileXXXX');
4108 my $brapi_module = $brapi->brapi_wrapper('Observations');
4109 my $brapi_package_result = $brapi_module->observations_store({
4110 observations => $observations,
4111 user_id => $user_id,
4112 username => $username,
4113 user_type => $user_type,
4114 version => $version,
4115 archive_path => $c->config->{archive_path},
4116 tempfiles_subdir => $c->config->{basepath}."/".$c->config->{tempfiles_subdir},
4117 basepath => $c->config->{basepath},
4118 dbhost => $c->config->{dbhost},
4119 dbname => $c->config->{dbname},
4120 dbuser => $c->config->{dbuser},
4121 dbpass => $c->config->{dbpass},
4122 temp_file_nd_experiment_id => $temp_file_nd_experiment_id
4123 },$c);
4125 my $status = $brapi_package_result->{status};
4126 my $http_status_code = _get_http_status_code($status);
4128 _standard_response_construction($c, $brapi_package_result, $http_status_code);
4131 =head2 brapi/v1/markers
4133 Usage: To retrieve markers
4134 Desc: BrAPI v1.3
4135 Args:
4136 Side Effects: deprecated on BrAPI v2.0
4138 =cut
4140 sub markers_search : Chained('brapi') PathPart('markers') Args(0) : ActionClass('REST') { }
4142 sub markers_search_GET {
4143 my $self = shift;
4144 my $c = shift;
4145 my ($auth) = _authenticate_user($c);
4146 my $clean_inputs = $c->stash->{clean_inputs};
4147 my $brapi = $self->brapi_module;
4148 my $brapi_module = $brapi->brapi_wrapper('Markers');
4149 my $brapi_package_result = $brapi_module->search();
4150 _standard_response_construction($c, $brapi_package_result);
4153 sub markers_search_save : Chained('brapi') PathPart('search/markers') Args(0) : ActionClass('REST') { }
4155 sub markers_search_save_POST {
4156 my $self = shift;
4157 my $c = shift; #print "--\n-" ; print Dumper($self); print "--\n-" ;
4158 save_results($self,$c,$c->stash->{clean_inputs},'Markers');
4161 sub markers_search_retrieve : Chained('brapi') PathPart('search/markers') Args(1) {
4162 my $self = shift;
4163 my $c = shift;
4164 my $search_id = shift;
4165 retrieve_results($self, $c, $search_id, 'Markers');
4169 =head2 brapi/v2/variants
4171 Usage: To retrieve variants
4172 Desc: BrAPI v2.0
4173 Args:
4174 Side Effects:
4176 =cut
4178 sub variants_search : Chained('brapi') PathPart('variants') Args(0) : ActionClass('REST') { }
4180 sub variants_search_GET {
4181 my $self = shift;
4182 my $c = shift;
4183 my ($auth) = _authenticate_user($c);
4184 my $clean_inputs = $c->stash->{clean_inputs};
4185 my $brapi = $self->brapi_module;
4186 my $brapi_module = $brapi->brapi_wrapper('Variants');
4187 my $brapi_package_result = $brapi_module->search($clean_inputs);
4188 _standard_response_construction($c, $brapi_package_result);
4191 sub variants_single : Chained('brapi') PathPart('variants') CaptureArgs(1) {
4192 my $self = shift;
4193 my $c = shift;
4194 print STDERR " Capturing variants id\n";
4195 $c->stash->{variants_id} = shift;
4198 sub variants_detail : Chained('variants_single') PathPart('') Args(0) ActionClass('REST') { }
4200 sub variants_detail_GET {
4201 my $self = shift;
4202 my $c = shift;
4203 my $clean_inputs = $c->stash->{clean_inputs};
4204 my $brapi = $self->brapi_module;
4205 my $brapi_module = $brapi->brapi_wrapper('Variants');
4206 my $brapi_package_result = $brapi_module->detail({
4207 variantDbId => $c->stash->{variants_id}
4209 _standard_response_construction($c, $brapi_package_result);
4212 sub variants_calls_detail : Chained('variants_single') PathPart('calls') Args(0) : ActionClass('REST') { }
4214 sub variants_calls_detail_POST {
4215 my $self = shift;
4216 my $c = shift;
4217 #my $auth = _authenticate_user($c);
4220 sub variants_calls_detail_GET {
4221 my $self = shift;
4222 my $c = shift;
4223 my ($auth) = _authenticate_user($c);
4224 my $clean_inputs = $c->stash->{clean_inputs};
4225 my $brapi = $self->brapi_module;
4226 my $brapi_module = $brapi->brapi_wrapper('Variants');
4227 my $brapi_package_result = $brapi_module->calls({
4228 variantDbId => $c->stash->{variants_id},
4229 variantSetDbId => $c->stash->{variantSetDbId},
4230 unknown_string => $clean_inputs->{unknownString}->[0],
4231 sep_phased => $clean_inputs->{sepPhased}->[0],
4232 sep_unphased => $clean_inputs->{sepUnphased}->[0],
4233 expand_homozygotes => $clean_inputs->{expandHomozygotes}->[0],
4235 _standard_response_construction($c, $brapi_package_result);
4238 sub variants_search_save : Chained('brapi') PathPart('search/variants') Args(0) : ActionClass('REST') { }
4240 sub variants_search_save_POST {
4241 my $self = shift;
4242 my $c = shift;
4243 save_results($self,$c,$c->stash->{clean_inputs},'Variants');
4246 sub variants_search_retrieve : Chained('brapi') PathPart('search/variants') Args(1) {
4247 my $self = shift;
4248 my $c = shift;
4249 my $search_id = shift;
4250 retrieve_results($self, $c, $search_id, 'Variants');
4254 =head2 brapi/v1/observations-search
4256 Usage: To retrieve observations
4257 Desc:
4258 Request body example:
4260 "collector": ["string","string"], //optional
4261 "observationDbId": ["string","string"], //optional
4262 "observationUnitDbId": ["string","string"], //optional
4263 "observationVariableDbId": ["string","string"] //optional
4265 Response JSON example:
4267 "metadata": {
4268 "datafiles": [],
4269 "pagination": {
4270 "currentPage": 0,
4271 "pageSize": 1000,
4272 "totalCount": 2,
4273 "totalPages": 1
4275 "status": []
4277 "result": {
4278 "data": [
4280 "germplasmDbId": "8383",
4281 "germplasmName": "Pahang",
4282 "observationDbId": "12345",
4283 "observationLevel": "plot",
4284 "observationTimestamp": "2015-11-05T15:12:56+01:00",
4285 "observationUnitDbId": "11",
4286 "observationUnitName": "ZIPA_68_Ibadan_2014",
4287 "observationVariableDbId": "CO_334:0100632",
4288 "observationVariableName": "Yield",
4289 "operator": "Jane Doe",
4290 "studyDbId": "35",
4291 "uploadedBy": "dbUserId",
4292 "value": "5"
4297 Args:
4298 Side Effects:
4300 =cut
4302 sub observations_search : Chained('brapi') PathPart('observations-search') Args(0) : ActionClass('REST') { }
4304 sub observations_search_POST {
4305 my $self = shift;
4306 my $c = shift;
4307 observations_search_process($self, $c);
4310 sub observations_search_GET {
4311 my $self = shift;
4312 my $c = shift;
4313 observations_search_process($self, $c);
4316 sub observations_search_process {
4317 my $self = shift;
4318 my $c = shift;
4319 # my ($auth) = _authenticate_user($c);
4320 my $clean_inputs = $c->stash->{clean_inputs};
4321 my $brapi = $self->brapi_module;
4322 my $brapi_module = $brapi->brapi_wrapper('Observations');
4323 my $brapi_package_result = $brapi_module->search({
4324 collectors => $clean_inputs->{collectors},
4325 observationDbIds => $clean_inputs->{observationDbIds},
4326 observationUnitDbIds => $clean_inputs->{observationUnitDbIds},
4327 observationVariableDbIds => $clean_inputs->{observationVariableDbIds}
4329 _standard_response_construction($c, $brapi_package_result);
4332 =head2 brapi/<version>/events
4333 Usage: To retrieve events (events are treatments/management factors in the database)
4334 Desc:
4335 Request body example:
4338 Response JSON example:
4340 "@context": [
4341 "https://brapi.org/jsonld/context/metadata.jsonld"
4343 "metadata": {
4344 "datafiles": [
4346 "fileDescription": "This is an Excel data file",
4347 "fileMD5Hash": "c2365e900c81a89cf74d83dab60df146",
4348 "fileName": "datafile.xlsx",
4349 "fileSize": 4398,
4350 "fileType": "application/vnd.ms-excel",
4351 "fileURL": "https://wiki.brapi.org/examples/datafile.xlsx"
4354 "pagination": {
4355 "currentPage": 0,
4356 "pageSize": 1000,
4357 "totalCount": 10,
4358 "totalPages": 1
4360 "status": [
4362 "message": "Request accepted, response successful",
4363 "messageType": "INFO"
4367 "result": {
4368 "data": [
4370 "additionalInfo": {},
4371 "date": [
4372 "2018-10-08T18:15:11Z",
4373 "2018-11-09T18:16:12Z"
4375 "eventDbId": "8566d4cb",
4376 "eventDescription": "A set of plots was watered",
4377 "eventParameters": [
4379 "key": "http://www.example.fr/vocabulary/2018#hasContact,",
4380 "value": "http://www.example.fr/id/agent/marie,",
4381 "valueRdfType": "http://xmlns.com/foaf/0.1/Agent,"
4384 "key": "fertilizer",
4385 "value": "nitrogen",
4386 "valueRdfType": null
4389 "eventType": "Watering",
4390 "eventTypeDbId": "4e7d691e",
4391 "observationUnitDbIds": [
4392 "8439eaff",
4393 "d7682e7a",
4394 "305ae51c"
4396 "studyDbId": "2cc2001f"
4401 Args:
4402 Side Effects:
4403 =cut
4405 sub events_search : Chained('brapi') PathPart('events') Args(0) : ActionClass('REST') { }
4407 sub events_search_POST {
4408 my $self = shift;
4409 my $c = shift;
4410 events_search_process($self, $c);
4413 sub events_search_GET {
4414 my $self = shift;
4415 my $c = shift;
4416 events_search_process($self, $c);
4419 sub events_search_process {
4420 my $self = shift;
4421 my $c = shift;
4422 my ($auth) = _authenticate_user($c);
4423 my $clean_inputs = $c->stash->{clean_inputs};
4424 my $brapi = $self->brapi_module;
4425 my $brapi_module = $brapi->brapi_wrapper('Events');
4426 my $brapi_package_result = $brapi_module->search($clean_inputs);
4427 _standard_response_construction($c, $brapi_package_result);
4430 =head2 brapi/<version>/images
4432 Usage: To retrieve observations
4433 Desc:
4434 Request body example:
4437 Response JSON example:
4440 "metadata": {
4441 "datafiles": [
4443 "pagination": {
4444 "currentPage": 0,
4445 "pageSize": 1000,
4446 "totalCount": 10,
4447 "totalPages": 1
4449 "status": [
4451 "message": "Request accepted, response successful",
4452 "messageType": "INFO"
4456 "result": {
4457 "data": [
4459 "additionalInfo": {},
4460 "copyright": "Copyright 2018 Bob Robertson",
4461 "description": "This is a picture of a tomato",
4462 "descriptiveOntologyTerms": [],
4463 "externalReferences": [
4465 "referenceID": "doi:10.155454/12349537E12",
4466 "referenceSource": "DOI"
4469 "imageDbId": "a55efb9c",
4470 "imageFileName": "image_0000231.jpg",
4471 "imageFileSize": 50000,
4472 "imageHeight": 550,
4473 "imageLocation": {
4474 "geometry": {
4475 "coordinates": [
4476 -76.506042,
4477 42.417373,
4480 "type": "Point"
4482 "type": "Feature"
4484 "imageName": "Tomato Image 1",
4485 "imageTimeStamp": "2018-01-01T14:47:23-0600",
4486 "imageURL": "https://wiki.brapi.org/images/tomato",
4487 "imageWidth": 700,
4488 "mimeType": "image/jpeg",
4489 "observationDbIds": [
4490 "d05dd235",
4491 "8875177d"
4493 "observationUnitDbId": "b7e690b6"
4499 Args:
4500 Side Effects:
4502 =cut
4504 sub images : Chained('brapi') PathPart('images') Args(0) : ActionClass('REST') { }
4506 sub images_GET {
4507 my $self = shift;
4508 my $c = shift;
4509 my ($auth) = _authenticate_user($c);
4510 my $clean_inputs = $c->stash->{clean_inputs};
4511 my $brapi = $self->brapi_module;
4512 my $brapi_module = $brapi->brapi_wrapper('Images');
4513 my $brapi_package_result = $brapi_module->search($clean_inputs);
4514 _standard_response_construction($c, $brapi_package_result);
4517 sub images_POST {
4518 my $self = shift;
4519 my $c = shift;
4521 # Check user auth. This matches observations PUT observations endpoint authorization.
4522 # No specific roles are check, just that the user has an account.
4523 my $force_authenticate = $c->config->{brapi_images_require_login};
4524 my ($auth_success, $user_id, $user_type, $user_pref, $expired) = _authenticate_user($c, $force_authenticate);
4526 my $clean_inputs = $c->stash->{clean_inputs};
4527 my @all_images;
4528 foreach my $image (values %{$clean_inputs}) {
4529 push @all_images, $image;
4531 my $brapi = $self->brapi_module;
4532 my $brapi_module = $brapi->brapi_wrapper('Images');
4533 my $image_dir = File::Spec->catfile($c->config->{static_datasets_path}, $c->config->{image_dir});
4535 my $brapi_package_result = $brapi_module->image_metadata_store(\@all_images, $image_dir, $user_id, $user_type);
4536 my $status = $brapi_package_result->{status};
4537 my $http_status_code = _get_http_status_code($status);
4539 _standard_response_construction($c, $brapi_package_result, $http_status_code);
4542 sub images_by_id : Chained('brapi') PathPart('images') CaptureArgs(1) {
4543 my $self = shift;
4544 my $c = shift;
4545 print STDERR "Images_base... capturing image_id\n";
4546 $c->stash->{image_id} = shift;
4549 sub images_single : Chained('images_by_id') PathPart('') Args(0) ActionClass('REST') { }
4551 sub images_single_GET {
4552 my $self = shift;
4553 my $c = shift;
4554 my $brapi = $self->brapi_module;
4555 my $brapi_module = $brapi->brapi_wrapper('Images');
4556 my $brapi_package_result = $brapi_module->detail( { image_id => $c->stash->{image_id} });
4557 _standard_response_construction($c, $brapi_package_result);
4560 # /brapi/v1/images PUT
4561 # sub image_store : Chained('brapi') PathPart('images') Args(0) ActionClass('REST') { }
4563 sub images_single_PUT {
4564 my $self = shift;
4565 my $c = shift;
4567 # Check user auth. This matches observations PUT observations endpoint authorization.
4568 # No specific roles are check, just that the user has an account.
4569 my $force_authenticate = $c->config->{brapi_images_require_login};
4570 my ($auth_success, $user_id, $user_type, $user_pref, $expired) = _authenticate_user($c, $force_authenticate);
4572 my $clean_inputs = $c->stash->{clean_inputs};
4573 my $image = $clean_inputs;
4574 $image->{imageDbId} = $c->stash->{image_id};
4575 my @all_images;
4576 push @all_images, $image;
4577 my $brapi = $self->brapi_module;
4578 my $brapi_module = $brapi->brapi_wrapper('Images');
4579 my $image_dir = File::Spec->catfile($c->config->{static_datasets_path}, $c->config->{image_dir});
4580 my $brapi_package_result = $brapi_module->image_metadata_store(\@all_images, $image_dir, $user_id, $user_type, $c->stash->{image_id});
4581 my $status = $brapi_package_result->{status};
4582 my $http_status_code = _get_http_status_code($status);
4584 _standard_response_construction($c, $brapi_package_result, $http_status_code);
4588 # /brapi/v1/images/<image_id>/imagecontent
4589 sub image_content_store : Chained('images_by_id') PathPart('imagecontent') Args(0) ActionClass('REST') { }
4591 sub image_content_store_PUT {
4592 my $self = shift;
4593 my $c = shift;
4595 # Check user auth. This matches observations PUT observations endpoint authorization.
4596 # No specific roles are check, just that the user has an account.
4597 my $force_authenticate = $c->config->{brapi_images_require_login};
4598 my ($auth_success, $user_id, $user_type, $user_pref, $expired) = _authenticate_user($c, $force_authenticate);
4600 my $clean_inputs = $c->stash->{clean_inputs};
4601 print STDERR Dumper($clean_inputs);print Dumper $c->req->body();
4602 my $brapi = $self->brapi_module;
4603 my $brapi_module = $brapi->brapi_wrapper('Images');
4604 my $image_dir = File::Spec->catfile($c->config->{static_datasets_path}, $c->config->{image_dir});
4606 my $brapi_package_result = $brapi_module->image_data_store($image_dir, $c->stash->{image_id}, $c->req->body(), $c->req->content_type());
4608 my $status = $brapi_package_result->{status};
4609 my $http_status_code = _get_http_status_code($status);
4611 _standard_response_construction($c, $brapi_package_result, $http_status_code);
4614 sub image_search_save : Chained('brapi') PathPart('search/images') Args(0) : ActionClass('REST') { }
4616 sub image_search_save_POST {
4617 my $self = shift;
4618 my $c = shift; #print "--\n-" ; print Dumper($self); print "--\n-" ;
4619 save_results($self,$c,$c->stash->{clean_inputs},'Images');
4622 sub image_search_retrieve : Chained('brapi') PathPart('search/images') Args(1) {
4623 my $self = shift;
4624 my $c = shift;
4625 my $search_id = shift;
4626 retrieve_results($self, $c, $search_id, 'Images');
4629 sub _get_http_status_code {
4630 my $status = shift;
4631 my $http_status_code = 200;
4633 foreach(@$status) {
4635 if ($_->{messageType} eq "403") {
4636 $http_status_code = 403;
4637 last;
4639 elsif ($_->{messageType} eq "401") {
4640 $http_status_code = 401;
4641 last;
4643 elsif ($_->{messageType} eq "400") {
4644 $http_status_code = 400;
4645 last;
4647 elsif ($_->{messageType} eq "200") {
4648 $http_status_code = 200;
4649 last;
4653 return $http_status_code;
4656 =head2 brapi/v2/callsets
4658 Usage: To retrieve data for callsets
4659 Desc:
4660 Return JSON example:
4662 "metadata" : {
4663 "pagination": {
4664 "pageSize": 10,
4665 "currentPage": 1,
4666 "totalCount": 10,
4667 "totalPages": 1
4669 "status": []
4672 "result": {
4673 "data": [
4675 "additionalInfo": {},
4676 "callSetDbId": "eb2bfd3d",
4677 "callSetName": "Sample_123_DNA_Run_456",
4678 "created": "2018-01-01T14:47:23-0600",
4679 "sampleDbId": "5e50e11d",
4680 "studyDbId": "708149c1",
4681 "updated": "2018-01-01T14:47:23-0600",
4682 "variantSetIds": [
4683 "cfd3d60f",
4684 "a4e8bfe9"
4690 Args:
4691 Side Effects:
4693 =cut
4695 sub callsets : Chained('brapi') PathPart('callsets') Args(0) : ActionClass('REST') { }
4697 sub callsets_GET {
4698 my $self = shift;
4699 my $c = shift;
4700 my ($auth) = _authenticate_user($c);
4701 my $clean_inputs = $c->stash->{clean_inputs};
4702 my $brapi = $self->brapi_module;
4703 my $brapi_module = $brapi->brapi_wrapper('CallSets');
4704 my $brapi_package_result = $brapi_module->search({
4705 variantSetDbId => $clean_inputs->{variantSetDbId},
4706 sampleDbId => $clean_inputs->{sampleDbId},
4707 callSetName => $clean_inputs->{callSetName},
4708 # studyDbId => $clean_inputs->{studyDbId},
4709 germplasmDbId => $clean_inputs->{germplasmDbId},
4710 callSetDbId => $clean_inputs->{callSetDbId},
4712 _standard_response_construction($c, $brapi_package_result);
4715 sub callsets_single : Chained('brapi') PathPart('callsets') CaptureArgs(1) {
4716 my $self = shift;
4717 my $c = shift;
4718 my $id = shift;
4719 $c->stash->{callset_id} = $id;
4722 sub callsets_fetch : Chained('callsets_single') PathPart('') Args(0) : ActionClass('REST') { }
4724 sub callsets_fetch_GET {
4725 my $self = shift;
4726 my $c = shift;
4727 my ($auth) = _authenticate_user($c);
4728 my $clean_inputs = $c->stash->{clean_inputs};
4729 my $brapi = $self->brapi_module;
4730 my $brapi_module = $brapi->brapi_wrapper('CallSets');
4731 my $brapi_package_result = $brapi_module->detail({
4732 callset_id => $c->stash->{callset_id},
4733 unknown_string => $clean_inputs->{unknownString}->[0],
4734 sep_phased => $clean_inputs->{sepPhased}->[0],
4735 sep_unphased => $clean_inputs->{sepUnphased}->[0],
4736 expand_homozygotes => $clean_inputs->{expandHomozygotes}->[0],
4738 _standard_response_construction($c, $brapi_package_result);
4741 sub callsets_call_detail : Chained('callsets_single') PathPart('calls') Args(0) : ActionClass('REST') { }
4743 sub callsets_call_detail_GET {
4744 my $self = shift;
4745 my $c = shift;
4746 my ($auth) = _authenticate_user($c);
4747 my $clean_inputs = $c->stash->{clean_inputs};
4748 my $brapi = $self->brapi_module;
4749 my $brapi_module = $brapi->brapi_wrapper('CallSets');
4750 my $brapi_package_result = $brapi_module->calls({
4751 callset_id => $c->stash->{callset_id},
4753 _standard_response_construction($c, $brapi_package_result);
4756 sub callsets_call_filter_detail : Chained('callsets_single') PathPart('calls') Args(1) : ActionClass('REST') { }
4758 sub callsets_call_filter_detail_GET {
4759 my $self = shift;
4760 my $c = shift;
4761 my ($auth) = _authenticate_user($c);
4762 my $clean_inputs = $c->stash->{clean_inputs};
4763 my $brapi = $self->brapi_module;
4764 my $brapi_module = $brapi->brapi_wrapper('CallSets');
4765 my $brapi_package_result = $brapi_module->calls({
4766 callset_id => $c->stash->{callset_id},
4768 _standard_response_construction($c, $brapi_package_result);
4771 sub callsets_search_save : Chained('brapi') PathPart('search/callsets') Args(0) : ActionClass('REST') { }
4773 sub callsets_search_save_POST {
4774 my $self = shift;
4775 my $c = shift;
4776 save_results($self,$c,$c->stash->{clean_inputs},'CallSets');
4779 sub callsets_search_retrieve : Chained('brapi') PathPart('search/callsets') Args(1) {
4780 my $self = shift;
4781 my $c = shift;
4782 my $search_id = shift;
4783 retrieve_results($self, $c, $search_id, 'CallSets');
4787 =head2 brapi/v2/variantsets
4789 Usage: To retrieve data for variantsets
4790 Desc:
4791 Return JSON example:
4793 "metadata" : {
4794 "pagination": {
4795 "pageSize": 10,
4796 "currentPage": 1,
4797 "totalCount": 10,
4798 "totalPages": 1
4800 "status": []
4803 "result": {
4804 "data": [
4806 "additionalInfo": {},
4807 "analysis": [
4809 "analysisDbId": "6191a6bd",
4810 "analysisName": "Standard QC",
4811 "created": "2018-01-01T14:47:23-0600",
4812 "description": "This is a formal description of a QC methodology.",
4813 "software": [
4814 "https://github.com/genotyping/QC"
4816 "type": "QC",
4817 "updated": "2018-01-01T14:47:23-0600"
4820 "availableFormats": [
4822 "dataFormat": "VCF",
4823 "fileFormat": "application/excel",
4824 "fileURL": "https://brapi.org/example/VCF_1.xlsx"
4827 "dataFormat": "VCF",
4828 "fileFormat": "text/csv",
4829 "fileURL": "https://brapi.org/example/VCF_2.csv"
4832 "callSetCount": 341,
4833 "referenceSetDbId": "57eae639",
4834 "studyDbId": "2fc3b034",
4835 "variantCount": 250,
4836 "variantSetDbId": "87a6ac1e",
4837 "variantSetName": "Maize QC DataSet 002334"
4842 Args:
4843 Side Effects:
4845 =cut
4847 sub variantsets : Chained('brapi') PathPart('variantsets') Args(0) : ActionClass('REST') { }
4849 sub variantsets_GET {
4850 my $self = shift;
4851 my $c = shift;
4852 my ($auth) = _authenticate_user($c);
4853 my $clean_inputs = $c->stash->{clean_inputs};
4854 my $brapi = $self->brapi_module;
4855 my $brapi_module = $brapi->brapi_wrapper('VariantSets');
4856 my $brapi_package_result = $brapi_module->search({
4857 variantSetDbId => $clean_inputs->{variantSetDbId},
4858 variantDbId => $clean_inputs->{variantDbId},
4859 callSetDbId => $clean_inputs->{callSetDbId},
4860 studyDbId => $clean_inputs->{studyDbId},
4861 studyName => $clean_inputs->{studyName}
4863 _standard_response_construction($c, $brapi_package_result);
4866 ### VariantSet single
4868 sub variantsets_single : Chained('brapi') PathPart('variantsets') CaptureArgs(1) {
4869 my $self = shift;
4870 my $c = shift;
4871 my $id = shift;
4872 $c->stash->{variantSetDbId} = $id;
4875 sub variantsets_fetch : Chained('variantsets_single') PathPart('') Args(0) : ActionClass('REST') { }
4878 sub variantsets_fetch_GET {
4879 my $self = shift;
4880 my $c = shift;
4881 my ($auth) = _authenticate_user($c);
4882 my $clean_inputs = $c->stash->{clean_inputs};
4883 my $brapi = $self->brapi_module;
4884 my $brapi_module = $brapi->brapi_wrapper('VariantSets');
4885 my $brapi_package_result = $brapi_module->detail({
4886 variantSetDbId => $c->stash->{variantSetDbId},
4888 _standard_response_construction($c, $brapi_package_result);
4891 sub variantsets_callset_detail : Chained('variantsets_single') PathPart('callsets') Args(0) : ActionClass('REST') { }
4893 sub variantsets_callset_detail_GET {
4894 my $self = shift;
4895 my $c = shift;
4896 my ($auth) = _authenticate_user($c);
4897 my $clean_inputs = $c->stash->{clean_inputs};
4898 my $brapi = $self->brapi_module;
4899 my $brapi_module = $brapi->brapi_wrapper('VariantSets');
4900 my $brapi_package_result = $brapi_module->callsets({
4901 variantSetDbId => $c->stash->{variantSetDbId},
4902 callSetDbId => $clean_inputs->{callSetDbId},
4903 callSetName => $clean_inputs->{callSetName}
4905 _standard_response_construction($c, $brapi_package_result);
4908 sub variantsets_calls_detail : Chained('variantsets_single') PathPart('calls') Args(0) : ActionClass('REST') { }
4910 sub variantsets_calls_detail_GET {
4911 my $self = shift;
4912 my $c = shift;
4913 my ($auth) = _authenticate_user($c);
4914 my $clean_inputs = $c->stash->{clean_inputs};
4915 my $brapi = $self->brapi_module;
4916 my $brapi_module = $brapi->brapi_wrapper('VariantSets');
4917 my $brapi_package_result = $brapi_module->calls({
4918 variantSetDbId => $c->stash->{variantSetDbId},
4919 unknown_string => $clean_inputs->{unknownString}->[0],
4920 sep_phased => $clean_inputs->{sepPhased}->[0],
4921 sep_unphased => $clean_inputs->{sepUnphased}->[0],
4922 expand_homozygotes => $clean_inputs->{expandHomozygotes}->[0],
4924 _standard_response_construction($c, $brapi_package_result);
4927 sub variantsets_variants_detail : Chained('variantsets_single') PathPart('variants') Args(0) : ActionClass('REST') { }
4929 sub variantsets_variants_detail_GET {
4930 my $self = shift;
4931 my $c = shift;
4932 my ($auth) = _authenticate_user($c);
4933 my $clean_inputs = $c->stash->{clean_inputs};
4934 my $brapi = $self->brapi_module;
4935 my $brapi_module = $brapi->brapi_wrapper('VariantSets');
4936 my $brapi_package_result = $brapi_module->variants({
4937 variantSetDbId => $c->stash->{variantSetDbId},
4939 _standard_response_construction($c, $brapi_package_result);
4942 sub variantsets_extract : Chained('brapi') PathPart('variantsets/extract') Args(0) : ActionClass('REST') { }
4944 sub variantsets_extract_POST {
4945 my $self = shift;
4946 my $c = shift;
4947 # my $force_authenticate = 1;
4948 # my ($auth_success, $user_id, $user_type, $user_pref, $expired) = _authenticate_user($c, $force_authenticate);
4950 my $clean_inputs = $c->stash->{clean_inputs};
4951 my $brapi = $self->brapi_module;
4952 my $brapi_module = $brapi->brapi_wrapper('VariantSets');
4953 my $brapi_package_result = $brapi_module->extract($clean_inputs);
4954 my $status = $brapi_package_result->{status};
4955 my $http_status_code = _get_http_status_code($status);
4957 _standard_response_construction($c, $brapi_package_result, $http_status_code);
4960 sub variantsets_search_save : Chained('brapi') PathPart('search/variantsets') Args(0) : ActionClass('REST') { }
4962 sub variantsets_search_save_POST {
4963 my $self = shift;
4964 my $c = shift;
4965 save_results($self,$c,$c->stash->{clean_inputs},'VariantSets');
4968 sub variantsets_search_retrieve : Chained('brapi') PathPart('search/variantsets') Args(1) {
4969 my $self = shift;
4970 my $c = shift;
4971 my $search_id = shift;
4972 retrieve_results($self, $c, $search_id, 'VariantSets');
4976 =head2 brapi/v2/calls
4978 Usage: To retrieve data for calls
4979 Desc:
4980 Return JSON example:
4982 "metadata" : {
4983 "pagination": {
4984 "pageSize": 10,
4985 "currentPage": 1,
4986 "totalCount": 10,
4987 "totalPages": 1
4989 "status": []
4992 "result": {
4993 "data": [
4995 "additionalInfo": {},
4996 "callSetDbId": "16466f55",
4997 "callSetName": "Sample_123_DNA_Run_456",
4998 "genotype": {
4999 "values": [
5000 "AA"
5003 "genotype_likelihood": [
5006 "phaseSet": "6410afc5",
5007 "variantDbId": "538c8ecf",
5008 "variantName": "Marker A"
5011 "expandHomozygotes": true,
5012 "sepPhased": "~",
5013 "sepUnphased": "|",
5014 "unknownString": "-"
5018 Args:
5019 Side Effects:
5021 =cut
5024 sub calls_search_save : Chained('brapi') PathPart('search/calls') Args(0) : ActionClass('REST') { }
5026 sub calls_search_save_POST {
5027 my $self = shift;
5028 my $c = shift;
5029 save_results($self,$c,$c->stash->{clean_inputs},'Calls');
5032 sub calls_search_retrieve : Chained('brapi') PathPart('search/calls') Args(1) {
5033 my $self = shift;
5034 my $c = shift;
5035 my $search_id = shift;
5036 retrieve_results($self, $c, $search_id, 'Calls');
5039 =head2 brapi/v2/referencesets
5041 Usage: To retrieve data for reference sets
5042 Desc:
5043 Return JSON example:
5045 "metadata" : {
5046 "pagination": {
5047 "pageSize": 10,
5048 "currentPage": 1,
5049 "totalCount": 10,
5050 "totalPages": 1
5052 "status": []
5055 "result": {
5056 "data": [
5058 "additionalInfo": {},
5059 "assemblyPUI": "doi://10.12345/fake/9876",
5060 "description": "Description for an assembly",
5061 "md5checksum": "c2365e900c81a89cf74d83dab60df146",
5062 "referenceSetDbId": "7e029a84",
5063 "referenceSetName": "Assembly version",
5064 "sourceAccessions": [
5065 "A0000002",
5066 "A0009393"
5068 "sourceURI": "https://wiki.brapi.org/files/demo.fast",
5069 "species": {
5070 "term": "sonic hedgehog",
5071 "termURI": "MGI:MGI:98297"
5077 Args:
5078 Side Effects:
5080 =cut
5082 sub referencesets : Chained('brapi') PathPart('referencesets') Args(0) : ActionClass('REST') { }
5084 sub referencesets_GET {
5085 my $self = shift;
5086 my $c = shift;
5087 my ($auth) = _authenticate_user($c);
5088 my $clean_inputs = $c->stash->{clean_inputs};
5089 my $brapi = $self->brapi_module;
5090 my $brapi_module = $brapi->brapi_wrapper('ReferenceSets');
5091 my $brapi_package_result = $brapi_module->search($clean_inputs);
5092 _standard_response_construction($c, $brapi_package_result);
5095 sub referencesets_single : Chained('brapi') PathPart('referencesets') CaptureArgs(1) {
5096 my $self = shift;
5097 my $c = shift;
5098 my $id = shift;
5099 $c->stash->{referenceSetDbId} = $id;
5102 sub referencesets_fetch : Chained('referencesets_single') PathPart('') Args(0) : ActionClass('REST') { }
5105 sub referencesets_fetch_GET {
5106 my $self = shift;
5107 my $c = shift;
5108 my ($auth) = _authenticate_user($c);
5109 my $clean_inputs = $c->stash->{clean_inputs};
5110 my $brapi = $self->brapi_module;
5111 my $brapi_module = $brapi->brapi_wrapper('ReferenceSets');
5112 my $brapi_package_result = $brapi_module->detail($c->stash->{referenceSetDbId});
5113 _standard_response_construction($c, $brapi_package_result);
5116 sub referencesets_search : Chained('brapi') PathPart('search/referencesets') Args(0) : ActionClass('REST') { }
5118 sub referencesets_search_POST {
5119 my $self = shift;
5120 my $c = shift;
5121 save_results($self,$c,$c->stash->{clean_inputs},'ReferenceSets');
5124 sub referencesets_search_retrieve : Chained('brapi') PathPart('search/referencesets') Args(1) {
5125 my $self = shift;
5126 my $c = shift;
5127 my $search_id = shift;
5128 retrieve_results($self, $c, $search_id, 'ReferenceSets');
5131 =head2 brapi/v2/reference
5133 Usage: To retrieve data for reference
5134 Desc:
5135 Return JSON example:
5137 "metadata" : {
5138 "pagination": {
5139 "pageSize": 10,
5140 "currentPage": 1,
5141 "totalCount": 10,
5142 "totalPages": 1
5144 "status": []
5147 "result": {
5148 "data": [
5150 "additionalInfo": {},
5151 "length": 50000000,
5152 "md5checksum": "c2365e900c81a89cf74d83dab60df146",
5153 "referenceDbId": "fc0a81d0",
5154 "referenceName": "Chromosome 2",
5155 "referenceSetDbId": "c1ecfef1",
5156 "sourceAccessions": [
5157 "GCF_000001405.26"
5159 "sourceDivergence": 0.01,
5160 "sourceURI": "https://wiki.brapi.org/files/demo.fast",
5161 "species": {
5162 "term": "sonic hedgehog",
5163 "termURI": "MGI:MGI:98297"
5169 Args:
5170 Side Effects:
5172 =cut
5174 sub reference : Chained('brapi') PathPart('references') Args(0) : ActionClass('REST') { }
5176 sub reference_GET {
5177 my $self = shift;
5178 my $c = shift;
5179 my ($auth) = _authenticate_user($c);
5180 my $clean_inputs = $c->stash->{clean_inputs};
5181 my $brapi = $self->brapi_module;
5182 my $brapi_module = $brapi->brapi_wrapper('References');
5183 my $brapi_package_result = $brapi_module->search($clean_inputs);
5184 _standard_response_construction($c, $brapi_package_result);
5187 sub reference_single : Chained('brapi') PathPart('references') CaptureArgs(1) {
5188 my $self = shift;
5189 my $c = shift;
5190 my $id = shift;
5191 $c->stash->{referenceDbId} = $id;
5194 sub reference_fetch : Chained('reference_single') PathPart('') Args(0) : ActionClass('REST') { }
5197 sub reference_fetch_GET {
5198 my $self = shift;
5199 my $c = shift;
5200 my ($auth) = _authenticate_user($c);
5201 my $clean_inputs = $c->stash->{clean_inputs};
5202 my $brapi = $self->brapi_module;
5203 my $brapi_module = $brapi->brapi_wrapper('References');
5204 my $brapi_package_result = $brapi_module->detail($c->stash->{referenceDbId});
5205 _standard_response_construction($c, $brapi_package_result);
5208 sub reference_search : Chained('brapi') PathPart('search/references') Args(0) : ActionClass('REST') { }
5210 sub reference_search_POST {
5211 my $self = shift;
5212 my $c = shift;
5213 save_results($self,$c,$c->stash->{clean_inputs},'References');
5216 sub reference_search_retrieve : Chained('brapi') PathPart('search/references') Args(1) {
5217 my $self = shift;
5218 my $c = shift;
5219 my $search_id = shift;
5220 retrieve_results($self, $c, $search_id, 'Referenced');
5224 =head2 brapi/v2/crossingprojects
5226 =cut
5228 sub crossingprojects : Chained('brapi') PathPart('crossingprojects') Args(0) : ActionClass('REST') { }
5230 sub crossingprojects_GET {
5231 my $self = shift;
5232 my $c = shift;
5233 my ($auth) = _authenticate_user($c);
5234 my $clean_inputs = $c->stash->{clean_inputs};
5235 my $brapi = $self->brapi_module;
5236 my $brapi_module = $brapi->brapi_wrapper('Crossing');
5237 my $brapi_package_result = $brapi_module->search($clean_inputs);
5238 _standard_response_construction($c, $brapi_package_result);
5241 sub crossingprojects_POST {
5242 my $self = shift;
5243 my $c = shift;
5244 my ($auth,$user_id) = _authenticate_user($c);
5245 my $clean_inputs = $c->stash->{clean_inputs};
5247 my $data = $clean_inputs;
5248 my @all_data;
5249 foreach my $project (values %{$data}) {
5250 push @all_data, $project;
5252 my $brapi = $self->brapi_module;
5253 my $brapi_module = $brapi->brapi_wrapper('Crossing');
5254 my $brapi_package_result = $brapi_module->store_crossingproject(\@all_data,$c,$user_id);
5257 my $status = $brapi_package_result->{status};
5258 my $http_status_code = _get_http_status_code($status);
5259 _standard_response_construction($c, $brapi_package_result);
5262 sub crossingproject_single : Chained('brapi') PathPart('crossingprojects') CaptureArgs(1) {
5263 my $self = shift;
5264 my $c = shift;
5265 my $id = shift;
5266 $c->stash->{crossingProjectDbId} = $id;
5269 sub crossingproject_fetch : Chained('crossingproject_single') PathPart('') Args(0) : ActionClass('REST') { }
5272 sub crossingproject_fetch_GET {
5273 my $self = shift;
5274 my $c = shift;
5275 my ($auth) = _authenticate_user($c);
5276 my $clean_inputs = $c->stash->{clean_inputs};
5277 my $brapi = $self->brapi_module;
5278 my $brapi_module = $brapi->brapi_wrapper('Crossing');
5279 my $brapi_package_result = $brapi_module->detail($c->stash->{crossingProjectDbId});
5280 _standard_response_construction($c, $brapi_package_result);
5283 sub crossingproject_fetch_PUT {
5284 my $self = shift;
5285 my $c = shift;
5286 my ($auth,$user_id,$user_type) = _authenticate_user($c);
5287 my $clean_inputs = $c->stash->{clean_inputs};
5288 my $brapi = $self->brapi_module;
5289 my $brapi_module = $brapi->brapi_wrapper('Crossing');
5290 my $brapi_package_result = $brapi_module->update_crossingproject($c->stash->{crossingProjectDbId}, $clean_inputs,$c,$user_id,$user_type);
5291 my $status = $brapi_package_result->{status};
5292 my $http_status_code = _get_http_status_code($status);
5293 _standard_response_construction($c, $brapi_package_result);
5296 =head2 brapi/v2/crosses
5298 =cut
5300 sub crosses : Chained('brapi') PathPart('crosses') Args(0) : ActionClass('REST') { }
5302 sub crosses_GET {
5303 my $self = shift;
5304 my $c = shift;
5305 my ($auth) = _authenticate_user($c);
5306 my $clean_inputs = $c->stash->{clean_inputs};
5307 my $brapi = $self->brapi_module;
5308 my $brapi_module = $brapi->brapi_wrapper('Crossing');
5309 my $brapi_package_result = $brapi_module->crosses($clean_inputs);
5310 _standard_response_construction($c, $brapi_package_result);
5313 sub crosses_POST {
5314 my $self = shift;
5315 my $c = shift;
5316 my ($auth,$user_id) = _authenticate_user($c);
5317 my $clean_inputs = $c->stash->{clean_inputs};
5318 my $data = $clean_inputs;
5319 my @all_crosses;
5320 foreach my $cross (values %{$data}) {
5321 push @all_crosses, $cross;
5323 my $brapi = $self->brapi_module;
5324 my $brapi_module = $brapi->brapi_wrapper('Crossing');
5325 my $brapi_package_result = $brapi_module->store_crosses(\@all_crosses,$c,$user_id);
5326 _standard_response_construction($c, $brapi_package_result);
5329 # sub crosses_PUT {
5330 # my $self = shift;
5331 # my $c = shift;
5332 # my ($auth) = _authenticate_user($c);
5333 # my $clean_inputs = $c->stash->{clean_inputs};
5334 # my $brapi = $self->brapi_module;
5335 # my $brapi_module = $brapi->brapi_wrapper('Crossing');
5336 # my $brapi_package_result = $brapi_module->update_crosses($clean_inputs);
5337 # _standard_response_construction($c, $brapi_package_result);
5340 =head2 brapi/v2/seedlots
5342 =cut
5344 sub seedlots : Chained('brapi') PathPart('seedlots') Args(0) : ActionClass('REST') { }
5346 sub seedlots_GET {
5347 my $self = shift;
5348 my $c = shift;
5349 my ($auth) = _authenticate_user($c);
5350 my $clean_inputs = $c->stash->{clean_inputs};
5351 my $brapi = $self->brapi_module;
5352 my $brapi_module = $brapi->brapi_wrapper('SeedLots');
5353 my $brapi_package_result = $brapi_module->search($clean_inputs);
5354 _standard_response_construction($c, $brapi_package_result);
5357 sub seedlots_POST {
5358 my $self = shift;
5359 my $c = shift;
5360 my ($auth,$user_id) = _authenticate_user($c);
5361 my $clean_inputs = $c->stash->{clean_inputs};
5362 my $data = $clean_inputs;
5363 my @all_data;
5364 foreach my $seedlot (values %{$data}) {
5365 push @all_data, $seedlot;
5367 my $brapi = $self->brapi_module;
5368 my $brapi_module = $brapi->brapi_wrapper('SeedLots');
5369 my $brapi_package_result = $brapi_module->store_seedlots(\@all_data,$c,$user_id);
5371 my $status = $brapi_package_result->{status};
5372 my $http_status_code = _get_http_status_code($status);
5374 _standard_response_construction($c, $brapi_package_result, $http_status_code);
5377 sub seedlot_transactions : Chained('brapi') PathPart('seedlots/transactions') Args(0) : ActionClass('REST') { }
5379 sub seedlot_transactions_GET {
5380 my $self = shift;
5381 my $c = shift;
5382 my ($auth) = _authenticate_user($c);
5383 my $clean_inputs = $c->stash->{clean_inputs};
5384 my $brapi = $self->brapi_module;
5385 my $brapi_module = $brapi->brapi_wrapper('SeedLots');
5386 my $brapi_package_result = $brapi_module->all_transactions($clean_inputs);
5387 _standard_response_construction($c, $brapi_package_result);
5390 sub seedlot_transactions_POST {
5391 my $self = shift;
5392 my $c = shift;
5393 my ($auth,$user_id) = _authenticate_user($c);
5394 my $clean_inputs = $c->stash->{clean_inputs};
5395 my $data = $clean_inputs;
5396 my @all_data;
5397 foreach my $transaction (values %{$data}) {
5398 push @all_data, $transaction;
5400 my $brapi = $self->brapi_module;
5401 my $brapi_module = $brapi->brapi_wrapper('SeedLots');
5402 my $brapi_package_result = $brapi_module->store_seedlot_transaction(\@all_data,$c,$user_id);
5403 my $status = $brapi_package_result->{status};
5404 my $http_status_code = _get_http_status_code($status);
5406 _standard_response_construction($c, $brapi_package_result);
5409 sub seedlot_single : Chained('brapi') PathPart('seedlots') CaptureArgs(1) {
5410 my $self = shift;
5411 my $c = shift;
5412 my $id = shift;
5413 $c->stash->{seedLotDbId} = $id;
5416 sub seedlot_single_fetch : Chained('seedlot_single') PathPart('') Args(0) : ActionClass('REST') { }
5419 sub seedlot_single_fetch_GET {
5420 my $self = shift;
5421 my $c = shift;
5422 my ($auth) = _authenticate_user($c);
5423 my $clean_inputs = $c->stash->{clean_inputs};
5424 my $brapi = $self->brapi_module;
5425 my $brapi_module = $brapi->brapi_wrapper('SeedLots');
5426 my $brapi_package_result = $brapi_module->detail($c->stash->{seedLotDbId});
5427 _standard_response_construction($c, $brapi_package_result);
5430 sub seedlot_single_fetch_PUT {
5431 my $self = shift;
5432 my $c = shift;
5433 my ($auth,$user_id) = _authenticate_user($c);
5434 my $clean_inputs = $c->stash->{clean_inputs};
5435 my $brapi = $self->brapi_module;
5436 my $brapi_module = $brapi->brapi_wrapper('SeedLots');
5437 my $brapi_package_result = $brapi_module->update_seedlot($c->stash->{seedLotDbId}, $clean_inputs,$c,$user_id);
5438 my $status = $brapi_package_result->{status};
5439 my $http_status_code = _get_http_status_code($status);
5440 _standard_response_construction($c, $brapi_package_result);
5443 sub seedlot_single_transaction_fetch : Chained('seedlot_single') PathPart('transactions') Args(0) : ActionClass('REST') { }
5446 sub seedlot_single_transaction_fetch_GET {
5447 my $self = shift;
5448 my $c = shift;
5449 my ($auth) = _authenticate_user($c);
5450 my $clean_inputs = $c->stash->{clean_inputs};
5451 my $brapi = $self->brapi_module;
5452 my $brapi_module = $brapi->brapi_wrapper('SeedLots');
5453 my $brapi_package_result = $brapi_module->transactions($c->stash->{seedLotDbId}, $clean_inputs);
5454 _standard_response_construction($c, $brapi_package_result);
5457 sub breedingmethods : Chained('brapi') PathPart('breedingmethods') Args(0) : ActionClass('REST') { }
5459 sub breedingmethods_GET {
5460 my $self = shift;
5461 my $c = shift;
5462 my $auth = _authenticate_user($c);
5463 my $clean_inputs = $c->stash->{clean_inputs};
5464 my $brapi = $self->brapi_module;
5465 my $brapi_module = $brapi->brapi_wrapper('BreedingMethods');
5466 my $brapi_package_result = $brapi_module->search($clean_inputs);
5468 _standard_response_construction($c, $brapi_package_result);
5471 sub nirs : Chained('brapi') PathPart('nirs') Args(0) : ActionClass('REST') { }
5473 sub nirs_GET {
5474 my $self = shift;
5475 my $c = shift;
5476 my $auth = _authenticate_user($c);
5477 my $clean_inputs = $c->stash->{clean_inputs};
5478 my $brapi = $self->brapi_module;
5479 my $brapi_module = $brapi->brapi_wrapper('Nirs');
5480 my $brapi_package_result = $brapi_module->search($clean_inputs);
5482 _standard_response_construction($c, $brapi_package_result);
5485 sub nirs_single : Chained('brapi') PathPart('nirs') CaptureArgs(1) {
5486 my $self = shift;
5487 my $c = shift;
5488 my $nd_protocol_id = shift;
5490 $c->stash->{nd_protocol_id} = $nd_protocol_id;
5493 sub nirs_detail : Chained('nirs_single') PathPart('') Args(0) : ActionClass('REST') { }
5495 sub nirs_detail_GET {
5496 my $self = shift;
5497 my $c = shift;
5498 my ($auth) = _authenticate_user($c);
5499 my $clean_inputs = $c->stash->{clean_inputs};
5500 my $brapi = $self->brapi_module;
5501 my $brapi_module = $brapi->brapi_wrapper('Nirs');
5502 my $brapi_package_result = $brapi_module->nirs_detail(
5503 $c->stash->{nd_protocol_id}
5505 _standard_response_construction($c, $brapi_package_result);
5508 sub nirs_matrix : Chained('nirs_single') PathPart('matrix') Args(0) : ActionClass('REST') { }
5510 sub nirs_matrix_GET {
5511 my $self = shift;
5512 my $c = shift;
5513 my ($auth) = _authenticate_user($c);
5514 my $clean_inputs = $c->stash->{clean_inputs};
5515 my $brapi = $self->brapi_module;
5516 my $brapi_module = $brapi->brapi_wrapper('Nirs');
5517 my $brapi_package_result = $brapi_module->nirs_matrix(
5518 $c->stash->{nd_protocol_id},
5519 $clean_inputs
5521 _standard_response_construction($c, $brapi_package_result);
5525 =head2 brapi/v2/pedigree
5527 =cut
5529 sub pedigree : Chained('brapi') PathPart('pedigree') Args(0) : ActionClass('REST') { }
5531 sub pedigree_GET {
5532 my $self = shift;
5533 my $c = shift;
5534 my ($auth) = _authenticate_user($c);
5535 my $clean_inputs = $c->stash->{clean_inputs};
5536 my $brapi = $self->brapi_module;
5537 my $brapi_module = $brapi->brapi_wrapper('Pedigree');
5538 my $brapi_package_result = $brapi_module->search({
5539 germplasmDbId => $clean_inputs->{germplasmDbId},
5540 pedigreeDepth => $clean_inputs->{pedigreeDepth},
5541 progenyDepth => $clean_inputs->{progenyDepth},
5542 includeFullTree => $clean_inputs->{includeFullTree},
5543 includeSiblings => $clean_inputs->{includeSiblings},
5544 includeParents => $clean_inputs->{includeParents},
5545 includeProgeny => $clean_inputs->{includeProgeny},
5547 _standard_response_construction($c, $brapi_package_result);
5550 sub pedigree_search : Chained('brapi') PathPart('search/pedigree') Args(0) : ActionClass('REST') { }
5552 sub pedigree_search_POST {
5553 my $self = shift;
5554 my $c = shift;
5555 save_results($self,$c,$c->stash->{clean_inputs},'Pedigree');
5558 sub pedigree_search_retrieve : Chained('brapi') PathPart('search/pedigree') Args(1) {
5559 my $self = shift;
5560 my $c = shift;
5561 my $search_id = shift;
5562 retrieve_results($self, $c, $search_id, 'Pedigree');
5567 #functions
5568 sub save_results {
5569 my $self = shift;
5570 my $c = shift;
5571 my $search_params = shift;
5572 my $search_type = shift;
5574 my %server_permission;
5575 my $rc = eval{
5576 my $server_permission = $c->config->{"brapi_GET"};
5577 my @server_permission = split ',', $server_permission;
5578 %server_permission = map { $_ => 1 } @server_permission;
5579 1; };
5580 if($rc && !$server_permission{'any'}){
5581 my $auth = _authenticate_user($c);
5584 my $brapi = $self->brapi_module;
5585 my $brapi_module = $brapi->brapi_wrapper($search_type);
5587 #set default value to 100000 to get as much as possible records when page size is not a parameter
5588 if(!$search_params->{pageSize}) {
5589 $brapi_module->{page_size} = 100000;
5592 my $search_result = $brapi_module->search($search_params,$c);
5594 my $dir = $c->tempfiles_subdir('/brapi_searches');
5595 my $tempfile = $c->config->{basepath}."/".$c->tempfile( TEMPLATE => 'brapi_searches/XXXXXXXXXXXXXXXX');
5596 my $results_module = $brapi->brapi_wrapper('Results');
5597 my $brapi_package_result = $results_module->save_results($tempfile, $search_result, $search_type);
5599 _standard_response_construction($c, $brapi_package_result, 202);
5602 sub retrieve_results {
5603 my $self = shift;
5604 my $c = shift;
5605 my $search_id = shift;
5606 my $search_type = shift;
5607 my $auth = _authenticate_user($c);
5609 my $clean_inputs = $c->stash->{clean_inputs};
5610 my $tempfiles_subdir = $c->config->{basepath} . $c->tempfiles_subdir('brapi_searches');
5611 my $brapi = $self->brapi_module;
5612 my $search_module = $brapi->brapi_wrapper('Results');
5613 my $brapi_package_result = $search_module->retrieve_results($tempfiles_subdir, $search_id);
5614 _standard_response_construction($c, $brapi_package_result);