From c852f8a8fc5a757bfd4ce8a713f22d390a49a7f1 Mon Sep 17 00:00:00 2001 From: erickson Date: Thu, 15 May 2008 19:32:08 +0000 Subject: [PATCH] added a ml search aggregator which creates the picklist and lineitems so that giants wads of MARC xml do not have to go to the client and back git-svn-id: svn://svn.open-ils.org/ILS/branches/acq-experiment@9623 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../perlmods/OpenILS/Application/Acq/Picklist.pm | 67 +++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Picklist.pm b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Picklist.pm index 0a5dac7fb2..fa3ec465af 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Picklist.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Picklist.pm @@ -497,7 +497,7 @@ my $PL_ENTRY_JSON_QUERY = { sub retrieve_pl_lineitem { my($self, $conn, $auth, $picklist_id, $options) = @_; my $e = new_editor(authtoken=>$auth); - return $e->die_event unless $e->checkauth; + return $e->event unless $e->checkauth; # collect the retrieval options my $sort_attr = $$options{sort_attr} || 'title'; @@ -540,6 +540,71 @@ sub retrieve_pl_lineitem { request open-ils.cstore open-ils.cstore.json_query.atomic {"select":{"jub":[{"transform":"count", "attregate":1, "column":"id","alias":"count"}]}, "from":"jub","where":{"picklist":1}} =cut +__PACKAGE__->register_method( + method => 'zsearch', + api_name => 'open-ils.acq.picklist.search.z3950', + stream => 1, + signature => { + desc => 'Performs a z3950 federated search and creates a picklist and associated lineitems', + params => [ + {desc => 'Authentication token', type => 'string'}, + {desc => 'Search definition', type => 'object'}, + {desc => 'Picklist name, optional', type => 'string'}, + ] + } +); + +sub zsearch { + my($self, $conn, $auth, $search, $name) = @_; + my $e = new_editor(authtoken=>$auth, xact=>1); + return $e->die_event unless $e->checkauth; + return $e->die_event unless $e->allowed('CREATE_PICKLIST'); + + $search->{limit} ||= 10; + + $name ||= ''; + my $picklist = $e->search_acq_picklist({owner=>$e->requestor->id, name=>$name})->[0]; + if($name eq '' and $picklist) { + delete_picklist($self, $conn, $auth, $picklist->id); + $picklist = undef; + } + + unless($picklist) { + $picklist = Fieldmapper::acq::picklist->new; + $picklist->owner($e->requestor->id); + $picklist->name($name); + $e->create_acq_picklist($picklist) or return $e->die_event; + } + + my $ses = OpenSRF::AppSession->create('open-ils.search'); + my $req = $ses->request('open-ils.search.z3950.search_class', $auth, $search); + + while(my $resp = $req->recv(timeout=>60)) { + + my $result = $resp->content; + use Data::Dumper; + $logger->info("results = ".Dumper($resp)); + my $count = $result->{count}; + my $total = (($count < $search->{limit}) ? $count : $search->{limit})+1; + my $ctr = 0; + $conn->respond({total=>$total, progress=>++$ctr}); + + for my $rec (@{$result->{records}}) { + my $li = Fieldmapper::acq::lineitem->new; + $li->picklist($picklist->id); + $li->source_label($result->{service}); + $li->selector($e->requestor->id); + $li->marc($rec->{marcxml}); + $li->eg_bib_id($rec->{bibid}) if $rec->{bibid}; + $e->create_acq_lineitem($li) or return $e->die_event; + $conn->respond({total=>$total, progress=>++$ctr}); + } + } + + return {complete=>1, picklist_id=>$picklist->id}; +} + + 1; -- 2.11.0