From e929396ed13a8ff6ee65ea131f0deb4d63477ae0 Mon Sep 17 00:00:00 2001
From: Andreas Romeyke <andreas.romeyke@slub-dresden.de>
Date: Wed, 5 Apr 2023 14:14:44 +0200
Subject: [PATCH] - fixed checkFixity() to handle absolute paths AND
 storedEntityIdentifier - fixed checkFixityAbs(), disabled parallel checks,
 because Rosetta is not threadsafe

---
 PLUGIN-INF/metadata_SLUBStoragePlugin.xml     |   2 +-
 .../plugin/storage/nfs/SLUBStoragePlugin.java | 244 +++++++++++-------
 2 files changed, 145 insertions(+), 101 deletions(-)

diff --git a/PLUGIN-INF/metadata_SLUBStoragePlugin.xml b/PLUGIN-INF/metadata_SLUBStoragePlugin.xml
index 67d3a9f..e8e6953 100644
--- a/PLUGIN-INF/metadata_SLUBStoragePlugin.xml
+++ b/PLUGIN-INF/metadata_SLUBStoragePlugin.xml
@@ -70,7 +70,7 @@
 		</fr:x_form>
 	</pl:initParameters>
 	<pl:description>SLUB Storage Plugin</pl:description>
-	<pl:version>2.845</pl:version>
+	<pl:version>2.92</pl:version>
 	<pl:materialType>DIGITAL</pl:materialType>
 	<pl:module>Repository</pl:module>
 	<pl:generalType>TASK</pl:generalType>
