From fb122f28db1e4a5a445531f8e549d9afa7f0f647 Mon Sep 17 00:00:00 2001 From: miker Date: Mon, 22 May 2006 21:14:00 +0000 Subject: [PATCH] adding freshmeat feed support git-svn-id: svn://svn.open-ils.org/ILS/trunk@4347 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../perlmods/OpenILS/Application/SuperCat.pm | 74 +++++++++--- Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm | 110 +++++++++++++----- 2 files changed, 141 insertions(+), 43 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/SuperCat.pm b/Open-ILS/src/perlmods/OpenILS/Application/SuperCat.pm index 04b014bcd5..e87a4fc072 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/SuperCat.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/SuperCat.pm @@ -42,8 +42,6 @@ sub child_init { # we need an XML parser $_parser = new XML::LibXML; - $logger->debug("Got here!"); - # and an xslt parser $_xslt = new XML::LibXSLT; @@ -73,8 +71,6 @@ sub child_init { $record_xslt{mods}{docs} = 'http://www.loc.gov/mods/'; $record_xslt{mods}{schema_location} = 'http://www.loc.gov/standards/mods/mods.xsd'; - $logger->debug("Got here!"); - # parse the ATOM entry xslt ... my $atom_xslt = $_parser->parse_file( OpenSRF::Utils::SettingsClient @@ -99,8 +95,6 @@ sub child_init { $record_xslt{rdf_dc}{namespace_uri} = 'http://purl.org/dc/elements/1.1/'; $record_xslt{rdf_dc}{schema_location} = 'http://purl.org/dc/elements/1.1/'; - $logger->debug("Got here!"); - # parse the SRWDC xslt ... my $srw_dc_xslt = $_parser->parse_file( OpenSRF::Utils::SettingsClient @@ -113,8 +107,6 @@ sub child_init { $record_xslt{srw_dc}{namespace_uri} = 'info:srw/schema/1/dc-schema'; $record_xslt{srw_dc}{schema_location} = 'http://www.loc.gov/z3950/agency/zing/srw/dc-schema.xsd'; - $logger->debug("Got here!"); - # parse the OAIDC xslt ... my $oai_dc_xslt = $_parser->parse_file( OpenSRF::Utils::SettingsClient @@ -127,8 +119,6 @@ sub child_init { $record_xslt{oai_dc}{namespace_uri} = 'http://www.openarchives.org/OAI/2.0/oai_dc/'; $record_xslt{oai_dc}{schema_location} = 'http://www.openarchives.org/OAI/2.0/oai_dc.xsd'; - $logger->debug("Got here!"); - # parse the RSS xslt ... my $rss_xslt = $_parser->parse_file( OpenSRF::Utils::SettingsClient @@ -139,8 +129,6 @@ sub child_init { # and stash a transformer $record_xslt{rss2}{xslt} = $_xslt->parse_stylesheet( $rss_xslt ); - $logger->debug("Got here!"); - # and finally, a storage server session register_record_transforms(); @@ -156,9 +144,8 @@ sub register_record_transforms { api_level => 1, argc => 1, signature => - { desc => <<" DESC", -Returns the \U$type\E representation of the requested bibliographic record - DESC + { desc => "Returns the \U$type\E representation ". + "of the requested bibliographic record", params => [ { name => 'bibId', @@ -181,6 +168,63 @@ sub entityize { } +sub recent_changes { + my $self = shift; + my $client = shift; + my $when = shift; + my $limit = shift; + + if (!$when) { + my ($d,$m,$y) = (localtime)[4,5,6]; + $when = sprintf('%4d-%02d-%02d', $y + 1900, $m + 1, $d); + } + + my $type = 'biblio'; + $type = 'authority' if ($self->api_name =~ /authority/o); + + my $axis = 'create_date'; + $axis = 'edit_date' if ($self->api_name =~ /edit/o); + + my $_storage = OpenSRF::AppSession->create( 'open-ils.storage' ); + + return $_storage + ->request( + "open-ils.storage.id_list.$type.record_entry.search_where.atomic", + { $axis => { ">" => $when } }, + { order_by => "$axis desc", limit => $limit } ) + ->gather(1); +} + +for my $t ( qw/biblio authority/ ) { + for my $a ( qw/import edit/ ) { + + __PACKAGE__->register_method( + method => 'recent_changes', + api_name => "open-ils.supercat.$t.record.$a.recent", + api_level => 1, + argc => 0, + signature => + { desc => "Returns a list of recently ${a}ed $t records", + params => + [ + { name => 'when', + desc => "Date to start looking for ${a}ed records", + default => 'today', + type => 'string' }, + + { name => 'limit', + desc => "Maximum count to retrieve", + type => 'number' }, + ], + 'return' => + { desc => "An id list of $t records", + type => 'array' } + }, + ); + } +} + + sub retrieve_record_marcxml { my $self = shift; my $client = shift; diff --git a/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm b/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm index 2015e8ab95..f1cd3d7315 100644 --- a/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm +++ b/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm @@ -88,7 +88,7 @@ sub unapi { my $base = (split 'unapi', $url)[0] . 'unapi'; - my $uri = $cgi->param('uri') || ''; + my $uri = $cgi->param('id') || ''; my $host = $cgi->virtual_host || $cgi->server_name; my $format = $cgi->param('format'); @@ -108,24 +108,18 @@ sub unapi { print "\n"; - my $body = - " - $uri - - opac - text/html - "; + my $body = ""; for my $h (@$list) { my ($type) = keys %$h; - $body .= "$typeapplication/xml"; + $body .= " (values %$_)[0] ) } @$list; $list = [ map { { $_ => $hash{$_} } } sort keys %hash ]; - print "\n - - opac - text/html - "; + print ""; for my $h (@$list) { my ($type) = keys %$h; - print "$typeapplication/xml"; + print "$$h{$type}{$part}" + print " $part='$$h{$type}{$part}'" if ($$h{$type}{$part}); } - print ''; + print '/>'; } print "\n"; @@ -180,9 +170,9 @@ sub unapi { } if ($format eq 'opac') { - print "Location: $base/../../en-US/skin/default/xml/rresult.xml?m=$id\n\n" + print "Location: /opac/en-US/skin/default/xml/rresult.xml?m=$id\n\n" if ($type eq 'metarecord'); - print "Location: $base/../../en-US/skin/default/xml/rdetail.xml?r=$id\n\n" + print "Location: /opac/en-US/skin/default/xml/rdetail.xml?r=$id\n\n" if ($type eq 'record'); return 302; } elsif ($format =~ /^html/o) { @@ -213,7 +203,7 @@ sub unapi {
-
Sorry, we couldn't $command a $type with the id of $id.
+
Sorry, we couldn't $command a $type with the id of $id in format $format.
HTML @@ -394,7 +384,7 @@ sub bookbag_feed { my $bucket_tag = "tag:$host,$year:record_bucket/$id"; if ($type eq 'opac') { - print "Location: $root/../en-US/skin/default/xml/rresult.xml?rt=list&" . + print "Location: /opac/en-US/skin/default/xml/rresult.xml?rt=list&" . join('&', map { "rl=" . $_->target_biblio_record_entry } @{ $bucket->items }) . "\n\n"; return Apache2::Const::OK; @@ -418,7 +408,7 @@ sub bookbag_feed { $feed->link( OPAC => - $root . '../en-US/skin/default/xml/rresult.xml?rt=list&' . + '/opac/en-US/skin/default/xml/rresult.xml?rt=list&' . join('&', map { 'rl=' . $_->target_biblio_record_entry } @{$bucket->items} ), 'text/html' ); @@ -430,6 +420,70 @@ sub bookbag_feed { return Apache2::Const::OK; } +sub changes_feed { + my $apache = shift; + return Apache2::Const::DECLINED if (-e $apache->filename); + + my $cgi = new CGI; + + my $year = (gmtime())[5] + 1900; + my $host = $cgi->virtual_host || $cgi->server_name; + + my $rel_name = quotemeta($cgi->url(-relative=>1)); + + my $add_path = 1; + $add_path = 0 if ($cgi->url(-path_info=>1) =~ /$rel_name$/); + + my $url = $cgi->url(-path_info=>$add_path); + my $root = (split 'feed', $url)[0]; + my $base = (split 'freshmeat', $url)[0] . 'freshmeat'; + my $path = (split 'freshmeat', $url)[1]; + my $unapi = (split 'feed', $url)[0] . 'unapi'; + + + #warn "URL breakdown: $url ($rel_name) -> $root -> $base -> $path -> $unapi"; + + $path =~ s/^\///og; + + my ($type,$rtype,$axis,$date,$limit) = split '/', $path; + $date ||= 'today'; + $limit ||= 10; + + my $list = $supercat->request("open-ils.supercat.$rtype.record.$axis.recent", $date, $limit)->gather(1); + + if ($type eq 'opac') { + print "Location: /opac/en-US/skin/default/xml/rresult.xml?rt=list&" . + join('&', map { "rl=" . $_ } @$list) . + "\n\n"; + return Apache2::Const::OK; + } + + my $feed = create_record_feed( $type, $list, $unapi); + $feed->root($root); + + $feed->title("$limit most recent $rtype changes from $date forward"); + $feed->creator($host); + $feed->update_ts(gmtime_ISO8601()); + + $feed->link(atom => $base . "/atom/$rtype/$axis/$date/$limit" => 'application/atom+xml'); + $feed->link(rss2 => $base . "/rss2/$rtype/$axis/$date/$limit"); + $feed->link(html => $base . "/html/$rtype/$axis/$date/$limit" => 'text/html'); + $feed->link(unapi => $unapi); + + $feed->link( + OPAC => + '/opac/en-US/skin/default/xml/rresult.xml?rt=list&' . + join('&', map { 'rl=' . $_} @$list ), + 'text/html' + ); + + + print "Content-type: ". $feed->type ."; charset=utf-8\n\n"; + print entityize($feed->toString) . "\n"; + + return Apache2::Const::OK; +} + sub opensearch_osd { my $version = shift; my $lib = shift; @@ -693,10 +747,10 @@ sub create_record_feed { my $node = $feed->add_item($xml); $node->id($item_tag); - $node->link(alternate => $feed->unapi . "?uri=$item_tag&format=opac" => 'text/html'); - $node->link(opac => $feed->unapi . "?uri=$item_tag&format=opac"); - $node->link(unapi => $feed->unapi . "?uri=$item_tag"); - $node->link('unapi-uri' => $item_tag); + $node->link(alternate => $feed->unapi . "?id=$item_tag&format=opac" => 'text/html'); + $node->link(opac => $feed->unapi . "?id=$item_tag&format=opac"); + $node->link(unapi => $feed->unapi . "?id=$item_tag"); + $node->link('unapi-id' => $item_tag); } return $feed; -- 2.43.2