LP#1347774 open-ils.search unapi API
authorBill Erickson <berick@esilibrary.com>
Fri, 1 Aug 2014 21:23:31 +0000 (17:23 -0400)
committerBill Erickson <berick@esilibrary.com>
Fri, 1 Aug 2014 21:23:31 +0000 (17:23 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm

index 15685b0..9c878b0 100644 (file)
@@ -2791,6 +2791,60 @@ sub copies_by_cn_label {
     return [ map { ($U->is_true($_->location->opac_visible) && $U->is_true($_->status->opac_visible)) ? ($_->id) : () } @$copies ];
 }
 
+__PACKAGE__->register_method(
+    method    => "unapi_records",
+    api_name  => "open-ils.search.unapi.bre",
+    stream    => 1,
+    # TODO
+);
+
+__PACKAGE__->register_method(
+    method    => "unapi_records",
+    api_name  => "open-ils.search.unapi.mmr",
+    stream    => 1,
+    # TODO
+);
+
+sub unapi_records {
+    my ($self, $client, $rec_id, $unapi_args) = @_;
+
+    my $rec_ids = ref $rec_id eq 'ARRAY' ? $rec_id : [$rec_id];
+
+    $unapi_args ||= {};
+    $unapi_args->{site} ||= $U->get_org_tree->shortname;
+    $unapi_args->{flesh} ||= '{bre}'; # default to just the record
+    $unapi_args->{flesh_depth} ||= 5;
+    $unapi_args->{flesh_limit} ||= '';
+    $unapi_args->{format} ||= 'marcxml';
+    $unapi_args->{ename} ||= 'record';
+
+    my $unapi_type = 
+        ($self->api_name =~ /bre/) ? 'unapi.bre' : 'unapi.mmr';
+
+    my $e = new_editor;
+    for my $id (@$rec_ids) {
+        $client->respond(
+            $e->json_query({
+                from => [
+                    $unapi_type, 
+                    $id, 
+                    $unapi_args->{format},
+                    $unapi_args->{ename},
+                    $unapi_args->{flesh},
+                    $unapi_args->{site}, 
+                    $unapi_args->{depth}, 
+                    $unapi_args->{flesh_limit},
+                    $unapi_args->{flesh_offset},
+                    $unapi_args->{inc_xmlns},
+                    $unapi_args->{pref_lib}
+                ]
+            })->[0]
+        );
+    }
+
+    return undef;
+}
+
 
 1;
 
index 18489c2..56ac994 100644 (file)
@@ -295,7 +295,7 @@ sub get_records_and_facets {
     my $outer_self = $self;
     $self->timelog("get_records_and_facets(): about to call multisession");
     my $ses = OpenSRF::MultiSession->new(
-        app => 'open-ils.cstore',
+        app => 'open-ils.search',
         cap => 10, # XXX config
         success_handler => sub {
             my($self, $req) = @_;
@@ -396,15 +396,18 @@ sub get_records_and_facets {
             # tag the record with the MR id
             $flesh =~ s/}$/,mmr.unapi}/g if $is_meta;
 
+            my $method = $is_meta ? 
+                'open-ils.search.unapi.mmr' : 
+                'open-ils.search.unapi.bre';
+
             $ses->request(
-                'open-ils.cstore.json_query',
-                 {from => [
-                    $unapi_type, $bid, 'marcxml','record', $flesh,
-                    $unapi_args->{site}, 
-                    $unapi_args->{depth}, 
-                    $slimit,
-                    undef, undef, $unapi_args->{pref_lib}
-                ]}
+                 $method, $bid, {
+                    flesh => $flesh,
+                    site => $unapi_args->{site},
+                    depth => $unapi_args->{depth},
+                    flesh_limit => $slimit,
+                    pref_lib => $unapi_args->{pref_lib}
+                }
             );
         }
     }