From 11c99a068f108a62a40f38022b78bae8b1d4cf6d Mon Sep 17 00:00:00 2001
From: Andreas Romeyke <art1@andreas-romeyke.de>
Date: Thu, 15 Jul 2021 11:58:28 +0200
Subject: [PATCH] - improved get_files()

---
 perl/exit_strategy.pl | 17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)

diff --git a/perl/exit_strategy.pl b/perl/exit_strategy.pl
index 7dfaacd..05aaeff 100644
--- a/perl/exit_strategy.pl
+++ b/perl/exit_strategy.pl
@@ -274,7 +274,7 @@ sub check_if_db_conform ($$) {
   my $str_local_reps = 'mets:techMD/mets:mdWrap/mets:xmlData/*[local-name()=\'dnx\']/*[local-name()=\'section\']/*[local-name()=\'record\']/*[local-name()=\'key\' and @id=\'label\']';
   my $compiled_xpath_localreps = XML::LibXML::XPathExpression->new( $str_local_reps);
   my $compiled_xpath_localreps2 = XML::LibXML::XPathExpression->new('/mets:mets/mets:amdSec/mets:techMD/mets:mdWrap/mets:xmlData/dnx/section/record/key[@id=\'label\']=\'LOCAL\'');
-  my $compiled_xpath_filegrps = XML::LibXML::XPathExpression->new('/mets:mets/mets:fileSec/mets:fileGrp');
+  my $compiled_xpath_filesec = XML::LibXML::XPathExpression->new('/mets:mets/mets:fileSec');
   my $compiled_xpath_flocat = XML::LibXML::XPathExpression->new('mets:file/mets:FLocat');
   my $compiled_xpath_id = XML::LibXML::XPathExpression->new('@ID');
   my $compiled_xpath_admid = XML::LibXML::XPathExpression->new('@ADMID');
@@ -347,18 +347,9 @@ sub check_if_db_conform ($$) {
     my $xp = shift;
     my $filename = shift;
     my $repid = shift;
-    my @files;
-    my $filegrpnodes = $xp->find($compiled_xpath_filegrps);
-    foreach my $filegrpnode ($filegrpnodes->get_nodelist) {
-      if ($filegrpnode->findvalue($compiled_xpath_admid) eq $repid) {
-        my $filesnodes = $filegrpnode->find($compiled_xpath_flocat);
-        foreach my $filesnode ($filesnodes->get_nodelist) {
-          my $value = $filesnode->findvalue($compiled_xpath_xlinhref);
-          check_if_db_conform($value, $filename);
-          push @files, sprintf("%s", $value);
-        }
-      }
-    }
+
+    my $files_nodes = $xp->find("mets:mets/mets:fileSec/mets:fileGrp[\@ADMID='$repid']/mets:file/mets:FLocat/\@xlin:href");
+    my @files = map { $_->nodeValue} $files_nodes->get_nodelist();
     return @files;
   }
 
-- 
GitLab