fix retrieval of correct column headers and data from non-holdings tags
authorGalen Charlton <gmc@esilibrary.com>
Mon, 15 Mar 2010 16:34:57 +0000 (16:34 +0000)
committerGalen Charlton <gmc@esilibrary.com>
Mon, 15 Mar 2010 16:34:57 +0000 (16:34 +0000)
This work was sponsored by the Indiana State Library.

Equinox-Migration/lib/Equinox/Migration/MapDrivenMARCXMLProc.pm
extract_holdings

index b98a7ff..77a96dc 100644 (file)
@@ -94,6 +94,22 @@ sub parse_record {
     for my $f (@fields)
       { process_field($f, $crec) }
 
+    # fill in blank values if needed
+    for my $mappedtag ( @{ $sfmap->tags }) {
+        unless (exists $crec->{tmap}{$mappedtag}) {
+            push @{ $crec->{tags} }, {};
+            for my $mappedsub ( @{ $sfmap->subfields($mappedtag) } ) {
+                my $fieldname = $sfmap->field($mappedtag, $mappedsub);
+                my $mods = $sfmap->mods($fieldname);
+                next if $mods->{multi};
+                $crec->{tags}[-1]{uni}{$mappedsub} = '';
+                $crec->{tags}[-1]{multi} = undef;
+                $crec->{tags}[-1]{tag} = $mappedtag;
+            }
+            push @{ $crec->{tmap}{$mappedtag} }, $#{ $crec->{tags} };
+        }
+    }
+
     # cleanup memory and increment pointer
     $record->purge;
     $reccount++;
@@ -137,10 +153,6 @@ sub process_field {
             $crec->{tags}[-1]{uni}{$mappedsub} = ''
               unless defined $crec->{tags}[-1]{uni}{$mappedsub};
         }
-        for my $mappedtag ( @{ $sfmap->tags }) {
-            $crec->{tmap}{$mappedtag} = undef
-              unless defined $crec->{tmap}{$mappedtag};
-        }
     }
 }
 
index d39aac9..fb44929 100755 (executable)
@@ -91,19 +91,19 @@ sub extract_holdings {
                     $limit = $#{ $rec->{tmap}{$othertag} };
                 }
                 foreach my $idx (0..$limit) {
-                    for my $sub ( sort keys %{$rec->{tags}[$idx]{uni}} ) {
-                        if ($m->first_only($rec->{tags}[$idx]{tag}, $sub)) {
-                            push @out, ($k == 1) ? $rec->{tags}[$idx]{uni}{$sub} : '';
+                    my $tag_idx = $rec->{tmap}{$othertag}[$idx];
+                    for my $sub ( sort keys %{$rec->{tags}[$tag_idx]{uni}} ) {
+                        if ($m->first_only($rec->{tags}[$tag_idx]{tag}, $sub)) {
+                            push @out, ($k == 1) ? $rec->{tags}[$tag_idx]{uni}{$sub} : '';
                         } else {
-                            push @out, $rec->{tags}[$idx]{uni}{$sub};
+                            push @out, $rec->{tags}[$tag_idx]{uni}{$sub};
                         }
-                        print HOLDINGS "l_", $m->name($rec->{tags}[$idx]{tag}, $sub), ", "
-                        unless $j;
+                        print HOLDINGS "l_", $m->name($rec->{tags}[$tag_idx]{tag}, $sub), ", " unless $j;
                     }
                     next unless exists($multis->{$othertag});
                     for my $sub ( sort keys %{$multis->{$othertag}} ) {
-                        next if $m->first_only($rec->{tags}[$idx]{tag}, $sub) and ($k > 1);
-                        for my $value ( @{$rec->{tags}[$idx]{multi}{$sub}} ) {
+                        next if $m->first_only($rec->{tags}[$tag_idx]{tag}, $sub) and ($k > 1);
+                        for my $value ( @{$rec->{tags}[$tag_idx]{multi}{$sub}} ) {
                             my $fh = $MULTIFILE{"$othertag$sub"};
                             print $fh join("\t", $rec->{egid}, $j, $value), "\n";
                         }