diff --git a/java/org/slub/rosetta/dps/repository/plugin/storage/nfs/SLUBStoragePlugin.java b/java/org/slub/rosetta/dps/repository/plugin/storage/nfs/SLUBStoragePlugin.java
index 6ce502f..65d7772 100644
--- a/java/org/slub/rosetta/dps/repository/plugin/storage/nfs/SLUBStoragePlugin.java
+++ b/java/org/slub/rosetta/dps/repository/plugin/storage/nfs/SLUBStoragePlugin.java
@@ -79,27 +79,34 @@ import java.util.Optional;
 public class SLUBStoragePlugin extends AbstractStorageHandler {
     private static final ExLogger log = ExLogger.getExLogger(SLUBStoragePlugin.class);
 
-    protected String getDirRoot() {
+    private String getDirRoot() {
         String path = parameters.get("DIR_ROOT");
         if (null == path) {
             log.error("Could not retrieve DIR_ROOT");
         }
         return path;
     }
-    protected class AbsolutePath {
-        private String filestring;
-        public AbsolutePath( String f) throws IOException {
+
+    private class AbsolutePath {
+        private final String fstring;
+        public AbsolutePath(String f) throws IOException {
+            if (f == null) {
+                throw  new IOException("AbsolutePath called with null path, shoult not occure!");
+            }
             if ((!f.startsWith(getDirRoot()))) {
                 String message = "SLUBStoragePlugin.AbsolutePath ='" + f + "' starts not with ROOT '" + getDirRoot() + "'";
                 log.error(message);
                 throw new IOException(message);
             }
             if ((f.startsWith(getDirRoot() + getDirRoot()))) {
-                String message = "SLUBStoragePlugin.AbsolutePath ='"+ f + "' starts with ROOT '" + getDirRoot() + "' twice!";
+                String message = "SLUBStoragePlugin.AbsolutePath ='" + f + "' starts with ROOT '" + getDirRoot() + "' twice!";
                 log.error(message);
                 throw new IOException(message);
             }
-            filestring = f;
+            fstring = f;
+        }
+        public String filestring() {
+            return fstring;
         }
     }
 
@@ -128,7 +135,7 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
 
     private String throughput(long starttime_in_ms, long endtime_in_ms, AbsolutePath filename) {
         try {
-            long fsize = Files.size(Paths.get(filename.filestring));
+            long fsize = Files.size(Paths.get(filename.filestring()));
             return throughput(starttime_in_ms, endtime_in_ms, fsize);
         } catch (IOException e) {
             log.warn("SLUBStoragePlugin.throughput, " + e.getMessage());
@@ -163,31 +170,68 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
     /**
      * checkFixity
      * @param fixities
-     * @param storedEntityIdentifier (relative filepath)
+     * @param absolutePath
      * @return true if valid, otherwise false
      * @throws Exception
      */
-    public boolean checkFixity(List<Fixity> fixities, String storedEntityIdentifier) throws IOException{
+    public boolean checkFixityAbs(List<Fixity> fixities, AbsolutePath absolutePath) throws IOException{
         //log.debug("SLUBStoragePlugin.checkFixity() storedEntityIdentifier='" + storedEntityIdentifier + "'");
-        AbsolutePath absolute_storedEntityIdentifier = new AbsolutePath(getFullFilePath(storedEntityIdentifier));
+        Path path = Paths.get(absolutePath.filestring());
+        if (Files.notExists(path)) {
+            log.warn("SLUBStoragePlugin.checkFixity() Path " + absolutePath.filestring() + " not exists, return false");
+            return false;
+        }
         //log.debug("SLUBStoragePlugin.checkFixity() absolute_storedEntityIdentifier='" + absolute_storedEntityIdentifier + "'");
         if (null==fixities) {
             log.warn("SLUBStoragePlugin.checkFixity() No fixity list provided");
             return true;
         }
-        return fixities.parallelStream().map(
-                fixity -> {
-                    try {
-                        return checkSpecificFixity(absolute_storedEntityIdentifier, fixity);
-                    } catch (Exception e) {
-                        throw new RuntimeException(e);
+        /* Rosetta is not threadsafe here, therefore the following code is commentd out */
+        /*
+        boolean res;
+        try {
+            res = fixities.parallelStream().map(
+                    fixity -> {
+                        try {
+                            return checkSpecificFixity(absolutePath, fixity);
+                        } catch (IOException e) {
+                            return false;
+                        } catch (NoSuchAlgorithmException e) {
+                            return false;
+                        }
                     }
-                }
-        ).reduce(
-                true, (all_result, result) -> all_result &= result
-        );
+            ).reduce(
+                    Boolean.TRUE, (all_result, result) -> all_result &= result
+            );
+        } catch (Exception e) {
+            log.warn( e.getMessage());
+            res = Boolean.FALSE;
+        }
+        return res;
+        */
+        boolean res = Boolean.TRUE;
+        try {
+            for (Fixity f : fixities) {
+                res &= checkSpecificFixity(absolutePath, f);
+            }
+        } catch (Exception e) {
+            return false;
+        }
+        return res;
     }
 
+    public boolean checkFixity(List<Fixity> fixities, String filepath) throws IOException{
+        String absolutePath;
+        if ((! filepath.startsWith(getDirRoot()))) {
+            /* is a identifier, need to get the avsolute path */
+            absolutePath = getFullFilePath(filepath);
+        } else {
+            Path path = Path.of(filepath);
+            absolutePath = path.toAbsolutePath().toString();
+
+        }
+        return checkFixityAbs(fixities, new AbsolutePath(absolutePath));
+    }
 
     /**
      * checkSpecificFixity
@@ -259,7 +303,7 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
         boolean result = fixity.getResult();
         is.close();
         long endtime = System.currentTimeMillis();
-        log.info("SLUBStoragePlugin.checkFixityByBuiltin() pathname='" + absolute_storedEntityIdentifier + "'"
+        log.info("SLUBStoragePlugin.checkFixityByBuiltin() pathname='" + absolute_storedEntityIdentifier.filestring() + "'"
                 + " algorithm=" + algorithm
                 + " oldvalue=" + oldValue
                 + " newvalue=" + newValue
@@ -269,10 +313,10 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
         return result;
     }
 
-    String relativePath(AbsolutePath absolute_storedEntityIdentifier) {
+     private String relativePath(AbsolutePath absolute_storedEntityIdentifier) {
         var begin = getDirRoot().length();
-        var end = absolute_storedEntityIdentifier.filestring.length();
-        var rel = absolute_storedEntityIdentifier.filestring.substring(begin, end);
+        var end = absolute_storedEntityIdentifier.filestring().length();
+        var rel = absolute_storedEntityIdentifier.filestring().substring(begin, end);
         //log.debug("SLUBStoragePlugin.relativePath('"+ absolute_storedEntityIdentifier + "') -> DirRoot="+getDirRoot() + " begin=" + begin + " end=" + end + " rel='" + rel + "'");
         assert(begin < end);
         return rel;
@@ -308,9 +352,9 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
         long starttime = System.currentTimeMillis();
         String newValue = "should not occur";
         try {
-            newValue = getChecksumUsingPlugin(absolute_storedEntityIdentifier.filestring, pluginname, oldValue);
+            newValue = getChecksumUsingPlugin(absolute_storedEntityIdentifier.filestring(), pluginname, oldValue);
         } catch  (Exception e) {
-            log.error("SLUBStoragePlugin.checkFixityByPlugin() exception in getChecksumUsingPlugin("+absolute_storedEntityIdentifier.filestring + ", "+ pluginname + ", " + oldValue +"), " + e.getMessage() );
+            log.error("SLUBStoragePlugin.checkFixityByPlugin() exception in getChecksumUsingPlugin("+absolute_storedEntityIdentifier.filestring() + ", "+ pluginname + ", " + oldValue +"), " + e.getMessage() );
         }
         fixity.setValue(newValue);
         /* HINT: if plugin name is still empty a java.lang.NullPointerException gets thrown
@@ -319,7 +363,7 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
         fixity.setResult((oldValue == null) || (oldValue.equals(newValue)));
         boolean result = fixity.getResult();
         long endtime = System.currentTimeMillis();
-        log.info("SLUBStoragePlugin.checkFixityByPlugin() pathname='" + absolute_storedEntityIdentifier + "'"
+        log.info("SLUBStoragePlugin.checkFixityByPlugin() pathname='" + absolute_storedEntityIdentifier.filestring() + "'"
                 + " plugin=" + pluginname
                 + " oldvalue=" + oldValue
                 + " newvalue=" + newValue
@@ -366,7 +410,7 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
     {
         //log.debug("SLUBStoragePlugin.getFullFilePath() with '" + storedEntityIdentifier + "'");
         try {
-            return new AbsolutePath( getDirRoot() + storedEntityIdentifier ).filestring;
+            return new AbsolutePath( getDirRoot() + storedEntityIdentifier ).filestring();
         } catch (IOException e) {
             throw new RuntimeException(e);
         }
@@ -442,58 +486,69 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
             throws IOException
     {
         log.info("SLUBStoragePlugin.storeEntity()");
-        AbsolutePath nullOrAbsoluteDestFilePath = getAbsolutePathInDescIfExists(storedEntityMetadata);
-        //log.debug("SLUBStoragePlugin.storeEntity() existsDescPath='" + existsDescPath + "'");
-        boolean isCopyFileNeeded = true;
-        Map<String, String> paths = getStoreEntityIdentifier(storedEntityMetadata, nullOrAbsoluteDestFilePath);
-        String storedEntityIdentifier = paths.get("relativeDirectoryPath");
-        contractAssertIsRelativePath(storedEntityIdentifier);
-        if (nullOrAbsoluteDestFilePath != null)
-        {
-            isCopyFileNeeded = !checkFixity(storedEntityMetadata.getFixities(), storedEntityIdentifier);
-        }
-        //log.debug("SLUBStoragePlugin.storeEntity() destFilePath='" + destFilePath + "'");
-        //log.debug("SLUBStoragePlugin.storeEntity() storedEntityIdentifier='" + storedEntityIdentifier + "'");
-        AbsolutePath absoluteDestFilePath = new AbsolutePath(paths.get("destFilePath"));
-        //log.debug("SLUBStoragePlugin.storeEntity() destFilePath (2)='" + absolute_destFilePath + "'");
-        //log.debug("SLUBStoragePlugin.storeEntity() isCopyFileNeeded='" + isCopyFileNeeded + "'");
-        if (isCopyFileNeeded)
-        {
-            if (canHandleSourcePath(storedEntityMetadata.getCurrentFilePath()))
-            {
-                //log.debug("SLUBStoragePlugin.storeEntity() absolute_destFilePath canhandle sourcepath");
+        AbsolutePath absoluteDestFilePath;
+
+        if (storedEntityMetadata.getIePid() == null) {
+            log.info("SLUBStoragePlugin.storeEntity(), found empty IE PID");
+            absoluteDestFilePath = generateAbsoluteDestPath(storedEntityMetadata);
+        } else {
+            log.info("SLUBStoragePlugin.storeEntity(), try to load absolute path...");
+            try {
+                absoluteDestFilePath = loadAbsoluteDestPathsTmpFile(storedEntityMetadata);
+                log.info("SLUBStoragePlugin.storeEntity(), loaded path=" + absoluteDestFilePath.filestring());
+            } catch (IOException e) {
+                log.info("SLUBStoragePlugin.storeEntity(), no stored absolute path loaded. try to generate...");
+                absoluteDestFilePath = generateAbsoluteDestPath(storedEntityMetadata);
+                log.info("SLUBStoragePlugin.storeEntity(), generated path=" + absoluteDestFilePath.filestring());
+            }
+        }
+        boolean isCopyFileNeeded = !checkFixityAbs(storedEntityMetadata.getFixities(), absoluteDestFilePath);
+        if (isCopyFileNeeded) {
+            log.info("SLUBStoragePlugin.storeEntity(), copyfile needed for path=" + absoluteDestFilePath.filestring());
+            if (canHandleSourcePath(storedEntityMetadata.getCurrentFilePath())) {
+                log.info("SLUBStoragePlugin.storeEntity() absolute_destFilePath canhandle sourcepath");
                 if (is != null) {
                     is.close();
                 }
                 copyStream(storedEntityMetadata, absoluteDestFilePath);
                 //log.debug("SLUBStoragePlugin.storeEntity() try copy (copyStream(storedEntityMetadata, '" + absolute_destFilePath + "')) was successfull");
-            }
-            else
-            {
-                //log.debug("SLUBStoragePlugin.storeEntity() Cannot handle source path: " + storedEntityMetadata.getCurrentFilePath());
-                if (is == null)
-                {
+            } else {
+                log.info("SLUBStoragePlugin.storeEntity() Cannot handle source path: " + storedEntityMetadata.getCurrentFilePath());
+                if (is == null) {
                     log.warn("SLUBStoragePlugin.storeEntity() InputStream is null");
                     return null;
                 }
-                try (OutputStream output = java.nio.file.Files.newOutputStream( Paths.get( absoluteDestFilePath.filestring)))
+                try (OutputStream output = java.nio.file.Files.newOutputStream( Paths.get( absoluteDestFilePath.filestring())))
                 {
                     var blocksize = getBlockSize();
                     long starttime = System.currentTimeMillis();
                     IOUtil.copy(is, output, blocksize);
                     long endtime = System.currentTimeMillis();
-                    log.info("SLUBStoragePlugin.storeEntity() try copy (IOUtil.copy(is, '"+absoluteDestFilePath+"', "+blocksize+") was successfull (" + throughput(starttime, endtime, absoluteDestFilePath)+ ")" );
+                    log.info("SLUBStoragePlugin.storeEntity() try copy (IOUtil.copy(is, '"+absoluteDestFilePath.filestring()+"', "+blocksize+") was successfull (" + throughput(starttime, endtime, absoluteDestFilePath)+ ")" );
                 }
             }
-            if (!checkFixity(storedEntityMetadata.getFixities(), storedEntityIdentifier)) {
-                log.warn("SLUBStoragePlugin.storeEntity() called checkFixity(fixities, '"+storedEntityIdentifier+"') failed");
+            if (!checkFixityAbs(storedEntityMetadata.getFixities(), absoluteDestFilePath)) {
+                log.warn("SLUBStoragePlugin.storeEntity() called checkFixity(fixities, '"+absoluteDestFilePath+"') failed");
                 return null;
             }
+        } else {
+            log.info("SLUBStoragePlugin.storeEntity(), copyfile NOT needed for path=" + absoluteDestFilePath.filestring());
         }
+        String storedEntityIdentifier = relativeFromStoreEntityMetadata(storedEntityMetadata);
         //log.debug("SLUBStoragePlugin.storeEntity() storedEntityIdentifier (2)='" + storedEntityIdentifier + "'");
         return storedEntityIdentifier;
     }
 
+    private AbsolutePath generateAbsoluteDestPath(StoredEntityMetaData storedEntityMetadata) throws IOException {
+        AbsolutePath absoluteDestFilePath;
+        String relativeDirectoryPath = getStreamRelativePath(storedEntityMetadata);
+        String fileName = createFileName(storedEntityMetadata);
+        File destFile = getStreamDirectory(relativeDirectoryPath, fileName);
+        log.info("generateAbsoluteDestPath, relativeDir=" + relativeDirectoryPath + " filename=" + fileName + " absolute=" + destFile.getAbsolutePath());
+        absoluteDestFilePath = new AbsolutePath(destFile.getAbsolutePath());
+        return absoluteDestFilePath;
+    }
+
     /**
      * copyFile, specialised function derived from FileUtil.copyFile using improved filecopy
      * @param source
@@ -505,19 +560,19 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
         if (!source.toLowerCase().trim().startsWith("http")) { /* simpleFilecopy, see https://www.digitalocean.com/community/tutorials/java-copy-file */
             try (
                     FileChannel sourceChannel = new FileInputStream(source).getChannel();
-                    FileChannel destChannel = new FileOutputStream(destination.filestring).getChannel()
+                    FileChannel destChannel = new FileOutputStream(destination.filestring()).getChannel()
             ) {
                 destChannel.transferFrom(sourceChannel, 0, sourceChannel.size());
             }
         } else {
             InputStream input = FileTransferUtil.getUrlContent(source);
-            FileOutputStream output = new FileOutputStream(destination.filestring);
+            FileOutputStream output = new FileOutputStream(destination.filestring());
             IOUtil.copy(input, output, getBlockSize());
             IOUtil.shutdownStream(input);
             IOUtil.shutdownStream(output);
         }
         long endtime = System.currentTimeMillis();
-        log.info("SLUBStoragePlugin.copyFile (" + source + ", " + destination.filestring + ") was successfull (" + throughput(starttime, endtime, destination) + ")");
+        log.info("SLUBStoragePlugin.copyFile (" + source + ", " + destination.filestring() + ") was successfull (" + throughput(starttime, endtime, destination) + ")");
     }
     protected void copyStream(StoredEntityMetaData storedEntityMetadata, AbsolutePath absoluteDestPath)
             throws IOException
@@ -528,11 +583,11 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
         //log.debug("SLUBStoragePlugin.copyStream() destPath='" + destPath + "'");
         //log.debug("SLUBStoragePlugin.copyStream() srcPath='" + srcPath + "'");
         //log.debug("SLUBStoragePlugin.copyStream() filesHandlingMethod='" + filesHandlingMethod + "'");
-        String pid = storedEntityMetadata.getEntityPid();
+        //String pid = storedEntityMetadata.getEntityPid();
         //log.debug("SLUBStoragePlugin.copyStream() pid='" + pid + "'");
-        String iePid = storedEntityMetadata.getIePid();
+        //String iePid = storedEntityMetadata.getIePid();
         //log.debug("SLUBStoragePlugin.copyStream() iePid='" + iePid + "'");
-        String attr = "('"+srcPath+"','" + absoluteDestPath.filestring + "')";
+        String attr = "('"+srcPath+"','" + absoluteDestPath.filestring() + "')";
         if ("copy".equalsIgnoreCase(filesHandlingMethod)) {
             // FileUtil.copyFile(srcPath, destPath);
             copyFile(srcPath, absoluteDestPath);
@@ -541,16 +596,16 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
         } else if ("move".equalsIgnoreCase(filesHandlingMethod)) {
             File canonicalSrcFile = getCanonicalFile(srcPath);
             assert canonicalSrcFile != null;
-            FileUtil.moveFile(canonicalSrcFile, new File(absoluteDestPath.filestring));
+            FileUtil.moveFile(canonicalSrcFile, new File(absoluteDestPath.filestring()));
             saveAbsoluteDestPathsTmpFile(storedEntityMetadata, absoluteDestPath);
             log.info("SLUBStoragePlugin.copyStream(), move"+attr+" was successful");
         }
         else if ("soft_link".equalsIgnoreCase(filesHandlingMethod)) {
-            softLink(srcPath, absoluteDestPath.filestring);
+            softLink(srcPath, absoluteDestPath.filestring());
             log.info("SLUBStoragePlugin.copyStream(), softlink"+attr+" was successful");
         }
         else if ("hard_link".equalsIgnoreCase(filesHandlingMethod)) {
-            hardLink(srcPath, absoluteDestPath.filestring);
+            hardLink(srcPath, absoluteDestPath.filestring());
             log.info("SLUBStoragePlugin.copyStream(), hardlink"+attr+" was successful");
         }
         else {
@@ -559,17 +614,6 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
             throw new IOException(msg);
         }
     }
-    protected AbsolutePath getAbsolutePathInDescIfExists(StoredEntityMetaData storedEntityMetadata) throws IOException {
-        log.info("SLUBStoragePlugin.getFilePathInDescIfExists()");
-        if (storedEntityMetadata.getIePid() == null) {
-            return null;
-        }
-        return loadAbsoluteDestPathsTmpFile(storedEntityMetadata);
-        //log.debug("SLUBStoragePlugin.getFilePathInDescIfExists() existsDescPath='" + existsDescPath + "'");
-
-    }
-
-
 
     /** copied from NFS Storage Plugin, enhanced with debugging info, {@inheritDoc} */
     private boolean canHandleSourcePath(String srcPath) {
@@ -618,30 +662,26 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
         }
         return null;
     }
+    private String relativeFromStoreEntityMetadata (StoredEntityMetaData storedEntityMetadata) throws IOException {
+        String fileName = createFileName(storedEntityMetadata);
+        String relativeDirectoryPath = getStreamRelativePath(storedEntityMetadata);
+        String relativePath = relativeDirectoryPath + File.separator + fileName;
+        contractAssertIsRelativePath(relativePath);
+        return relativePath;
+    }
 
     /** copied from NFS Storage Plugin, enhanced with debugging info, {@inheritDoc} */
     private Map<String, String> getStoreEntityIdentifier(StoredEntityMetaData storedEntityMetadata, AbsolutePath absoluteDestFilePath) throws IOException {
-        log.info("SLUBStoragePlugin.getStoreEntityIdentifier() destFilePath='" + absoluteDestFilePath +"'");
-        Map<String, String> paths = new HashMap<>();
-        //log.debug("(1) storedEntityMetadata is null?" + (null == storedEntityMetadata));
-        String fileName = createFileName(storedEntityMetadata);
-        //log.debug("fileName='" + fileName + "'");
-        //log.debug("(2) storedEntityMetadata is null?" + (null == storedEntityMetadata));
-        String relativeDirectoryPath = getStreamRelativePath(storedEntityMetadata);
-        //log.debug("relativeDirectoryPath='" + relativeDirectoryPath + "'");
-        if (absoluteDestFilePath == null)
-        {
-            File destFile = getStreamDirectory(relativeDirectoryPath, fileName);
-            absoluteDestFilePath = new AbsolutePath(destFile.getAbsolutePath());
-        }
+        log.info("SLUBStoragePlugin.getStoreEntityIdentifier() destFilePath='" + absoluteDestFilePath.filestring() +"'");
         //log.debug("destFilePath (2)='" + destFilePath + "'");
-        paths.put("destFilePath", absoluteDestFilePath.filestring);
-        String relativePath = relativeDirectoryPath + File.separator + fileName;
+        Map<String, String> paths = new HashMap<>();
+        paths.put("destFilePath", absoluteDestFilePath.filestring());
+        String relativePath = relativeFromStoreEntityMetadata(storedEntityMetadata);
         contractAssertIsRelativePath(relativePath);
         paths.put("relativeDirectoryPath", relativePath);
         log.info(
                 "SLUBStoragePlugin.getStoreEntityIdentifier() stored:"
-                + " destFilePath='" + absoluteDestFilePath + "'"
+                + " destFilePath='" + absoluteDestFilePath.filestring() + "'"
                 + " relativeDirectoryPath='" + relativePath + "'"
         );
         return paths;
@@ -649,7 +689,7 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
     /** copied from NFS Storage Plugin, enhanced with debugging info,
      * this combines full file path and creates parent directories if needed  {@inheritDoc}
      */
-    File getStreamDirectory(String path, String fileName) {
+     File getStreamDirectory(String path, String fileName) {
         log.info("SLUBStoragePlugin.getStreamDirectory path='" + path + "' fileName='" + fileName + "'");
         File newDir = new File(getDirRoot() + File.separator + path);
         //log.debug("SLUBStoragePlugin.getStreamDirectory newDir.getAbsolutePath()=" + newDir.getAbsolutePath());
@@ -715,7 +755,7 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
         try {
             d = sdf.parse(datestring);
         } catch (ParseException e) {
-            throw new IOException("Could not parse datestring from creation date=" + datestring + ", which is base for relative IE path, " + e);
+            throw new IOException("Could not parse datestring from creation date=" + datestring + ", which is base for relative IE path. ", e);
         }
         date.setTime(d);
         //log.debug("SLUBStoragePlugin.getStreamRelativePath creation Date read=" + datestring + " parsed=" + date);
@@ -750,18 +790,18 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
      * @param absolutePath
      */
     private void saveAbsoluteDestPathsTmpFile(StoredEntityMetaData storedEntityMetadata, AbsolutePath absolutePath) {
-        log.info("SLUBStoragePlugin.saveDestPathsTmpFile()");
+        log.info("SLUBStoragePlugin.saveAbsoluteDestPathsTmpFile()");
         String tmpFilePath = getTempStorageDirectory(false) + "destPath";
-        //log.debug("SLUBStoragePlugin.saveDestPathsTmpFile tmpFilePath='" + tmpFilePath + "'");
+        log.info("SLUBStoragePlugin.saveAbsoluteDestPathsTmpFile tmpFilePath='" + tmpFilePath + "'");
         File destPathDir = new File(getTempStorageDirectory(false) + "destPath" + File.separator);
         //log.debug("SLUBStoragePlugin.saveDestPathsTmpFile destPathDir='" + destPathDir + "'");
         if (!destPathDir.exists()) {
             boolean res = destPathDir.mkdirs();
             if (!res) {
-                log.error("SLUBStoragePlugin.saveDestPathsTmpFile() destPathdir='" + destPathDir + "' could not be created");
+                log.error("SLUBStoragePlugin.saveAbsoluteDestPathsTmpFile() destPathdir='" + destPathDir + "' could not be created");
             }
         }
-        StorageUtil.saveDestPathToTmpFile(storedEntityMetadata.getIePid(), tmpFilePath, storedEntityMetadata.getEntityPid(), absolutePath.filestring);
+        StorageUtil.saveDestPathToTmpFile(storedEntityMetadata.getIePid(), tmpFilePath, storedEntityMetadata.getEntityPid(), absolutePath.filestring());
     }
 
     /**
@@ -771,7 +811,11 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
      */
     private AbsolutePath loadAbsoluteDestPathsTmpFile(StoredEntityMetaData storedEntityMetadata) throws IOException {
         String tmpFilePath = getTempStorageDirectory(false) + "destPath";
+        log.info("SLUBStoragePlugin.loadAbsoluteDestPathsTmpFile tmpFilePath='" + tmpFilePath + "'");
         String absolutePath = StorageUtil.readDestPathFromTmpFile(storedEntityMetadata.getIePid(), tmpFilePath, storedEntityMetadata.getEntityPid());
+        if (null == absolutePath) {
+            throw new IOException("no destpath read from tmpfilePath '"+tmpFilePath+"' and IEPID="+storedEntityMetadata.getIePid() + " and PID="+storedEntityMetadata.getEntityPid() + ", got null");
+        }
         return new AbsolutePath(absolutePath);
     }
 }
-- 
GitLab