Z39 Batch ML : queueing results
authorBill Erickson <berick@esilibrary.com>
Mon, 11 Feb 2013 19:39:42 +0000 (14:39 -0500)
committerBill Erickson <berick@esilibrary.com>
Mon, 11 Feb 2013 19:39:42 +0000 (14:39 -0500)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Z3950.pm

index c508fd5..191e6ce 100644 (file)
@@ -18,6 +18,7 @@ use OpenSRF::Utils::JSON;
 use OpenILS::Application::AppUtils;
 use OpenSRF::Utils::Logger qw/$logger/;
 use OpenILS::Utils::CStoreEditor q/:funcs/;
+use OpenILS::Utils::Normalize qw/clean_marc/;                                  
 
 MARC::Charset->assume_unicode(1);
 MARC::Charset->ignore_errors(1);
@@ -605,6 +606,37 @@ sub create_z39_bucket_queue {
     return $queue;
 }
 
+# sets the 901c value to the Z39 service and 
+# adds the record to the growing vandelay queue
+sub stamp_and_queue_results {
+    my ($e, $queue, $service, $bre_id, $result) = @_;
+    $logger->info("z3950 got bucket response for $bre_id");
+
+    for my $rec (@{$result->{records}}) {
+        $logger->info("z39: got result for $bre_id : $rec");
+
+        # insert z39 service as the 901z
+        my $marc = MARC::Record->new_from_xml(
+            $rec->{marcxml}, 'UTF-8', 'USMARC');
+
+        $marc->insert_fields_ordered(
+            MARC::Field->new('901', '', '', z => $service));
+
+        # put the record into the queue
+        my $qrec = Fieldmapper::vandelay::queued_bib_record->new;
+        $qrec->marc(clean_marc($marc));
+        $qrec->queue($queue->id);
+
+        $e->xact_begin;
+        if ($e->create_vandelay_queued_bib_record($qrec)) {
+            $e->commit;
+        } else {
+            my $evt = $e->die_event;
+            $logger->error("z39: unable to queue record: $evt");
+        }
+    }
+}
+
 sub send_and_queue_bucket_searches {
     my ($conn, $e, $queue, $z_searches) = @_;
 
@@ -628,17 +660,9 @@ sub send_and_queue_bucket_searches {
         # there will be one response per z-source
         for my $resp (@{$req->{response}}) {
             $response->{search_complete}++;
-
-            $logger->info("z3950 got bucket response for $bre_id");
-
             my $result = $resp->content or next;
             my $service = $result->{service};
-
-            for my $rec (@{$result->{records}}) {
-                # TODO stamp zsource 901z; add to queue
-                $response->{queue_count}++;
-                $logger->info("z39: got result for $bre_id : $rec");
-            }
+            stamp_and_queue_results($e, $queue, $service, $bre_id, $result);
         }
 
         $conn->respond($response);