Koha/misc/z3950_responder.pl
Jesse Weaver f089d393dc
Bug 13937: Add a Z39.50 daemon that can inject item status MARC subfields
This creates a new daemon, misc/z3950_responder.pl, which can respond to
Z39.50 requests. By default, it just proxies searches to Zebra.

If desired, however, it can also add a subfield to the item tags on
outgoing records with a textual description of the item's status
(checked out, lost, etc.). This is useful for certain ILL systems. These
strings can be translated using the 'Z3950_STATUS' authorized value.

Test plan:
  1) Start the Z39.50 server using `perl misc/z3950_responder.pl`.
  2) Connect to the server using `yaz-client 127.0.0.1:9999/biblios`.
  3) Run a search, such as `find @attr 1=1016 book`.
  4) Fetch the results both one at a time with `show 1` and in a batch
     using `show 1+5`.
  5) Turn on MARCXML using `format xml` and `elements marcxml`, and
     verify that the records are still correctly fetched.
  6) Enable the item status subfield by restarting the server with the
     option `--add-item-status=k`.
  7) Search for and fetch records, and verify that a $k subfield is
     added to the item tags as appropriate. It should show some
     combination of "Checked Out", "Lost", "Not For Loan", "Damaged",
     "Withdrawn", "In Transit", or "On Hold" as appropriate, or
     "Available".
  8) Add an authorized value named "Z3950_STATUS" with any of the keys
     "AVAILABLE", "CHECKED_OUT", "LOST", "NOT_FOR_LOAN", "DAMAGED",
     "WITHDRAWN", "IN_TRANSIT" or "ON_HOLD", and verify that their
     descriptions are used instead of the default values above.

Signed-off-by: George Williams <george@nekls.org>
Signed-off-by: Stefan Berndtsson <stefan.berndtsson@ub.gu.se>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
2019-10-08 14:39:30 +01:00

153 lines
3.7 KiB
Perl
Executable file

#!/usr/bin/perl
#
# Copyright ByWater Solutions 2015
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 3 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with Koha; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
use Modern::Perl;
use Carp;
use Getopt::Long;
use Pod::Usage;
use C4::Context;
use Koha::Z3950Responder;
=head1 SYNOPSIS
z3950_responder.pl [-h|--help] [--man] [-a <pdufile>] [-v <loglevel>] [-l <logfile>] [-u <user>]
[-c <config>] [-t <minutes>] [-k <kilobytes>] [-d <daemon>] [-p <pidfile>]
[-C certfile] [-zKiDST1] [-m <time-format>] [-w <directory>] [--debug]
[--add-item-status=SUBFIELD] [--prefetch=NUM_RECORDS]
[<listener-addr>... ]
=head1 OPTIONS
=over 8
=item B<--help>
Prints a brief usage message and exits.
=item B<--man>
Displays manual page and exits.
=item B<--debug>
Turns on debug logging to the screen, and turns on single-process mode.
=item B<--add-item-status=SUBFIELD>
If given, adds item status information to the given subfield.
=item B<--add-status-multi-subfield>
With the above, instead of putting multiple item statuses in one subfield, adds a subfield for each
status string.
=item B<--prefetch=NUM_RECORDS>
Number of records to prefetch from Zebra. Defaults to 20.
=back
=head1 CONFIGURATION
The item status strings added by B<--add-item-status> can be configured with the B<Z3950_STATUS>
authorized value, using the following keys:
=over 4
=item AVAILABLE
=item CHECKED_OUT
=item LOST
=item NOT_FOR_LOAN
=item DAMAGED
=item WITHDRAWN
=item IN_TRANSIT
=item ON_HOLD
=back
=cut
my $add_item_status_subfield;
my $add_status_multi_subfield;
my $debug = 0;
my $help;
my $man;
my $prefetch = 20;
my @yaz_options;
sub add_yaz_option {
my ( $opt_name, $opt_value ) = @_;
push @yaz_options, "-$opt_name", "$opt_value";
}
GetOptions(
'-h|help' => \$help,
'--man' => \$man,
'--debug' => \$debug,
'--add-item-status=s' => \$add_item_status_subfield,
'--add-status-multi-subfield' => \$add_status_multi_subfield,
'--prefetch=i' => \$prefetch,
# Pass through YAZ options.
'a=s' => \&add_yaz_option,
'v=s' => \&add_yaz_option,
'l=s' => \&add_yaz_option,
'u=s' => \&add_yaz_option,
'c=s' => \&add_yaz_option,
't=s' => \&add_yaz_option,
'k=s' => \&add_yaz_option,
'd=s' => \&add_yaz_option,
'p=s' => \&add_yaz_option,
'C=s' => \&add_yaz_option,
'm=s' => \&add_yaz_option,
'w=s' => \&add_yaz_option,
'z' => \&add_yaz_option,
'K' => \&add_yaz_option,
'i' => \&add_yaz_option,
'D' => \&add_yaz_option,
'S' => \&add_yaz_option,
'T' => \&add_yaz_option,
'1' => \&add_yaz_option
) || pod2usage(2);
pod2usage(1) if $help;
pod2usage( -verbose => 2 ) if $man;
# Create and start the server.
die "This tool only works with Zebra" if C4::Context->preference('SearchEngine') ne 'Zebra';
my $z = Koha::Z3950Responder->new( {
add_item_status_subfield => $add_item_status_subfield,
add_status_multi_subfield => $add_status_multi_subfield,
debug => $debug,
num_to_prefetch => $prefetch,
yaz_options => [ @yaz_options, @ARGV ],
} );
$z->start();