package JCRCite; # -------------------------------------------------------------------- # The copyright and all other proprietary rights in this Database # (including software - SEE LICENSING AGREEMENT) are the sole and # exclusive property of the Institute for Scientific Information # (ISI). This Database and source code, or any derivative works # thereof, are confidential and proprietary to ISI . Therefore, # duplication, reuse, redistribution, reverse assembling, reverse # compiling, or translation of the Database, source code, or any # portion thereof IS NOT PERMITTED. Consult Licensing Agreement. # -------------------------------------------------------------------- # $Id: JCRCite.pm,v 1.21 2006/07/31 18:31:44 jsims Exp $ # $Name: JCR_4_5_BETA_5 $ use strict; use Data::Dumper; use ISIBench; use JCRErrorList; use JCR::Journal; use JCR::Category; use Log::Log4perl qw(get_logger); use VCRControl; use URL; use base qq(JCRPage); sub build_page { ISIBench::start(); my $logger = get_logger("JCRCite"); my $self = shift; my $args = (ref $_[0] eq 'HASH') ? shift : { @_ }; my $request = $self->{request}; my $journal = $request->{journal}; my $category = $request->{category}; my $session = $self->{session}; # Save required query params $self->_save_params(); # Execute the query based upon the request RQ. my ($ecode, $jtitle, $jlist, $jimpact, $jall) = $self->_execute_query; my $count = $self->_execute_count; if ((ref($count) =~ /hash/i) && ($count->{count}>=0)) { $logger->debug("Execute Query Count Returned: ", sub{Dumper($count);}); my $url_params; if ( $journal ) { $url_params = qq|RQ=$request->{RQ}&journal=$self->{j20_enc}&rank=$request->{rank}|; } elsif ( $category ) { $url_params = qq|RQ=$request->{RQ}&category=$self->{category_enc}&rank=$request->{rank}|; } # Build the JCRCite page template my $vcr = VCRControl->new( 'lines_per_page' => $CF::recs_per_summary, 'num_page_links' => 10, 'total_lines' => $count->{count}, 'url_target' => $CF::app_path, 'url_params' => $url_params, 'images_url' => $CF::image_path, 'cursor' => $self->{cite_cursor}, ); unless (defined($vcr) && (ref($vcr) =~ /vcrcontrol/i)) { $logger->error("Could not create VCRControl Object! (#$vcr)"); ISIBench::stop(); return $vcr; } # Get the journal start and end count my $journal_count = $vcr->range(); # Add the toolbar my $toolbar = $self->build_toolbar( 'help' => $self->{help} ); if ( $journal ) { #Add the return to summary button $toolbar->add( 'button' => 'TB_RET2JOURNAL', 'URI' => qq|$CF::base_path/JCR?RQ=RECORD&rank=$request->{rank}&journal=$self->{j20_enc}|, ); } elsif ( $category ) { #Add the return to summary button $toolbar->add( 'button' => 'TB_RET2CATEGORY', 'URI' => qq|$CF::base_path/JCR?RQ=RECORD&rank=$request->{rank}&category=$self->{category_enc}|, ); } unless (defined($toolbar) && (ref($toolbar) =~ /toolbar/i)) { ISIBench::stop(); return $toolbar; } # Set other template vars $self->set( 'name' => 'j20', 'value' => $self->{j20}, ); $self->set( 'name' => 'journal_enc', 'value' => $self->{j20_enc}, ); $self->set( 'name' => 'category', 'value' => $self->{category}, ); $self->set( 'name' => 'category_enc', 'value' => $self->{category_enc}, ); $self->set( 'name' => 'jtitle', 'value' => $jtitle->{title}, ); $self->set( 'name' => 'rank', 'value' => $request->{rank}, ); $self->set( 'name' => 'records', 'value' => $jlist, ); $self->set( 'name' => 'impact', 'value' => $jimpact, ); $self->set( 'name' => 'allyears', 'value' => $jall, ); $self->set( 'name' => 'record_start', 'value' => $self->{cite_cursor}, ); # Vars for the VCR control $self->set( 'name' => 'vcr_control', 'value' => $vcr->draw(), ); $self->set( 'name' => 'journal_start', 'value' => $journal_count->{start}, ); $self->set( 'name' => 'journal_end', 'value' => $journal_count->{end}, ); $self->set( 'name' => 'journal_total', 'value' => $count->{count}, ); $self->set( 'name' => 'page_current', 'value' => $vcr->get_page(), ); $self->set( 'name' => 'page_total', 'value' => $vcr->{_total_pages}, ); $self->set( 'name' => 'error', 'value' => $self->{ERROR}, ); # End VCR Control vars } if ( $self->{request_from} =~ /FULL_REC/i ) { # Log the Cited/Citing Page View event # only if you just came to the Cited/Citing page # from the full record page i.e. don't log this # event navigating thru pages $session->log_event( 'event' => 'event_record_view', 'data' => { 'count' => 1, }, ); # error checking my $error_string = $session->getError(); if ( length($error_string) > 1 ) { $logger->error("WURS Event not logged: $error_string"); } } ISIBench::stop(); return 0; } sub _save_params { ISIBench::start(); my $logger = get_logger("JCRCite"); my $self = shift; my $args = (ref $_[0] eq 'HASH') ? shift : { @_ }; my $session = $self->{session}; my $request = $self->{request}; my $journal = $request->{journal}; my $category = $request->{category}; my $request_from = $request->{req_from}; # save the RQ to decide the mode for query. if ($request->{RQ} =~ /cite_cited/i) { $self->{mode} = 'cited'; $self->set_title( 'title' => 'Cited Journal List' ); if ( $journal ) { $self->{help} = '2.7.b'; $self->set_template( 'template' => "jcr_journal_cited_list.html" ); } elsif ( $category ) { $self->{help} = '2.13.c'; $self->set_template( 'template' => "jcr_category_cited_list.html" ); } } else { $self->{mode} = 'citing'; $self->set_title( 'title' => 'Citing Journal List' ); if ( $journal ) { $self->{help} = '2.7.a'; $self->set_template( 'template' => "jcr_journal_citing_list.html" ); } elsif ( $category ) { $self->{help} = '2.13.d'; $self->set_template( 'template' => "jcr_category_citing_list.html" ); } } if ( $journal ) { $self->{j20} = $request->{journal}; $self->{j20_enc} = URL::encode($self->{j20}); } elsif ( $category ) { $self->{category} = $request->{category}; $self->{category_enc} = URL::encode($self->{category}); } # Get the current page number $self->{cite_cursor} = $request->{cursor} || 1; $self->{request_from} = $request_from; ISIBench::stop(); return 0; } sub _execute_query { ISIBench::start(); my $logger = get_logger("JCRCite"); my $self = shift; my $args = (ref $_[0] eq 'HASH') ? shift : { @_ }; my $session = $self->{session}; my $edition = $session->get( 'value' => 'edition' ); my $year = $session->get( 'value' => 'year' ); my $request = $self->{request}; my $j20 = $request->{journal}; my $cat_name = $request->{category}; my ($ec, $jtitle, $jlist, $jimpact, $jall); if ( $j20 ) { my $journal = JCR::Journal->new( 'db' => $self->{db}, 'edition' => $edition->{edition}, 'year' => $year->{year}, ); unless (defined($journal) && (ref($journal) =~ /journal/i)) { $logger->error("Could not create journal object (#$journal)!"); ISIBench::stop(); return ($journal, $jtitle, $jlist, $jimpact, $jall); } # get the journal title for displaying full title on the page. $jtitle = $journal->get_journal_title('j20' => $self->{j20}); unless (defined($jtitle) && (ref($jtitle) =~ /hash/i)) { $logger->error("Could not retrieve journal Title! (#$jtitle)"); ISIBench::stop(); return ($jtitle, $jtitle, $jlist, $jimpact, $jall); } $logger->debug("Journal Title: ", sub{Dumper($jtitle);}); # get yearly cited/citing count $jlist = $journal->get_journal_cite_cites( 'j20' => $self->{j20}, 'mode' => $self->{mode}, 'limit' => $CF::recs_per_summary, 'start' => ($self->{cite_cursor}-1), ); unless (defined($jlist) && (ref($jlist) =~ /array/i)) { $logger->error("Could not retrieve journal Cited list! (#$jlist)"); ISIBench::stop(); return ($jlist, $jtitle, $jlist, $jimpact, $jall); } $logger->debug("Journal Cited List: ", sub{Dumper($jlist);}); # get the journal impcact_current values. $jimpact = $journal->get_journal_impact(); unless (defined($jimpact) && (ref($jimpact) =~ /hash/i)) { $logger->error("Could not retrieve journal impact_current! (#$jimpact)"); ISIBench::stop(); return ($jimpact, $jtitle, $jlist, $jimpact, $jall); } $logger->debug("All Journals Impact Current Values: ", sub{Dumper($jimpact);}); # execute only if it is clicked on the cited/citing image. # get cited/citing yearly total count if(($self->{cite_cursor}) == 1) { $jall = $journal->get_journal_cites( 'j20' => $self->{j20}, 'mode' => $self->{mode} ); unless (defined($jall) && (ref($jall) =~ /hash/i)) { $logger->error("Could not retrieve journal Yearly Total Cited list! (#$jall)"); ISIBench::stop(); return ($jall, $jtitle, $jlist, $jimpact, $jall); } $logger->debug("Journal Total Cited/Citing List: ", sub{Dumper($jall);}); } } elsif ( $cat_name ) { my $category = JCR::Category->new( 'db' => $self->{db}, 'edition' => $edition->{edition}, 'year' => $year->{year}, ); unless (defined($category) && (ref($category) =~ /category/i)) { $logger->error("Could not create category object (#$category)!"); ISIBench::stop(); return $category; } # get the category title for displaying full title on the page. $jtitle = { 'title' => $cat_name }; $logger->debug("Category Title: ", sub{Dumper($jtitle);}); # get subject by category name my $cathash = $category->get_category_by_name( 'name' => $cat_name, 'order_by' => 'name', ); $logger->debug("Cat Hash : ", sub{Dumper($cathash)}); # get yearly cited/citing count $jlist = $category->get_category_cite_cites( 'subject' => $cathash, 'mode' => $self->{mode}, 'limit' => $CF::recs_per_summary, 'start' => ($self->{cite_cursor}-1), ); unless (defined($jlist) && (ref($jlist) =~ /array/i)) { $logger->error("Could not retrieve Category Cited list! (#$jlist)"); ISIBench::stop(); return ($jlist, $jtitle, $jlist, $jimpact, $jall); } $logger->debug("Category Cited List: ", sub{Dumper($jlist);}); # execute only if it is clicked on the cited/citing image. # get cited/citing yearly total count if(($self->{cite_cursor}) == 1) { $jall = $category->get_category_cites( 'subject' => $cathash, 'mode' => $self->{mode} ); unless (defined($jall) && (ref($jall) =~ /hash/i)) { $logger->error("Could not retrieve Category Yearly Total Cited list! (#$jall)"); ISIBench::stop(); return ($jall, $jtitle, $jlist, $jimpact, $jall); } $logger->debug("Category Total Cited/Citing List: ", sub{Dumper($jall);}); } } ISIBench::stop(); return ($ec, $jtitle, $jlist, $jimpact, $jall); } sub _execute_count { ISIBench::start(); my $logger = get_logger("JCRCite"); my $self = shift; my $args = (ref $_[0] eq 'HASH') ? shift : { @_ }; my $session = $self->{session}; my $request = $self->{request}; my $j20 = $request->{journal}; my $cat_name = $request->{category}; my $edition = $session->get( 'value' => 'edition' ); my $year = $session->get( 'value' => 'year' ); my($journal,$jcount); if ( $j20 ) { $journal = JCR::Journal->new( 'db' => $self->{db}, 'edition' => $edition->{edition}, 'year' => $year->{year}, ); unless (defined($journal) && (ref($journal) =~ /journal/i)) { $logger->error("Could not create journal object (#$journal)!"); ISIBench::stop(); return $journal; } $jcount = $journal->get_journal_cite_cites_count( 'j20' => $self->{j20}, 'mode' => $self->{mode} ); unless (defined($jcount) && (ref($jcount) =~ /hash/i)) { $logger->error("Could not retrieve journal count! (#$jcount)"); } else { $logger->debug("Journal Count: ", sub{Dumper($jcount);}); } } elsif ( $cat_name ) { my $category = JCR::Category->new( 'db' => $self->{db}, 'edition' => $edition->{edition}, 'year' => $year->{year}, ); unless (defined($category) && (ref($category) =~ /category/i)) { $logger->error("Could not create category object (#$category)!"); ISIBench::stop(); return $category; } # get subject by category name my $cathash = $category->get_category_by_name( 'name' => $cat_name, 'order_by' => 'name', ); $logger->debug("Cat Hash : ", sub{Dumper($cathash)}); $jcount = $category->get_category_cite_cites_count( 'subject' => $cathash, 'mode' => $self->{mode} ); unless (defined($jcount) && (ref($jcount) =~ /hash/i)) { $logger->error("Could not retrieve category count! (#$jcount)"); } else { $logger->debug("Category Count: ", sub{Dumper($jcount);}); } } ISIBench::stop(); return $jcount; } 1;