minor fixups to make unapi fully compliant
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 4 Jul 2006 01:35:26 +0000 (01:35 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 4 Jul 2006 01:35:26 +0000 (01:35 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@4887 dcc99617-32d9-48b4-a31d-7c20da2025e4

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

index 59b439e..8b15085 100644 (file)
@@ -568,13 +568,9 @@ sub retrieve_record_marcxml {
 
        my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
 
-       return
-       entityize(
-               $_storage
-                       ->request( 'open-ils.cstore.direct.biblio.record_entry.retrieve' => $rid )
-                       ->gather(1)
-                       ->marc
-       );
+       my $record = $_storage->request( 'open-ils.cstore.direct.biblio.record_entry.retrieve' => $rid )->gather(1);
+       return entityize( $record->marc ) if ($record);
+       return undef;
 }
 
 __PACKAGE__->register_method(
@@ -608,16 +604,14 @@ sub retrieve_record_transform {
        my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
        $_storage->connect;
 
-       warn "Fetching record entry $rid\n";
-       my $marc = $_storage->request(
+       my $record = $_storage->request(
                'open-ils.cstore.direct.biblio.record_entry.retrieve',
                $rid
-       )->gather(1)->marc;
-       warn "Fetched record entry $rid\n";
+       )->gather(1);
 
-       $_storage->disconnect;
+       return undef unless ($record);
 
-       return entityize($record_xslt{$transform}{xslt}->transform( $_parser->parse_string( $marc ) )->toString);
+       return entityize($record_xslt{$transform}{xslt}->transform( $_parser->parse_string( $record->marc ) )->toString);
 }
 
 sub retrieve_record_objects {
index dd5f822..66a36d1 100644 (file)
@@ -118,7 +118,7 @@ sub unapi {
                                ->gather(1);
 
                        if ($type eq 'record') {
-                               $body = <<"                             FORMATS";
+                               $body .= <<"                            FORMATS";
 <formats id='$uri'>
        <format name='opac' type='text/html'/>
        <format name='html' type='text/html'/>
@@ -127,7 +127,7 @@ sub unapi {
        <format name='htmlholdings-full' type='text/html'/>
                                FORMATS
                        } elsif ($type eq 'metarecord') {
-                               $body = <<"                             FORMATS";
+                               $body .= <<"                            FORMATS";
                                <formats id='$uri'>
                                        <format name='opac' type='text/html'/>
                                FORMATS
@@ -172,7 +172,7 @@ sub unapi {
                        my %hash = map { ( (keys %$_)[0] => (values %$_)[0] ) } @$list;
                        $list = [ map { { $_ => $hash{$_} } } sort keys %hash ];
 
-                       $body = <<"                     FORMATS";
+                       $body .= <<"                    FORMATS";
 <formats>
        <format name='opac' type='text/html'/>
        <format name='html' type='text/html'/>
@@ -208,11 +208,10 @@ sub unapi {
                        $body .= "</formats>\n";
 
                }
-               $apache->custom_response( 300, $body);
-               return 300;
+               print $body;
+               return Apache2::Const::OK;
        }
 
-               
        if ($uri =~ m{^tag:[^:]+:([^\/]+)/(\d+)(?:/(.+))?}o) {
                $id = $2;
                $lib = $3;
@@ -221,6 +220,28 @@ sub unapi {
                $command = 'retrieve';
        }
 
+       if ( !grep
+              { (keys(%$_))[0] eq $base_format }
+              @{ $supercat->request("open-ils.supercat.$type.formats")->gather(1) }
+            and !grep
+              { $_ eq $base_format }
+              qw/opac html htmlholdings/
+       ) {
+               print "Content-type: text/html; charset=utf-8\n\n";
+               $apache->custom_response( 406, <<"              HTML");
+               <html>
+                       <head>
+                               <title>Invalid format [$format] for type [$type]!</title>
+                       </head>
+                       <body>
+                               <br/>
+                               <center>Sorry, format $format is not valid for type $type.</center>
+                       </body>
+               </html>
+               HTML
+               return 406;
+       }
+
        if ($format eq 'opac') {
                print "Location: $root/../../en-US/skin/default/xml/rresult.xml?m=$id\n\n"
                        if ($type eq 'metarecord');
@@ -235,6 +256,22 @@ sub unapi {
                        $flesh_feed
                );
 
+               if (!$feed->count) {
+                       print "Content-type: text/html; charset=utf-8\n\n";
+                       $apache->custom_response( 404, <<"                      HTML");
+                       <html>
+                               <head>
+                                       <title>Type [$type] with id [$id] not found!</title>
+                               </head>
+                               <body>
+                                       <br/>
+                                       <center>Sorry, we couldn't $command a $type with the id of $id in format $format.</center>
+                               </body>
+                       </html>
+                       HTML
+                       return 404;
+               }
+
                $feed->root($root);
                $feed->creator($host);
                $feed->update_ts(gmtime_ISO8601());
@@ -247,9 +284,9 @@ sub unapi {
        }
 
        my $req = $supercat->request("open-ils.supercat.$type.$format.$command",$id);
-       $req->wait_complete;
+       my $data = $req->gather(1);
 
-       if ($req->failed) {
+       if ($req->failed || !$data) {
                print "Content-type: text/html; charset=utf-8\n\n";
                $apache->custom_response( 404, <<"              HTML");
                <html>
@@ -265,8 +302,7 @@ sub unapi {
                return 404;
        }
 
-       print "Content-type: application/xml; charset=utf-8\n\n";
-       print $req->gather(1);
+       print "Content-type: application/xml; charset=utf-8\n\n$data";
 
        return Apache2::Const::OK;
 }
@@ -966,6 +1002,7 @@ sub create_record_feed {
 
        #$records = $supercat->request( "open-ils.supercat.record.object.retrieve", $records )->gather(1);
 
+       my $count = 0;
        for my $record (@$records) {
                next unless($record);
 
index 96381dc..81b5dec 100644 (file)
@@ -34,7 +34,9 @@ sub build {
 
        my $self = { doc => $parser->parse_string($xml), items => [] };
 
-       return bless $self => $class;
+       $self = bless $self => $class;
+       $self->{count} = 0;
+       return $self;
 }
 
 sub type {
@@ -44,6 +46,11 @@ sub type {
        return $self->{type};
 }
 
+sub count {
+       my $self = shift;
+       return $self->{count};
+}
+
 sub search {
        my $self = shift;
        my $search = shift;
@@ -88,6 +95,7 @@ sub unapi {
 
 sub push_item {
        my $self = shift;
+       $self->{count} += scalar(@_);
        push @{ $self->{items} }, @_;
 }