Skip to content
Snippets Groups Projects
Commit fb748e85 authored by Andreas Romeyke's avatar Andreas Romeyke
Browse files

- added support for dir_path column in table aip

- added support for filesize column in table sourcedatalocat
parent 41c79409
No related branches found
No related tags found
No related merge requests found
......@@ -43,7 +43,7 @@ use constant DEBUG => 0; # no debug
use Carp;
use DBD::SQLite;
use DBI;
use File::Basename qw(basename);
use File::Basename qw(basename dirname);
use File::Find;
use Getopt::Long;
use IO::Handle;
......@@ -105,6 +105,7 @@ sub write_tables_creation ($dbh) {
ie_id TEXT NOT NULL,
lza_id TEXT,
version INTEGER NOT NULL,
dir_path TEXT NOT NULL,
PRIMARY KEY(id AUTOINCREMENT)
);
SQL_CREATE1
......@@ -144,6 +145,7 @@ SQL_CREATE4
file_id INTEGER NOT NULL REFERENCES sourcedatafile (id),
location TEXT NOT NULL,
sourcetype TEXT NOT NULL,
filesize INTEGER,
PRIMARY KEY(id AUTOINCREMENT)
);
SQL_CREATE5
......@@ -168,7 +170,6 @@ CREATE TABLE transferAIP (
);
SQL_CREATE7
my $sth1 = $dbh->prepare($sql1); $sth1->execute() or die "sql problem detected", $dbh->errstr;
my $sth2 = $dbh->prepare($sql2); $sth2->execute() or die "sql problem detected", $dbh->errstr;
my $sth3 = $dbh->prepare($sql3); $sth3->execute() or die "sql problem detected", $dbh->errstr;
......@@ -188,7 +189,7 @@ sub write_prepare_insert ($dbh) {
sub prepare_addsql( $dbh) {
my $sql_aip_plan=<<"SQL_AIP_PLAN";
INSERT INTO aip (ie_id, lza_id, version) VALUES (\$1, \$2, \$3);
INSERT INTO aip (ie_id, lza_id, version, dir_path) VALUES (\$1, \$2, \$3, \$4);
SQL_AIP_PLAN
my $sql_ie_plan=<<"SQL_IE_PLAN";
INSERT INTO metadatafile (aip_id, location, sourcetype) VALUES (
......@@ -201,10 +202,10 @@ SQL_IE_PLAN
);
SQL_FILE_PLAN
my $sql_locat_plan=<<"SQL_LOCAT_PLAN";
INSERT INTO sourcedatalocat (file_id, location, sourcetype) VALUES (
INSERT INTO sourcedatalocat (file_id, location, sourcetype, filesize) VALUES (
(SELECT sourcedatafile.id FROM sourcedatafile,aip WHERE
sourcedatafile.aip_id=aip.id AND aip.ie_id=\$1 AND aip.version=\$2 AND
sourcedatafile.name=\$3), \$4, \$5
sourcedatafile.name=\$3), \$4, \$5, \$6
);
SQL_LOCAT_PLAN
my $sql_dc_plan=<<"SQL_DC_PLAN";
......@@ -260,6 +261,7 @@ SQL_DELETE_PLAN
my %lza_id_counter_hash;
sub write_addsql($dbh, $plans, $refhash) {
my $iefile = basename($refhash->{"filename"});
my $dir = dirname($refhash->{"filename"});
my ($ieid, $ieversion);
if ($iefile =~ m/^V(\d+)-(IE\d*)\.xml$/) {
$ieversion = $1;
......@@ -284,14 +286,16 @@ SQL_DELETE_PLAN
}
}
# start SQL insert
eval {$plans->{aip}->execute($ieid, $lza_id, $ieversion)} or die "sql problem detected with $ieid ($ieversion), plz check if there is a dublette dir, ", $dbh->errstr;
eval {$plans->{aip}->execute($ieid, $lza_id, $ieversion, $dir)} or die "sql problem detected with $ieid ($ieversion), plz check if there is a dublette dir, ", $dbh->errstr;
# FIXME if multiple locations exists
eval {$plans->{ie}->execute($ieid, $ieversion, $iefile, $sourcetype)} or die "sql problem detected with $ieid ($ieversion, $iefile, $sourcetype), ", $dbh->errstr;
foreach my $location (@{$refhash->{"files"}}) {
my $file = basename($location); # FIXME if multiple locations
my $size = $refhash->{"sizes"}->{$location};
$location=~s#//#/#g; # post correct file paths, because sometimes in Rosetta // is used
eval {$plans->{file}->execute($ieid, $ieversion, $file)} or die "sql problem detected with $ieid ($ieversion, $file), ", $dbh->errstr;
eval {$plans->{locat}->execute($ieid, $ieversion, $file, $location, $sourcetype)} or die "sql problem detected with $ieid ($ieversion, $file, $location, $sourcetype), ", $dbh->errstr;
eval {$plans->{locat}->execute($ieid, $ieversion, $file, $location, $sourcetype, $size)} or die "sql problem detected with $ieid ($ieversion, $file, $location, $sourcetype, $size), ", $dbh->errstr;
}
foreach my $dcpair (@{$refhash->{"dcrecords"}}) {
my ($dckey, $dcvalue) = @{$dcpair};
......@@ -406,6 +410,7 @@ sub check_if_db_conform ($string, $filename) {
my $compiled_xpath_purged_event_date = XML::LibXML::XPathExpression->new($xpath_if_purged_expr .'dnx:key[@id="eventDateTime"]/text()');
my $compiled_xpath_purged_event_authorized_by = XML::LibXML::XPathExpression->new($xpath_if_purged_expr . 'dnx:key[@id="linkingAgentIdentifierValue1"]/text()');
my $compiled_xpath_purged_event_reason = XML::LibXML::XPathExpression->new($xpath_if_purged_expr . 'dnx:key[@id="eventOutcomeDetail1"]/text()');
############################################################
sub get_title ($xp, $dmd){
# get title
......@@ -446,10 +451,29 @@ sub check_if_db_conform ($string, $filename) {
sub get_files_ref ($xp, $fsp, $repid){
my $filegrp = $xp->findnodes("mets:fileGrp[\@ADMID='$repid']", $fsp)->[0];
my @files_nodes = $xp->findnodes($compiled_xpath_files, $filegrp);
my @files = map { my $tmp= $_->nodeValue; $tmp=~ s#//#/#g; $tmp } @files_nodes;
my @files = map { my $tmp= $_->nodeValue; $tmp } @files_nodes;
return \@files;
}
sub get_filesize ($xp, $filepath) {
my $xpath_id =<<"XPATH";
/mets:mets/mets:fileSec/mets:fileGrp/mets:file[mets:FLocat/\@*[
namespace-uri()='http://www.w3.org/1999/xlink' and local-name()='href']='$filepath']/\@ID
XPATH
my $xpath =<<"XPATH2";
/mets:mets/mets:amdSec/mets:techMD[
$xpath_id
and
starts-with(\@ID,$xpath_id)
]/mets:mdWrap/mets:xmlData/*[namespace-uri()='http://www.exlibrisgroup.com/dps/dnx' and local-name()='dnx']
/*[namespace-uri()='http://www.exlibrisgroup.com/dps/dnx' and local-name()='section']
/*[namespace-uri()='http://www.exlibrisgroup.com/dps/dnx' and local-name()='record']
/*[namespace-uri()='http://www.exlibrisgroup.com/dps/dnx' and local-name()='key' and \@id='fileSizeBytes']/text()
XPATH2
my $size = $xp->findvalue($xpath);
return $size;
}
sub get_purged_states($xp, $amd) {
# we need to earch for eventIdentifierValue 272 or 274.
# the eventDescription should be
......@@ -536,6 +560,10 @@ sub check_if_db_conform ($string, $filename) {
############################################
# get all files of LOCAL representation
$ret->{"files"} = get_files_ref($xp, $filesec, $repid);
foreach my $location (@{$ret->{"files"}}) {
$ret->{"sizes"}->{$location} = get_filesize($xp, $location);
}
return $ret;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment