From b5e5f86014c74fc495a22ad386d7d9b845b0d302 Mon Sep 17 00:00:00 2001 From: Shawn Boyette Date: Mon, 27 Apr 2009 05:01:16 +0000 Subject: [PATCH] required mod looks to be working --- .../lib/Equinox/Migration/MapDrivenMARCXMLProc.pm | 41 ++++++++++++++++---- 1 files changed, 33 insertions(+), 8 deletions(-) diff --git a/Equinox-Migration/lib/Equinox/Migration/MapDrivenMARCXMLProc.pm b/Equinox-Migration/lib/Equinox/Migration/MapDrivenMARCXMLProc.pm index 2854546..236036e 100644 --- a/Equinox-Migration/lib/Equinox/Migration/MapDrivenMARCXMLProc.pm +++ b/Equinox-Migration/lib/Equinox/Migration/MapDrivenMARCXMLProc.pm @@ -4,7 +4,7 @@ use warnings; use strict; use XML::Twig; -use Equinox::Migration::SubfieldMapper 1.002; +use Equinox::Migration::SubfieldMapper 1.003; # FIXME # @@ -65,7 +65,7 @@ sub new { my ($class, %args) = @_; my $self = bless { mods => { multi => {}, - once => {}, + bib => {}, required => {}, }, data => { recs => undef, # X::T record objects @@ -133,7 +133,8 @@ sub parse_record { $record->purge; $self->{data}{rptr}++; - # FIXME check for required fields here + # check for required fields + $self->check_required; return $self->{data}{crec}; } @@ -195,17 +196,41 @@ sub process_subs { my $dataf = $self->{data}{crec}{tags}[-1]; my $field = $map->field($tag, $code); - # handle modifiers, or slug data in normally + # handle modifiers if (my $mods = $map->mods($field)) { if ($mods->{multi}) { my $name = $tag . $code; push @{$dataf->{multi}{$name}}, $sub->text; + return; } - } else { - die "Multiple occurances of a non-multi field: $tag$code at rec ",($self->{data}{rptr} + 1),"\n" - if (defined $dataf->{uni}{$code}); - $dataf->{uni}{$code} = $sub->text; } + + die "Multiple occurances of a non-multi field: $tag$code at rec ",($self->{data}{rptr} + 1),"\n" + if (defined $dataf->{uni}{$code}); + $dataf->{uni}{$code} = $sub->text; +} + + +sub check_required { + my ($self) = @_; + my $mods = $self->{map}->mods; + my $crec = $self->{data}{crec}; + + for my $tag_id (keys %{$mods->{required}}) { + for my $code (@{$mods->{required}{$tag_id}}) { + my $found = 0; + + $found = 1 if ($crec->{bib}{($tag_id . $code)}); + for my $tag (@{$crec->{tags}}) { + $found = 1 if ($tag->{multi}{($tag_id . $code)}); + $found = 1 if ($tag->{uni}{$code}); + } + + die "Required mapping $tag_id$code not found in rec ",$self->{data}{rptr},"\n" + unless ($found); + } + } + } =head1 MODIFIERS -- 1.7.2.5