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 return OpenILS::Event->new('BIB_QUEUE_EXISTS')
72 if $e->search_vandelay_bib_queue(
73 {name => $name, owner => $owner, queue_type => $type})->[0];
75 my $queue = new Fieldmapper::vandelay::bib_queue();
76 $queue->name( $name );
77 $queue->owner( $owner );
78 $queue->queue_type( $type ) if ($type);
79 $queue->item_attr_def( $import_def ) if ($import_def);
81 my $new_q = $e->create_vandelay_bib_queue( $queue );
82 return $e->die_event unless ($new_q);
87 __PACKAGE__->register_method(
88 api_name => "open-ils.vandelay.bib_queue.create",
89 method => "create_bib_queue",
95 sub create_auth_queue {
103 my $e = new_editor(authtoken => $auth, xact => 1);
105 return $e->die_event unless $e->checkauth;
106 return $e->die_event unless $e->allowed('CREATE_AUTHORITY_IMPORT_QUEUE');
107 $owner ||= $e->requestor->id;
109 return OpenILS::Event->new('AUTH_QUEUE_EXISTS')
110 if $e->search_vandelay_bib_queue(
111 {name => $name, owner => $owner, queue_type => $type})->[0];
113 my $queue = new Fieldmapper::vandelay::authority_queue();
114 $queue->name( $name );
115 $queue->owner( $owner );
116 $queue->queue_type( $type ) if ($type);
118 my $new_q = $e->create_vandelay_authority_queue( $queue );
119 $e->die_event unless ($new_q);
124 __PACKAGE__->register_method(
125 api_name => "open-ils.vandelay.authority_queue.create",
126 method => "create_auth_queue",
131 sub add_record_to_bib_queue {
138 my $bib_source = shift;
140 my $e = new_editor(authtoken => $auth, xact => 1);
142 $queue = $e->retrieve_vandelay_bib_queue($queue);
144 return $e->die_event unless $e->checkauth;
145 return $e->die_event unless
146 ($e->allowed('CREATE_BIB_IMPORT_QUEUE', undef, $queue) ||
147 $e->allowed('CREATE_BIB_IMPORT_QUEUE'));
149 my $new_rec = _add_bib_rec($e, $marc, $queue->id, $purpose, $bib_source);
151 return $e->die_event unless ($new_rec);
155 __PACKAGE__->register_method(
156 api_name => "open-ils.vandelay.queued_bib_record.create",
157 method => "add_record_to_bib_queue",
167 my $bib_source = shift;
169 my $rec = new Fieldmapper::vandelay::queued_bib_record();
171 $rec->queue( $queue );
172 $rec->purpose( $purpose ) if ($purpose);
173 $rec->bib_source($bib_source);
175 return $e->create_vandelay_queued_bib_record( $rec );
178 sub add_record_to_authority_queue {
186 my $e = new_editor(authtoken => $auth, xact => 1);
188 $queue = $e->retrieve_vandelay_authority_queue($queue);
190 return $e->die_event unless $e->checkauth;
191 return $e->die_event unless
192 ($e->allowed('CREATE_AUTHORITY_IMPORT_QUEUE', undef, $queue) ||
193 $e->allowed('CREATE_AUTHORITY_IMPORT_QUEUE'));
195 my $new_rec = _add_auth_rec($e, $marc, $queue->id, $purpose);
197 return $e->die_event unless ($new_rec);
201 __PACKAGE__->register_method(
202 api_name => "open-ils.vandelay.queued_authority_record.create",
203 method => "add_record_to_authority_queue",
214 my $rec = new Fieldmapper::vandelay::queued_authority_record();
216 $rec->queue( $queue );
217 $rec->purpose( $purpose ) if ($purpose);
219 return $e->create_vandelay_queued_authority_record( $rec );
226 my $fingerprint = shift || '';
227 my $queue_id = shift;
229 my $filename = shift;
230 my $bib_source = shift;
232 my $e = new_editor(authtoken => $auth, xact => 1);
233 return $e->die_event unless $e->checkauth;
236 my $type = $self->{record_type};
239 $queue = $e->retrieve_vandelay_bib_queue($queue_id) or return $e->die_event;
241 $queue = $e->retrieve_vandelay_authority_queue($queue_id) or return $e->die_event;
244 my $evt = check_queue_perms($e, $type, $queue);
247 my $cache = new OpenSRF::Utils::Cache();
250 my $data = $cache->get_cache('vandelay_import_spool_' . $fingerprint);
251 $purpose = $data->{purpose};
252 $filename = $data->{path};
253 $bib_source = $data->{bib_source};
256 unless(-r $filename) {
257 $logger->error("unable to read MARC file $filename");
258 return -1; # make this an event XXX
261 $logger->info("vandelay spooling $fingerprint purpose=$purpose file=$filename");
263 my $marctype = 'USMARC';
266 $marctype = 'XML' if (getc(F) =~ /^\D/o);
269 my $batch = new MARC::Batch ($marctype, $filename);
272 my $response_scale = 10;
275 while (try { $r = $batch->next } otherwise { $r = -1 }) {
277 $logger->warn("Processing of record $count in set $filename failed. Skipping this record");
281 $logger->info("processing record $count");
284 # Avoid an over-eager MARC::File::XML that may try to convert
285 # our record from MARC8 to UTF8 and break because the record
286 # is obviously already UTF8
287 my $ldr = $r->leader();
288 if (($marctype eq 'XML') && (substr($ldr, 9, 1) ne 'a')) {
289 $logger->warn("MARCXML record LDR/09 was not 'a'; record leader may be corrupt");
290 substr($ldr,9,1,'a');
293 (my $xml = $r->as_xml_record()) =~ s/\n//sog;
294 $xml =~ s/^<\?xml.+\?\s*>//go;
295 $xml =~ s/>\s+</></go;
296 $xml =~ s/\p{Cc}//go;
297 $xml = $U->entityize($xml);
298 $xml =~ s/[\x00-\x1f]//go;
301 # Check the leader to ensure we've got something resembling the expected
302 # Allow spaces to give records the benefit of the doubt
303 my $ldr_type = substr($r->leader(), 6, 1);
304 if ($type eq 'bib' && ($record_types{$ldr_type}) eq 'bib' || $ldr_type eq ' ') {
305 $qrec = _add_bib_rec( $e, $xml, $queue_id, $purpose, $bib_source ) or return $e->die_event;
306 } elsif ($type eq 'auth' && ($record_types{$ldr_type}) eq 'auth' || $ldr_type eq ' ') {
307 $qrec = _add_auth_rec( $e, $xml, $queue_id, $purpose ) or return $e->die_event;
309 # I don't know how to handle this type; rock on
310 $logger->error("In process_spool(), type was $type and leader type was $ldr_type ; not currently supported");
314 if($self->api_name =~ /stream_results/ and $qrec) {
315 $client->respond($qrec->id)
317 $client->respond($count) if (++$count % $response_scale) == 0;
318 $response_scale *= 10 if ($count == ($response_scale * 10));
322 $logger->warn("Encountered a bad record at Vandelay ingest: ".$error);
328 $cache->delete_cache('vandelay_import_spool_' . $fingerprint) if $fingerprint;
332 __PACKAGE__->register_method(
333 api_name => "open-ils.vandelay.bib.process_spool",
334 method => "process_spool",
339 __PACKAGE__->register_method(
340 api_name => "open-ils.vandelay.auth.process_spool",
341 method => "process_spool",
344 record_type => 'auth'
347 __PACKAGE__->register_method(
348 api_name => "open-ils.vandelay.bib.process_spool.stream_results",
349 method => "process_spool",
355 __PACKAGE__->register_method(
356 api_name => "open-ils.vandelay.auth.process_spool.stream_results",
357 method => "process_spool",
361 record_type => 'auth'
364 __PACKAGE__->register_method(
365 api_name => "open-ils.vandelay.bib_queue.records.retrieve",
366 method => 'retrieve_queued_records',
372 __PACKAGE__->register_method(
373 api_name => "open-ils.vandelay.auth_queue.records.retrieve",
374 method => 'retrieve_queued_records',
378 record_type => 'auth'
381 __PACKAGE__->register_method(
382 api_name => "open-ils.vandelay.bib_queue.records.matches.retrieve",
383 method => 'retrieve_queued_records',
387 record_type => 'bib',
389 desc => q/Only retrieve queued bib records that have matches against existing records/
392 __PACKAGE__->register_method(
393 api_name => "open-ils.vandelay.auth_queue.records.matches.retrieve",
394 method => 'retrieve_queued_records',
398 record_type => 'auth',
400 desc => q/Only retrieve queued authority records that have matches against existing records/
405 sub retrieve_queued_records {
406 my($self, $conn, $auth, $queue_id, $options) = @_;
407 my $e = new_editor(authtoken => $auth);
408 return $e->event unless $e->checkauth;
410 my $limit = $$options{limit} || 20;
411 my $offset = $$options{offset} || 0;
413 my $type = $self->{record_type};
416 $queue = $e->retrieve_vandelay_bib_queue($queue_id) or return $e->die_event;
418 $queue = $e->retrieve_vandelay_authority_queue($queue_id) or return $e->die_event;
420 my $evt = check_queue_perms($e, $type, $queue);
423 my $class = ($type eq 'bib') ? 'vqbr' : 'vqar';
424 my $search = ($type eq 'bib') ?
425 'search_vandelay_queued_bib_record' : 'search_vandelay_queued_authority_record';
426 my $retrieve = ($type eq 'bib') ?
427 'retrieve_vandelay_queued_bib_record' : 'retrieve_vandelay_queued_authority_record';
429 my $filter = ($$options{non_imported}) ? {import_time => undef} : {};
432 if($self->api_name =~ /matches/) {
433 # fetch only matched records
434 $record_ids = queued_records_with_matches($e, $type, $queue_id, $limit, $offset, $filter);
436 # fetch all queue records
437 $record_ids = $e->$search([
438 {queue => $queue_id, %$filter},
439 {order_by => {$class => 'id'}, limit => $limit, offset => $offset}
446 for my $rec_id (@$record_ids) {
449 flesh_fields => {$class => ['attributes', 'matches']},
451 my $rec = $e->$retrieve([$rec_id, $params]);
452 $rec->clear_marc if $$options{clear_marc};
453 $conn->respond($rec);
458 sub check_queue_perms {
459 my($e, $type, $queue) = @_;
460 if ($type eq 'bib') {
461 return $e->die_event unless
462 ($e->allowed('CREATE_BIB_IMPORT_QUEUE', undef, $queue) ||
463 $e->allowed('CREATE_BIB_IMPORT_QUEUE'));
465 return $e->die_event unless
466 ($e->allowed('CREATE_AUTHORITY_IMPORT_QUEUE', undef, $queue) ||
467 $e->allowed('CREATE_AUTHORITY_IMPORT_QUEUE'));
473 __PACKAGE__->register_method(
474 api_name => "open-ils.vandelay.bib_record.list.import",
475 method => 'import_record_list',
482 __PACKAGE__->register_method(
483 api_name => "open-ils.vandelay.auth_record.list.import",
484 method => 'import_record_list',
488 record_type => 'auth'
491 sub import_record_list {
492 my($self, $conn, $auth, $rec_ids, $args) = @_;
493 my $e = new_editor(authtoken => $auth);
494 return $e->event unless $e->checkauth;
496 my $err = import_record_list_impl($self, $conn, $rec_ids, $e->requestor, $args);
498 return {complete => 1};
502 __PACKAGE__->register_method(
503 api_name => "open-ils.vandelay.bib_queue.import",
504 method => 'import_queue',
511 __PACKAGE__->register_method(
512 api_name => "open-ils.vandelay.auth_queue.import",
513 method => 'import_queue',
517 record_type => 'auth'
519 __PACKAGE__->register_method(
520 api_name => "open-ils.vandelay.bib_queue.nomatch.import",
521 method => 'import_queue',
526 desc => q/Only import records that have no collisions/
531 __PACKAGE__->register_method(
532 api_name => "open-ils.vandelay.auth_queue.nomatch.import",
533 method => 'import_queue',
538 desc => q/Only import records that have no collisions/
540 record_type => 'auth'
543 my($self, $conn, $auth, $q_id, $options) = @_;
544 my $e = new_editor(authtoken => $auth);
545 return $e->event unless $e->checkauth;
547 my $type = $self->{record_type};
548 my $class = ($type eq 'bib') ? 'vqbr' : 'vqar';
550 my $query = {queue => $q_id, import_time => undef};
552 if($self->api_name =~ /nomatch/) {
553 my $matched_recs = queued_records_with_matches($e, $type, $q_id, undef, undef, {import_time => undef});
554 $query->{id} = {'not in' => $matched_recs} if @$matched_recs;
557 my $search = ($type eq 'bib') ?
558 'search_vandelay_queued_bib_record' : 'search_vandelay_queued_authority_record';
559 my $rec_ids = $e->$search($query, {idlist => 1});
560 my $err = import_record_list_impl($self, $conn, $rec_ids, $e->requestor, $options);
562 return {complete => 1};
565 # returns a list of queued record IDs for a given queue that
566 # have at least one entry in the match table
567 sub queued_records_with_matches {
568 my($e, $type, $q_id, $limit, $offset, $filter) = @_;
570 my $match_class = 'vbm';
571 my $rec_class = 'vqbr';
572 if($type eq 'auth') {
573 $match_class = 'vam';
578 $filter->{queue} = $q_id;
582 select => {$match_class => ['queued_record']},
587 fkey => 'queued_record',
594 if($limit or defined $offset) {
597 $query->{limit} = $limit;
598 $query->{offset} = $offset;
601 my $data = $e->json_query($query);
602 return [ map {$_->{queued_record}} @$data ];
605 sub import_record_list_impl {
606 my($self, $conn, $rec_ids, $requestor, $args) = @_;
608 my $overlay_map = $args->{overlay_map} || {};
609 my $type = $self->{record_type};
610 my $total = @$rec_ids;
612 my $step = '1' . '0' x ((length($total) * 3) - 2);
614 my $auto_overlay_exact = $$args{auto_overlay_exact};
615 my $auto_overlay_1match = $$args{auto_overlay_1match};
616 my $merge_profile = $$args{merge_profile};
617 my $bib_source = $$args{bib_source};
619 my $overlay_func = 'vandelay.overlay_bib_record';
620 my $auto_overlay_func = 'vandelay.auto_overlay_bib_record';
621 my $retrieve_func = 'retrieve_vandelay_queued_bib_record';
622 my $update_func = 'update_vandelay_queued_bib_record';
623 my $search_func = 'search_vandelay_queued_bib_record';
624 my $retrieve_queue_func = 'retrieve_vandelay_bib_queue';
625 my $update_queue_func = 'update_vandelay_bib_queue';
626 my $rec_class = 'vqbr';
629 my $editor = new_editor();
630 my $sources = $editor->search_config_bib_source({id => {'!=' => undef}});
631 foreach my $src (@$sources) {
632 $bib_sources{$src->id} = $src->source;
635 if($type eq 'auth') {
636 $overlay_func =~ s/bib/auth/o;
637 $auto_overlay_func = s/bib/auth/o;
638 $retrieve_func =~ s/bib/authority/o;
639 $retrieve_queue_func =~ s/bib/authority/o;
640 $update_queue_func =~ s/bib/authority/o;
641 $update_func =~ s/bib/authority/o;
642 $search_func =~ s/bib/authority/o;
646 for my $rec_id (@$rec_ids) {
648 my $overlay_target = $overlay_map->{$rec_id};
650 my $e = new_editor(xact => 1);
651 $e->requestor($requestor);
653 my $rec = $e->$retrieve_func([
656 flesh_fields => { $rec_class => ['matches']},
661 $conn->respond({total => $total, progress => ++$count, imported => $rec_id, err_event => $e->die_event});
666 if($rec->import_time) {
671 $queues{$rec->queue} = 1;
676 if(defined $overlay_target) {
677 # Caller chose an explicit overlay target
679 my $res = $e->json_query(
690 if($res->{$overlay_func} eq 't') {
691 $logger->info("vl: $type direct overlay succeeded for queued rec " .
692 $rec->id . " and overlay target $overlay_target");
698 if($auto_overlay_1match) {
699 # caller says to overlay if there is exactly 1 match
701 my %match_recs = map { $_->eg_record => 1 } @{$rec->matches};
703 if( scalar(keys %match_recs) == 1) { # all matches point to the same record
705 my $res = $e->json_query(
710 $rec->matches->[0]->eg_record,
716 if($res->{$overlay_func} eq 't') {
717 $logger->info("vl: $type overlay-1match succeeded for queued rec " . $rec->id);
723 if(!$imported and $auto_overlay_exact and scalar(@{$rec->matches}) == 1 ) {
725 # caller says to overlay if there is an /exact/ match
727 my $res = $e->json_query(
737 if($res->{$auto_overlay_func} eq 't') {
738 $logger->info("vl: $type auto-overlay succeeded for queued rec " . $rec->id);
745 # No overlay / merge occurred. Do a traditional record import by creating a new record
748 $record = OpenILS::Application::Cat::BibCommon->biblio_record_xml_import($e, $rec->marc, $bib_sources{$rec->bib_source});
751 $record = OpenILS::Application::Cat::AuthCommon->import_authority_record($e, $rec->marc); #$source);
754 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);
773 # Send an update whenever there's an error
774 $conn->respond({total => $total, progress => ++$count, imported => $rec_id, err_event => $e->die_event});
777 $conn->respond({total => $total, progress => $count, imported => $rec_id}) if (++$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 $conn->respond({total => $total, progress => $count});
805 __PACKAGE__->register_method(
806 api_name => "open-ils.vandelay.bib_queue.owner.retrieve",
807 method => 'owner_queue_retrieve',
813 __PACKAGE__->register_method(
814 api_name => "open-ils.vandelay.authority_queue.owner.retrieve",
815 method => 'owner_queue_retrieve',
819 record_type => 'auth'
822 sub owner_queue_retrieve {
823 my($self, $conn, $auth, $owner_id, $filters) = @_;
824 my $e = new_editor(authtoken => $auth);
825 return $e->die_event unless $e->checkauth;
826 $owner_id = $e->requestor->id; # XXX add support for viewing other's queues?
829 my $search = {owner => $owner_id};
830 $search->{$_} = $filters->{$_} for keys %$filters;
832 if($self->{record_type} eq 'bib') {
833 $queues = $e->search_vandelay_bib_queue(
834 [$search, {order_by => {vbq => 'lower(name)'}}]);
836 $queues = $e->search_vandelay_authority_queue(
837 [$search, {order_by => {vaq => 'lower(name)'}}]);
839 $conn->respond($_) for @$queues;
843 __PACKAGE__->register_method(
844 api_name => "open-ils.vandelay.bib_queue.delete",
845 method => "delete_queue",
850 __PACKAGE__->register_method(
851 api_name => "open-ils.vandelay.auth_queue.delete",
852 method => "delete_queue",
855 record_type => 'auth'
859 my($self, $conn, $auth, $q_id) = @_;
860 my $e = new_editor(xact => 1, authtoken => $auth);
861 return $e->die_event unless $e->checkauth;
862 if($self->{record_type} eq 'bib') {
863 return $e->die_event unless $e->allowed('CREATE_BIB_IMPORT_QUEUE');
864 my $queue = $e->retrieve_vandelay_bib_queue($q_id)
865 or return $e->die_event;
866 $e->delete_vandelay_bib_queue($queue)
867 or return $e->die_event;
869 return $e->die_event unless $e->allowed('CREATE_AUTHORITY_IMPORT_QUEUE');
870 my $queue = $e->retrieve_vandelay_authority_queue($q_id)
871 or return $e->die_event;
872 $e->delete_vandelay_authority_queue($queue)
873 or return $e->die_event;
880 __PACKAGE__->register_method(
881 api_name => "open-ils.vandelay.queued_bib_record.html",
882 method => 'queued_record_html',
888 __PACKAGE__->register_method(
889 api_name => "open-ils.vandelay.queued_authority_record.html",
890 method => 'queued_record_html',
894 record_type => 'auth'
897 sub queued_record_html {
898 my($self, $conn, $auth, $rec_id) = @_;
899 my $e = new_editor(authtoken => $auth);
900 return $e->event unless $e->checkauth;
902 if($self->{record_type} eq 'bib') {
903 $rec = $e->retrieve_vandelay_queued_bib_record($rec_id)
906 $rec = $e->retrieve_vandelay_queued_authority_record($rec_id)
910 return $U->simplereq(
912 'open-ils.search.biblio.record.html', undef, 1, $rec->marc);
916 __PACKAGE__->register_method(
917 api_name => "open-ils.vandelay.bib_queue.summary.retrieve",
918 method => 'retrieve_queue_summary',
924 __PACKAGE__->register_method(
925 api_name => "open-ils.vandelay.auth_queue.summary.retrieve",
926 method => 'retrieve_queue_summary',
930 record_type => 'auth'
933 sub retrieve_queue_summary {
934 my($self, $conn, $auth, $queue_id) = @_;
935 my $e = new_editor(authtoken => $auth);
936 return $e->event unless $e->checkauth;
939 my $type = $self->{record_type};
941 $queue = $e->retrieve_vandelay_bib_queue($queue_id)
944 $queue = $e->retrieve_vandelay_authority_queue($queue_id)
948 my $evt = check_queue_perms($e, $type, $queue);
951 my $search = 'search_vandelay_queued_bib_record';
952 $search =~ s/bib/authority/ if $type ne 'bib';
956 total => scalar(@{$e->$search({queue => $queue_id}, {idlist=>1})}),
957 imported => scalar(@{$e->$search({queue => $queue_id, import_time => {'!=' => undef}}, {idlist=>1})}),
962 __PACKAGE__->register_method(
963 api_name => "open-ils.vandelay.bib_record.list.asset.import",
964 method => 'import_record_list_assets',
970 __PACKAGE__->register_method(
971 api_name => "open-ils.vandelay.bib_record.queue.asset.import",
972 method => 'import_record_queue_assets',
979 sub import_record_list_assets {
980 my($self, $conn, $auth, $import_def, $rec_ids) = @_;
981 my $e = new_editor(authtoken => $auth);
982 return $e->event unless $e->checkauth;
983 my $err = import_record_asset_list_impl($conn, $import_def, $rec_ids, $e->requestor);
985 return {complete => 1};
988 sub import_record_queue_assets {
989 my($self, $conn, $auth, $import_def, $q_id) = @_;
990 my $e = new_editor(authtoken => $auth);
991 return $e->event unless $e->checkauth;
992 my $rec_ids = $e->search_vandelay_queued_bib_record(
993 {queue => $q_id, import_time => {'!=' => undef}}, {idlist => 1});
994 my $err = import_record_asset_list_impl($conn, $import_def, $rec_ids, $e->requestor);
996 return {complete => 1};
999 # --------------------------------------------------------------------------------
1000 # Given a list of queued record IDs, imports all items attached to those records
1001 # --------------------------------------------------------------------------------
1002 sub import_record_asset_list_impl {
1003 my($conn, $import_def, $rec_ids, $requestor) = @_;
1005 my $total = @$rec_ids;
1008 my $roe = new_editor(requestor => $requestor);
1010 for my $rec_id (@$rec_ids) {
1011 my $rec = $roe->retrieve_vandelay_queued_bib_record($rec_id);
1012 next unless $rec and $rec->import_time;
1013 my $item_ids = $roe->search_vandelay_import_item({definition => $import_def, record => $rec->id}, {idlist=>1});
1015 for my $item_id (@$item_ids) {
1016 my $e = new_editor(requestor => $requestor, xact => 1);
1017 my $item = $e->retrieve_vandelay_import_item($item_id);
1020 # --------------------------------------------------------------------------------
1021 # Find or create the volume
1022 # --------------------------------------------------------------------------------
1024 OpenILS::Application::Cat::AssetCommon->find_or_create_volume(
1025 $e, $item->call_number, $rec->imported_as, $item->owning_lib);
1028 respond_with_status($conn, $total, $try_count, $in_count, $evt);
1033 # --------------------------------------------------------------------------------
1034 # Create the new copy
1035 # --------------------------------------------------------------------------------
1036 my $copy = Fieldmapper::asset::copy->new;
1037 $copy->loan_duration(2);
1038 $copy->fine_level(2);
1039 $copy->barcode($item->barcode);
1040 $copy->location($item->location);
1041 $copy->circ_lib($item->circ_lib || $item->owning_lib);
1042 $copy->status($item->status || OILS_COPY_STATUS_IN_PROCESS);
1043 $copy->circulate($item->circulate);
1044 $copy->deposit($item->deposit);
1045 $copy->deposit_amount($item->deposit_amount);
1046 $copy->ref($item->ref);
1047 $copy->holdable($item->holdable);
1048 $copy->price($item->price);
1049 $copy->circ_as_type($item->circ_as_type);
1050 $copy->alert_message($item->alert_message);
1051 $copy->opac_visible($item->opac_visible);
1052 $copy->circ_modifier($item->circ_modifier);
1054 # --------------------------------------------------------------------------------
1055 # see if a valid circ_modifier was provided
1056 # --------------------------------------------------------------------------------
1057 #if($copy->circ_modifier and not $e->retrieve_config_circ_modifier($item->circ_modifier)) {
1058 if($copy->circ_modifier and not $e->search_config_circ_modifier({code=>$item->circ_modifier})->[0]) {
1059 respond_with_status($conn, $total, $try_count, $in_count, $e->die_event);
1064 if($evt = OpenILS::Application::Cat::AssetCommon->create_copy($e, $vol, $copy)) {
1066 respond_with_status($conn, $total, $try_count, $in_count, $evt);
1070 # --------------------------------------------------------------------------------
1072 # --------------------------------------------------------------------------------
1073 $evt = OpenILS::Application::Cat::AssetCommon->create_copy_note(
1074 $e, $copy, '', $item->pub_note, 1) if $item->pub_note;
1077 respond_with_status($conn, $total, $try_count, $in_count, $evt);
1082 $evt = OpenILS::Application::Cat::AssetCommon->create_copy_note(
1083 $e, $copy, '', $item->priv_note, 1) if $item->priv_note;
1086 respond_with_status($conn, $total, $try_count, $in_count, $evt);
1091 # --------------------------------------------------------------------------------
1092 # Item import succeeded
1093 # --------------------------------------------------------------------------------
1095 respond_with_status($conn, $total, $try_count, ++$in_count, undef, imported_as => $copy->id);
1102 sub respond_with_status {
1103 my($conn, $total, $try_count, $success_count, $err, %args) = @_;
1106 progress => $try_count,
1108 success_count => $success_count, %args }) if $err or ($try_count % 5 == 0);