[open-ils-commits] r16971 - in trunk/Open-ILS: src/extras/import tests/datasets (dbs)

svn at svn.open-ils.org svn at svn.open-ils.org
Sat Jul 17 16:54:00 EDT 2010


Author: dbs
Date: 2010-07-17 16:53:55 -0400 (Sat, 17 Jul 2010)
New Revision: 16971

Added:
   trunk/Open-ILS/tests/datasets/serials_lib.map
Modified:
   trunk/Open-ILS/src/extras/import/marc2sre.pl
   trunk/Open-ILS/tests/datasets/README
Log:
Teach marc2sre.pl MFHD record ingest script to read a mapping of library names to OU IDs

The past approach required workarounds that weren't fun for a library
without in-house scripting expertise; this provides a straightforward
mapping approach with docs and a working sample. Which should be helpful
for all of the libraries that will go with the MFHD serials approach in
the future. Heh.


Modified: trunk/Open-ILS/src/extras/import/marc2sre.pl
===================================================================
--- trunk/Open-ILS/src/extras/import/marc2sre.pl	2010-07-17 20:51:15 UTC (rev 16970)
+++ trunk/Open-ILS/src/extras/import/marc2sre.pl	2010-07-17 20:53:55 UTC (rev 16971)
@@ -25,7 +25,7 @@
 
 MARC::Charset->ignore_errors(1);
 
-my ($idfield, $count, $user, $password, $config, $marctype, $idsubfield, @files, @trash_fields, $quiet) =
+my ($idfield, $count, $user, $password, $config, $marctype, $idsubfield, @files, @trash_fields, $quiet, $libmap) =
 	('001', 1, 'admin', 'open-ils', '/openils/conf/opensrf_core.xml', 'USMARC');
 
 GetOptions(
@@ -37,6 +37,7 @@
 	'config=s'	=> \$config,
 	'marctype=s'	=> \$marctype,
 	'file=s'	=> \@files,
+	'libmap=s'	=> \$libmap,
 	'quiet'		=> \$quiet,
 );
 
@@ -45,6 +46,10 @@
 my @ses;
 my @req;
 my %processing_cache;
+my $lib_id_map;
+if ($libmap) {
+	$lib_id_map = map_libraries_to_ID($libmap);
+}
 
 OpenSRF::System->bootstrap_client( config_file => $config );
 Fieldmapper->import(IDL => OpenSRF::Utils::SettingsClient->new->config_value("IDL"));
@@ -98,6 +103,13 @@
 	$bib->edit_date('now');
 	$bib->last_xact_id('IMPORT-'.$starttime);
 
+	if ($libmap) {
+		my $lib_id = get_library_id($rec);
+		if ($lib_id) {
+			$bib->owning_lib($lib_id);
+		}
+	}
+
 	print OpenSRF::Utils::JSON->perl2JSON($bib)."\n";
 
 	$count++;
@@ -137,3 +149,45 @@
         return $authtoken;
 }       
 
+=head2
+
+map_libraries_to_ID
+
+Parses a file to return a hash of library names to integers representing
+the actor.org_unit.id value of the library. This enables us to generate
+an ingest file that does not subsequently need to manually manipulated.
+
+The library name must correspond to the 'b' subfield of the 852 field.
+Well, it does not have to, but you will have to modify this script
+accordingly.
+
+The format of the map file should be the name of the library, followed
+by a tab, followed by the desired numeric ID of the library. For example:
+
+BR1	4
+BR2	5
+
+=cut
+
+sub map_libraries_to_ID {
+	my $map_filename = shift;
+
+	my %lib_id_map;
+
+	open(MAP_FH, '<', $map_filename) or die "Could not load [$map_filename] $!";
+	while (<MAP_FH>) {
+		my ($lib, $id) = $_ =~ /^(.*?)\t(.*?)$/;
+		$lib_id_map{$lib} = $id;
+	}
+
+	return \%lib_id_map;
+}
+
+sub get_library_id {
+	my $record = shift;
+
+	my $lib_name = $record->field('852')->subfield('b');
+	my $lib_id = $lib_id_map->{$lib_name};
+
+	return $lib_id;
+}

Modified: trunk/Open-ILS/tests/datasets/README
===================================================================
--- trunk/Open-ILS/tests/datasets/README	2010-07-17 20:51:15 UTC (rev 16970)
+++ trunk/Open-ILS/tests/datasets/README	2010-07-17 20:53:55 UTC (rev 16971)
@@ -19,16 +19,14 @@
 =====How to load the test MFHD records=====
 
   - First load the MARC21 records:
-    - PERL5LIB=/openils/lib/perl5/ perl ../../src/extras/import/marc2bre.pl --marctype XML --start 1 --idfield 901 --idsubfield a serials_marc21.xml | perl ../../src/extras/import/direct_ingest.pl  | perl ../../src/extras/import/pg_loader.pl -or bre -or mrd -or mfr -or mtfe -or mafe -or msfe -or mkfe -or msefe -a mrd -a mfr -a mtfe -a mafe -a msfe -a mkfe -a msefe | psql -U evergreen -h localhost
+    - PERL5LIB=/openils/lib/perl5/ perl ../../src/extras/import/marc2bre.pl --marctype XML --start 1 --idfield 901 --idsubfield a serials_marc21.xml | perl ../../src/extras/import/pg_loader.pl -or bre -or mrd -or mfr -or mtfe -or mafe -or msfe -or mkfe -or msefe -a mrd -a mfr -a mtfe -a mafe -a msfe -a mkfe -a msefe | psql -U evergreen -h localhost
 
   - Then generate the metarecord map:
     - pgsql -f ../../src/extras/import/quick_metarecord_map.sql
 
-  - Then process and load the MFHD records - ingest is not used:
-    - PERL5LIB=/openils/lib/perl5/ perl ../../src/extras/import/marc2sre.pl --marctype XML --password open-ils serials_mfhd.xml | perl ../../src/extras/import/pg_loader.pl -or sre > mfhd21.sql
-    - Open the file in a text editor and change the final "\N" on each line
-      to the numeric ID of the org_unit that owns the MFHD record. Yes, this
-      is a gross hack that effectively limits you to loading MFHD records in
-      per-org_unit batches; enhancements to marc2sre.pl are welcomed.
+  - Then process and load the MFHD records - ingest is not used. Adjust the
+    contents of serials_lib.map to match your library-to-actor.org_unit.id
+    mappings:
+    - PERL5LIB=/openils/lib/perl5/ perl ../../src/extras/import/marc2sre.pl --marctype XML --libmap serials_lib.map --password open-ils serials_mfhd.xml | perl ../../src/extras/import/pg_loader.pl -or sre > mfhd21.sql
     - psql -f mfhd21.sql
 

Added: trunk/Open-ILS/tests/datasets/serials_lib.map
===================================================================
--- trunk/Open-ILS/tests/datasets/serials_lib.map	                        (rev 0)
+++ trunk/Open-ILS/tests/datasets/serials_lib.map	2010-07-17 20:53:55 UTC (rev 16971)
@@ -0,0 +1,2 @@
+DESMARAIS	4
+HRSRH	5



More information about the open-ils-commits mailing list