From d166d54c7828ca552dfdd48bd6a5fb2c8518c439 Mon Sep 17 00:00:00 2001
From: Jens Steidl <Jens.Steidl@slub-dresden.de>
Date: Fri, 9 Oct 2020 17:53:34 +0200
Subject: [PATCH] - refactor: fallback to K10plus if SWB PPN fails (source
 index key: https://swbtools.bsz-bw.de/cgi-bin/k10plushelp.pl?cmd=idx_s)

---
 bin/slubsipbuilderbagit.pl | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/bin/slubsipbuilderbagit.pl b/bin/slubsipbuilderbagit.pl
index cb80ae8..96805ae 100644
--- a/bin/slubsipbuilderbagit.pl
+++ b/bin/slubsipbuilderbagit.pl
@@ -61,7 +61,8 @@ package SLUB::LZA::SIPBuilderBagIt;
     my $marc_mods_url  = 'http://www.loc.gov/standards/mods/v3/MARC21slim2MODS3-6.xsl';
     my $marc_utils_url = 'http://www.loc.gov/standards/marcxml/xslt/MARC21slimUtils.xsl';
     my $swb_url        = 'https://sru.bsz-bw.de/swb';
-    my $searchkey      = 'pica.all';
+    my $searchkey_swb  = 'pica.swn';
+    my $searchkey_k10p = 'pica.ppn';
     my $recordschema   = 'marcxmlvbos';
     our $with_debug    = 0;
 
@@ -85,7 +86,20 @@ MODS
         if(! defined $_[0]){ croak "ppn not defined!"; }
 
         my $ppn  = shift;
-        my $mods = SLUB::LZA::SIPBuilderBagIt::get_mods_from($swb_url, $ppn, $searchkey, $recordschema);
+        my $mods;
+        eval {
+            $mods = SLUB::LZA::SIPBuilderBagIt::get_mods_from($swb_url, $ppn, $searchkey_swb, $recordschema);
+        };
+        # Fallback to K10plus PPN
+        if ($@ =~ m#ERROR: Did not get any <recordData/> for PPN#) {
+            print_scalar_data("", "WARNING: '$ppn' not a SWB PPN, fallback to K10plus", "", "yellow");
+            $mods = SLUB::LZA::SIPBuilderBagIt::get_mods_from($swb_url, $ppn, $searchkey_k10p, $recordschema);
+        }
+        else {
+            die $@; # throw exception again
+        }
+        print_scalar_data("", "INFO: Found metadata for PPN '$ppn'", "", "white");
+
 
         if($with_debug){
             SLUB::LZA::SIPBuilderBagIt::write_file("DEBUG_${ppn}_mods.xml", $mods);
-- 
GitLab