From: Bill Erickson Date: Mon, 5 Dec 2011 16:40:06 +0000 (-0500) Subject: acq vandelay : ACQ ML work X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=eafb65ea47a5c25aa8b39970f70f2663c65a6ce9;p=evergreen%2Fequinox.git acq vandelay : ACQ ML work Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm index 99ef10aada..f72f378824 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm @@ -2,7 +2,6 @@ package OpenILS::Application::Acq::BatchManager; use OpenILS::Application::Acq::Financials; use OpenSRF::AppSession; use OpenSRF::EX qw/:try/; -use Digest::MD5 qw(md5_hex); use strict; use warnings; sub new { @@ -11,6 +10,7 @@ sub new { $self->{args} = { lid => 0, li => 0, + vqbr => 0, copies => 0, bibs => 0, progress => 0, @@ -96,6 +96,12 @@ sub add_li { $self->{args}->{progress} += 1; return $self; } +sub add_vqbr { + my $self = shift; + $self->{args}->{vqbr} += 1; + $self->{args}->{progress} += 1; + return $self; +} sub add_copy { my $self = shift; $self->{args}->{copies} += 1; @@ -154,6 +160,8 @@ use OpenILS::Application::Cat::AssetCommon; use MARC::Record; use MARC::Batch; use MARC::File::XML (BinaryEncoding => 'UTF-8'); +use Digest::MD5 qw(md5_hex); +use Data::Dumper; my $U = 'OpenILS::Application::AppUtils'; @@ -312,9 +320,13 @@ sub import_li_bibs_via_vandelay { if ($vandelay->{tmp_queue}) { my $queue = new Fieldmapper::vandelay::bib_queue; - $queue->name(md5_hex($$.rand().time)); # since it's temp, should the DB generate the name? + + # since it's temp, should the DB generate the name? + my $name = md5_hex($$.rand().time); + $logger->info("acq-vl: creating new vandelay queue $name"); + $queue->name($name); + $queue->owner($e->requestor->id); - $queue->queue_type('acq'); $queue->temp(1); $queue = $e->create_vandelay_bib_queue($queue) or return $res; $queue_id = $queue->id; @@ -329,19 +341,23 @@ sub import_li_bibs_via_vandelay { my $li = $e->retrieve_acq_lineitem($li_id) or return $res; - my $rec = new Fieldmapper::vandelay::queued_bib_record; - $rec->marc($li->marc); - $rec->queue($queue_id); - $rec->bib_source($vandelay->{bib_source}); - $rec = $e->create_vandelay_queued_bib_record->new($rec) or return $res; - push(@vqbr_ids, $rec->id); + my $vqbr = Fieldmapper::vandelay::queued_bib_record->new; + $vqbr->marc($li->marc); + $vqbr->queue($queue_id); + $vqbr->bib_source($vandelay->{bib_source}); + $vqbr = $e->create_vandelay_queued_bib_record($vqbr) or return $res; + push(@vqbr_ids, $vqbr->id); + $mgr->add_vqbr; + $mgr->respond; # tell the acq record which vandelay record it's linked to - $li->queued_record($rec->id); + $li->queued_record($vqbr->id); $e->update_acq_lineitem($li) or return $res; push(@lis, $li); } + $logger->info("acq-vl: created vandelay records [@vqbr_ids]"); + # we have to commit the transaction now since # vandelay uses its own transactions. $e->commit; @@ -353,16 +369,29 @@ sub import_li_bibs_via_vandelay { my $ses = OpenSRF::AppSession->create('open-ils.vandelay'); my $req = $ses->request( 'open-ils.vandelay.bib_record.list.import', - \@vqbr_ids, $vandelay); + $e->authtoken, \@vqbr_ids, $vandelay); # pull the responses, noting all that were successfully imported + $mgr->{args}->{vqbr} = 0; my @success_lis; - while (my $resp = $req->recv) { + while (my $resp = $req->recv(timeout => 600) { my $stat = $resp->content; - push(@success_lis, map {$_->queued_rec eq $stat->{imported}} @lis) - if $stat and $stat->{imported}; + if ($stat) { + if($U->event_code($stat)) { + $logger->error("acq-vl: error importing vandelay record " . Dumper($stat)); + } else { + push(@success_lis, map {$_->queued_rec eq $stat->{imported}} @lis) + if $stat->{imported}; + } + } + $mgr->add_vqbr; + $mgr->respond; } + $logger->info("acq-vl: successfully imported lineitems [@success_lis]"); + + $ses->kill_me; + return {queue => $queue_id, li_ids => \@success_lis}; }