package JCRListSummary; # -------------------------------------------------------------------- # 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: JCRListSummary.pm,v 1.20 2008/08/14 18:01:09 ssidanal Exp $ use strict; use JCR::Category; use JCR::Country; use Data::Dumper; use ISIBench; use JCRErrorList; use JCR::Journal; use Log::Log4perl qw(get_logger); use JCR::Publisher; use Tie::IxHash; use Toolbar; use base qq(JCRList); use JCR::MarkedList; sub _save_params { ISIBench::start(); my $logger = get_logger("JCRListSummary"); my $self = shift; my $args = (ref $_[0] eq 'HASH') ? shift : { @_ }; my $session = $self->{session}; my $request = $self->{request}; # If this is a new search, wipe out the old search values if ($request->{query_new} eq 'true') { $logger->debug("Erasing old search parameters..."); $session->remove( 'name' => 'summary_data', ); $session->remove( 'name' => 'summary_data_type', ); $session->remove( 'name' => 'summary_data_display', ); $session->remove( 'name' => 'summary_sort', ); $session->remove( 'name' => 'summary_cursor', ); } # Get the sort order and save it in the session. my $sort = $session->get( 'value' => 'summary_sort' ); $logger->debug("Summary order is: ", sub{Dumper($self->{summary_sort})}); $logger->debug("Request order (Journal) is: ", sub{Dumper($request->{journal_sort_by})}); $logger->debug("Request order (Category) is: ", sub{Dumper($request->{category_sort_by})}); if ( $request->{RQ} =~ /LIST_SUMMARY_JOURNAL/i && !($self->{summary_sort}) ) { $self->{summary_sort} = $request->{journal_sort_by} || $sort->{summary_sort} || 'journal'; if ( $self->{summary_sort} !~ /(journal|title|cites_all|impact_current|immediacy|source_current|cited_hlife|eigen_factor|article_influence|impact_5year)/) { $self->{summary_sort} = 'journal'; $self->{summary_cursor} = 1; } } elsif ( $request->{RQ} =~ /LIST_SUMMARY_CATEGORY/i && !($self->{summary_sort}) ) { $self->{summary_sort} = $request->{category_sort_by} || $sort->{summary_sort} || 'category'; if ( $self->{summary_sort} !~ /(category|cat_title|journal_cites|median_if|aggregate_if|aggregate_immed_index|cited_hlife|journal_count|articles_count)/ ) { $self->{summary_sort} = 'category'; $self->{summary_cursor} = 1; } } elsif ( $request->{RQ} =~ /SELECT_ALL/i && !($self->{summary_sort}) ) { $self->{summary_sort} = $request->{journal_sort_by} || $sort->{summary_sort} || 'journal'; } if ($self->{summary_sort} ne $sort->{summary_sort}) { $session->set( 'name' => 'summary_sort', 'value' => $self->{summary_sort}, ); } $logger->debug("Sort order is: ", sub{Dumper($self->{summary_sort})}); # Get the current page number my $cursor = $session->get( 'value' => 'summary_cursor' ); if (! $self->{summary_cursor} ) { $self->{summary_cursor} = $request->{cursor} || $cursor->{summary_cursor} || 1; } if ($self->{summary_cursor} ne $cursor->{summary_cursor}) { $session->set( 'name' => 'summary_cursor', 'value' => $self->{summary_cursor}, ); } $logger->debug("Cursor is: ", $self->{summary_cursor}); ISIBench::stop(); return 0; } sub _get_query { ISIBench::start(); my $logger = get_logger("JCRListSummary"); my $self = shift; my $args = (ref $_[0] eq 'HASH') ? shift : { @_ }; my $session = $self->{session}; my $request = $self->{request}; my ($data, $type, $display); # Do we have a new query? if ($request->{query_new} eq 'true') { my $query = $request->{query_data}; $type = $request->{query_type}; if ($type =~ /(category|publisher|country)/i) { # The user is making a selection my $method = "_get_$1"; unless (ref($query) =~ /array/i) { $query = [split /, /, $query]; } # This checks the selection against the DB - to get only valid ones # and to get the actual text descriptions of the selected elements my $temp_query = $self->$method( 'type' => $type, 'data' => $query ); if ( $type =~ /category/i ) { $display = qq{ subject categories }; } elsif ( $type =~ /publisher/i ) { $display = qq{ publishers }; } elsif ( $type =~ /country/i ) { $display = qq{ countries/territories }; } # Change our selection to a string to store in the session $query = [keys(%$temp_query)]; $data = join(', ', keys(%$temp_query)); $display .= join('; ', values(%$temp_query)); } elsif ($type =~ /search_(.*)/i) { # Determine the type of search we are running my $search_type = $1; if ($search_type =~ /full_title/i) { $display = "search Full Journal Title for "; } elsif ($search_type =~ /j20/i) { $display = "search JCR Abbreviated Journal Title for "; } elsif ($search_type =~ /title_word/i) { $display = "search Journal Title for "; } elsif ($search_type =~ /issn/i) { $display = "search ISSN for "; } $display .= "'". uc($query)."'"; } else { # The user wants to view all $type = 'ALL'; $query = 'View All Journals'; $display = 'All Journals'; } # Save our query properties in the session $logger->debug("Saving search params in session"); $session->set( 'name' => 'summary_data', 'value' => $data || $query, ); $session->set( 'name' => 'summary_data_type', 'value' => $type, ); $session->set( 'name' => 'summary_data_display', 'value' => $display, ); $data = $query; } else { # Get the query type from the session $type = $session->get( 'value' => 'summary_data_type' ); $type = $type->{summary_data_type}; # We are loading a query from the session $data = $session->get( 'value' => 'summary_data' ); $data = $data->{summary_data}; if ($type =~ /(?:category|publisher|country)/i) { $data = [split(', ', $data)]; } # Get the query display string from the session $display = $session->get( 'value' => 'summary_data_display' ); $display = $display->{summary_data_display}; } $logger->debug("Query Data: ", sub{Dumper($data)}); $logger->debug("Query Type: $type"); $logger->debug("Query Display: $display"); ISIBench::stop(); return { 'type' => $type, 'data' => $data, 'display' => $display }; } sub _execute_query { ISIBench::start(); my $logger = get_logger("JCRListSummary"); my $self = shift; my $args = (ref $_[0] eq 'HASH') ? shift : { @_ }; my $query = $args->{query}; my $data; if ($query->{type} =~ /search.*/i) { $data = $self->_execute_search_query( 'query' => $query ); } else { $data = $self->_execute_select_query( 'query' => $query ); } $logger->debug("$query->{type} :Execute Query Returned: ", sub{Dumper($data);}); ISIBench::stop(); return $data; } sub _execute_count { ISIBench::start(); my $logger = get_logger("JCRListSummary"); my $self = shift; my $args = (ref $_[0] eq 'HASH') ? shift : { @_ }; my $query = $args->{query}; my $count; # Get the total hit count for the VCR Control if ($query->{type} =~ /search/i) { $count = $self->_execute_search_count( 'query' => $query ); } else { $count = $self->_execute_select_count( 'query' => $query ); } $logger->debug("Execute Count Returned: ", sub{Dumper($count);}); ISIBench::stop(); return $count; } sub _execute_select_query { ISIBench::start(); my $logger = get_logger("JCRListSummary"); my $self = shift; my $args = (ref $_[0] eq 'HASH') ? shift : { @_ }; my $query = $args->{query}; my $session = $self->{session}; my $edition = $session->get( 'value' => 'edition' ); my $year = $session->get( 'value' => 'year' ); my $request = $self->{request}; $logger->debug("Request: ", sub{Dumper($request);}); if ( $request->{RQ} =~ /LIST_SUMMARY_JOURNAL/i || $request->{RQ} =~ /SELECT_ALL/i ) { 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 $jlist = $journal->get_journals_by_selection( 'data' => $query->{data}, 'mode' => $query->{type}, 'order_by' => $self->{summary_sort}, 'limit' => ($self->{summary_cursor}-1) + $CF::recs_per_summary, 'page_recs'=> $CF::recs_per_summary, ); $logger->debug("Journal %%%%: ", sub{Dumper($query);}); $logger->debug("HERE 1 data =$query, mode = $query->{type}, order_by => $self->{summary_sort},limit => ($self->{summary_cursor}-1) + $CF::recs_per_summary, page_recs=> $CF::recs_per_summary"); print STDERR 'here 1'; unless (defined($jlist) && (ref($jlist) =~ /array/i)) { $logger->error("Could not retrieve journal list! (#$jlist)"); ISIBench::stop(); $logger->debug("Journal Selection: ", sub{Dumper($jlist);}); return $jlist; } $logger->debug("Journal Selection: ", sub{Dumper($jlist);}); ISIBench::stop(); return $jlist; } elsif ( $request->{RQ} =~ /LIST_SUMMARY_CATEGORY/i ) { 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; } my $cat_list = $category->get_categories_by_selection( 'data' => $query->{data}, 'order_by' => $self->{summary_sort}, 'limit' => ($self->{summary_cursor}-1) + $CF::recs_per_summary, 'page_recs'=> $CF::recs_per_summary, ); unless (defined($cat_list) && (ref($cat_list) =~ /array/i)) { $logger->error("Could not retrieve category list! (#$cat_list)"); ISIBench::stop(); $logger->debug("Category Selection: ", sub{Dumper($cat_list);}); return $cat_list; } ISIBench::stop(); return $cat_list; } } sub _execute_search_query { ISIBench::start(); my $logger = get_logger("JCRListSummary"); my $self = shift; my $args = (ref $_[0] eq 'HASH') ? shift : { @_ }; my $query = $args->{query}; my $session = $self->{session}; $logger->debug("SEARCH: ", sub{Dumper($args);}); # Determine our search mode my $search; if ($query->{type} =~ /search_(.*)/i) { $search = $1; } else { $search = 'topic'; } my $session = $self->{session}; my $edition = $session->get( 'value' => 'edition' ); my $year = $session->get( 'value' => 'year' ); 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 $jlist = $journal->search( 'search' => $search, 'query' => $query->{data}, 'order_by' => $self->{summary_sort}, 'limit' => ($self->{summary_cursor}-1) + $CF::recs_per_summary, 'page_recs'=> $CF::recs_per_summary, ); unless (defined($jlist) && (ref($jlist) =~ /array/i)) { $logger->error("Could not retrieve journal list! (#$jlist)"); ISIBench::stop(); return $jlist; } $logger->debug("Journal Selection: ", sub{Dumper($jlist);}); ISIBench::stop(); return $jlist; } sub _execute_select_count { ISIBench::start(); my $logger = get_logger("JCRListSummary"); my $self = shift; my $args = (ref $_[0] eq 'HASH') ? shift : { @_ }; my $query = $args->{query}; my $session = $self->{session}; my $edition = $session->get( 'value' => 'edition' ); my $year = $session->get( 'value' => 'year' ); my $request = $self->{request}; if ( $request->{RQ} =~ /LIST_SUMMARY_JOURNAL/i || $request->{RQ} =~ /SELECT_ALL/i ) { 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 $jcount = $journal->get_journals_by_selection_count( 'data' => $query->{data}, 'mode' => $query->{type}, ); unless (defined($jcount) && (ref($jcount) =~ /hash/i)) { $logger->error("Could not retrieve journal count! (#$jcount)"); ISIBench::stop(); return $jcount; } $logger->debug("Journal Count: ", sub{Dumper($jcount);}); ISIBench::stop(); return $jcount; } elsif ( $request->{RQ} =~ /LIST_SUMMARY_CATEGORY/i ) { 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; } my $cat_count = $category->get_categories_by_selection_count( 'data' => $query->{data}, ); unless (defined($cat_count) && (ref($cat_count) =~ /hash/i)) { $logger->error("Could not retrieve category count! (#$cat_count)"); ISIBench::stop(); return $cat_count; } $logger->debug("Category Count: ", sub{Dumper($cat_count);}); ISIBench::stop(); return $cat_count; } } sub _execute_search_count { ISIBench::start(); my $logger = get_logger("JCRListSummary"); my $self = shift; my $args = (ref $_[0] eq 'HASH') ? shift : { @_ }; my $query = $args->{query}; my $session = $self->{session}; # Determine our search mode my $search; if ($query->{type} =~ /search_(.*)/i) { $search = $1; } else { $search = 'topic'; } my $session = $self->{session}; my $edition = $session->get( 'value' => 'edition' ); my $year = $session->get( 'value' => 'year' ); 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 $jcount = $journal->search_count( 'query' => $query->{data}, 'search' => $search, ); unless (defined($jcount) && (ref($jcount) =~ /hash/i)) { $logger->error("Could not retrieve journal count! (#$jcount)"); ISIBench::stop(); return $jcount; } $logger->debug("Journal Count: ", sub{Dumper($jcount);}); ISIBench::stop(); return $jcount; } sub _get_category { ISIBench::start(); my $logger = get_logger("JCRListSummary"); my $self = shift; my $args = (ref $_[0] eq 'HASH') ? shift : { @_ }; my $session = $self->{session}; my $request = $self->{request}; my $edition = $session->get( 'value' => 'edition' ); my $year = $session->get( 'value' => 'year' ); my $cat = JCR::Category->new( 'db' => $self->{db}, 'edition' => $edition->{edition}, 'year' => $year->{year}, ); unless (defined($cat) && (ref($cat) =~ /category/i)) { $logger->error("Could not create category object (#$cat)!"); ISIBench::stop(); return $cat; } # Get the category hash my $cathash = {}; if (length($args->{data}[0])>0) { $cathash = $cat->get_category_by_subject( 'subject' => $args->{data}, 'order_by' => 'name', ); } else { $cathash = $cat->get_category_hash(); } $logger->debug("cathash is $cathash : ", sub{Dumper($cathash);}); ISIBench::stop(); return $cathash; } sub _get_publisher { ISIBench::start(); my $logger = get_logger("JCRListSummary"); my $self = shift; my $args = (ref $_[0] eq 'HASH') ? shift : { @_ }; my $session = $self->{session}; my $request = $self->{request}; my $edition = $session->get( 'value' => 'edition' ); my $year = $session->get( 'value' => 'year' ); # Get the publisher list from the database my $pub = JCR::Publisher->new( 'db' => $self->{db}, 'edition' => $edition->{edition}, 'year' => $year->{year}, ); unless (defined($pub) && (ref($pub) =~ /publisher/i)) { $logger->error("Could not create publisher object (#$pub)!"); ISIBench::stop(); return $pub; } # Get the publisher hash my $pubhash; if (length($args->{data}[0])>0) { $pubhash = $pub->get_publishers( 'publishers' => $args->{data} ); } else { $pubhash = $pub->get_publishers(); } $logger->debug("pubhash is $pubhash : ", sub{Dumper($pubhash);}); ISIBench::stop(); return $pubhash; } sub _get_country { ISIBench::start(); my $logger = get_logger("JCRListSummary"); my $self = shift; my $args = (ref $_[0] eq 'HASH') ? shift : { @_ }; my $data = $args->{data}; my $session = $self->{session}; my $request = $self->{request}; my %conhash; tie %conhash, "Tie::IxHash"; unless (length($args->{data}[0])>0) { my $edition = $session->get( 'value' => 'edition' ); my $year = $session->get( 'value' => 'year' ); # Get the country list from the database my $con = JCR::Country->new( 'db' => $self->{db}, 'edition' => $edition->{edition}, 'year' => $year->{year}, ); unless (defined($con) && (ref($con) =~ /country/i)) { $logger->error("Could not create country object (#$con)!"); ISIBench::stop(); return $con; } # Get the country array $data = $con->get_countries(); } else { # Sort the selection $data = [sort(@$data)]; } foreach my $value (@$data) { $conhash{$value} = $value; } $logger->debug("conhash is %conhash : ", sub{Dumper(\%conhash);}); ISIBench::stop(); return \%conhash; } sub _get_buttons { ISIBench::start(); my $logger = get_logger("JCRListSummary"); my $self = shift; my $args = (ref $_[0] eq 'HASH') ? shift : { @_ }; my $session = $self->{session}; my $request = $self->{request}; if ( $request->{RQ} =~ /LIST_SUMMARY_JOURNAL/i || $request->{RQ} =~ /SELECT_ALL/i ) { my $buttons = { 'Mark All on Summary' => { 'name' => 'Mark All on Summary', 'filename' => 'markall.gif', 'alttext' => 'Mark All on Summary', 'weight' => 0, }, 'Update Marked List' => { 'name' => 'Update Marked List', 'filename' => 'update.gif', 'alttext' => 'Update Marked List', 'weight' => 1, }, }; my $toolbar = Toolbar->new( 'buttons' => $buttons, 'path' => $CF::image_path, 'default' => ['Mark All on Summary', 'Update Marked List'], 'SID' => $session->{SID}, ); my $toolbar_html = $toolbar->build(); ISIBench::stop(); return {'html' => $toolbar_html->{html}}; } ISIBench::stop(); } sub _process_button_clicks { ISIBench::start(); my $logger = get_logger("JCRListSummary"); my $self = shift; my $args = (ref $_[0] eq 'HASH') ? shift : { @_ }; my $request = $self->{request}; if ( $request->{RQ} =~ /LIST_SUMMARY_JOURNAL/i ) { # only need to check for Marking Record actions on Journal Summary list pages. if (($request->{'Mark All on Summary.x'}>0) || ($request->{'Mark All on Summary.y'}>0)) { $self->_mark_all('query' => $args->{query}); } elsif (($request->{'Update Marked List.x'}>0) || ($request->{'Update Marked List.y'}>0)) { $self->_update_marked_list(); } } ISIBench::stop(); } sub _mark_all { ISIBench::start(); my $logger = get_logger("JCRListSummary"); my $self = shift; my $args = (ref $_[0] eq 'HASH') ? shift : { @_ }; my $request = $self->{request}; my $session = $self->{session}; my $query = $args->{query}; my $edition = $session->get( 'value' => 'edition' ); my $year = $session->get( 'value' => 'year' ); $logger->debug("Args are: ", sub{Dumper($args)}); 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; } # Get all of the journals in this result set my $jlist; if ($query->{type} =~ /search_(.*)/i) { $jlist = $journal->search_j20s( 'search' => $1, 'query' => $query->{data}, 'order_by' => $self->{summary_sort}, 'limit' => ($CF::marked_list_max + 1), ); } else { $jlist = $journal->get_j20s_by_selection( 'data' => $query->{data}, 'mode' => $query->{type}, 'order_by' => $self->{summary_sort}, 'limit' => ($CF::marked_list_max + 1), ); } unless (defined($jlist) && (ref($jlist) =~ /array/i)) { $logger->error("Could not retrieve journal list for marking all! (#$jlist)"); ISIBench::stop(); return $jlist; } $logger->debug("ALL Selected Journals: ", sub{Dumper($jlist);}); # Create the new MarkedList object my $edition = $session->get( 'value' => 'edition' ); my $year = $session->get( 'value' => 'year' ); my $marked_list = JCR::MarkedList->new( 'session' => $session, 'max_marked' => $CF::marked_list_max, 'db' => $self->{db}, 'edition' => $edition->{edition}, 'year' => $year->{year}, ); unless (defined($marked_list) && (ref($marked_list) =~ /markedlist/i)) { $logger->debug("Could not create Marked List Object"); ISIBench::stop(); return $marked_list; } # Build our update hash my %update; tie %update, "Tie::IxHash"; foreach my $j20 (@$jlist) { $update{"$j20"} = 'checked'; } $logger->debug("Built Update Hash: ", sub{Dumper(\%update);}); my $ret = $marked_list->update_marked_list( 'journals' => \%update ); $logger->debug("Marking records return value is: $ret"); if ($ret > 0) { my $errorlist = JCRErrorList->new(); my $error = $errorlist->map( 'error' => $ret ); $self->{ERROR} = $error->{error}; } ISIBench::stop(); return $ret; } sub _get_marked_list { ISIBench::start(); my $logger = get_logger("JCRListSummary"); my $self = shift; my $args = (ref $_[0] eq 'HASH') ? shift : { @_ }; my $request = $self->{request}; my $session = $self->{session}; # Create the new MarkedList object my $edition = $session->get( 'name' => 'edition' ); my $year = $session->get( 'name' => 'year' ); my $marked_list = JCR::MarkedList->new( 'session' => $session, 'max_marked' => $CF::marked_list_max, 'db' => $self->{db}, 'edition' => $edition->{edition}, 'year' => $year->{year}, ); unless (defined($marked_list) && (ref($marked_list) =~ /markedlist/i)) { $logger->debug("Could not create Marked List Object"); ISIBench::stop(); return $marked_list; } # Send the updated marked list to the DB ISIBench::stop(); return $marked_list->get_marked_list( 'return' => 'array' ); } sub _set_template { ISIBench::start(); my $logger = get_logger("JCRListSummary"); my $self = shift; my $args = (ref $_[0] eq 'HASH') ? shift : { @_ }; my $request = $self->{request}; if ( $request->{RQ} =~ /LIST_SUMMARY_JOURNAL/i || $request->{RQ} =~ /SELECT_ALL/i ) { ISIBench::stop(); return $self->set_template( 'template' => "jcr_journal_summary_list.html" ); } elsif ( $request->{RQ} =~ /LIST_SUMMARY_CATEGORY/i ) { ISIBench::stop(); return $self->set_template( 'template' => "jcr_category_summary_list.html" ); } } 1;