[open-ils-commits] r16914 - trunk/Open-ILS/src/perlmods/OpenILS/Application (dbs)

svn at svn.open-ils.org svn at svn.open-ils.org
Mon Jul 12 16:52:05 EDT 2010


Author: dbs
Date: 2010-07-12 16:51:59 -0400 (Mon, 12 Jul 2010)
New Revision: 16914

Modified:
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Vandelay.pm
Log:
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.


Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Vandelay.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Vandelay.pm	2010-07-12 19:24:28 UTC (rev 16913)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Vandelay.pm	2010-07-12 20:51:59 UTC (rev 16914)
@@ -23,6 +23,29 @@
 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 @@
 			$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)



More information about the open-ils-commits mailing list