From d7733b743eda032e3d17f45c7ec37c49f800650c Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 5 Dec 2011 15:42:51 -0500 Subject: [PATCH] acq vandelay : acq ML work Signed-off-by: Bill Erickson --- .../perlmods/lib/OpenILS/Application/Acq/Order.pm | 110 ++++++++++----------- 1 file changed, 53 insertions(+), 57 deletions(-) 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 f72f378824..62e0d7929b 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Order.pm @@ -162,6 +162,7 @@ use MARC::Batch; use MARC::File::XML (BinaryEncoding => 'UTF-8'); use Digest::MD5 qw(md5_hex); use Data::Dumper; +$Data::Dumper::Indent = 0; my $U = 'OpenILS::Application::AppUtils'; @@ -295,6 +296,8 @@ sub create_lineitem_list_assets { my($mgr, $li_ids, $vandelay) = @_; return undef if check_import_li_marc_perms($mgr, $li_ids); + $logger->info("acq-vl: procesing recs via Vandelay with args " . Dumper($vandelay)); + my $res = import_li_bibs_via_vandelay($mgr, $li_ids, $vandelay); return undef unless $res; @@ -316,19 +319,30 @@ sub import_li_bibs_via_vandelay { my $e = $mgr->editor; $e->xact_begin; - my $queue_id = $vandelay->{named_queue}; - if ($vandelay->{tmp_queue}) { + my $queue_id = $vandelay->{existing_queue}; + if (my $name = $vandelay->{queue_name}) { + + # first, see if a queue w/ this name already exists + # for this user. If so, use that instead. + + my $queue = $e->search_vandelay_bib_queue( + {name => $name, owner => $e->requestor->id})->[0]; - my $queue = new Fieldmapper::vandelay::bib_queue; + if ($queue) { - # 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); + $logger->info("acq-vl: using existing queue $name"); + + } else { + + $logger->info("acq-vl: creating new vandelay queue $name"); + + $queue = new Fieldmapper::vandelay::bib_queue; + $queue->name($name); + $queue->owner($e->requestor->id); + $queue->match_set($vandelay->{match_set}); + $queue = $e->create_vandelay_bib_queue($queue) or return $res; + } - $queue->owner($e->requestor->id); - $queue->temp(1); - $queue = $e->create_vandelay_bib_queue($queue) or return $res; $queue_id = $queue->id; } @@ -362,8 +376,8 @@ sub import_li_bibs_via_vandelay { # vandelay uses its own transactions. $e->commit; - # Import the bibs via vandelay. Note: Vandely will update - # the acq.lineitem's eg_bib_id on successful import. + # Import the bibs via vandelay. Note: Vandely will + # update acq.lineitem.eg_bib_id on successful import. $vandelay->{report_all} = 1; my $ses = OpenSRF::AppSession->create('open-ils.vandelay'); @@ -372,25 +386,36 @@ sub import_li_bibs_via_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(timeout => 600) { + while (my $resp = $req->recv(timeout => 600)) { my $stat = $resp->content; - 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}; - } + + if(!$stat or $U->event_code($stat)) { # import failure + $logger->error("acq-vl: error importing vandelay record " . Dumper($stat)); + next; } - $mgr->add_vqbr; - $mgr->respond; - } - $logger->info("acq-vl: successfully imported lineitems [@success_lis]"); + # "imported" here refers to the vqbr, not the + # success/failure of the vqbr merge attempt + next unless $stat->{imported}; + + my ($imported) = grep {$_->queued_record eq $stat->{imported}} @lis; + my $vqbr_id = $imported->id; + + if ($stat->{no_import}) { + $logger->info("acq-vl: vandelay record $vqbr_id did not import"); + + } else { # successful import + + push(@success_lis, $vqbr_id); + $mgr->add_bib; + $mgr->respond; + $logger->info("acq-vl: vandelay record $vqbr_id successfully imported"); + } + } $ses->kill_me; + $logger->info("acq-vl: successfully imported lineitems [@success_lis]"); return {queue => $queue_id, li_ids => \@success_lis}; } @@ -1024,15 +1049,7 @@ sub create_lineitem_assets { } ]) or return 0; - # ----------------------------------------------------------------- - # first, create the bib record if necessary - # ----------------------------------------------------------------- - my $new_bib = 0; - unless($li->eg_bib_id) { - create_bib($mgr, $li) or return 0; - $new_bib = 1; - } - + # note: at this point, the bib record this LI links to should already be created # ----------------------------------------------------------------- # The lineitem is going live, promote user request holds to real holds @@ -1071,29 +1088,7 @@ sub create_lineitem_assets { create_copy($mgr, $volume, $lid, $li) or return 0; } - return { li => $li, new_bib => $new_bib }; -} - -sub create_bib { - my($mgr, $li) = @_; - - my $record = OpenILS::Application::Cat::BibCommon->biblio_record_xml_import( - $mgr->editor, - $li->marc, - undef, # bib source - undef, - 1, # override tcn collisions - ); - - if($U->event_code($record)) { - $mgr->editor->event($record); - $mgr->editor->rollback; - return 0; - } - - $li->eg_bib_id($record->id); - $mgr->add_bib; - return update_lineitem($mgr, $li); + return { li => $li }; } sub create_volume { @@ -1245,6 +1240,7 @@ __PACKAGE__->register_method( method => 'upload_records', api_name => 'open-ils.acq.process_upload_records', stream => 1, + max_chunk_count => 1 ); sub upload_records { -- 2.11.0