1 package CXGN
::BrAPI
::v1
::Trials
;
5 use SGN
::Model
::Cvterm
;
6 use CXGN
::Trial
::Folder
;
7 use CXGN
::BrAPI
::Pagination
;
8 use CXGN
::BrAPI
::JSONResponse
;
11 isa
=> 'Bio::Chado::Schema',
16 has
'metadata_schema' => (
17 isa
=> 'CXGN::Metadata::Schema',
22 has
'phenome_schema' => (
23 isa
=> 'CXGN::Phenome::Schema',
41 isa
=> 'ArrayRef[Maybe[HashRef]]',
48 my $search_params = shift;
49 my $page_size = $self->page_size;
50 my $page = $self->page;
51 my $status = $self->status;
52 my $schema = $self->bcs_schema;
53 #my $auth = _authenticate_user($c);
55 my @location_dbids = $search_params->{locationDbIds
} ? @
{$search_params->{locationDbIds
}} : ();
56 my @program_dbids = $search_params->{programDbIds
} ? @
{$search_params->{programDbIds
}} : ();
59 if (scalar(@location_dbids)>0){
60 %location_id_list = map { $_ => 1} @location_dbids;
63 if (scalar(@program_dbids)>0){
64 %program_id_list = map { $_ => 1} @program_dbids;
69 my $folder_cvterm_id = SGN
::Model
::Cvterm
->get_cvterm_row($self->bcs_schema,'trial_folder', 'project_property')->cvterm_id();
70 my $folder_rs = $self->bcs_schema()->resultset("Project::Project")->search_related('projectprops', {'projectprops.type_id'=>$folder_cvterm_id});
76 $total_count = $folder_rs->count();
77 my $rs_slice = $folder_rs->slice($page_size*$page, $page_size*($page+1)-1);
78 while (my $p = $rs_slice->next()) {
79 my $folder = CXGN
::Trial
::Folder
->new({bcs_schema
=>$self->bcs_schema, folder_id
=>$p->project_id});
80 if ($folder->is_folder) {
81 my $children = $folder->children();
82 foreach (@
$children) {
83 my $passes_search = 1;
84 if (%location_id_list) {
85 if (!exists($location_id_list{$_->location_id})) {
90 push @folder_studies, {
91 studyDbId
=>$_->folder_id,
93 locationDbId
=>$_->location_id
98 my $passes_search = 1;
99 if (%program_id_list) {
100 if (!exists($program_id_list{$folder->breeding_program->project_id})) {
106 trialDbId
=>$folder->folder_id,
107 trialName
=>$folder->name,
108 programDbId
=>$folder->breeding_program->project_id(),
109 programName
=>$folder->breeding_program->name(),
113 studies
=>\
@folder_studies,
114 additionalInfo
=>\
%additional_info
120 my %result = (data
=> \
@data);
122 my $pagination = CXGN
::BrAPI
::Pagination
->pagination_response($total_count,$page_size,$page);
123 return CXGN
::BrAPI
::JSONResponse
->return_success(\
%result, $pagination, \
@data_files, $status, 'Trials-search result constructed');
128 my $folder_id = shift;
130 my $page_size = $self->page_size;
131 my $page = $self->page;
132 my $status = $self->status;
133 my $schema = $self->bcs_schema;
134 my $trial_check = $schema->resultset('Project::Project')->find({project_id
=>$folder_id});
136 my $folder = CXGN
::Trial
::Folder
->new(bcs_schema
=>$self->bcs_schema(), folder_id
=>$folder_id);
137 if ($folder->is_folder) {
141 my $children = $folder->children();
142 foreach (@
$children) {
143 push @folder_studies, {
144 studyDbId
=>$_->folder_id,
146 locationDbId
=>$_->location_id
150 trialDbId
=>$folder->folder_id,
151 trialName
=>$folder->name,
152 programDbId
=>$folder->breeding_program->project_id(),
153 programName
=>$folder->breeding_program->name(),
157 studies
=>\
@folder_studies,
158 additionalInfo
=>\
%additional_info
161 my $pagination = CXGN
::BrAPI
::Pagination
->pagination_response($total_count,$page_size,$page);
162 return CXGN
::BrAPI
::JSONResponse
->return_success(\
%result, $pagination, \
@data_files, $status, 'Trial detail result constructed');
164 return CXGN
::BrAPI
::JSONResponse
->return_error($status, 'The given trialDbId does not match an actual trial.');
167 return CXGN
::BrAPI
::JSONResponse
->return_error($status, 'The given trialDbId not found.');