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

svn at svn.open-ils.org svn at svn.open-ils.org
Sun Jun 14 23:32:56 EDT 2009


Author: dbs
Date: 2009-06-14 23:32:54 -0400 (Sun, 14 Jun 2009)
New Revision: 13384

Modified:
   trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHDParser.pm
Log:
Add some logging to MFHDParser.pm, and prevent returning raw parsing errors to the client

In concert with c13383, this will give cataloguers the ability to fix errors in MFHD records
without requiring a system administrator to manipulate SQL directly. Sweet relief.


Modified: trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHDParser.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHDParser.pm	2009-06-15 03:28:56 UTC (rev 13383)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHDParser.pm	2009-06-15 03:32:54 UTC (rev 13384)
@@ -54,6 +54,9 @@
 sub mfhd_to_hash {
 	my ($self, $mfhd_xml) = @_;
 
+	my $marc;
+	my $mfhd;
+
 	my $location = '';
 	my $holdings = [];
 	my $supplements = [];
@@ -65,81 +68,109 @@
 	my $missing = []; # Laurentian extension to MFHD standard
 	my $incomplete = []; # Laurentian extension to MFHD standard
 
-	my $marc = MARC::Record->new_from_xml($mfhd_xml);
-	my $mfhd = MFHD->new($marc);
+	try {
+		$marc = MARC::Record->new_from_xml($mfhd_xml);
+	} otherwise {
+		$logger->error("Failed to convert MFHD XML to MARC: " . shift());
+		$logger->error("Failed MFHD XML: $mfhd_xml");
+	};
 
-	foreach my $field ($marc->field('852')) {
-		foreach my $subfield_ref ($field->subfields) {
-			my ($subfield, $data) = @$subfield_ref;
-			$location .= $data . " -- ";
+	if (!$marc) {
+		return undef;
+	}
+
+	try {
+		$mfhd = MFHD->new($marc);
+	} otherwise {
+		$logger->error("Failed to parse MFHD: " . shift());
+		$logger->error("Failed MFHD XML: $mfhd_xml");
+	};
+
+	if (!$mfhd) {
+		return undef;
+	}
+
+	try {
+		foreach my $field ($marc->field('852')) {
+			foreach my $subfield_ref ($field->subfields) {
+				my ($subfield, $data) = @$subfield_ref;
+				$location .= $data . " -- ";
+			}
 		}
-	}
+	} otherwise {
+		$logger->error("MFHD location parsing error: " . shift());
+	};
+
 	$location =~ s/ -- $//;
 
-	foreach my $field ($marc->field('866')) {
-		my $textual_holdings = $self->format_textual_holdings($field);
-		if ($textual_holdings) {
-			push @$holdings, $textual_holdings;
+	try {
+		foreach my $field ($marc->field('866')) {
+			my $textual_holdings = $self->format_textual_holdings($field);
+			if ($textual_holdings) {
+				push @$holdings, $textual_holdings;
+			}
 		}
-	}
-	foreach my $field ($marc->field('867')) {
-		my $textual_holdings = $self->format_textual_holdings($field);
-		if ($textual_holdings) {
-			push @$supplements, $textual_holdings;
+		foreach my $field ($marc->field('867')) {
+			my $textual_holdings = $self->format_textual_holdings($field);
+			if ($textual_holdings) {
+				push @$supplements, $textual_holdings;
+			}
 		}
-	}
-	foreach my $field ($marc->field('868')) {
-		my $textual_holdings = $self->format_textual_holdings($field);
-		if ($textual_holdings) {
-			push @$indexes, $textual_holdings;
+		foreach my $field ($marc->field('868')) {
+			my $textual_holdings = $self->format_textual_holdings($field);
+			if ($textual_holdings) {
+				push @$indexes, $textual_holdings;
+			}
 		}
-	}
 
-	foreach my $cap_id ($mfhd->captions('853')) {
-		my @curr_holdings = $mfhd->holdings('863', $cap_id);
-		next unless scalar @curr_holdings;
-		foreach (@curr_holdings) {
-			push @$current_holdings, $_->format();
+		foreach my $cap_id ($mfhd->captions('853')) {
+			my @curr_holdings = $mfhd->holdings('863', $cap_id);
+			next unless scalar @curr_holdings;
+			foreach (@curr_holdings) {
+				push @$current_holdings, $_->format();
+			}
 		}
-	}
 
-	foreach my $cap_id ($mfhd->captions('854')) {
-		my @curr_supplements = $mfhd->holdings('864', $cap_id);
-		next unless scalar @curr_supplements;
-		foreach (@curr_supplements) {
-			push @$current_supplements, $_->format();
+		foreach my $cap_id ($mfhd->captions('854')) {
+			my @curr_supplements = $mfhd->holdings('864', $cap_id);
+			next unless scalar @curr_supplements;
+			foreach (@curr_supplements) {
+				push @$current_supplements, $_->format();
+			}
 		}
-	}
 
-	foreach my $cap_id ($mfhd->captions('855')) {
-		my @curr_indexes = $mfhd->holdings('865', $cap_id);
-		next unless scalar @curr_indexes;
-		foreach (@curr_indexes) {
-			push @$current_indexes, $_->format();
+		foreach my $cap_id ($mfhd->captions('855')) {
+			my @curr_indexes = $mfhd->holdings('865', $cap_id);
+			next unless scalar @curr_indexes;
+			foreach (@curr_indexes) {
+				push @$current_indexes, $_->format();
+			}
 		}
-	}
 
-	# Laurentian extensions
-	foreach my $field ($marc->field('530')) {
-		my $online_stmt = $self->format_textual_holdings($field);
-		if ($online_stmt) {
-			push @$online, $online_stmt;
+		# Laurentian extensions
+		foreach my $field ($marc->field('530')) {
+			my $online_stmt = $self->format_textual_holdings($field);
+			if ($online_stmt) {
+				push @$online, $online_stmt;
+			}
 		}
-	}
 
-	foreach my $field ($marc->field('590')) {
-		my $missing_stmt = $self->format_textual_holdings($field);
-		if ($missing_stmt) {
-			push @$missing, $missing_stmt;
+		foreach my $field ($marc->field('590')) {
+			my $missing_stmt = $self->format_textual_holdings($field);
+			if ($missing_stmt) {
+				push @$missing, $missing_stmt;
+			}
 		}
-	}
 
-	foreach my $field ($marc->field('591')) {
-		my $incomplete_stmt = $self->format_textual_holdings($field);
-		if ($incomplete_stmt) {
-			push @$incomplete, $incomplete_stmt;
+		foreach my $field ($marc->field('591')) {
+			my $incomplete_stmt = $self->format_textual_holdings($field);
+			if ($incomplete_stmt) {
+				push @$incomplete, $incomplete_stmt;
+			}
 		}
-	}
+	} otherwise {
+		$logger->error("MFHD statement parsing error: " . shift());
+	};
 
 	return { location => $location, holdings => $holdings, current_holdings => $current_holdings,
 			supplements => $supplements, current_supplements => $current_supplements,
@@ -194,6 +225,11 @@
 
 	$record->id($id);
 	$record->owning_lib($owning_lib);
+
+	if (!$holdings) {
+		return $record;
+	}
+
 	$record->location($holdings->{location});
 	$record->holdings($holdings->{holdings});
 	$record->current_holdings($holdings->{current_holdings});
@@ -209,3 +245,5 @@
 }
 
 1;
+
+# vim: ts=4:sw=4:noet



More information about the open-ils-commits mailing list