From: dbs Date: Sat, 17 Jul 2010 20:53:55 +0000 (+0000) Subject: Teach marc2sre.pl MFHD record ingest script to read a mapping of library names to... X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=056058eef96b9b9ad1f4b9892dd0086c5686c69e;p=evergreen%2Fbjwebb.git 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. git-svn-id: svn://svn.open-ils.org/ILS/trunk@16971 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/extras/import/marc2sre.pl b/Open-ILS/src/extras/import/marc2sre.pl index 26121ba1f..cad3af25c 100755 --- a/Open-ILS/src/extras/import/marc2sre.pl +++ b/Open-ILS/src/extras/import/marc2sre.pl @@ -25,7 +25,7 @@ use MARC::Charset; 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 @@ GetOptions( 'config=s' => \$config, 'marctype=s' => \$marctype, 'file=s' => \@files, + 'libmap=s' => \$libmap, 'quiet' => \$quiet, ); @@ -45,6 +46,10 @@ GetOptions( 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 @@ while ( try { $rec = $batch->next } otherwise { $rec = -1 } ) { $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 @@ sub login { 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 () { + 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; +} diff --git a/Open-ILS/tests/datasets/README b/Open-ILS/tests/datasets/README index a824a0973..ef88a1829 100644 --- a/Open-ILS/tests/datasets/README +++ b/Open-ILS/tests/datasets/README @@ -19,16 +19,14 @@ The following table lists the data sets we have collected for testing purposes. =====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 diff --git a/Open-ILS/tests/datasets/serials_lib.map b/Open-ILS/tests/datasets/serials_lib.map new file mode 100644 index 000000000..91f1159f4 --- /dev/null +++ b/Open-ILS/tests/datasets/serials_lib.map @@ -0,0 +1,2 @@ +DESMARAIS 4 +HRSRH 5