1 package SGN
::Controller
::Publication
;
5 SGN::Controller::Publication - Catalyst controller for the SGN publication page
6 (replacing the old cgi script)
11 use namespace
::autoclean
;
14 use URI
::FromHash
'uri';
16 use CXGN
::Chado
::Publication
;
18 BEGIN { extends
'Catalyst::Controller' }
19 with
'Catalyst::Component::ApplicationAttribute';
24 isa
=> 'DBIx::Class::Schema',
30 sub pub_search
: Path
('/search/publication') Args
(0) {
35 template
=> '/search/pub.mas',
42 shift->_app->dbic_schema( 'Bio::Chado::Schema', 'sgn_chado' )
48 Public path: /pub/0/new
50 Create a new publication.
52 Chained off of L</get_pub> below.
56 sub new_pub
: Chained
('get_pub') PathPart
('new') Args
(0) {
57 my ( $self, $c ) = @_;
59 template
=> '/publication/index.mas',
64 pub
=> $c->stash->{pub
},
65 schema
=> $self->schema,
72 Public path: /doi/pub/
74 View publication by doi.
76 Since DOIs can have "/" in them this path captures 3 args and then concatenates to recreate the DOI (hopefully no DOI has more than 3 slashes! )
81 sub view_by_doi
: Path
('/doi/pub/') CaptureArgs
(3) {
82 my ($self, $c , @doi_parts) = @_;
83 my $doi = join '/' , @doi_parts;
84 my $matching_pubs = $self->schema->resultset('Pub::Pub')->search(
86 'dbxref.accession' => $doi,
88 join => { 'pub_dbxrefs' => 'dbxref' },
91 if( $matching_pubs->count > 1 ) {
92 $c->throw_client_error( public_message
=> 'Multiple matching publications' );
95 my ( $publication ) = $matching_pubs->all
96 or $c->throw_404( "publication $doi not found" );
97 my $found_pub_id = $publication->pub_id;
98 my $pub = CXGN
::Chado
::Publication
->new($c->dbc->dbh, $found_pub_id);
99 $c->{stash
}->{pub
} = $pub;
101 my $logged_user = $c->user;
102 my $person_id = $logged_user->get_object->get_sp_person_id if $logged_user;
103 my $curator = $logged_user->check_roles('curator') if $logged_user;
104 my $submitter = $logged_user->check_roles('submitter') if $logged_user;
105 my $sequencer = $logged_user->check_roles('sequencer') if $logged_user;
106 my $dbh = $c->dbc->dbh;
107 my $dbxrefs = $pub->get_dbxrefs;
108 my $stocks = $self->_get_stocks( $c);
111 template
=> '/publication/index.mas',
113 pub_id
=> $found_pub_id ,
115 submitter
=> $submitter,
116 sequencer
=> $sequencer,
117 person_id
=> $person_id,
131 Public path: /publication/<pub_id>/view
133 View a publication detail page.
135 Chained off of L</get_pub> below.
139 sub view_pub
: Chained
('get_pub') PathPart
('view') Args
(0) {
140 my ( $self, $c, $action) = @_;
141 my $pub = $c->stash->{pub
};
144 my $logged_user = $c->user;
145 my $person_id = $logged_user->get_object->get_sp_person_id if $logged_user;
146 my $curator = $logged_user->check_roles('curator') if $logged_user;
147 my $submitter = $logged_user->check_roles('submitter') if $logged_user;
148 my $sequencer = $logged_user->check_roles('sequencer') if $logged_user;
149 my $dbh = $c->dbc->dbh;
153 ###Check if a publication page can be printed###
154 my $pub_id = $pub ?
$pub->get_pub_id : undef ;
156 # print message if pub_id is not valid
157 unless ( ( $pub_id =~ m
/^\d+$/ ) || ($action eq 'new' && !$pub_id) ) {
158 $c->throw_404( "No publication exists for that identifier." );
160 unless ( $pub || !$pub_id && $action && $action eq 'new' ) {
161 $c->throw_404( "No publication exists for that identifier." );
164 # print message if pub_id does not exist
165 if ( !$pub && $action ne 'new' && $action ne 'store' ) {
166 $c->throw_404('No publication exists for this identifier');
171 my $dbxrefs = $pub->get_dbxrefs;
172 my $stocks = $self->_get_stocks( $c );
176 template
=> '/publication/index.mas',
181 submitter
=> $submitter,
182 sequencer
=> $sequencer,
183 person_id
=> $person_id,
184 user
=> $logged_user,
194 =head1 PRIVATE ACTIONS
198 Chain root for fetching a publication object to operate on.
200 Path part: /publication/<pub_id>
204 sub get_pub
: Chained
('/') PathPart
('publication') CaptureArgs
(1) {
205 my ($self, $c, $pub_id) = @_;
207 my $identifier_type = $c->stash->{identifier_type
}
208 || $pub_id =~ /[^-\d]/ ?
'accession' : 'pub_id';
210 if( $identifier_type eq 'pub_id' ) {
211 if ( $pub_id == 0 ) {
212 $c->stash->{pub
} = CXGN
::Chado
::Publication
->new($c->dbc->dbh);
216 or $c->throw_client_error( public_message
=> 'Publication ID must be a positive integer.' );
220 if ($identifier_type eq 'pub_id' ) {
221 $matching_pubs = $self->schema->resultset('Pub::Pub')->search(
226 if( $matching_pubs->count > 1 ) {
227 $c->throw_client_error( public_message
=> 'Multiple matching publications' );
230 my ( $publication ) = $matching_pubs->all
231 or $c->throw_404( "publication $pub_id not found" );
232 my $found_pub_id = $publication->pub_id;
234 $c->stash->{pub
} = CXGN
::Chado
::Publication
->new($c->dbc->dbh, $found_pub_id);
242 my ( $self, $c) = @_;
243 my $pub = $c->stash->{pub
};
244 my $schema = $self->schema;
245 my @stock_ids = $pub->get_stock_ids;
247 foreach my $stock_id (@stock_ids) {
248 my $stock = CXGN
::Stock
->new( { schema
=> $schema, stock_id
=> $stock_id } ) ;
249 push @stocks, $stock;
258 Public path: /doibanner/
260 Return SGN logo if DOI exists, or a 1x1 empty pixel if does not exist.
261 Used by Elsevier for banner linking publications to solgenomics publication page /pub/doi/<doi>
266 sub doi_banner
: Path
('/doibanner/') CaptureArgs
(3) {
267 my ($self, $c , @doi_parts) = @_;
268 my $doi = join '/' , @doi_parts;
269 my $matching_pubs = $self->schema->resultset('Pub::Pub')->search(
271 'dbxref.accession' => $doi,
273 join => { 'pub_dbxrefs' => 'dbxref' },
275 my $pub_count = $matching_pubs->count;
276 if( $matching_pubs->count > 1 ) {
277 $c->throw_client_error( public_message
=> 'Multiple matching publications' );
280 my $image = $c->path_to('/documents/img/white_pixel.png');
282 if ($pub_count == 1 ) {
283 $image = $c->path_to( '/documents/img/sgn_logo_26x60.png') ;
286 my $image_file = read_file
($image , { binmode => ':raw' } );
288 $c->response->content_type('image/png');
289 $c->response->body($image_file);
293 __PACKAGE__
->meta->make_immutable;