[open-ils-commits] r9623 -
branches/acq-experiment/Open-ILS/src/perlmods/OpenILS/Application/Acq
svn at svn.open-ils.org
svn at svn.open-ils.org
Thu May 15 15:32:11 EDT 2008
Author: erickson
Date: 2008-05-15 15:32:08 -0400 (Thu, 15 May 2008)
New Revision: 9623
Modified:
branches/acq-experiment/Open-ILS/src/perlmods/OpenILS/Application/Acq/Picklist.pm
Log:
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
Modified: branches/acq-experiment/Open-ILS/src/perlmods/OpenILS/Application/Acq/Picklist.pm
===================================================================
--- branches/acq-experiment/Open-ILS/src/perlmods/OpenILS/Application/Acq/Picklist.pm 2008-05-15 19:20:15 UTC (rev 9622)
+++ branches/acq-experiment/Open-ILS/src/perlmods/OpenILS/Application/Acq/Picklist.pm 2008-05-15 19:32:08 UTC (rev 9623)
@@ -497,7 +497,7 @@
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 @@
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;
More information about the open-ils-commits
mailing list