minor fixes
[sgn.git] / cgi-bin / gem / template.pl
blob947f10b49fe1f1fb6fcf0983c594201da9632861
1 #!/usr/bin/perl
3 =head1 NAME
5 template.pl
6 Controller to show the web_page for template using MASON.
8 =cut
10 =head1 SYNOPSIS
13 =head1 DESCRIPTION
15 This is the script controller to show the template web_page using MASON
17 =cut
19 =head1 AUTHORS
21 Aureliano Bombarely Gomez
22 (ab782@cornell.edu)
24 =cut
27 use strict;
28 use warnings;
30 use CXGN::MasonFactory;
31 use CXGN::Page;
33 use CXGN::DB::Connection;
34 use CXGN::DB::DBICFactory;
35 use CXGN::GEM::Schema;
36 use CXGN::GEM::Template;
37 use CXGN::GEM::Expression;
39 ## Create the mason object
41 my $m = CXGN::MasonFactory->new();
44 ## Create the schema object
46 my $psqlv = `psql --version`;
47 chomp($psqlv);
49 my @schema_list = ('gem', 'biosource', 'metadata', 'public');
50 if ($psqlv =~ /8\.1/) {
51 push @schema_list, 'tsearch2';
54 my $schema = CXGN::DB::DBICFactory->open_schema( 'CXGN::GEM::Schema', search_path => \@schema_list, );
56 ## Another schema to create is a schema that use sgn as schema
58 my $sgn_schema = CXGN::DB::DBICFactory->open_schema( 'SGN::Schema', search_path => ['sgn'], );
61 ## Also it will create a dbi-connection object ($dbh) for all the methods that do not use schemas
62 ## (as CXGN::People::Person) to not interfiere with them
64 my $dbh = CXGN::DB::Connection->new();
67 ## Use of CXGN::Page to take the arguments from the URL
70 my $page = CXGN::Page->new();
72 my %args = $page->get_all_encoded_arguments();
75 ## Get template object (by default it will create an empty template object)
77 my $template = CXGN::GEM::Template->new($schema);
79 if (exists $args{'id'}) {
80 $template = CXGN::GEM::Template->new($schema, $args{'id'});
81 } elsif (exists $args{'name'}) {
82 $template = CXGN::GEM::Template->new_by_name($schema, $args{'name'});
85 ## Get the unigene list associated with this template to use with the annotations
87 my @unigene_ids = ();
88 if (defined $template->get_template_id) {
89 @unigene_ids = $template->get_internal_accessions('unigene');
92 ## Add expression object
94 my $expression = CXGN::GEM::Expression->new($schema);
96 if (defined $template->get_template_id()) {
97 $expression = CXGN::GEM::Expression->new($schema, $template->get_template_id());
102 ## There are two ways to access to the page, using id=int or name=something. If use other combinations give an error message
104 if (defined $template->get_template_id() or defined $template->get_template_name() ) {
105 $m->exec( '/gem/template_detail.mas',
106 dbh => $dbh,
107 schema => $schema,
108 sgn_schema => $sgn_schema,
109 template => $template,
110 expression => $expression,
111 unigene_list => \@unigene_ids
113 } else {
114 $m->exec('/gem/gem_page_error.mas',
115 schema => $schema,
116 object => $template );