package PaintGraphImpact; # -------------------------------------------------------------------- # 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. # -------------------------------------------------------------------- use strict; use Data::Dumper; use JCR::GraphImpact; use ISIBench; use JCR::Journal; use Log::Log4perl qw(get_logger); use base qq(JCRPage); sub build_page { ISIBench::start(); my $logger = get_logger("PaintGraphImpact"); my $self = shift; my $args = (ref $_[0] eq 'HASH') ? shift : { @_ }; my ($edition, $year, $results); #Get input parameters my $request = $self->{request}; my $j20 = $request->{'journal'}; my $issn = $request->{'issn'}; my $source = $request->{'source'}; $logger->debug("Args are : ", sub{Dumper($request)}); # Get session object my $session = $self->{session}; # Get year & edition if ((defined $source)) { my $permissions = $session->get_editions( 'year_min' => $CF::data_year_start, 'year_max' => $CF::data_year_end, ); foreach my $edition_name (keys %$permissions) { $year->{year} = $permissions->{$edition_name}->{end_year}; $edition->{edition} = $edition_name; my $journal = JCR::Journal->new( 'db' => $self->{db}, 'edition' => $edition_name, 'year' => $year->{year}, ); if (defined($journal) && (ref($journal) =~ /journal/i)) { if (defined $j20) { my $journal_hash = $journal->get_journal_title( 'j20' => $j20 ); last if ((ref($journal_hash) =~ /hash/i) && (defined $journal_hash->{title})); } elsif (defined $issn) { # If we have a ISSN, we're probably coming from JUR, so # we need to get the J20 before we proceed my $journal_hash = $journal->get_journal_j20( 'issn' => $issn ); if ((ref($journal_hash) =~ /hash/i) && (defined $journal_hash->{journal})) { $j20 = $journal_hash->{journal} if (!defined($j20)); last; } } } } } else { $edition = $session->get( 'value' => 'edition' ); $year = $session->get( 'value' => 'year' ); } if ($j20) { # Get graph object my $graph = JCR::GraphImpact->new( 'year' => $year->{year} ); # Build cache directory path my $path = $CF::cache_directory . qq{/journals/$year->{year}/$edition->{edition}/$j20/Graphs}; $path =~ tr/ /_/; # Are we cached? $results = $graph->load( 'path' => $path, 'filename' => $CF::ImpactFactorCacheFilename, ) if ($CF::cache_impact_graph); unless (defined($results)) { # Not cached, so build the graph $logger->debug("Impact Graph Built, not found in $path"); 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; } my $title = $journal->get_journal_title('j20' => $j20); if (defined($title) && (ref($title) =~ /hash/i)) { unless (length($title->{'title'})) { $logger->error("Could not retrieve title for : $j20!"); ISIBench::stop(); return $title; } } my $impact = $journal->get_journal_impact('j20' => $j20); $results = $graph->build( 'title' => $title->{'title'}, 'impact' => $impact, ); # save Impact Factor graph in cache if ($CF::cache_impact_graph) { $graph->save( 'path' => $path, 'filename' => $CF::ImpactFactorCacheFilename, ); $logger->debug("Saving Impact Graph into: $path/$CF::ImpactFactorCacheFilename"); } } else { $logger->debug("Impact Graph Loaded from: $path"); $logger->debug("Impact Graph Data: ", sub{Dumper($results)}); } } $self->set_header( 'name' => 'Expires', 'value' => 'Thu, 01 Jan 1970 00:00:01 GMT', ); $self->set_header( 'name' => 'Cache-Control', 'value' => 'no-cache', ); $self->set_header( 'name' => 'Pragma', 'value' => 'no-cache', ); $self->set_header( 'name' => 'Content-type', 'value' => 'image/jpeg', ); $self->{CONTENT} = $results->{'data'} if (defined($results) && (ref($results) =~ /hash/i)); ISIBench::stop(); return 0; } # Overriding Page.pm's get_content method since we don't use a template for this output sub get_content { my $self = shift; return $self->{CONTENT}; } 1;