]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/extras/import/direct_ingest.pl
revert the too-much-change
[Evergreen.git] / Open-ILS / src / extras / import / direct_ingest.pl
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4
5 use lib '/openils/lib/perl5/';
6
7 use OpenSRF::System;
8 use OpenSRF::EX qw/:try/;
9 use OpenSRF::AppSession;
10 use OpenSRF::Application;
11 use OpenSRF::MultiSession;
12 use OpenSRF::Utils::SettingsClient;
13 use OpenILS::Application::Ingest;
14 use OpenILS::Application::AppUtils;
15 use OpenILS::Utils::Fieldmapper;
16 use Digest::MD5 qw/md5_hex/;
17 use OpenSRF::Utils::JSON;
18 use Data::Dumper;
19 use FileHandle;
20
21 use Time::HiRes qw/time/;
22 use Getopt::Long;
23 use MARC::Batch;
24 use MARC::File::XML;
25 use MARC::Charset;
26
27 MARC::Charset->ignore_errors(1);
28
29 my ($auth, $config, $quiet) =
30         (0, '/openils/conf/opensrf_core.xml');
31
32 GetOptions(
33         'config=s'      => \$config,
34         'authority'     => \$auth,
35         'quiet'         => \$quiet,
36 );
37
38 my @ses;
39
40 open NEWERR,     ">&STDERR";
41
42 select NEWERR; $| = 1;
43 select STDERR; $| = 1;
44 select STDOUT; $| = 1;
45
46 OpenSRF::System->bootstrap_client( config_file => $config );
47 Fieldmapper->import(IDL => OpenSRF::Utils::SettingsClient->new->config_value("IDL"));
48
49 OpenILS::Application::Ingest->use;
50
51 my $meth = 'open-ils.ingest.full.biblio.object.readonly';
52 $meth = 'open-ils.ingest.full.authority.object.readonly' if ($auth);
53
54 $meth = OpenILS::Application::Ingest->method_lookup( $meth );
55
56 my $count = 0;
57 my $starttime = time;
58 while (my $rec = <>) {
59         next unless ($rec);
60
61         my $bib = OpenSRF::Utils::JSON->JSON2perl($rec);
62         my $data;
63
64         try {
65                 ($data) = $meth->run( $bib );
66         } catch Error with {
67                 my $e = shift;
68                 warn "Couldn't process record: $e\n >>> $rec\n";
69         };
70
71         next unless $data;
72
73         postprocess( { bib => $bib, ingest_data => $data } );
74
75         if (!$quiet && !($count % 20)) {
76                 print NEWERR "\r$count\t". $count / (time - $starttime);
77         }
78
79         $count++;
80 }
81
82 sub postprocess {
83         my $data = shift;
84
85         my $bib = $data->{bib};
86         my $full_rec = $data->{ingest_data}->{full_rec};
87
88         my $field_entries = $data->{ingest_data}->{field_entries} unless ($auth);
89         my $fp = $data->{ingest_data}->{fingerprint} unless ($auth);
90         my $rd = $data->{ingest_data}->{descriptor} unless ($auth);
91
92         $bib->fingerprint( $fp->{fingerprint} ) unless ($auth);
93         $bib->quality( $fp->{quality} ) unless ($auth);
94
95         print( OpenSRF::Utils::JSON->perl2JSON($bib)."\n" );
96         unless ($auth) {
97                 print( OpenSRF::Utils::JSON->perl2JSON($rd)."\n" );
98                 print( OpenSRF::Utils::JSON->perl2JSON($_)."\n" ) for (@$field_entries);
99         }
100
101         print( OpenSRF::Utils::JSON->perl2JSON($_)."\n" ) for (@$full_rec);
102 }
103