2 # Copyright (C) 2008 Equinox Software, Inc.
3 # Author: Bill Erickson <erickson@esilibrary.com>
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
17 marc_stream_importer.pl - Import MARC records via bare socket connection.
21 ./marc_stream_importer.pl /openils/conf/opensrf_core.xml \
22 <eg_username> <eg_password> <bib_source> --port <port> --min_servers 2 \
23 --max_servers 20 --log_file /openils/var/log/marc_net_importer.log &
25 Note: this script has to be run in the same directory as oils_header.pl
29 This script is a Net::Server::PreFork instance for shoving records into Evergreen from a remote system.
35 To use this script with OCLC Connexion, configure the client as follows:
37 Under Tools -> Options -> Export (tab)
38 Create -> Choose Connection -> OK -> Leave translation at "None"
39 -> Create -> Create -> choose TCP/IP (internet)
40 -> Enter hostname and Port, leave 'Use Telnet Protocol' checked
41 -> Create/OK your way out of the dialogs
42 Record Characteristics (button) -> Choose 'UTF-8 Unicode' for the Character Set
45 OCLC and Connexion are trademark/service marks of OCLC Online Computer Library Center, Inc.
49 WARNING: This script provides no inherent security layer. Any client that has
50 access to the server+port can inject MARC records into the system.
51 Use the available options (like allow/deny) in the Net::Server config file
52 or via the command line to restrict access as necessary.
56 ./marc_stream_importer.pl /openils/conf/opensrf_core.xml \
57 admin open-ils connexion --port 5555 --min_servers 2 \
58 --max_servers 20 --log_file /openils/var/log/marc_net_importer.log &
62 L<Net::Server::PreFork>, L<marc_stream_importer.conf>
66 Bill Erickson <erickson@esilibrary.com>
67 Joe Atzberger <jatzberger@esilibrary.com>
72 use strict; use warnings;
73 use Net::Server::PreFork;
74 use base qw/Net::Server::PreFork/;
78 use MARC::File::USMARC;
79 use File::Basename qw/fileparse/;
82 use OpenSRF::Utils::Logger qw/$logger/;
83 use OpenILS::Utils::Cronscript;
84 require 'oils_header.pl';
85 use vars qw/$apputils/;
90 my $bib_source = 'connexion';
91 my $osrf_config = '/openils/conf/opensrf_core.xml';
92 my $oils_username = 'admin';
94 # DEFAULTS for Net::Server
95 my $filename = fileparse($0, '.pl');
96 my $conf_file = (-r "$filename.conf") ? "$filename.conf" : undef;
97 # $conf_file is the Net::Server config for THIS script (not EG), if it exists and is readable
99 # $script->session('open-ils.cat') or die "No session created";
101 my $oils_password = shift;
107 WARNING: This script provides no security layer. Any client that has
108 access to the server+port can inject MARC records into the system.
114 # $0 = 'Evergreen MARC Stream Listener';
117 return $apputils->simplereq(
119 'open-ils.cat.biblio.record.xml.import',
124 sub process_batch_data {
125 my $data = shift or $logger->error("process_batch_data called without any data");
129 open $handle, '<', \$data;
130 my $batch = MARC::Batch->new('USMARC', $handle);
139 eval { $rec = $batch->next; };
142 $logger->error("Failed parsing MARC record $index");
148 my $resp = xml_import($authtoken, $rec->as_xml_record, $bib_source);
150 # has the session timed out?
151 if (oils_event_equals($resp, 'NO_SESSION')) {
153 $resp = xml_import($authtoken, $rec->as_xml_record, $bib_source); # try again w/ new token
155 oils_event_die($resp);
160 sub process_request {
162 my $socket = $self->{server}->{client};
166 # Reading <STDIN> blocks until the client is closed. Instead of waiting
167 # for that, give each inbound record $wait_time seconds to fully arrive
168 # and pull the data directly from the socket
170 local $SIG{ALRM} = sub { die "alarm\n" };
173 last unless $socket->sysread($buf, $bufsize);
178 process_batch_data($data);
182 # the authtoken will timeout after the configured inactivity period.
183 # When that happens, get a new one.
185 $authtoken = oils_login($oils_username, $oils_password, 'staff')
186 or die "Unable to login to Evergreen";
190 osrf_connect($osrf_config);