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
52 # --------------------------------------------------------------------------------
55 sub create_bib_queue {
62 my $import_def = shift;
64 my $e = new_editor(authtoken => $auth, xact => 1);
66 return $e->die_event unless $e->checkauth;
67 return $e->die_event unless $e->allowed('CREATE_BIB_IMPORT_QUEUE');
68 $owner ||= $e->requestor->id;
70 return OpenILS::Event->new('BIB_QUEUE_EXISTS')
71 if $e->search_vandelay_bib_queue(
72 {name => $name, owner => $owner, queue_type => $type})->[0];
74 my $queue = new Fieldmapper::vandelay::bib_queue();
75 $queue->name( $name );
76 $queue->owner( $owner );
77 $queue->queue_type( $type ) if ($type);
78 $queue->item_attr_def( $import_def ) if ($import_def);
80 my $new_q = $e->create_vandelay_bib_queue( $queue );
81 return $e->die_event unless ($new_q);
86 __PACKAGE__->register_method(
87 api_name => "open-ils.vandelay.bib_queue.create",
88 method => "create_bib_queue",
94 sub create_auth_queue {
102 my $e = new_editor(authtoken => $auth, xact => 1);
104 return $e->die_event unless $e->checkauth;
105 return $e->die_event unless $e->allowed('CREATE_AUTHORITY_IMPORT_QUEUE');
106 $owner ||= $e->requestor->id;
108 return OpenILS::Event->new('AUTH_QUEUE_EXISTS')
109 if $e->search_vandelay_bib_queue(
110 {name => $name, owner => $owner, queue_type => $type})->[0];
112 my $queue = new Fieldmapper::vandelay::authority_queue();
113 $queue->name( $name );
114 $queue->owner( $owner );
115 $queue->queue_type( $type ) if ($type);
117 my $new_q = $e->create_vandelay_authority_queue( $queue );
118 $e->die_event unless ($new_q);
123 __PACKAGE__->register_method(
124 api_name => "open-ils.vandelay.authority_queue.create",
125 method => "create_auth_queue",
130 sub add_record_to_bib_queue {
137 my $bib_source = shift;
139 my $e = new_editor(authtoken => $auth, xact => 1);
141 $queue = $e->retrieve_vandelay_bib_queue($queue);
143 return $e->die_event unless $e->checkauth;
144 return $e->die_event unless
145 ($e->allowed('CREATE_BIB_IMPORT_QUEUE', undef, $queue) ||
146 $e->allowed('CREATE_BIB_IMPORT_QUEUE'));
148 my $new_rec = _add_bib_rec($e, $marc, $queue->id, $purpose, $bib_source);
150 return $e->die_event unless ($new_rec);
154 __PACKAGE__->register_method(
155 api_name => "open-ils.vandelay.queued_bib_record.create",
156 method => "add_record_to_bib_queue",
166 my $bib_source = shift;
168 my $rec = new Fieldmapper::vandelay::queued_bib_record();
170 $rec->queue( $queue );
171 $rec->purpose( $purpose ) if ($purpose);
172 $rec->bib_source($bib_source);
174 return $e->create_vandelay_queued_bib_record( $rec );
177 sub add_record_to_authority_queue {
185 my $e = new_editor(authtoken => $auth, xact => 1);
187 $queue = $e->retrieve_vandelay_authority_queue($queue);
189 return $e->die_event unless $e->checkauth;
190 return $e->die_event unless
191 ($e->allowed('CREATE_AUTHORITY_IMPORT_QUEUE', undef, $queue) ||
192 $e->allowed('CREATE_AUTHORITY_IMPORT_QUEUE'));
194 my $new_rec = _add_auth_rec($e, $marc, $queue->id, $purpose);
196 return $e->die_event unless ($new_rec);
200 __PACKAGE__->register_method(
201 api_name => "open-ils.vandelay.queued_authority_record.create",
202 method => "add_record_to_authority_queue",
213 my $rec = new Fieldmapper::vandelay::queued_authority_record();
215 $rec->queue( $queue );
216 $rec->purpose( $purpose ) if ($purpose);
218 return $e->create_vandelay_queued_authority_record( $rec );
225 my $fingerprint = shift || '';
226 my $queue_id = shift;
228 my $filename = shift;
229 my $bib_source = shift;
231 my $e = new_editor(authtoken => $auth, xact => 1);
232 return $e->die_event unless $e->checkauth;
235 my $type = $self->{record_type};
238 $queue = $e->retrieve_vandelay_bib_queue($queue_id) or return $e->die_event;
240 $queue = $e->retrieve_vandelay_authority_queue($queue_id) or return $e->die_event;
243 my $evt = check_queue_perms($e, $type, $queue);
246 my $cache = new OpenSRF::Utils::Cache();
249 my $data = $cache->get_cache('vandelay_import_spool_' . $fingerprint);
250 $purpose = $data->{purpose};
251 $filename = $data->{path};
252 $bib_source = $data->{bib_source};
255 unless(-r $filename) {
256 $logger->error("unable to read MARC file $filename");
257 return -1; # make this an event XXX
260 $logger->info("vandelay spooling $fingerprint purpose=$purpose file=$filename");
262 my $marctype = 'USMARC';
265 $marctype = 'XML' if (getc(F) =~ /^\D/o);
268 my $batch = new MARC::Batch ($marctype, $filename);
271 my $response_scale = 10;
274 while (try { $r = $batch->next } otherwise { $r = -1 }) {
276 $logger->warn("Proccessing of record $count in set $filename failed. Skipping this record");
280 $logger->info("processing record $count");
283 (my $xml = $r->as_xml_record()) =~ s/\n//sog;
284 $xml =~ s/^<\?xml.+\?\s*>//go;
285 $xml =~ s/>\s+</></go;
286 $xml =~ s/\p{Cc}//go;
287 $xml = $U->entityize($xml);
288 $xml =~ s/[\x00-\x1f]//go;
291 # Check the leader to ensure we've got something resembling the expected
292 # Allow spaces to give records the benefit of the doubt
293 my $ldr_type = substr($r->leader(), 6, 1);
294 if ($type eq 'bib' && ($record_types{$ldr_type}) eq 'bib') {
295 $qrec = _add_bib_rec( $e, $xml, $queue_id, $purpose, $bib_source ) or return $e->die_event;
296 } elsif ($type eq 'auth' && ($record_types{$ldr_type}) eq 'auth') {
297 $qrec = _add_auth_rec( $e, $xml, $queue_id, $purpose ) or return $e->die_event;
299 # I don't know how to handle this type; rock on
300 $logger->error("In process_spool(), type was $type and leader type was $ldr_type ; not currently supported");
304 if($self->api_name =~ /stream_results/ and $qrec) {
305 $client->respond($qrec->id)
307 $client->respond($count) if (++$count % $response_scale) == 0;
308 $response_scale *= 10 if ($count == ($response_scale * 10));
312 $logger->warn("Encountered a bad record at Vandelay ingest: ".$error);
318 $cache->delete_cache('vandelay_import_spool_' . $fingerprint) if $fingerprint;
322 __PACKAGE__->register_method(
323 api_name => "open-ils.vandelay.bib.process_spool",
324 method => "process_spool",
329 __PACKAGE__->register_method(
330 api_name => "open-ils.vandelay.auth.process_spool",
331 method => "process_spool",
334 record_type => 'auth'
337 __PACKAGE__->register_method(
338 api_name => "open-ils.vandelay.bib.process_spool.stream_results",
339 method => "process_spool",
345 __PACKAGE__->register_method(
346 api_name => "open-ils.vandelay.auth.process_spool.stream_results",
347 method => "process_spool",
351 record_type => 'auth'
354 __PACKAGE__->register_method(
355 api_name => "open-ils.vandelay.bib_queue.records.retrieve",
356 method => 'retrieve_queued_records',
362 __PACKAGE__->register_method(
363 api_name => "open-ils.vandelay.auth_queue.records.retrieve",
364 method => 'retrieve_queued_records',
368 record_type => 'auth'
371 __PACKAGE__->register_method(
372 api_name => "open-ils.vandelay.bib_queue.records.matches.retrieve",
373 method => 'retrieve_queued_records',
377 record_type => 'bib',
379 desc => q/Only retrieve queued bib records that have matches against existing records/
382 __PACKAGE__->register_method(
383 api_name => "open-ils.vandelay.auth_queue.records.matches.retrieve",
384 method => 'retrieve_queued_records',
388 record_type => 'auth',
390 desc => q/Only retrieve queued authority records that have matches against existing records/
395 sub retrieve_queued_records {
396 my($self, $conn, $auth, $queue_id, $options) = @_;
397 my $e = new_editor(authtoken => $auth);
398 return $e->event unless $e->checkauth;
400 my $limit = $$options{limit} || 20;
401 my $offset = $$options{offset} || 0;
403 my $type = $self->{record_type};
406 $queue = $e->retrieve_vandelay_bib_queue($queue_id) or return $e->die_event;
408 $queue = $e->retrieve_vandelay_authority_queue($queue_id) or return $e->die_event;
410 my $evt = check_queue_perms($e, $type, $queue);
413 my $class = ($type eq 'bib') ? 'vqbr' : 'vqar';
414 my $search = ($type eq 'bib') ?
415 'search_vandelay_queued_bib_record' : 'search_vandelay_queued_authority_record';
416 my $retrieve = ($type eq 'bib') ?
417 'retrieve_vandelay_queued_bib_record' : 'retrieve_vandelay_queued_authority_record';
419 my $filter = ($$options{non_imported}) ? {import_time => undef} : {};
422 if($self->api_name =~ /matches/) {
423 # fetch only matched records
424 $record_ids = queued_records_with_matches($e, $type, $queue_id, $limit, $offset, $filter);
426 # fetch all queue records
427 $record_ids = $e->$search([
428 {queue => $queue_id, %$filter},
429 {order_by => {$class => 'id'}, limit => $limit, offset => $offset}
436 for my $rec_id (@$record_ids) {
439 flesh_fields => {$class => ['attributes', 'matches']},
441 my $rec = $e->$retrieve([$rec_id, $params]);
442 $rec->clear_marc if $$options{clear_marc};
443 $conn->respond($rec);
448 sub check_queue_perms {
449 my($e, $type, $queue) = @_;
450 if ($type eq 'bib') {
451 return $e->die_event unless
452 ($e->allowed('CREATE_BIB_IMPORT_QUEUE', undef, $queue) ||
453 $e->allowed('CREATE_BIB_IMPORT_QUEUE'));
455 return $e->die_event unless
456 ($e->allowed('CREATE_AUTHORITY_IMPORT_QUEUE', undef, $queue) ||
457 $e->allowed('CREATE_AUTHORITY_IMPORT_QUEUE'));
463 __PACKAGE__->register_method(
464 api_name => "open-ils.vandelay.bib_record.list.import",
465 method => 'import_record_list',
472 __PACKAGE__->register_method(
473 api_name => "open-ils.vandelay.auth_record.list.import",
474 method => 'import_record_list',
478 record_type => 'auth'
481 sub import_record_list {
482 my($self, $conn, $auth, $rec_ids, $args) = @_;
483 my $e = new_editor(authtoken => $auth);
484 return $e->event unless $e->checkauth;
486 my $err = import_record_list_impl($self, $conn, $rec_ids, $e->requestor, $args);
488 return {complete => 1};
492 __PACKAGE__->register_method(
493 api_name => "open-ils.vandelay.bib_queue.import",
494 method => 'import_queue',
501 __PACKAGE__->register_method(
502 api_name => "open-ils.vandelay.auth_queue.import",
503 method => 'import_queue',
507 record_type => 'auth'
509 __PACKAGE__->register_method(
510 api_name => "open-ils.vandelay.bib_queue.nomatch.import",
511 method => 'import_queue',
516 desc => q/Only import records that have no collisions/
521 __PACKAGE__->register_method(
522 api_name => "open-ils.vandelay.auth_queue.nomatch.import",
523 method => 'import_queue',
528 desc => q/Only import records that have no collisions/
530 record_type => 'auth'
533 my($self, $conn, $auth, $q_id, $options) = @_;
534 my $e = new_editor(authtoken => $auth);
535 return $e->event unless $e->checkauth;
537 my $type = $self->{record_type};
538 my $class = ($type eq 'bib') ? 'vqbr' : 'vqar';
540 my $query = {queue => $q_id, import_time => undef};
542 if($self->api_name =~ /nomatch/) {
543 my $matched_recs = queued_records_with_matches($e, $type, $q_id, undef, undef, {import_time => undef});
544 $query->{id} = {'not in' => $matched_recs} if @$matched_recs;
547 my $search = ($type eq 'bib') ?
548 'search_vandelay_queued_bib_record' : 'search_vandelay_queued_authority_record';
549 my $rec_ids = $e->$search($query, {idlist => 1});
550 my $err = import_record_list_impl($self, $conn, $rec_ids, $e->requestor, $options);
552 return {complete => 1};
555 # returns a list of queued record IDs for a given queue that
556 # have at least one entry in the match table
557 sub queued_records_with_matches {
558 my($e, $type, $q_id, $limit, $offset, $filter) = @_;
560 my $match_class = 'vbm';
561 my $rec_class = 'vqbr';
562 if($type eq 'auth') {
563 $match_class = 'vam';
568 $filter->{queue} = $q_id;
572 select => {$match_class => ['queued_record']},
577 fkey => 'queued_record',
584 if($limit or defined $offset) {
587 $query->{limit} = $limit;
588 $query->{offset} = $offset;
591 my $data = $e->json_query($query);
592 return [ map {$_->{queued_record}} @$data ];
595 sub import_record_list_impl {
596 my($self, $conn, $rec_ids, $requestor, $args) = @_;
598 my $overlay_map = $args->{overlay_map} || {};
599 my $type = $self->{record_type};
600 my $total = @$rec_ids;
604 my $auto_overlay_exact = $$args{auto_overlay_exact};
605 my $auto_overlay_1match = $$args{auto_overlay_1match};
606 my $merge_profile = $$args{merge_profile};
607 my $bib_source = $$args{bib_source};
609 my $overlay_func = 'vandelay.overlay_bib_record';
610 my $auto_overlay_func = 'vandelay.auto_overlay_bib_record';
611 my $retrieve_func = 'retrieve_vandelay_queued_bib_record';
612 my $update_func = 'update_vandelay_queued_bib_record';
613 my $search_func = 'search_vandelay_queued_bib_record';
614 my $retrieve_queue_func = 'retrieve_vandelay_bib_queue';
615 my $update_queue_func = 'update_vandelay_bib_queue';
616 my $rec_class = 'vqbr';
618 if($type eq 'auth') {
619 $overlay_func =~ s/bib/auth/o;
620 $auto_overlay_func = s/bib/auth/o;
621 $retrieve_func =~ s/bib/authority/o;
622 $retrieve_queue_func =~ s/bib/authority/o;
623 $update_queue_func =~ s/bib/authority/o;
624 $update_func =~ s/bib/authority/o;
625 $search_func =~ s/bib/authority/o;
629 my $ingest_ses = OpenSRF::AppSession->connect('open-ils.ingest');
631 for my $rec_id (@$rec_ids) {
633 my $overlay_target = $overlay_map->{$rec_id};
635 my $e = new_editor(xact => 1);
636 $e->requestor($requestor);
638 my $rec = $e->$retrieve_func([
641 flesh_fields => { $rec_class => ['matches']},
646 $conn->respond({total => $total, progress => ++$count, imported => $rec_id, err_event => $e->die_event});
651 if($rec->import_time) {
656 $queues{$rec->queue} = 1;
661 if(defined $overlay_target) {
662 # Caller chose an explicit overlay target
664 my $res = $e->json_query(
675 if($res->{$overlay_func} eq 't') {
676 $logger->info("vl: $type direct overlay succeeded for queued rec " .
677 $rec->id . " and overlay target $overlay_target");
683 if($auto_overlay_1match) {
684 # caller says to overlay if there is exactly 1 match
686 my %match_recs = map { $_->eg_record => 1 } @{$rec->matches};
688 if( scalar(keys %match_recs) == 1) { # all matches point to the same record
690 my $res = $e->json_query(
695 $rec->matches->[0]->eg_record,
701 if($res->{$overlay_func} eq 't') {
702 $logger->info("vl: $type overlay-1match succeeded for queued rec " . $rec->id);
708 if(!$imported and $auto_overlay_exact and scalar(@{$rec->matches}) == 1 ) {
710 # caller says to overlay if there is an /exact/ match
712 my $res = $e->json_query(
722 if($res->{$auto_overlay_func} eq 't') {
723 $logger->info("vl: $type auto-overlay succeeded for queued rec " . $rec->id);
730 # No overlay / merge occured. Do a traditional record import by creating a new record
733 $record = OpenILS::Application::Cat::BibCommon->biblio_record_xml_import($e, $rec->marc); #$rec->bib_source
737 $record = OpenILS::Application::Cat::AuthCommon->import_authority_record($e, $rec->marc); #$source);
738 push @ingest_queue, {
739 req => $ingest_ses->request('open-ils.ingest.full.authority.record', $record->id),
740 rec_id => $record->id
744 if($U->event_code($record)) {
750 $logger->info("vl: successfully importid new $type record");
751 $rec->imported_as($record->id);
752 $rec->import_time('now');
754 $imported = 1 if $e->$update_func($rec);
762 $conn->respond({total => $total, progress => ++$count, imported => $rec_id});
767 $conn->respond({total => $total, progress => ++$count, imported => $rec_id, err_event => $e->die_event});
770 $conn->respond({total => $total, progress => $count, imported => $rec_id}) if (++$count % 10) == 0;
773 # see if we need to mark any queues as complete
774 my $e = new_editor(xact => 1);
775 for my $q_id (keys %queues) {
777 my $remaining = $e->$search_func(
778 [{queue => $q_id, import_time => undef}, {limit =>1}], {idlist => 1});
780 unless(@$remaining) {
781 my $queue = $e->$retrieve_queue_func($q_id);
783 unless($U->is_true($queue->complete)) {
784 $queue->complete('t');
785 $e->$update_queue_func($queue) or return $e->die_event;
795 for my $ingest (@ingest_queue) {
796 try { $ingest->{req}->gather(1); } otherwise {};
797 $conn->respond({total => $total, progress => $count, imported => $ingest->{rec_id}}) if (++$count % 10) == 0;
800 $ingest_ses->disconnect();
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);