improving ISBN based unapi stuff
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 24 Jul 2006 14:22:17 +0000 (14:22 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 24 Jul 2006 14:22:17 +0000 (14:22 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@5098 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/SuperCat.pm
Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm

index 9b0cfba..5108505 100644 (file)
@@ -686,6 +686,48 @@ Returns the Fieldmapper object representation of the requested bibliographic rec
 );
 
 
+sub retrieve_isbn_object {
+       my $self = shift;
+       my $client = shift;
+       my $isbn = shift;
+
+       return undef unless ($isbn);
+
+       my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
+       my $recs = $_storage->request(
+                       'open-ils.cstore.direct.metabib.full_rec.search.atomic',
+                       { tag => { like => '02%'}, value => {like => "$isbn\%"}}
+       )->gather(1);
+
+       return undef unless (@$recs);
+
+       return $_storage->request(
+               'open-ils.cstore.direct.biblio.record_entry.search.atomic',
+               { id => $recs->[0]->record }
+       )->gather(1);
+}
+__PACKAGE__->register_method(
+       method    => 'retrieve_isbn_object',
+       api_name  => 'open-ils.supercat.isbn.object.retrieve',
+       api_level => 1,
+       argc      => 1,
+       signature =>
+               { desc     => <<"                 DESC",
+Returns the Fieldmapper object representation of the requested bibliographic record
+                 DESC
+                 params   =>
+                       [
+                               { name => 'isbn',
+                                 desc => 'an ISBN',
+                                 type => 'string' },
+                       ],
+                 'return' =>
+                       { desc => 'The bib record',
+                         type => 'object' }
+               }
+);
+
+
 
 sub retrieve_metarecord_mods {
        my $self = shift;
index fe9ec79..86bb93e 100644 (file)
@@ -312,12 +312,47 @@ sub unapi {
                $command = 'browse' if ($type eq 'call_number');
        }
 
+       if (!$lib) {
+               $lib = $actor->request(
+                       'open-ils.actor.org_unit_list.search' => parent_ou => undef
+               )->gather(1)->[0]->shortname;
+       }
+
+       my $lib_object = $actor->request(
+               'open-ils.actor.org_unit_list.search' => shortname => $lib
+       )->gather(1)->[0];
+       my $lib_id = $lib_object->id;
+
+       my $ou_types = $actor->request( 'open-ils.actor.org_types.retrieve' )->gather(1);
+       my $lib_depth = (grep { $_->id == $lib_object->ou_type } @$ou_types)[0]->depth;
+
        if ($type eq 'call_number' and $command eq 'browse') {
                $lib = uc($lib);
                print "Location: $root/browse/$base_format/call_number/$lib/$id\n\n";
                return 302;
        }
 
+       if ($type eq 'isbn') {
+               my $rec = $supercat->request('open-ils.supercat.isbn.object.retrieve',$id)->gather(1);
+               if (!@$rec) {
+                       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;
+               }
+               $id = $rec->[0]->id;
+               $type = 'record';
+       }
+
        if ( !grep
               { (keys(%$_))[0] eq $base_format }
               @{ $supercat->request("open-ils.supercat.$type.formats")->gather(1) }
@@ -341,9 +376,9 @@ sub unapi {
        }
 
        if ($format eq 'opac') {
-               print "Location: $root/../../en-US/skin/default/xml/rresult.xml?m=$id\n\n"
+               print "Location: $root/../../en-US/skin/default/xml/rresult.xml?m=$id&l=$lib_id&d=$lib_depth\n\n"
                        if ($type eq 'metarecord');
-               print "Location: $root/../../en-US/skin/default/xml/rdetail.xml?r=$id\n\n"
+               print "Location: $root/../../en-US/skin/default/xml/rdetail.xml?r=$id&l=$lib_id&d=$lib_depth\n\n"
                        if ($type eq 'record');
                return 302;
        } elsif (OpenILS::WWW::SuperCat::Feed->exists($base_format)) {