check ids
[sgn.git] / lib / SGN / Controller / Analysis.pm
blob05b70999d6f260ee44a25179c447494eaf6bf7d9
2 package SGN::Controller::Analysis;
4 use Moose;
5 use URI::FromHash 'uri';
6 use Data::Dumper;
8 BEGIN { extends 'Catalyst::Controller' };
10 sub view_analyses :Path('/analyses') Args(0) {
11 my $self = shift;
12 my $c = shift;
14 my $user_id;
15 if ($c->user()) {
16 $user_id = $c->user->get_object()->get_sp_person_id();
18 if (!$user_id) {
19 $c->res->redirect( uri( path => '/user/login', query => { goto_url => $c->req->uri->path_query } ) );
22 my $schema = $c->dbic_schema("Bio::Chado::Schema", undef, $user_id);
24 $c->stash->{template} = '/analyses/index.mas';
27 sub analysis_detail :Path('/analyses') Args(1) {
28 my $self = shift;
29 my $c = shift;
30 my $analysis_id = shift;
31 my $user = $c->user();
33 my $user_id;
34 if ($c->user()) {
35 $user_id = $c->user->get_object()->get_sp_person_id();
37 if (!$user_id) {
38 $c->res->redirect( uri( path => '/user/login', query => { goto_url => $c->req->uri->path_query } ) );
39 $c->detach();
42 my $bcs_schema = $c->dbic_schema("Bio::Chado::Schema", undef, $user_id);
43 print STDERR "Viewing analysis with id $analysis_id\n";
45 my $a = CXGN::Analysis->new({
46 bcs_schema => $bcs_schema,
47 people_schema => $c->dbic_schema("CXGN::People::Schema", undef, $user_id),
48 metadata_schema => $c->dbic_schema("CXGN::Metadata::Schema", undef, $user_id),
49 phenome_schema => $c->dbic_schema("CXGN::Phenome::Schema", undef, $user_id),
50 trial_id => $analysis_id,
51 });
53 if (! $a) {
54 $c->stash->{template} = '/generic_message.mas';
55 $c->stash->{message} = 'The requested analysis ID does not exist in the database.';
56 return;
59 $c->stash->{analysis_id} = $analysis_id;
60 $c->stash->{analysis_name} = $a->name();
61 $c->stash->{analysis_description} = $a->description();
62 $c->stash->{breeding_program_name} = $a->get_breeding_program();
63 $c->stash->{breeding_program_id} = $bcs_schema->resultset("Project::Project")->find({name=>$a->get_breeding_program()})->project_id();
64 $c->stash->{year} = $a->get_year();
65 $c->stash->{trial_stock_type} = 'accession';
66 $c->stash->{trial_phenotype_stock_type} = 'analysis_instance';
67 $c->stash->{has_col_and_row_numbers} = $a->has_col_and_row_numbers();
68 $c->stash->{identifier_prefix} = $c->config->{identifier_prefix};
69 $c->stash->{analysis_metadata} = $a->metadata();
70 $c->stash->{user_can_modify} = $user->check_roles("submitter") || $user->check_roles("curator");
71 $c->stash->{template} = '/analyses/detail.mas';
74 sub analysis_model_detail :Path('/analyses_model') Args(1) {
75 my $self = shift;
76 my $c = shift;
77 my $model_id = shift;
79 my $user_id;
80 if ($c->user()) {
81 $user_id = $c->user->get_object()->get_sp_person_id();
83 if (!$user_id) {
84 $c->res->redirect( uri( path => '/user/login', query => { goto_url => $c->req->uri->path_query } ) );
85 $c->detach();
88 my $bcs_schema = $c->dbic_schema("Bio::Chado::Schema", undef, $user_id);
89 print STDERR "Viewing analysis model with id $model_id\n";
91 my $m = CXGN::AnalysisModel::GetModel->new({
92 bcs_schema=>$bcs_schema,
93 metadata_schema=>$c->dbic_schema("CXGN::Metadata::Schema", undef, $user_id),
94 phenome_schema=>$c->dbic_schema("CXGN::Phenome::Schema", undef, $user_id),
95 nd_protocol_id=>$model_id
96 });
97 my $saved_model_object = $m->get_model();
98 #print STDERR Dumper $saved_model_object;
100 if (!$saved_model_object->{model_id}) {
101 $c->stash->{template} = '/generic_message.mas';
102 $c->stash->{message} = 'The requested model ID does not exist in the database.';
103 return;
106 $c->stash->{model_id} = $saved_model_object->{model_id};
107 $c->stash->{model_name} = $saved_model_object->{model_name};
108 $c->stash->{model_description} = $saved_model_object->{model_description};
109 $c->stash->{model_properties} = $saved_model_object->{model_properties};
110 $c->stash->{model_file_ids} = $saved_model_object->{model_file_ids};
111 $c->stash->{model_type_name} = $saved_model_object->{model_type_name};
112 $c->stash->{model_files} = $saved_model_object->{model_files};
113 $c->stash->{identifier_prefix} = $c->config->{identifier_prefix}."_Model_";
114 $c->stash->{template} = '/analyses/model_detail.mas';