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;
110 template
=> '/publication/index.mas',
112 pub_id
=> $found_pub_id ,
114 submitter
=> $submitter,
115 sequencer
=> $sequencer,
116 person_id
=> $person_id,
129 Public path: /publication/<pub_id>/view
131 View a publication detail page.
133 Chained off of L</get_pub> below.
137 sub view_pub
: Chained
('get_pub') PathPart
('view') Args
(0) {
138 my ( $self, $c, $action) = @_;
139 my $pub = $c->stash->{pub
};
142 my $logged_user = $c->user;
143 my $person_id = $logged_user->get_object->get_sp_person_id if $logged_user;
144 my $curator = $logged_user->check_roles('curator') if $logged_user;
145 my $submitter = $logged_user->check_roles('submitter') if $logged_user;
146 my $sequencer = $logged_user->check_roles('sequencer') if $logged_user;
147 my $dbh = $c->dbc->dbh;
151 ###Check if a publication page can be printed###
152 my $pub_id = $pub ?
$pub->get_pub_id : undef ;
154 # print message if pub_id is not valid
155 unless ( ( $pub_id =~ m
/^\d+$/ ) || ($action eq 'new' && !$pub_id) ) {
156 $c->throw_404( "No publication exists for that identifier." );
158 unless ( $pub || !$pub_id && $action && $action eq 'new' ) {
159 $c->throw_404( "No publication exists for that identifier." );
162 # print message if pub_id does not exist
163 if ( !$pub && $action ne 'new' && $action ne 'store' ) {
164 $c->throw_404('No publication exists for this identifier');
169 my $dbxrefs = $pub->get_dbxrefs;
174 template
=> '/publication/index.mas',
179 submitter
=> $submitter,
180 sequencer
=> $sequencer,
181 person_id
=> $person_id,
182 user
=> $logged_user,
191 =head1 PRIVATE ACTIONS
195 Chain root for fetching a publication object to operate on.
197 Path part: /publication/<pub_id>
201 sub get_pub
: Chained
('/') PathPart
('publication') CaptureArgs
(1) {
202 my ($self, $c, $pub_id) = @_;
204 my $identifier_type = $c->stash->{identifier_type
}
205 || $pub_id =~ /[^-\d]/ ?
'accession' : 'pub_id';
207 if( $identifier_type eq 'pub_id' ) {
208 if ( $pub_id == 0 ) {
209 $c->stash->{pub
} = CXGN
::Chado
::Publication
->new($c->dbc->dbh);
213 or $c->throw_client_error( public_message
=> 'Publication ID must be a positive integer.' );
217 if ($identifier_type eq 'pub_id' ) {
218 $matching_pubs = $self->schema->resultset('Pub::Pub')->search(
223 if( $matching_pubs->count > 1 ) {
224 $c->throw_client_error( public_message
=> 'Multiple matching publications' );
227 my ( $publication ) = $matching_pubs->all
228 or $c->throw_404( "publication $pub_id not found" );
229 my $found_pub_id = $publication->pub_id;
231 $c->stash->{pub
} = CXGN
::Chado
::Publication
->new($c->dbc->dbh, $found_pub_id);
239 Public path: /doibanner/
241 Return SGN logo if DOI exists, or a 1x1 empty pixel if does not exist.
242 Used by Elsevier for banner linking publications to solgenomics publication page /pub/doi/<doi>
247 sub doi_banner
: Path
('/doibanner/') CaptureArgs
(3) {
248 my ($self, $c , @doi_parts) = @_;
249 my $doi = join '/' , @doi_parts;
250 my $matching_pubs = $self->schema->resultset('Pub::Pub')->search(
252 'dbxref.accession' => $doi,
254 join => { 'pub_dbxrefs' => 'dbxref' },
256 my $pub_count = $matching_pubs->count;
257 if( $matching_pubs->count > 1 ) {
258 $c->throw_client_error( public_message
=> 'Multiple matching publications' );
261 my $image = $c->path_to('/documents/img/white_pixel.png');
263 if ($pub_count == 1 ) {
264 $image = $c->path_to( '/documents/img/sgn_logo_26x60.png') ;
267 my $image_file = read_file
($image , { binmode => ':raw' } );
269 $c->response->content_type('image/png');
270 $c->response->body($image_file);
274 __PACKAGE__
->meta->make_immutable;