feed improvements
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 23 Jun 2006 07:24:00 +0000 (07:24 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 23 Jun 2006 07:24:00 +0000 (07:24 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@4732 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/metabib.pm
Open-ILS/src/perlmods/OpenILS/Application/SuperCat.pm
Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm
Open-ILS/src/perlmods/OpenILS/WWW/SuperCat/Feed.pm
Open-ILS/xsl/ATOM2XHTML.xsl

index c6e5619..bfedb17 100644 (file)
@@ -55,7 +55,7 @@ sub ordered_records_from_metarecord {
                        item_type,
                        item_form,
                        quality,
-                       FIRST(COALESCE(LTRIM(SUBSTR( value, COALESCE(SUBSTRING(ind2 FROM '\\\\d+'),'0')::INT )),'zzzzzzzz')) AS title
+                       FIRST(COALESCE(LTRIM(SUBSTR( value, COALESCE(SUBSTRING(ind2 FROM '\\\\d+'),'0')::INT + 1 )),'zzzzzzzz')) AS title
                FROM    (
                        SELECT  rd.record,
                                rd.item_type,
@@ -538,7 +538,7 @@ sub biblio_multi_search_full_rec {
        } elsif (lc($sort) eq 'title') {
                $rank = <<"             RANK";
                        ( FIRST ((
-                               SELECT  COALESCE(LTRIM(SUBSTR( frt.value, COALESCE(SUBSTRING(frt.ind2 FROM '\\\\d+'),'0')::INT )),'zzzzzzzz')
+                               SELECT  COALESCE(LTRIM(SUBSTR( frt.value, COALESCE(SUBSTRING(frt.ind2 FROM '\\\\d+'),'0')::INT + 1 )),'zzzzzzzz')
                                  FROM  $metabib_full_rec frt
                                  WHERE frt.record = f.record
                                        AND frt.tag = '245'
@@ -1158,7 +1158,7 @@ sub postfilter_search_class_fts {
        } elsif (lc($sort) eq 'title') {
                $rank = <<"             RANK";
                        ( FIRST ((
-                               SELECT  COALESCE(LTRIM(SUBSTR( frt.value, COALESCE(SUBSTRING(frt.ind2 FROM '\\\\d+'),'0')::INT )),'zzzzzzzz')
+                               SELECT  COALESCE(LTRIM(SUBSTR( frt.value, COALESCE(SUBSTRING(frt.ind2 FROM '\\\\d+'),'0')::INT + 1 )),'zzzzzzzz')
                                  FROM  $metabib_full_rec frt
                                  WHERE frt.record = mr.master_record
                                        AND frt.tag = '245'
@@ -1559,7 +1559,7 @@ sub postfilter_search_multi_class_fts {
 
        my $secondary_sort = <<"        SORT";
                ( FIRST ((
-                       SELECT  COALESCE(LTRIM(SUBSTR( sfrt.value, COALESCE(SUBSTRING(sfrt.ind2 FROM '\\\\d+'),'0')::INT )),'zzzzzzzz')
+                       SELECT  COALESCE(LTRIM(SUBSTR( sfrt.value, COALESCE(SUBSTRING(sfrt.ind2 FROM '\\\\d+'),'0')::INT + 1 )),'zzzzzzzz')
                          FROM  $metabib_full_rec sfrt,
                                $metabib_metarecord mr
                          WHERE sfrt.record = mr.master_record
@@ -1592,7 +1592,7 @@ sub postfilter_search_multi_class_fts {
        } elsif (lc($sort) eq 'title') {
                $rank = <<"             RANK";
                        ( FIRST ((
-                               SELECT  COALESCE(LTRIM(SUBSTR( frt.value, COALESCE(SUBSTRING(frt.ind2 FROM '\\\\d+'),'0')::INT )),'zzzzzzzz')
+                               SELECT  COALESCE(LTRIM(SUBSTR( frt.value, COALESCE(SUBSTRING(frt.ind2 FROM '\\\\d+'),'0')::INT + 1 )),'zzzzzzzz')
                                  FROM  $metabib_full_rec frt
                                  WHERE frt.record = mr.master_record
                                        AND frt.tag = '245'
@@ -2018,7 +2018,7 @@ sub biblio_search_multi_class_fts {
        } elsif (lc($sort) eq 'title') {
                $rank = <<"             RANK";
                        ( FIRST ((
-                               SELECT  COALESCE(LTRIM(SUBSTR( frt.value, COALESCE(SUBSTRING(frt.ind2 FROM '\\\\d+'),'0')::INT )),'zzzzzzzz')
+                               SELECT  COALESCE(LTRIM(SUBSTR( frt.value, COALESCE(SUBSTRING(frt.ind2 FROM '\\\\d+'),'0')::INT + 1 )),'zzzzzzzz')
                                  FROM  $metabib_full_rec frt
                                  WHERE frt.record = b.id
                                        AND frt.tag = '245'
index 130c273..29e60d4 100644 (file)
@@ -307,7 +307,7 @@ sub new_record_holdings {
                }
        )->gather(1);
 
-       my $o_search = { shortname => $ou };
+       my $o_search = { shortname => uc($ou) };
        if (!$ou || $ou eq '-') {
                $o_search = { parent_ou => undef };
        }
@@ -620,6 +620,41 @@ sub retrieve_record_transform {
        return entityize($record_xslt{$transform}{xslt}->transform( $_parser->parse_string( $marc ) )->toString);
 }
 
+sub retrieve_record_objects {
+       my $self = shift;
+       my $client = shift;
+       my $ids = shift;
+
+       $ids = [$ids] unless (ref $ids);
+       $ids = [grep {$_} @$ids];
+
+       return [] unless (@$ids);
+
+       my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
+       return $_storage->request('open-ils.cstore.direct.biblio.record_entry.search.atomic' => { id => [grep {$_} @$ids] })->gather(1);
+}
+__PACKAGE__->register_method(
+       method    => 'retrieve_record_objects',
+       api_name  => 'open-ils.supercat.record.object.retrieve',
+       api_level => 1,
+       argc      => 1,
+       signature =>
+               { desc     => <<"                 DESC",
+Returns the Fieldmapper object representation of the requested bibliographic records
+                 DESC
+                 params   =>
+                       [
+                               { name => 'bibIds',
+                                 desc => 'OpenILS biblio::record_entry ids',
+                                 type => 'array' },
+                       ],
+                 'return' =>
+                       { desc => 'The bib records',
+                         type => 'array' }
+               }
+);
+
+
 
 sub retrieve_metarecord_mods {
        my $self = shift;
index 993783a..494019b 100644 (file)
@@ -25,7 +25,7 @@ use OpenILS::WWW::SuperCat::Feed;
 
 
 # set the bootstrap config when this module is loaded
-my ($bootstrap, $supercat, $actor, $parser, $search);
+my ($bootstrap, $cstore, $supercat, $actor, $parser, $search);
 
 sub import {
        my $self = shift;
@@ -36,6 +36,7 @@ sub import {
 sub child_init {
        OpenSRF::System->bootstrap_client( config_file => $bootstrap );
        $supercat = OpenSRF::AppSession->create('open-ils.supercat');
+       $cstore = OpenSRF::AppSession->create('open-ils.cstore');
        $actor = OpenSRF::AppSession->create('open-ils.actor');
        $search = OpenSRF::AppSession->create('open-ils.search');
        $parser = new XML::LibXML;
@@ -405,8 +406,8 @@ sub bookbag_feed {
        $feed->creator($host);
        $feed->update_ts(gmtime_ISO8601());
 
-       $feed->link(atom => $base . "/atom/$id" => 'application/atom+xml');
-       $feed->link(rss2 => $base . "/rss2/$id");
+       $feed->link(rss => $base . "/rss2/$id" => 'application/rss+xml');
+       $feed->link(alternate => $base . "/atom/$id" => 'application/atom+xml');
        $feed->link(html => $base . "/html/$id" => 'text/html');
        $feed->link(unapi => $unapi);
 
@@ -473,9 +474,9 @@ sub changes_feed {
        $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(rss => $base . "/rss2/$rtype/$axis/$limit/$date" => 'application/rss+xml');
+       $feed->link(alternate => $base . "/atom/$rtype/$axis/$limit/$date" => 'application/atom+xml');
+       $feed->link(html => $base . "/html/$rtype/$axis/$limit/$date" => 'text/html');
        $feed->link(unapi => $unapi);
 
        $feed->link(
@@ -526,10 +527,10 @@ Content-type: application/opensearchdescription+xml; charset=utf-8
   <ShortName>$lib</ShortName>
   <Description>Search the $lib OPAC by $class.</Description>
   <Tags>$lib book library</Tags>
+  <Url type="application/rss+xml"
+       template="$base/1.1/$lib/rss2/$class/{searchTerms}?startPage={startPage?}&amp;startIndex={startIndex?}&amp;count={count?}&amp;language={language?}"/>
   <Url type="application/atom+xml"
        template="$base/1.1/$lib/atom/$class/{searchTerms}?startPage={startPage?}&amp;startIndex={startIndex?}&amp;count={count?}&amp;language={language?}"/>
-  <Url type="application/x-rss+xml"
-       template="$base/1.1/$lib/rss2/$class/{searchTerms}?startPage={startPage?}&amp;startIndex={startIndex?}&amp;count={count?}&amp;language={language?}"/>
   <Url type="application/x-mods3+xml"
        template="$base/1.1/$lib/mods3/$class/{searchTerms}?startPage={startPage?}&amp;startIndex={startIndex?}&amp;count={count?}&amp;language={language?}"/>
   <Url type="application/x-mods+xml"
@@ -612,11 +613,12 @@ sub opensearch_feed {
                $offset -= 1;
        }
 
-       my ($version,$org,$type,$class,$terms,$sort);
-       (undef,$version,$org,$type,$class,$terms,$sort,$lang) = split '/', $path;
+       my ($version,$org,$type,$class,$terms,$sort,$sortdir);
+       (undef,$version,$org,$type,$class,$terms,$sort,$sortdir,$lang) = split '/', $path;
 
        $lang ||= $cgi->param('searchLang');
        $sort ||= $cgi->param('searchSort');
+       $sortdir ||= $cgi->param('searchSortDir');
        $terms ||= $cgi->param('searchTerms');
        $class ||= $cgi->param('searchClass') || '-';
        $type ||= $cgi->param('responseType') || '-';
@@ -652,20 +654,28 @@ sub opensearch_feed {
 
        my $cache_key = '';
        my $searches = {};
-       while ($term_copy =~ /(keyword|title|author|subject|series|site|sort|lang):([^:]+?)$/o) {
-               my $c = $1;
-               my $t = $2;
-               $term_copy =~ s/(keyword|title|author|subject|series|site|sort|lang):([^:]+?)$//o;
+       while ($term_copy =~ s/((?:keyword|title|author|subject|series|site|dir|sort|lang):[^:]+)$//so) {
+               warn $1 . "  <<< ";
+               my ($c,$t) = split ':' => $1;
                if ($c eq 'site') {
-                       ($org = uc($t)) =~ s/\s+//go;
+                       $org = $t;
+                       $org =~ s/^\s*//o;
+                       $org =~ s/\s*$//o;
+                       warn $org . "  >>> ";
                } elsif ($c eq 'sort') {
-                       ($sort = lc($t)) =~ s/^\s*(\w+)/$1/go;
+                       ($sort = lc($t)) =~ s/^\s*(\w+)\s*$/$1/go;
+                       warn $sort . "  >>> ";
+               } elsif ($c eq 'dir') {
+                       ($sortdir = lc($t)) =~ s/^\s*(\w+)\s*$/$1/go;
+                       warn $sortdir . "  >>> ";
                } elsif ($c eq 'lang') {
-                       ($lang = lc($t)) =~ s/^\s*(\w+)/$1/go;
+                       ($lang = lc($t)) =~ s/^\s*(\w+)\s*$/$1/go;
+                       warn $lang . "  >>> ";
                } else {
-                       $$searches{$c} = { term => $t };
+                       $$searches{$c}{term} .= ' '.$t;
                        $cache_key .= $c . $t;
                        $complex_terms = 1;
+                       warn $t . "  >>> ";
                }
        }
 
@@ -683,11 +693,11 @@ sub opensearch_feed {
                )->gather(1);
        } else {
                $org_unit = $actor->request(
-                       'open-ils.actor.org_unit_list.search' => shortname => $org
+                       'open-ils.actor.org_unit_list.search' => shortname => uc($org)
                )->gather(1);
        }
 
-       $cache_key .= $org.$sort.$lang;
+       $cache_key .= $org.$sort.$sortdir.$lang;
 
        my $rs_name = $cgi->cookie('os_session');
        my $cached_res = OpenSRF::Utils::Cache->new->get_cache( "os_session:$rs_name" ) if ($rs_name);
@@ -699,10 +709,11 @@ sub opensearch_feed {
                        'open-ils.search.biblio.multiclass' => {
                                searches        => $searches,
                                org_unit        => $org_unit->[0]->id,
-                               ($sort ? ( 'sort' => $sort, sort_dir => 'asc' ) : ()),
-                               ($lang ? ( 'language' => $lang) : ()),
                                offset          => 0,
                                limit           => 5000,
+                               ($sort ?    ( 'sort'     => $sort    ) : ()),
+                               ($sortdir ? ( 'sort_dir' => $sortdir ) : ( sort_dir => 'asc' )),
+                               ($lang ?    ( 'language' => $lang    ) : ()),
                        }
                )->gather(1);
                try {
@@ -772,14 +783,25 @@ sub opensearch_feed {
                'application/opensearch+xml'
        );
 
-       $feed->link( unapi => $unapi);
+       $feed->link(
+               rss =>
+               $base .  "/$version/$org/rss2/$class?searchTerms=$terms" =>
+               'application/rss+xml'
+       );
+
+       $feed->link(
+               alternate =>
+               $base .  "/$version/$org/atom/$class?searchTerms=$terms" =>
+               'application/atom+xml'
+       );
 
-#      $feed->link(
-#              alternate =>
-#              $root . "../$lang/skin/default/xml/rresult.xml?rt=list&" .
-#                      join('&', map { 'rl=' . $_->[0] } @{$recs->{ids}} ),
-#              'text/html'
-#      );
+       $feed->link(
+               html =>
+               $base .  "/$version/$org/html/$class?searchTerms=$terms" =>
+               'text/html'
+       );
+
+       $feed->link( unapi => $unapi);
 
        $feed->link(
                opac =>
@@ -804,7 +826,7 @@ sub create_record_feed {
        my $records = shift;
        my $unapi = shift;
 
-       my $lib = shift || '';
+       my $lib = shift || '-';
 
        my $cgi = new CGI;
        my $base = $cgi->url;
@@ -819,8 +841,12 @@ sub create_record_feed {
        $type = 'atom' if ($type eq 'html');
        $type = 'marcxml' if ($type eq 'htmlcard' or $type eq 'htmlholdings');
 
-       for my $rec (@$records) {
-               next unless($rec);
+       $records = $supercat->request( "open-ils.supercat.record.object.retrieve", $records )->gather(1);
+
+       for my $record (@$records) {
+               #next unless($record);
+               my $rec = $record->id;
+               #my $record = $supercat->request( "open-ils.supercat.record.object.retrieve", $rec )->gather(1)->[0];
 
                my $item_tag = "tag:$host,$year:biblio-record_entry/$rec/$lib";
 
@@ -839,6 +865,7 @@ sub create_record_feed {
                }
 
                $node->id($item_tag);
+               $node->update_ts(clense_ISO8601($record->edit_date));
                $node->link(alternate => $feed->unapi . "?id=$item_tag&format=htmlholdings" => 'text/html');
                $node->link(opac => $feed->unapi . "?id=$item_tag&format=opac");
                $node->link(unapi => $feed->unapi . "?id=$item_tag");
index 1aa1f88..58370a1 100644 (file)
@@ -119,6 +119,7 @@ sub _create_node {
 
                if (ref($attrs)) {
                        for my $key (keys %$attrs) {
+                               next unless $$attrs{$key};
                                $new->setAttribute( $key => $$attrs{$key} );
                        }
                }
@@ -188,7 +189,8 @@ use base 'OpenILS::WWW::SuperCat::Feed';
 
 sub new {
        my $class = shift;
-       my $self = $class->SUPER::build('<atom:feed xmlns:atom="http://www.w3.org/2005/Atom"/>');
+       my $self = $class->SUPER::build('<feed xmlns:atom="http://www.w3.org/2005/Atom"/>');
+       $self->{doc}->documentElement->setNamespace('http://www.w3.org/2005/Atom', undef);
        $self->{type} = 'application/xml';
        $self->{item_xpath} = '/atom:feed';
        return $self;
@@ -197,20 +199,20 @@ sub new {
 sub title {
        my $self = shift;
        my $text = shift;
-       $self->_create_node('/atom:feed','http://www.w3.org/2005/Atom','atom:title', $text);
+       $self->_create_node('/atom:feed','http://www.w3.org/2005/Atom','title', $text);
 }
 
 sub update_ts {
        my $self = shift;
        my $text = shift;
-       $self->_create_node('/atom:feed','http://www.w3.org/2005/Atom','atom:updated', $text);
+       $self->_create_node($self->{item_xpath},'http://www.w3.org/2005/Atom','updated', $text);
 }
 
 sub creator {
        my $self = shift;
        my $text = shift;
-       $self->_create_node('/atom:feed','http://www.w3.org/2005/Atom','atom:author');
-       $self->_create_node('/atom:feed/atom:author', 'http://www.w3.org/2005/Atom','atom:name', $text);
+       $self->_create_node('/atom:feed','http://www.w3.org/2005/Atom','author');
+       $self->_create_node('/atom:feed/atom:author', 'http://www.w3.org/2005/Atom','name', $text);
 }
 
 sub link {
@@ -225,7 +227,7 @@ sub link {
        $self->_create_node(
                $self->{item_xpath},
                'http://www.w3.org/2005/Atom',
-               'atom:link',
+               'link',
                undef,
                { rel => $type,
                  href => $id,
@@ -239,7 +241,7 @@ sub id {
        my $self = shift;
        my $id = shift;
 
-       $self->_create_node( '/atom:feed', 'http://www.w3.org/2005/Atom', 'atom:id', $id );
+       $self->_create_node( '/atom:feed', 'http://www.w3.org/2005/Atom', 'id', $id );
 }
 
 package OpenILS::WWW::SuperCat::Feed::atom::item;
@@ -279,7 +281,7 @@ sub title {
 sub update_ts {
        my $self = shift;
        my $text = shift;
-       $self->_create_node('/rss/channel',undef,'lastBuildDate', $text);
+       $self->_create_node($self->{item_xpath},undef,'lastBuildDate', $text);
 }
 
 sub creator {
@@ -320,6 +322,13 @@ sub new {
        return $self;
 }
 
+sub update_ts {
+       my $self = shift;
+       my $text = shift;
+       $self->_create_node($self->{item_xpath},undef,'pubDate', $text);
+}
+
+
 
 #----------------------------------------------------------
 
index db8da61..693a842 100644 (file)
@@ -149,7 +149,7 @@ To-do list:
                                </xsl:if>
                                <xsl:for-each select="atom:link[(@rel='alternate' or @rel='self' or @rel='description') and @href]">
                                        <xsl:variable name="linkurl"><xsl:call-template name="resolvelink"><xsl:with-param name="url" select="@href" /></xsl:call-template></xsl:variable>
-                                       <link rel="alternate" href="{$linkurl}" hreflang="{@hreflang}" title="{@title}" type="{@type}"/>
+                                       <link rel="{@rel}" href="{$linkurl}" hreflang="{@hreflang}" title="{@title}" type="{@type}"/>
                                </xsl:for-each>
                        </head>
                        <body>
@@ -160,6 +160,7 @@ To-do list:
 
                                        <xsl:variable name="htmllink" select="(atom:link[@rel='alternate' or not(@rel)]/@href | link | rss1:link)[1]" />
                                        <h1>
+                                               <!--
                                                <xsl:choose>
                                                        <xsl:when test="$htmllink">
                                                                <xsl:variable name="htmlversion"><xsl:if test="$htmllink"><xsl:call-template name="resolvelink"><xsl:with-param name="url" select="$htmllink" /></xsl:call-template></xsl:if></xsl:variable>
@@ -167,6 +168,8 @@ To-do list:
                                                        </xsl:when>
                                                        <xsl:otherwise><xsl:value-of select="$title" /></xsl:otherwise>
                                                </xsl:choose>
+                                               -->
+                                               <xsl:value-of select="$title" />
                                        </h1>
                                        <xsl:variable name="imgurl" select="(atom:logo | image/url | rss1:image/rss1:url | rss9:image/rss9:url)[1]" />
                                        <xsl:variable name="absimgurl"><xsl:if test="$imgurl"><xsl:call-template name="resolvelink"><xsl:with-param name="url" select="$imgurl" /></xsl:call-template></xsl:if></xsl:variable>