General fixes, plus fix Springer "software" item forms
authorDan Scott <dscott@laurentian.ca>
Sat, 17 Jan 2015 17:26:34 +0000 (12:26 -0500)
committerDan Scott <dscott@laurentian.ca>
Sat, 17 Jan 2015 17:26:34 +0000 (12:26 -0500)
856 z -> y, delete 596 holding codes, springer doi link text

Signed-off-by: Dan Scott <dscott@laurentian.ca>
Open-ILS/src/sql/Pg/fix_old_springer.sql [new file with mode: 0644]
Open-ILS/src/sql/Pg/update_marc_records_in_database.sql

diff --git a/Open-ILS/src/sql/Pg/fix_old_springer.sql b/Open-ILS/src/sql/Pg/fix_old_springer.sql
new file mode 100644 (file)
index 0000000..cef309f
--- /dev/null
@@ -0,0 +1,121 @@
+CREATE OR REPLACE FUNCTION conifer.cleanup_old_springer(record BIGINT) RETURNS TEXT AS $func$
+use strict;
+use MARC::Record;
+use MARC::File::XML (BinaryEncoding => 'UTF-8');
+use MARC::Charset;
+use Encode;
+use Unicode::Normalize;
+use LWP::UserAgent;
+use JSON::XS;
+
+MARC::Charset->assume_unicode(1);
+
+my $q = spi_prepare('SELECT marc FROM biblio.record_entry WHERE id = $1', 'BIGINT');
+my $marc = spi_exec_prepared($q, $_[0])->{rows}->[0]->{marc};
+
+my $record = MARC::Record->new_from_xml($marc);
+
+# Fixing "Software and video game" type
+# Set type to book ('a')
+my $leader = $record->leader();
+my $newleader = substr $leader, 6, 1, 'a';
+$record->leader($leader);
+
+# Set form 008/23 to online ('o')
+my @fates = $record->field('008');
+foreach my $fate (@fates) {
+    my $data = $fate->data();
+    my $newdata = substr $data, 23, 1, 'o';
+    $fate->update($data);
+}
+
+# Add explicit publisher relator code
+my @added = $record->field('710');
+foreach my $entry (@added) {
+    next if $entry->subfield('4');
+    if ($entry->subfield('a') =~ 'SpringerLink \(Online service\)') {
+        $entry->add_subfields('4' => 'pbl');
+    }
+}
+
+my @eights = $record->field('856');
+foreach my $ocho (@eights) {
+    my @ous = $ocho->subfield('9');
+    foreach my $ou (@ous) {
+        if ($ou eq 'WINDSYS' or $ou eq 'OWA') {
+            $record->delete_field($ocho);
+        }
+        if ($ou eq 'OSUL') {
+            $ocho->update('9' => 'LUSYS');
+        }
+    }
+
+    # Fix URIs that raise SSL cert issues
+    my $uri = $ocho->subfield('u');
+    if ($uri =~ m#^https://librweb#) {
+        $uri =~ s{^https://librweb}{http://librweb};
+        $ocho->update('u' => $uri);
+    }
+
+    # Provide an indication of the platform
+    if ($uri =~ m#scholarsportal#) {
+        $ocho->update('y' => 'Available online / disponible en ligne (ScholarsPortal)');
+        $ocho->delete_subfield(code => 'z', match => qr/Available/);
+    } elsif ($uri =~ m#dx.doi.org/10.1007#) {
+        $ocho->update('y' => 'Available online / disponible en ligne (Springer)');
+        $ocho->delete_subfield(code => 'z', match => qr/Available/);
+    } elsif ($uri =~ m#myilibrary#) {
+        $ocho->update('y' => 'Available online / disponible en ligne (MyiLibrary)');
+        $ocho->delete_subfield(code => 'z', match => qr/Available/);
+    } elsif ($uri =~ m#sagepub#) {
+        $ocho->update('y' => 'Available online / disponible en ligne (Sage)');
+        $ocho->delete_subfield(code => 'z', match => qr/Available/);
+    }
+}
+
+# Do not need access notes anymore
+my @access = $record->field('506');
+foreach my $note (@access) {
+    my @ous = $note->subfield('9');
+    foreach my $ou (@ous) {
+        if ($ou eq 'OWA') {
+            $record->delete_field($note);
+        }
+    }
+}
+
+# Do not need 596 holding fields anymore
+my @access = $record->field('596');
+foreach my $note (@access) {
+    my @ous = $note->subfield('a');
+    foreach my $ou (@ous) {
+        if ($ou eq '1') {
+            $record->delete_field($note);
+        }
+    }
+}
+
+my $xml = $record->as_xml_record();
+
+$xml =~ s/\n//sgo;
+$xml =~ s/^<\?xml.+\?\s*>//go;
+$xml =~ s/>\s+</></go;
+$xml =~ s/\p{Cc}//go;
+
+# Embed a version of OpenILS::Application::AppUtils->entityize()
+# to avoid having to set PERL5LIB for PostgreSQL as well
+
+$xml = NFC($xml);
+
+# Convert raw ampersands to entities
+$xml =~ s/&(?!\S+;)/&amp;/gso;
+
+# Convert Unicode characters to entities
+$xml =~ s/([\x{0080}-\x{fffd}])/sprintf('&#x%X;',ord($1))/sgoe;
+
+$xml =~ s/[\x00-\x1f]//go;
+
+return $xml;
+$func$ LANGUAGE PLPERLU;
+
+
index f077a3b..133dbb1 100644 (file)
@@ -37,10 +37,16 @@ foreach my $ocho (@eights) {
     # Provide an indication of the platform
     if ($uri =~ m#scholarsportal#) {
         $ocho->update('y' => 'Available online / disponible en ligne (ScholarsPortal)');
+        $ocho->delete_subfield(code => 'z', match => qr/Available/);
+    } elsif ($uri =~ m#dx.doi.org/10.1007#) {
+        $ocho->update('y' => 'Available online / disponible en ligne (Springer)');
+        $ocho->delete_subfield(code => 'z', match => qr/Available/);
     } elsif ($uri =~ m#myilibrary#) {
         $ocho->update('y' => 'Available online / disponible en ligne (MyiLibrary)');
+        $ocho->delete_subfield(code => 'z', match => qr/Available/);
     } elsif ($uri =~ m#sagepub#) {
         $ocho->update('y' => 'Available online / disponible en ligne (Sage)');
+        $ocho->delete_subfield(code => 'z', match => qr/Available/);
     }
 }
 
@@ -55,6 +61,17 @@ foreach my $note (@access) {
     }
 }
 
+# Do not need 596 holding fields anymore
+my @access = $record->field('596');
+foreach my $note (@access) {
+    my @ous = $note->subfield('a');
+    foreach my $ou (@ous) {
+        if ($ou eq '1') {
+            $record->delete_field($note);
+        }
+    }
+}
+
 # Update provenance of the records
 my @provs = $record->field('040');
 foreach my $prov (@provs) {
@@ -206,3 +223,4 @@ EXCEPTION
     RETURN next_id;
 END;
 $func$ LANGUAGE PLPGSQL;
+