Skip to content
Snippets Groups Projects
Commit 85c9643c authored by Jens Steidl's avatar Jens Steidl :baby_chick:
Browse files

- added funtionality for adding metadata (that become bag-info.txt keys later)

parent dcdbf1c2
No related branches found
No related tags found
No related merge requests found
......@@ -94,6 +94,39 @@ package SLUB::LZA::SIPBuilderBagIt;
{ tag => "246", code => "a", key => "Title" },
{ tag => "246", code => "b", key => "Title" },
];
sub add_metadata($$$$) {
if(! defined $_[0]) { croak "array of hashes not defined for bag-info.txt!"; }
my $refAddBagInfo = $_[0]; # ref to array of hashes
my $ppn = $_[1];
my $noppn = $_[2];
my $marc21 = $_[3];
push @{$refAddBagInfo}, {'External-Identifier' => "PPN:$ppn"} unless (! $ppn);
push @{$refAddBagInfo}, {'External-Identifier' => "$noppn"} unless (! $noppn);
if ($marc21) {
foreach my $mapping (@{$marc21_to_baginfo_mappings}) {
my $text = get_marc21_text_node($marc21, $mapping);
push @{$refAddBagInfo}, {$mapping->{key} => $text} unless (! $text);
}
}
return 1;
}
sub get_marc21_text_node($$) {
my $marc21 = $_[0];
my $mapping = $_[1];
my $xpath = "//*[\@tag='" . $mapping->{tag} . "']/";
$xpath .= "*[local-name()='subfield' and \@code='" . $mapping->{code} . "']/" unless (! exists $mapping->{code});
$xpath .= "text()";
# HINT: xpath example //*[@tag='245']/*[local-name()='subfield' and @code='a']/text()
my $text = XML::XPath->new($marc21)->findnodes_as_string($xpath);
return $text;
}
sub get_marc21_from_catalogue($){
if(! defined $_[0]){ croak "ppn not defined!"; }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment