1 package OpenILS::Application::Vandelay;
2 use strict; use warnings;
3 use OpenILS::Application;
4 use base qw/OpenILS::Application/;
5 use Unicode::Normalize;
6 use OpenSRF::EX qw/:try/;
7 use OpenSRF::AppSession;
8 use OpenSRF::Utils::SettingsClient;
9 use OpenSRF::Utils::Cache;
10 use OpenILS::Utils::Fieldmapper;
11 use OpenILS::Utils::CStoreEditor qw/:funcs/;
15 use OpenILS::Utils::Fieldmapper;
16 use Time::HiRes qw(time);
17 use OpenSRF::Utils::Logger qw/$logger/;
19 use OpenILS::Const qw/:const/;
20 use OpenILS::Application::AppUtils;
21 use OpenILS::Application::Cat::BibCommon;
22 use OpenILS::Application::Cat::AuthCommon;
23 use OpenILS::Application::Cat::AssetCommon;
24 my $U = 'OpenILS::Application::AppUtils';
26 # A list of LDR/06 values from http://loc.gov/marc
53 # --------------------------------------------------------------------------------
56 sub create_bib_queue {
63 my $import_def = shift;
65 my $e = new_editor(authtoken => $auth, xact => 1);
67 return $e->die_event unless $e->checkauth;
68 return $e->die_event unless $e->allowed('CREATE_BIB_IMPORT_QUEUE');
69 $owner ||= $e->requestor->id;
71 if ($e->search_vandelay_bib_queue( {name => $name, owner => $owner, queue_type => $type})->[0]) {
73 return OpenILS::Event->new('BIB_QUEUE_EXISTS')
76 my $queue = new Fieldmapper::vandelay::bib_queue();
77 $queue->name( $name );
78 $queue->owner( $owner );
79 $queue->queue_type( $type ) if ($type);
80 $queue->item_attr_def( $import_def ) if ($import_def);
82 my $new_q = $e->create_vandelay_bib_queue( $queue );
83 return $e->die_event unless ($new_q);
88 __PACKAGE__->register_method(
89 api_name => "open-ils.vandelay.bib_queue.create",
90 method => "create_bib_queue",
96 sub create_auth_queue {
104 my $e = new_editor(authtoken => $auth, xact => 1);
106 return $e->die_event unless $e->checkauth;
107 return $e->die_event unless $e->allowed('CREATE_AUTHORITY_IMPORT_QUEUE');
108 $owner ||= $e->requestor->id;
110 if ($e->search_vandelay_bib_queue({name => $name, owner => $owner, queue_type => $type})->[0]) {
112 return OpenILS::Event->new('AUTH_QUEUE_EXISTS')
115 my $queue = new Fieldmapper::vandelay::authority_queue();
116 $queue->name( $name );
117 $queue->owner( $owner );
118 $queue->queue_type( $type ) if ($type);
120 my $new_q = $e->create_vandelay_authority_queue( $queue );
121 $e->die_event unless ($new_q);
126 __PACKAGE__->register_method(
127 api_name => "open-ils.vandelay.authority_queue.create",
128 method => "create_auth_queue",
133 sub add_record_to_bib_queue {
140 my $bib_source = shift;
142 my $e = new_editor(authtoken => $auth, xact => 1);
144 $queue = $e->retrieve_vandelay_bib_queue($queue);
146 return $e->die_event unless $e->checkauth;
147 return $e->die_event unless
148 ($e->allowed('CREATE_BIB_IMPORT_QUEUE', undef, $queue) ||
149 $e->allowed('CREATE_BIB_IMPORT_QUEUE'));
151 my $new_rec = _add_bib_rec($e, $marc, $queue->id, $purpose, $bib_source);
153 return $e->die_event unless ($new_rec);
157 __PACKAGE__->register_method(
158 api_name => "open-ils.vandelay.queued_bib_record.create",
159 method => "add_record_to_bib_queue",
169 my $bib_source = shift;
171 my $rec = new Fieldmapper::vandelay::queued_bib_record();
173 $rec->queue( $queue );
174 $rec->purpose( $purpose ) if ($purpose);
175 $rec->bib_source($bib_source);
177 return $e->create_vandelay_queued_bib_record( $rec );
180 sub add_record_to_authority_queue {
188 my $e = new_editor(authtoken => $auth, xact => 1);
190 $queue = $e->retrieve_vandelay_authority_queue($queue);
192 return $e->die_event unless $e->checkauth;
193 return $e->die_event unless
194 ($e->allowed('CREATE_AUTHORITY_IMPORT_QUEUE', undef, $queue) ||
195 $e->allowed('CREATE_AUTHORITY_IMPORT_QUEUE'));
197 my $new_rec = _add_auth_rec($e, $marc, $queue->id, $purpose);
199 return $e->die_event unless ($new_rec);
203 __PACKAGE__->register_method(
204 api_name => "open-ils.vandelay.queued_authority_record.create",
205 method => "add_record_to_authority_queue",
216 my $rec = new Fieldmapper::vandelay::queued_authority_record();
218 $rec->queue( $queue );
219 $rec->purpose( $purpose ) if ($purpose);
221 return $e->create_vandelay_queued_authority_record( $rec );
228 my $fingerprint = shift || '';
229 my $queue_id = shift;
231 my $filename = shift;
232 my $bib_source = shift;
234 my $e = new_editor(authtoken => $auth, xact => 1);
235 return $e->die_event unless $e->checkauth;
238 my $type = $self->{record_type};
241 $queue = $e->retrieve_vandelay_bib_queue($queue_id) or return $e->die_event;
243 $queue = $e->retrieve_vandelay_authority_queue($queue_id) or return $e->die_event;
246 my $evt = check_queue_perms($e, $type, $queue);
247 return $evt if ($evt);
249 my $cache = new OpenSRF::Utils::Cache();
252 my $data = $cache->get_cache('vandelay_import_spool_' . $fingerprint);
253 $purpose = $data->{purpose};
254 $filename = $data->{path};
255 $bib_source = $data->{bib_source};
258 unless(-r $filename) {
259 $logger->error("unable to read MARC file $filename");
260 return -1; # make this an event XXX
263 $logger->info("vandelay spooling $fingerprint purpose=$purpose file=$filename");
265 my $marctype = 'USMARC';
268 $marctype = 'XML' if (getc(F) =~ /^\D/o);
271 my $batch = new MARC::Batch ($marctype, $filename);
274 my $response_scale = 10;
277 while (try { $r = $batch->next } otherwise { $r = -1 }) {
279 $logger->warn("Processing of record $count in set $filename failed. Skipping this record");
283 $logger->info("processing record $count");
286 (my $xml = $r->as_xml_record()) =~ s/\n//sog;
287 $xml =~ s/^<\?xml.+\?\s*>//go;
288 $xml =~ s/>\s+</></go;
289 $xml =~ s/\p{Cc}//go;
290 $xml = $U->entityize($xml);
291 $xml =~ s/[\x00-\x1f]//go;
294 # Check the leader to ensure we've got something resembling the expected
295 # Allow spaces to give records the benefit of the doubt
296 my $ldr_type = substr($r->leader(), 6, 1);
297 if ($type eq 'bib' && ($record_types{$ldr_type}) eq 'bib' || $ldr_type eq ' ') {
298 $qrec = _add_bib_rec( $e, $xml, $queue_id, $purpose, $bib_source ) or return $e->die_event;
299 } elsif ($type eq 'auth' && ($record_types{$ldr_type}) eq 'auth' || $ldr_type eq ' ') {
300 $qrec = _add_auth_rec( $e, $xml, $queue_id, $purpose ) or return $e->die_event;
302 # I don't know how to handle this type; rock on
303 $logger->error("In process_spool(), type was $type and leader type was $ldr_type ; not currently supported");
307 if($self->api_name =~ /stream_results/ and $qrec) {
308 $client->respond($qrec->id)
310 $client->respond($count) if (++$count % $response_scale) == 0;
311 $response_scale *= 10 if ($count == ($response_scale * 10));
315 $logger->warn("Encountered a bad record at Vandelay ingest: ".$error);
321 $cache->delete_cache('vandelay_import_spool_' . $fingerprint) if $fingerprint;
325 __PACKAGE__->register_method(
326 api_name => "open-ils.vandelay.bib.process_spool",
327 method => "process_spool",
332 __PACKAGE__->register_method(
333 api_name => "open-ils.vandelay.auth.process_spool",
334 method => "process_spool",
337 record_type => 'auth'
340 __PACKAGE__->register_method(
341 api_name => "open-ils.vandelay.bib.process_spool.stream_results",
342 method => "process_spool",
348 __PACKAGE__->register_method(
349 api_name => "open-ils.vandelay.auth.process_spool.stream_results",
350 method => "process_spool",
354 record_type => 'auth'
357 __PACKAGE__->register_method(
358 api_name => "open-ils.vandelay.bib_queue.records.retrieve",
359 method => 'retrieve_queued_records',
365 __PACKAGE__->register_method(
366 api_name => "open-ils.vandelay.auth_queue.records.retrieve",
367 method => 'retrieve_queued_records',
371 record_type => 'auth'
374 __PACKAGE__->register_method(
375 api_name => "open-ils.vandelay.bib_queue.records.matches.retrieve",
376 method => 'retrieve_queued_records',
380 record_type => 'bib',
382 desc => q/Only retrieve queued bib records that have matches against existing records/
385 __PACKAGE__->register_method(
386 api_name => "open-ils.vandelay.auth_queue.records.matches.retrieve",
387 method => 'retrieve_queued_records',
391 record_type => 'auth',
393 desc => q/Only retrieve queued authority records that have matches against existing records/
398 sub retrieve_queued_records {
399 my($self, $conn, $auth, $queue_id, $options) = @_;
400 my $e = new_editor(authtoken => $auth, xact => 1);
401 return $e->die_event unless $e->checkauth;
403 my $limit = $$options{limit} || 20;
404 my $offset = $$options{offset} || 0;
406 my $type = $self->{record_type};
409 $queue = $e->retrieve_vandelay_bib_queue($queue_id) or return $e->die_event;
411 $queue = $e->retrieve_vandelay_authority_queue($queue_id) or return $e->die_event;
413 my $evt = check_queue_perms($e, $type, $queue);
414 return $evt if ($evt);
416 my $class = ($type eq 'bib') ? 'vqbr' : 'vqar';
417 my $search = ($type eq 'bib') ?
418 'search_vandelay_queued_bib_record' : 'search_vandelay_queued_authority_record';
419 my $retrieve = ($type eq 'bib') ?
420 'retrieve_vandelay_queued_bib_record' : 'retrieve_vandelay_queued_authority_record';
422 my $filter = ($$options{non_imported}) ? {import_time => undef} : {};
425 if($self->api_name =~ /matches/) {
426 # fetch only matched records
427 $record_ids = queued_records_with_matches($e, $type, $queue_id, $limit, $offset, $filter);
429 # fetch all queue records
430 $record_ids = $e->$search([
431 {queue => $queue_id, %$filter},
432 {order_by => {$class => 'id'}, limit => $limit, offset => $offset}
439 for my $rec_id (@$record_ids) {
442 flesh_fields => {$class => ['attributes', 'matches']},
444 my $rec = $e->$retrieve([$rec_id, $params]);
445 $rec->clear_marc if $$options{clear_marc};
446 $conn->respond($rec);
452 sub check_queue_perms {
453 my($e, $type, $queue) = @_;
454 if ($type eq 'bib') {
455 return $e->die_event unless
456 ($e->allowed('CREATE_BIB_IMPORT_QUEUE', undef, $queue) ||
457 $e->allowed('CREATE_BIB_IMPORT_QUEUE'));
459 return $e->die_event unless
460 ($e->allowed('CREATE_AUTHORITY_IMPORT_QUEUE', undef, $queue) ||
461 $e->allowed('CREATE_AUTHORITY_IMPORT_QUEUE'));
467 __PACKAGE__->register_method(
468 api_name => "open-ils.vandelay.bib_record.list.import",
469 method => 'import_record_list',
476 __PACKAGE__->register_method(
477 api_name => "open-ils.vandelay.auth_record.list.import",
478 method => 'import_record_list',
482 record_type => 'auth'
485 sub import_record_list {
486 my($self, $conn, $auth, $rec_ids, $args) = @_;
487 my $e = new_editor(authtoken => $auth, xact => 1);
488 return $e->die_event unless $e->checkauth;
490 my $err = import_record_list_impl($self, $conn, $rec_ids, $e->requestor, $args);
493 return {complete => 1};
497 __PACKAGE__->register_method(
498 api_name => "open-ils.vandelay.bib_queue.import",
499 method => 'import_queue',
506 __PACKAGE__->register_method(
507 api_name => "open-ils.vandelay.auth_queue.import",
508 method => 'import_queue',
512 record_type => 'auth'
514 __PACKAGE__->register_method(
515 api_name => "open-ils.vandelay.bib_queue.nomatch.import",
516 method => 'import_queue',
521 desc => q/Only import records that have no collisions/
526 __PACKAGE__->register_method(
527 api_name => "open-ils.vandelay.auth_queue.nomatch.import",
528 method => 'import_queue',
533 desc => q/Only import records that have no collisions/
535 record_type => 'auth'
538 my($self, $conn, $auth, $q_id, $options) = @_;
539 my $e = new_editor(authtoken => $auth, xact => 1);
540 return $e->die_event unless $e->checkauth;
542 my $type = $self->{record_type};
543 my $class = ($type eq 'bib') ? 'vqbr' : 'vqar';
545 my $query = {queue => $q_id, import_time => undef};
547 if($self->api_name =~ /nomatch/) {
548 my $matched_recs = queued_records_with_matches($e, $type, $q_id, undef, undef, {import_time => undef});
549 $query->{id} = {'not in' => $matched_recs} if @$matched_recs;
552 my $search = ($type eq 'bib') ?
553 'search_vandelay_queued_bib_record' : 'search_vandelay_queued_authority_record';
554 my $rec_ids = $e->$search($query, {idlist => 1});
555 my $err = import_record_list_impl($self, $conn, $rec_ids, $e->requestor, $options);
556 try {$e->rollback} otherwise {}; # only using this to make the read authoritative -- don't die from it
558 return {complete => 1};
561 # returns a list of queued record IDs for a given queue that
562 # have at least one entry in the match table
563 sub queued_records_with_matches {
564 my($e, $type, $q_id, $limit, $offset, $filter) = @_;
566 my $match_class = 'vbm';
567 my $rec_class = 'vqbr';
568 if($type eq 'auth') {
569 $match_class = 'vam';
574 $filter->{queue} = $q_id;
578 select => {$match_class => ['queued_record']},
583 fkey => 'queued_record',
590 if($limit or defined $offset) {
593 $query->{limit} = $limit;
594 $query->{offset} = $offset;
597 my $data = $e->json_query($query);
598 return [ map {$_->{queued_record}} @$data ];
601 sub import_record_list_impl {
602 my($self, $conn, $rec_ids, $requestor, $args) = @_;
604 my $overlay_map = $args->{overlay_map} || {};
605 my $type = $self->{record_type};
606 my $total = @$rec_ids;
608 my $step = '1' . '0' x ((length($total) * 3) - 2);
610 my $auto_overlay_exact = $$args{auto_overlay_exact};
611 my $auto_overlay_1match = $$args{auto_overlay_1match};
612 my $merge_profile = $$args{merge_profile};
613 my $bib_source = $$args{bib_source};
614 my $report_all = $$args{report_all};
616 my $overlay_func = 'vandelay.overlay_bib_record';
617 my $auto_overlay_func = 'vandelay.auto_overlay_bib_record';
618 my $retrieve_func = 'retrieve_vandelay_queued_bib_record';
619 my $update_func = 'update_vandelay_queued_bib_record';
620 my $search_func = 'search_vandelay_queued_bib_record';
621 my $retrieve_queue_func = 'retrieve_vandelay_bib_queue';
622 my $update_queue_func = 'update_vandelay_bib_queue';
623 my $rec_class = 'vqbr';
626 my $editor = new_editor();
627 my $sources = $editor->search_config_bib_source({id => {'!=' => undef}});
629 foreach my $src (@$sources) {
630 $bib_sources{$src->id} = $src->source;
633 if($type eq 'auth') {
634 $overlay_func =~ s/bib/auth/o;
635 $auto_overlay_func = s/bib/auth/o;
636 $retrieve_func =~ s/bib/authority/o;
637 $retrieve_queue_func =~ s/bib/authority/o;
638 $update_queue_func =~ s/bib/authority/o;
639 $update_func =~ s/bib/authority/o;
640 $search_func =~ s/bib/authority/o;
645 for my $rec_id (@$rec_ids) {
647 my $overlay_target = $overlay_map->{$rec_id};
649 my $e = new_editor(xact => 1);
650 $e->requestor($requestor);
652 my $rec = $e->$retrieve_func([
655 flesh_fields => { $rec_class => ['matches']},
660 $conn->respond({total => $total, progress => ++$count, imported => $rec_id, err_event => $e->event});
665 if($rec->import_time) {
670 $queues{$rec->queue} = 1;
675 if(defined $overlay_target) {
676 # Caller chose an explicit overlay target
678 my $res = $e->json_query(
689 if($res->{$overlay_func} eq 't') {
690 $logger->info("vl: $type direct overlay succeeded for queued rec " .
691 $rec->id . " and overlay target $overlay_target");
697 if($auto_overlay_1match) {
698 # caller says to overlay if there is exactly 1 match
700 my %match_recs = map { $_->eg_record => 1 } @{$rec->matches};
702 if( scalar(keys %match_recs) == 1) { # all matches point to the same record
704 my $res = $e->json_query(
709 $rec->matches->[0]->eg_record,
715 if($res->{$overlay_func} eq 't') {
716 $logger->info("vl: $type overlay-1match succeeded for queued rec " . $rec->id);
722 if(!$imported and $auto_overlay_exact and scalar(@{$rec->matches}) == 1 ) {
724 # caller says to overlay if there is an /exact/ match
726 my $res = $e->json_query(
736 if($res->{$auto_overlay_func} eq 't') {
737 $logger->info("vl: $type auto-overlay succeeded for queued rec " . $rec->id);
744 # No overlay / merge occurred. Do a traditional record import by creating a new record
747 $record = OpenILS::Application::Cat::BibCommon->biblio_record_xml_import($e, $rec->marc, $bib_sources{$rec->bib_source});
750 $record = OpenILS::Application::Cat::AuthCommon->import_authority_record($e, $rec->marc); #$source);
753 if($U->event_code($record)) {
760 $logger->info("vl: successfully imported new $type record");
761 $rec->imported_as($record->id);
762 $rec->import_time('now');
764 $imported = 1 if $e->$update_func($rec);
770 push @success_rec_ids, $rec_id;
773 # Send an update whenever there's an error
774 $conn->respond({total => $total, progress => ++$count, imported => $rec_id, err_event => $e->event});
777 $conn->respond({total => $total, progress => $count, imported => $rec_id}) if (!$report_all and ++$count % $step) == 0;
780 # see if we need to mark any queues as complete
781 for my $q_id (keys %queues) {
783 my $e = new_editor(xact => 1);
784 my $remaining = $e->$search_func(
785 [{queue => $q_id, import_time => undef}, {limit =>1}], {idlist => 1});
787 unless(@$remaining) {
788 my $queue = $e->$retrieve_queue_func($q_id);
790 unless($U->is_true($queue->complete)) {
791 $queue->complete('t');
792 $e->$update_queue_func($queue) or return $e->die_event;
800 import_record_asset_list_impl($conn, \@success_rec_ids, $requestor);
802 $conn->respond({total => $total, progress => $count});
807 __PACKAGE__->register_method(
808 api_name => "open-ils.vandelay.bib_queue.owner.retrieve",
809 method => 'owner_queue_retrieve',
815 __PACKAGE__->register_method(
816 api_name => "open-ils.vandelay.authority_queue.owner.retrieve",
817 method => 'owner_queue_retrieve',
821 record_type => 'auth'
824 sub owner_queue_retrieve {
825 my($self, $conn, $auth, $owner_id, $filters) = @_;
826 my $e = new_editor(authtoken => $auth, xact => 1);
827 return $e->die_event unless $e->checkauth;
828 $owner_id = $e->requestor->id; # XXX add support for viewing other's queues?
831 my $search = {owner => $owner_id};
832 $search->{$_} = $filters->{$_} for keys %$filters;
834 if($self->{record_type} eq 'bib') {
835 $queues = $e->search_vandelay_bib_queue(
836 [$search, {order_by => {vbq => 'lower(name)'}}]);
838 $queues = $e->search_vandelay_authority_queue(
839 [$search, {order_by => {vaq => 'lower(name)'}}]);
841 $conn->respond($_) for @$queues;
846 __PACKAGE__->register_method(
847 api_name => "open-ils.vandelay.bib_queue.delete",
848 method => "delete_queue",
853 __PACKAGE__->register_method(
854 api_name => "open-ils.vandelay.auth_queue.delete",
855 method => "delete_queue",
858 record_type => 'auth'
862 my($self, $conn, $auth, $q_id) = @_;
863 my $e = new_editor(xact => 1, authtoken => $auth);
864 return $e->die_event unless $e->checkauth;
865 if($self->{record_type} eq 'bib') {
866 return $e->die_event unless $e->allowed('CREATE_BIB_IMPORT_QUEUE');
867 my $queue = $e->retrieve_vandelay_bib_queue($q_id)
868 or return $e->die_event;
869 $e->delete_vandelay_bib_queue($queue)
870 or return $e->die_event;
872 return $e->die_event unless $e->allowed('CREATE_AUTHORITY_IMPORT_QUEUE');
873 my $queue = $e->retrieve_vandelay_authority_queue($q_id)
874 or return $e->die_event;
875 $e->delete_vandelay_authority_queue($queue)
876 or return $e->die_event;
883 __PACKAGE__->register_method(
884 api_name => "open-ils.vandelay.queued_bib_record.html",
885 method => 'queued_record_html',
891 __PACKAGE__->register_method(
892 api_name => "open-ils.vandelay.queued_authority_record.html",
893 method => 'queued_record_html',
897 record_type => 'auth'
900 sub queued_record_html {
901 my($self, $conn, $auth, $rec_id) = @_;
902 my $e = new_editor(xact=>1,authtoken => $auth);
903 return $e->die_event unless $e->checkauth;
905 if($self->{record_type} eq 'bib') {
906 $rec = $e->retrieve_vandelay_queued_bib_record($rec_id)
907 or return $e->die_event;
909 $rec = $e->retrieve_vandelay_queued_authority_record($rec_id)
910 or return $e->die_event;
914 return $U->simplereq(
916 'open-ils.search.biblio.record.html', undef, 1, $rec->marc);
920 __PACKAGE__->register_method(
921 api_name => "open-ils.vandelay.bib_queue.summary.retrieve",
922 method => 'retrieve_queue_summary',
928 __PACKAGE__->register_method(
929 api_name => "open-ils.vandelay.auth_queue.summary.retrieve",
930 method => 'retrieve_queue_summary',
934 record_type => 'auth'
937 sub retrieve_queue_summary {
938 my($self, $conn, $auth, $queue_id) = @_;
939 my $e = new_editor(xact=>1, authtoken => $auth);
940 return $e->die_event unless $e->checkauth;
943 my $type = $self->{record_type};
945 $queue = $e->retrieve_vandelay_bib_queue($queue_id)
946 or return $e->die_event;
948 $queue = $e->retrieve_vandelay_authority_queue($queue_id)
949 or return $e->die_event;
952 my $evt = check_queue_perms($e, $type, $queue);
955 my $search = 'search_vandelay_queued_bib_record';
956 $search =~ s/bib/authority/ if $type ne 'bib';
960 total => scalar(@{$e->$search({queue => $queue_id}, {idlist=>1})}),
961 imported => scalar(@{$e->$search({queue => $queue_id, import_time => {'!=' => undef}}, {idlist=>1})}),
966 __PACKAGE__->register_method(
967 api_name => "open-ils.vandelay.bib_record.list.asset.import",
968 method => 'noop_import_items',
974 __PACKAGE__->register_method(
975 api_name => "open-ils.vandelay.bib_record.queue.asset.import",
976 method => 'noop_import_items',
983 sub noop_import_items { return {complete => 1} }
985 #sub import_record_list_assets {
986 # my($self, $conn, $auth, $import_def, $rec_ids) = @_;
987 # my $e = new_editor(xact=>1, authtoken => $auth);
988 # return $e->die_event unless $e->checkauth;
989 # my $err = import_record_asset_list_impl($conn, $import_def, $rec_ids, $e->requestor);
991 # return $err if $err;
992 # return {complete => 1};
995 #sub import_record_queue_assets {
996 # my($self, $conn, $auth, $import_def, $q_id) = @_;
997 # my $e = new_editor(xact=>1, authtoken => $auth);
998 # return $e->die_event unless $e->checkauth;
999 # my $rec_ids = $e->search_vandelay_queued_bib_record(
1000 # {queue => $q_id, import_time => {'!=' => undef}}, {idlist => 1});
1001 # my $err = import_record_asset_list_impl($conn, $import_def, $rec_ids, $e->requestor);
1003 # return $err if $err;
1004 # return {complete => 1};
1007 # --------------------------------------------------------------------------------
1008 # Given a list of queued record IDs, imports all items attached to those records
1009 # --------------------------------------------------------------------------------
1010 sub import_record_asset_list_impl {
1011 my($conn, $rec_ids, $requestor) = @_;
1013 my $total = @$rec_ids;
1016 my $roe = new_editor(xact=> 1, requestor => $requestor);
1018 for my $rec_id (@$rec_ids) {
1019 my $rec = $roe->retrieve_vandelay_queued_bib_record($rec_id);
1020 next unless $rec and $rec->import_time;
1021 my $item_ids = $roe->search_vandelay_import_item({record => $rec->id}, {idlist=>1});
1023 for my $item_id (@$item_ids) {
1024 my $e = new_editor(requestor => $requestor, xact => 1);
1025 my $item = $e->retrieve_vandelay_import_item($item_id);
1028 # --------------------------------------------------------------------------------
1029 # Find or create the volume
1030 # --------------------------------------------------------------------------------
1032 OpenILS::Application::Cat::AssetCommon->find_or_create_volume(
1033 $e, $item->call_number, $rec->imported_as, $item->owning_lib);
1036 respond_with_status($conn, $total, $try_count, $in_count, $evt);
1040 # --------------------------------------------------------------------------------
1041 # Create the new copy
1042 # --------------------------------------------------------------------------------
1043 my $copy = Fieldmapper::asset::copy->new;
1044 $copy->loan_duration(2);
1045 $copy->fine_level(2);
1046 $copy->barcode($item->barcode);
1047 $copy->location($item->location);
1048 $copy->circ_lib($item->circ_lib || $item->owning_lib);
1049 $copy->status($item->status || OILS_COPY_STATUS_IN_PROCESS);
1050 $copy->circulate($item->circulate);
1051 $copy->deposit($item->deposit);
1052 $copy->deposit_amount($item->deposit_amount);
1053 $copy->ref($item->ref);
1054 $copy->holdable($item->holdable);
1055 $copy->price($item->price);
1056 $copy->circ_as_type($item->circ_as_type);
1057 $copy->alert_message($item->alert_message);
1058 $copy->opac_visible($item->opac_visible);
1059 $copy->circ_modifier($item->circ_modifier);
1061 # --------------------------------------------------------------------------------
1062 # see if a valid circ_modifier was provided
1063 # --------------------------------------------------------------------------------
1064 #if($copy->circ_modifier and not $e->retrieve_config_circ_modifier($item->circ_modifier)) {
1065 if($copy->circ_modifier and not $e->search_config_circ_modifier({code=>$item->circ_modifier})->[0]) {
1066 respond_with_status($conn, $total, $try_count, $in_count, $e->die_event);
1070 if($evt = OpenILS::Application::Cat::AssetCommon->create_copy($e, $vol, $copy)) {
1071 try { $e->rollback } otherwise {}; # sometimes calls die_event, sometimes not
1072 respond_with_status($conn, $total, $try_count, $in_count, $evt);
1076 # --------------------------------------------------------------------------------
1078 # --------------------------------------------------------------------------------
1079 $evt = OpenILS::Application::Cat::AssetCommon->create_copy_note(
1080 $e, $copy, '', $item->pub_note, 1) if $item->pub_note;
1083 respond_with_status($conn, $total, $try_count, $in_count, $evt);
1087 $evt = OpenILS::Application::Cat::AssetCommon->create_copy_note(
1088 $e, $copy, '', $item->priv_note, 1) if $item->priv_note;
1091 respond_with_status($conn, $total, $try_count, $in_count, $evt);
1095 # --------------------------------------------------------------------------------
1096 # Item import succeeded
1097 # --------------------------------------------------------------------------------
1099 respond_with_status($conn, $total, $try_count, ++$in_count, undef, imported_as => $copy->id);
1107 sub respond_with_status {
1108 my($conn, $total, $try_count, $success_count, $err, %args) = @_;
1111 progress => $try_count,
1113 success_count => $success_count, %args }) if $err or ($try_count % 5 == 0);