From f079d65d928288ad0d193391391bfca69cdcaff0 Mon Sep 17 00:00:00 2001 From: dbs Date: Mon, 12 Jul 2010 20:51:59 +0000 Subject: [PATCH] Prevent MARC batch import from blindly trusting the user by checking LDR/06 With this commit, Vandelay will now check the leader of the incoming MARC record to ensure that its MARC type matches the indicated import record type. This is useful, for example, if you have a mixed set of bib & holdings records that you want to import; you don't want to import the holdings records as bib records. This is a fairly strict implementation; we could relax this by turning the check on its head and allowing the import as the user-indicated type as long as the LDR/06 doesn't explicitly match another record type. git-svn-id: svn://svn.open-ils.org/ILS/trunk@16914 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../src/perlmods/OpenILS/Application/Vandelay.pm | 40 +++++++++++++++++++--- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Vandelay.pm b/Open-ILS/src/perlmods/OpenILS/Application/Vandelay.pm index fc2b2a5a99..f33b533b0e 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Vandelay.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Vandelay.pm @@ -23,6 +23,29 @@ use OpenILS::Application::Cat::AuthCommon; use OpenILS::Application::Cat::AssetCommon; my $U = 'OpenILS::Application::AppUtils'; +# A list of LDR/06 values from http://loc.gov/marc +my %record_types = ( + a => 'bib', + c => 'bib', + d => 'bib', + e => 'bib', + f => 'bib', + g => 'bib', + i => 'bib', + j => 'bib', + k => 'bib', + m => 'bib', + o => 'bib', + p => 'bib', + r => 'bib', + t => 'bib', + u => 'holdings', + v => 'holdings', + x => 'holdings', + y => 'holdings', + z => 'auth', +); + sub initialize {} sub child_init {} @@ -265,11 +288,18 @@ sub process_spool { $xml =~ s/[\x00-\x1f]//go; my $qrec; - if ($type eq 'bib') { - $qrec = _add_bib_rec( $e, $xml, $queue_id, $purpose, $bib_source ) or return $e->die_event; - } else { - $qrec = _add_auth_rec( $e, $xml, $queue_id, $purpose ) or return $e->die_event; - } + # Check the leader to ensure we've got something resembling the expected + # Allow spaces to give records the benefit of the doubt + my $ldr_type = substr($r->leader(), 6, 1); + if ($type eq 'bib' && ($record_types{$ldr_type}) eq 'bib') { + $qrec = _add_bib_rec( $e, $xml, $queue_id, $purpose, $bib_source ) or return $e->die_event; + } elsif ($type eq 'auth' && ($record_types{$ldr_type}) eq 'auth') { + $qrec = _add_auth_rec( $e, $xml, $queue_id, $purpose ) or return $e->die_event; + } else { + # I don't know how to handle this type; rock on + $logger->error("In process_spool(), type was $type and leader type was $ldr_type ; not currently supported"); + next; + } if($self->api_name =~ /stream_results/ and $qrec) { $client->respond($qrec->id) -- 2.11.0