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",
333 __PACKAGE__->register_method(
334 api_name => "open-ils.vandelay.auth.process_spool",
335 method => "process_spool",
339 record_type => 'auth'
342 __PACKAGE__->register_method(
343 api_name => "open-ils.vandelay.bib.process_spool.stream_results",
344 method => "process_spool",
351 __PACKAGE__->register_method(
352 api_name => "open-ils.vandelay.auth.process_spool.stream_results",
353 method => "process_spool",
358 record_type => 'auth'
361 __PACKAGE__->register_method(
362 api_name => "open-ils.vandelay.bib_queue.records.retrieve",
363 method => 'retrieve_queued_records',
369 __PACKAGE__->register_method(
370 api_name => "open-ils.vandelay.auth_queue.records.retrieve",
371 method => 'retrieve_queued_records',
375 record_type => 'auth'
378 __PACKAGE__->register_method(
379 api_name => "open-ils.vandelay.bib_queue.records.matches.retrieve",
380 method => 'retrieve_queued_records',
384 record_type => 'bib',
386 desc => q/Only retrieve queued bib records that have matches against existing records/
389 __PACKAGE__->register_method(
390 api_name => "open-ils.vandelay.auth_queue.records.matches.retrieve",
391 method => 'retrieve_queued_records',
395 record_type => 'auth',
397 desc => q/Only retrieve queued authority records that have matches against existing records/
402 sub retrieve_queued_records {
403 my($self, $conn, $auth, $queue_id, $options) = @_;
404 my $e = new_editor(authtoken => $auth, xact => 1);
405 return $e->die_event unless $e->checkauth;
407 my $limit = $$options{limit} || 20;
408 my $offset = $$options{offset} || 0;
410 my $type = $self->{record_type};
413 $queue = $e->retrieve_vandelay_bib_queue($queue_id) or return $e->die_event;
415 $queue = $e->retrieve_vandelay_authority_queue($queue_id) or return $e->die_event;
417 my $evt = check_queue_perms($e, $type, $queue);
418 return $evt if ($evt);
420 my $class = ($type eq 'bib') ? 'vqbr' : 'vqar';
421 my $search = ($type eq 'bib') ?
422 'search_vandelay_queued_bib_record' : 'search_vandelay_queued_authority_record';
423 my $retrieve = ($type eq 'bib') ?
424 'retrieve_vandelay_queued_bib_record' : 'retrieve_vandelay_queued_authority_record';
426 my $filter = ($$options{non_imported}) ? {import_time => undef} : {};
429 if($self->api_name =~ /matches/) {
430 # fetch only matched records
431 $record_ids = queued_records_with_matches($e, $type, $queue_id, $limit, $offset, $filter);
433 # fetch all queue records
434 $record_ids = $e->$search([
435 {queue => $queue_id, %$filter},
436 {order_by => {$class => 'id'}, limit => $limit, offset => $offset}
443 for my $rec_id (@$record_ids) {
446 flesh_fields => {$class => ['attributes', 'matches']},
448 my $rec = $e->$retrieve([$rec_id, $params]);
449 $rec->clear_marc if $$options{clear_marc};
450 $conn->respond($rec);
456 sub check_queue_perms {
457 my($e, $type, $queue) = @_;
458 if ($type eq 'bib') {
459 return $e->die_event unless
460 ($e->allowed('CREATE_BIB_IMPORT_QUEUE', undef, $queue) ||
461 $e->allowed('CREATE_BIB_IMPORT_QUEUE'));
463 return $e->die_event unless
464 ($e->allowed('CREATE_AUTHORITY_IMPORT_QUEUE', undef, $queue) ||
465 $e->allowed('CREATE_AUTHORITY_IMPORT_QUEUE'));
471 __PACKAGE__->register_method(
472 api_name => "open-ils.vandelay.bib_record.list.import",
473 method => 'import_record_list',
480 __PACKAGE__->register_method(
481 api_name => "open-ils.vandelay.auth_record.list.import",
482 method => 'import_record_list',
486 record_type => 'auth'
489 sub import_record_list {
490 my($self, $conn, $auth, $rec_ids, $args) = @_;
491 my $e = new_editor(authtoken => $auth, xact => 1);
492 return $e->die_event unless $e->checkauth;
494 my $err = import_record_list_impl($self, $conn, $rec_ids, $e->requestor, $args);
497 return {complete => 1};
501 __PACKAGE__->register_method(
502 api_name => "open-ils.vandelay.bib_queue.import",
503 method => 'import_queue',
511 __PACKAGE__->register_method(
512 api_name => "open-ils.vandelay.auth_queue.import",
513 method => 'import_queue',
518 record_type => 'auth'
520 __PACKAGE__->register_method(
521 api_name => "open-ils.vandelay.bib_queue.nomatch.import",
522 method => 'import_queue',
527 desc => q/Only import records that have no collisions/
533 __PACKAGE__->register_method(
534 api_name => "open-ils.vandelay.auth_queue.nomatch.import",
535 method => 'import_queue',
540 desc => q/Only import records that have no collisions/
543 record_type => 'auth'
546 my($self, $conn, $auth, $q_id, $options) = @_;
547 my $e = new_editor(authtoken => $auth, xact => 1);
548 return $e->die_event unless $e->checkauth;
550 my $type = $self->{record_type};
551 my $class = ($type eq 'bib') ? 'vqbr' : 'vqar';
553 my $query = {queue => $q_id, import_time => undef};
555 if($self->api_name =~ /nomatch/) {
556 my $matched_recs = queued_records_with_matches($e, $type, $q_id, undef, undef, {import_time => undef});
557 $query->{id} = {'not in' => $matched_recs} if @$matched_recs;
560 my $search = ($type eq 'bib') ?
561 'search_vandelay_queued_bib_record' : 'search_vandelay_queued_authority_record';
562 my $rec_ids = $e->$search($query, {idlist => 1});
563 my $err = import_record_list_impl($self, $conn, $rec_ids, $e->requestor, $options);
564 try {$e->rollback} otherwise {}; # only using this to make the read authoritative -- don't die from it
566 return {complete => 1};
569 # returns a list of queued record IDs for a given queue that
570 # have at least one entry in the match table
571 sub queued_records_with_matches {
572 my($e, $type, $q_id, $limit, $offset, $filter) = @_;
574 my $match_class = 'vbm';
575 my $rec_class = 'vqbr';
576 if($type eq 'auth') {
577 $match_class = 'vam';
582 $filter->{queue} = $q_id;
586 select => {$match_class => ['queued_record']},
591 fkey => 'queued_record',
598 if($limit or defined $offset) {
601 $query->{limit} = $limit;
602 $query->{offset} = $offset;
605 my $data = $e->json_query($query);
606 return [ map {$_->{queued_record}} @$data ];
609 sub import_record_list_impl {
610 my($self, $conn, $rec_ids, $requestor, $args) = @_;
612 my $overlay_map = $args->{overlay_map} || {};
613 my $type = $self->{record_type};
614 my $total = @$rec_ids;
620 my $auto_overlay_exact = $$args{auto_overlay_exact};
621 my $auto_overlay_1match = $$args{auto_overlay_1match};
622 my $merge_profile = $$args{merge_profile};
623 my $bib_source = $$args{bib_source};
624 my $report_all = $$args{report_all};
626 my $overlay_func = 'vandelay.overlay_bib_record';
627 my $auto_overlay_func = 'vandelay.auto_overlay_bib_record';
628 my $retrieve_func = 'retrieve_vandelay_queued_bib_record';
629 my $update_func = 'update_vandelay_queued_bib_record';
630 my $search_func = 'search_vandelay_queued_bib_record';
631 my $retrieve_queue_func = 'retrieve_vandelay_bib_queue';
632 my $update_queue_func = 'update_vandelay_bib_queue';
633 my $rec_class = 'vqbr';
636 my $editor = new_editor();
637 my $sources = $editor->search_config_bib_source({id => {'!=' => undef}});
639 foreach my $src (@$sources) {
640 $bib_sources{$src->id} = $src->source;
643 if($type eq 'auth') {
644 $overlay_func =~ s/bib/auth/o;
645 $auto_overlay_func = s/bib/auth/o;
646 $retrieve_func =~ s/bib/authority/o;
647 $retrieve_queue_func =~ s/bib/authority/o;
648 $update_queue_func =~ s/bib/authority/o;
649 $update_func =~ s/bib/authority/o;
650 $search_func =~ s/bib/authority/o;
655 for my $rec_id (@$rec_ids) {
657 my $overlay_target = $overlay_map->{$rec_id};
660 my $e = new_editor(xact => 1);
661 $e->requestor($requestor);
663 my $rec = $e->$retrieve_func([
666 flesh_fields => { $rec_class => ['matches']},
671 $conn->respond({total => $total, progress => ++$count, imported => $rec_id, err_event => $e->event});
676 if($rec->import_time) {
681 $queues{$rec->queue} = 1;
686 if(defined $overlay_target) {
687 # Caller chose an explicit overlay target
689 my $res = $e->json_query(
700 if($res and ($res = $res->[0])) {
702 if($res->{$overlay_func} eq 't') {
703 $logger->info("vl: $type direct overlay succeeded for queued rec " .
704 $rec->id . " and overlay target $overlay_target");
710 $logger->error("vl: Error attempting overlay with func=$overlay_func, profile=$merge_profile, record=$rec_id");
715 if($auto_overlay_1match) {
716 # caller says to overlay if there is exactly 1 match
718 my %match_recs = map { $_->eg_record => 1 } @{$rec->matches};
720 if( scalar(keys %match_recs) == 1) { # all matches point to the same record
722 my $res = $e->json_query(
727 $rec->matches->[0]->eg_record,
733 if($res and ($res = $res->[0])) {
735 if($res->{$overlay_func} eq 't') {
736 $logger->info("vl: $type overlay-1match succeeded for queued rec " . $rec->id);
742 $logger->error("vl: Error attempting overlay with func=$overlay_func, profile=$merge_profile, record=$rec_id");
747 if(!$imported and !$error and $auto_overlay_exact and scalar(@{$rec->matches}) == 1 ) {
749 # caller says to overlay if there is an /exact/ match
751 my $res = $e->json_query(
761 if($res and ($res = $res->[0])) {
763 if($res->{$auto_overlay_func} eq 't') {
764 $logger->info("vl: $type auto-overlay succeeded for queued rec " . $rec->id);
770 $logger->error("vl: Error attempting overlay with func=$auto_overlay_func, profile=$merge_profile, record=$rec_id");
774 if(!$imported and !$error) {
776 # No overlay / merge occurred. Do a traditional record import by creating a new record
779 $record = OpenILS::Application::Cat::BibCommon->biblio_record_xml_import($e, $rec->marc, $bib_sources{$rec->bib_source});
782 $record = OpenILS::Application::Cat::AuthCommon->import_authority_record($e, $rec->marc); #$source);
785 if($U->event_code($record)) {
792 $logger->info("vl: successfully imported new $type record");
793 $rec->imported_as($record->id);
794 $rec->import_time('now');
796 $imported = 1 if $e->$update_func($rec);
802 push @success_rec_ids, $rec_id;
805 # Send an update whenever there's an error
806 $conn->respond({total => $total, progress => ++$count, imported => $rec_id, err_event => $e->event});
809 if($report_all or (++$count % $step) == 0) {
810 $conn->respond({total => $total, progress => $count, imported => $rec_id});
811 # report often at first, climb quickly, then hold steady
812 $step *= 2 unless $step == 256;
816 # see if we need to mark any queues as complete
817 for my $q_id (keys %queues) {
819 my $e = new_editor(xact => 1);
820 my $remaining = $e->$search_func(
821 [{queue => $q_id, import_time => undef}, {limit =>1}], {idlist => 1});
823 unless(@$remaining) {
824 my $queue = $e->$retrieve_queue_func($q_id);
826 unless($U->is_true($queue->complete)) {
827 $queue->complete('t');
828 $e->$update_queue_func($queue) or return $e->die_event;
836 import_record_asset_list_impl($conn, \@success_rec_ids, $requestor);
838 $conn->respond({total => $total, progress => $count});
843 __PACKAGE__->register_method(
844 api_name => "open-ils.vandelay.bib_queue.owner.retrieve",
845 method => 'owner_queue_retrieve',
851 __PACKAGE__->register_method(
852 api_name => "open-ils.vandelay.authority_queue.owner.retrieve",
853 method => 'owner_queue_retrieve',
857 record_type => 'auth'
860 sub owner_queue_retrieve {
861 my($self, $conn, $auth, $owner_id, $filters) = @_;
862 my $e = new_editor(authtoken => $auth, xact => 1);
863 return $e->die_event unless $e->checkauth;
864 $owner_id = $e->requestor->id; # XXX add support for viewing other's queues?
867 my $search = {owner => $owner_id};
868 $search->{$_} = $filters->{$_} for keys %$filters;
870 if($self->{record_type} eq 'bib') {
871 $queues = $e->search_vandelay_bib_queue(
872 [$search, {order_by => {vbq => 'lower(name)'}}]);
874 $queues = $e->search_vandelay_authority_queue(
875 [$search, {order_by => {vaq => 'lower(name)'}}]);
877 $conn->respond($_) for @$queues;
882 __PACKAGE__->register_method(
883 api_name => "open-ils.vandelay.bib_queue.delete",
884 method => "delete_queue",
889 __PACKAGE__->register_method(
890 api_name => "open-ils.vandelay.auth_queue.delete",
891 method => "delete_queue",
894 record_type => 'auth'
898 my($self, $conn, $auth, $q_id) = @_;
899 my $e = new_editor(xact => 1, authtoken => $auth);
900 return $e->die_event unless $e->checkauth;
901 if($self->{record_type} eq 'bib') {
902 return $e->die_event unless $e->allowed('CREATE_BIB_IMPORT_QUEUE');
903 my $queue = $e->retrieve_vandelay_bib_queue($q_id)
904 or return $e->die_event;
905 $e->delete_vandelay_bib_queue($queue)
906 or return $e->die_event;
908 return $e->die_event unless $e->allowed('CREATE_AUTHORITY_IMPORT_QUEUE');
909 my $queue = $e->retrieve_vandelay_authority_queue($q_id)
910 or return $e->die_event;
911 $e->delete_vandelay_authority_queue($queue)
912 or return $e->die_event;
919 __PACKAGE__->register_method(
920 api_name => "open-ils.vandelay.queued_bib_record.html",
921 method => 'queued_record_html',
927 __PACKAGE__->register_method(
928 api_name => "open-ils.vandelay.queued_authority_record.html",
929 method => 'queued_record_html',
933 record_type => 'auth'
936 sub queued_record_html {
937 my($self, $conn, $auth, $rec_id) = @_;
938 my $e = new_editor(xact=>1,authtoken => $auth);
939 return $e->die_event unless $e->checkauth;
941 if($self->{record_type} eq 'bib') {
942 $rec = $e->retrieve_vandelay_queued_bib_record($rec_id)
943 or return $e->die_event;
945 $rec = $e->retrieve_vandelay_queued_authority_record($rec_id)
946 or return $e->die_event;
950 return $U->simplereq(
952 'open-ils.search.biblio.record.html', undef, 1, $rec->marc);
956 __PACKAGE__->register_method(
957 api_name => "open-ils.vandelay.bib_queue.summary.retrieve",
958 method => 'retrieve_queue_summary',
964 __PACKAGE__->register_method(
965 api_name => "open-ils.vandelay.auth_queue.summary.retrieve",
966 method => 'retrieve_queue_summary',
970 record_type => 'auth'
973 sub retrieve_queue_summary {
974 my($self, $conn, $auth, $queue_id) = @_;
975 my $e = new_editor(xact=>1, authtoken => $auth);
976 return $e->die_event unless $e->checkauth;
979 my $type = $self->{record_type};
981 $queue = $e->retrieve_vandelay_bib_queue($queue_id)
982 or return $e->die_event;
984 $queue = $e->retrieve_vandelay_authority_queue($queue_id)
985 or return $e->die_event;
988 my $evt = check_queue_perms($e, $type, $queue);
991 my $search = 'search_vandelay_queued_bib_record';
992 $search =~ s/bib/authority/ if $type ne 'bib';
996 total => scalar(@{$e->$search({queue => $queue_id}, {idlist=>1})}),
997 imported => scalar(@{$e->$search({queue => $queue_id, import_time => {'!=' => undef}}, {idlist=>1})}),
1001 # --------------------------------------------------------------------------------
1002 # Given a list of queued record IDs, imports all items attached to those records
1003 # --------------------------------------------------------------------------------
1004 sub import_record_asset_list_impl {
1005 my($conn, $rec_ids, $requestor) = @_;
1007 my $total = @$rec_ids;
1010 my $roe = new_editor(xact=> 1, requestor => $requestor);
1012 for my $rec_id (@$rec_ids) {
1013 my $rec = $roe->retrieve_vandelay_queued_bib_record($rec_id);
1014 next unless $rec and $rec->import_time;
1015 my $item_ids = $roe->search_vandelay_import_item({record => $rec->id}, {idlist=>1});
1017 for my $item_id (@$item_ids) {
1018 my $e = new_editor(requestor => $requestor, xact => 1);
1019 my $item = $e->retrieve_vandelay_import_item($item_id);
1022 # --------------------------------------------------------------------------------
1023 # Find or create the volume
1024 # --------------------------------------------------------------------------------
1026 OpenILS::Application::Cat::AssetCommon->find_or_create_volume(
1027 $e, $item->call_number, $rec->imported_as, $item->owning_lib);
1030 respond_with_status($conn, $total, $try_count, $in_count, $evt);
1034 # --------------------------------------------------------------------------------
1035 # Create the new copy
1036 # --------------------------------------------------------------------------------
1037 my $copy = Fieldmapper::asset::copy->new;
1038 $copy->loan_duration(2);
1039 $copy->fine_level(2);
1040 $copy->barcode($item->barcode);
1041 $copy->location($item->location);
1042 $copy->circ_lib($item->circ_lib || $item->owning_lib);
1043 $copy->status($item->status || OILS_COPY_STATUS_IN_PROCESS);
1044 $copy->circulate($item->circulate);
1045 $copy->deposit($item->deposit);
1046 $copy->deposit_amount($item->deposit_amount);
1047 $copy->ref($item->ref);
1048 $copy->holdable($item->holdable);
1049 $copy->price($item->price);
1050 $copy->circ_as_type($item->circ_as_type);
1051 $copy->alert_message($item->alert_message);
1052 $copy->opac_visible($item->opac_visible);
1053 $copy->circ_modifier($item->circ_modifier);
1055 # --------------------------------------------------------------------------------
1056 # see if a valid circ_modifier was provided
1057 # --------------------------------------------------------------------------------
1058 #if($copy->circ_modifier and not $e->retrieve_config_circ_modifier($item->circ_modifier)) {
1059 if($copy->circ_modifier and not $e->search_config_circ_modifier({code=>$item->circ_modifier})->[0]) {
1060 respond_with_status($conn, $total, $try_count, $in_count, $e->die_event);
1064 if($evt = OpenILS::Application::Cat::AssetCommon->create_copy($e, $vol, $copy)) {
1065 try { $e->rollback } otherwise {}; # sometimes calls die_event, sometimes not
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);
1081 $evt = OpenILS::Application::Cat::AssetCommon->create_copy_note(
1082 $e, $copy, '', $item->priv_note, 1) if $item->priv_note;
1085 respond_with_status($conn, $total, $try_count, $in_count, $evt);
1089 # --------------------------------------------------------------------------------
1090 # Item import succeeded
1091 # --------------------------------------------------------------------------------
1093 respond_with_status($conn, $total, $try_count, ++$in_count, undef, imported_as => $copy->id);
1101 sub respond_with_status {
1102 my($conn, $total, $try_count, $success_count, $err, %args) = @_;
1105 progress => $try_count,
1107 success_count => $success_count, %args }) if $err or ($try_count % 5 == 0);