From 9fc0e3d33d181762c9da80c26c836d25ae713388 Mon Sep 17 00:00:00 2001 From: Andreas Romeyke <andreas.romeyke@slub-dresden.de> Date: Tue, 21 Oct 2014 14:53:01 +0000 Subject: [PATCH] - works with Rosetta 4.0 again (using stuff from nfsstorage plugin by ExLibris), needs more code cleanup --- .idea/workspace.xml | 116 +++-- PLUGIN-INF/metadata_SLUBStoragepPlugin.xml | 4 +- .../plugin/storage/nfs/SLUBStoragePlugin.java | 418 ++++++++++-------- 3 files changed, 322 insertions(+), 216 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index fbda5a0..a0e8f88 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -84,26 +84,54 @@ <file leaf-file-name="SLUBStoragePlugin.java" pinned="false" current="true" current-in-tab="true"> <entry file="file://$PROJECT_DIR$/java/org/slub/rosetta/dps/repository/plugin/storage/nfs/SLUBStoragePlugin.java"> <provider selected="true" editor-type-id="text-editor"> - <state vertical-scroll-proportion="0.6167883" vertical-offset="6457" max-vertical-offset="7005"> - <caret line="453" column="5" selection-start-line="453" selection-start-column="5" selection-end-line="453" selection-end-column="5" /> + <state vertical-scroll-proportion="0.33205375" vertical-offset="5302" max-vertical-offset="8025"> + <caret line="365" column="42" selection-start-line="365" selection-start-column="42" selection-end-line="365" selection-end-column="42" /> <folding> - <element signature="e#0#19071#0" expanded="true" /> + <element signature="e#0#24417#0" expanded="true" /> <element signature="imports" expanded="true" /> - <element signature="e#2675#2676#0" expanded="true" /> - <element signature="e#2727#2728#0" expanded="true" /> - <element signature="e#3607#3608#0" expanded="true" /> - <element signature="e#3669#3670#0" expanded="true" /> - <element signature="e#18552#18568#0" expanded="true" /> + <element signature="e#3017#3018#0" expanded="true" /> + <element signature="e#3075#3076#0" expanded="true" /> + <element signature="e#15717#15733#0" expanded="true" /> </folding> </state> </provider> </entry> </file> + <file leaf-file-name="StorageUtil.class" pinned="false" current="false" current-in-tab="false"> + <entry file="jar:///exlibris/dps/d4_1/system.dir/dps-sdk-4.0.0/lib/dps-sdk-4.0.0.jar!/com/exlibris/core/sdk/storage/handler/StorageUtil.class"> + <provider selected="true" editor-type-id="text-editor"> + <state vertical-scroll-proportion="-3.0" vertical-offset="0" max-vertical-offset="465"> + <caret line="6" column="13" selection-start-line="6" selection-start-column="13" selection-end-line="6" selection-end-column="13" /> + <folding /> + </state> + </provider> + </entry> + </file> + <file leaf-file-name="StoredEntityMetaData.class" pinned="false" current="false" current-in-tab="false"> + <entry file="jar:///exlibris/dps/d4_1/system.dir/dps-sdk-4.0.0/lib/dps-sdk-4.0.0.jar!/com/exlibris/core/sdk/storage/containers/StoredEntityMetaData.class"> + <provider selected="true" editor-type-id="text-editor"> + <state vertical-scroll-proportion="-7.16" vertical-offset="466" max-vertical-offset="1290"> + <caret line="44" column="56" selection-start-line="44" selection-start-column="56" selection-end-line="44" selection-end-column="56" /> + <folding /> + </state> + </provider> + </entry> + </file> + <file leaf-file-name="AbstractStorageHandler.class" pinned="false" current="false" current-in-tab="false"> + <entry file="jar:///exlibris/dps/d4_1/system.dir/dps-sdk-4.0.0/lib/dps-sdk-4.0.0.jar!/com/exlibris/core/sdk/storage/handler/AbstractStorageHandler.class"> + <provider selected="true" editor-type-id="text-editor"> + <state vertical-scroll-proportion="-3.0" vertical-offset="0" max-vertical-offset="720"> + <caret line="6" column="22" selection-start-line="6" selection-start-column="22" selection-end-line="6" selection-end-column="22" /> + <folding /> + </state> + </provider> + </entry> + </file> <file leaf-file-name="NFSStoragePlugin.java" pinned="false" current="false" current-in-tab="false"> <entry file="file://$PROJECT_DIR$/java/org/slub/rosetta/dps/repository/plugin/storage/nfs/NFSStoragePlugin.java"> <provider selected="true" editor-type-id="text-editor"> - <state vertical-scroll-proportion="-12.555555" vertical-offset="2586" max-vertical-offset="6885"> - <caret line="195" column="0" selection-start-line="185" selection-start-column="2" selection-end-line="195" selection-end-column="0" /> + <state vertical-scroll-proportion="102.85185" vertical-offset="6362" max-vertical-offset="6885"> + <caret line="239" column="38" selection-start-line="239" selection-start-column="38" selection-end-line="239" selection-end-column="38" /> <folding> <element signature="imports" expanded="true" /> <element signature="e#12505#12506#0" expanded="true" /> @@ -132,8 +160,8 @@ <treeState /> </component> <component name="ProjectFrameBounds"> - <option name="x" value="88" /> - <option name="y" value="68" /> + <option name="x" value="92" /> + <option name="y" value="93" /> <option name="width" value="1594" /> <option name="height" value="1000" /> </component> @@ -372,14 +400,14 @@ </todo-panel> </component> <component name="ToolWindowManager"> - <frame x="88" y="68" width="1594" height="1000" extended-state="0" /> - <editor active="true" /> + <frame x="92" y="93" width="1594" height="1000" extended-state="0" /> + <editor active="false" /> <layout> <window_info id="Changes" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.32954547" sideWeight="0.5" order="12" side_tool="false" content_ui="tabs" /> <window_info id="Problems" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.32954547" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" /> <window_info id="Palette" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" /> <window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.32954547" sideWeight="0.5" order="8" side_tool="false" content_ui="tabs" /> - <window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" /> + <window_info id="Find" active="true" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.32954547" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" /> <window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" /> <window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" /> <window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="9" side_tool="true" content_ui="tabs" /> @@ -392,7 +420,7 @@ <window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="SLIDING" type="SLIDING" visible="false" weight="0.4" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" /> <window_info id="Application Servers" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="11" side_tool="false" content_ui="tabs" /> <window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.21826425" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" /> - <window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.32954547" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" /> + <window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.32954547" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" /> <window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" /> <window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" /> <window_info id="Module Dependencies" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.06282383" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" /> @@ -429,13 +457,11 @@ <state vertical-scroll-proportion="0.0" vertical-offset="0" max-vertical-offset="2775"> <caret line="23" column="0" selection-start-line="23" selection-start-column="0" selection-end-line="23" selection-end-column="0" /> <folding> - <element signature="e#0#19071#0" expanded="true" /> + <element signature="e#0#24417#0" expanded="true" /> <element signature="imports" expanded="true" /> - <element signature="e#2675#2676#0" expanded="true" /> - <element signature="e#2727#2728#0" expanded="true" /> - <element signature="e#3607#3608#0" expanded="true" /> - <element signature="e#3669#3670#0" expanded="true" /> - <element signature="e#18552#18568#0" expanded="true" /> + <element signature="e#3017#3018#0" expanded="true" /> + <element signature="e#3075#3076#0" expanded="true" /> + <element signature="e#15717#15733#0" expanded="true" /> </folding> </state> </provider> @@ -457,29 +483,43 @@ <state vertical-scroll-proportion="0.0" vertical-offset="675" max-vertical-offset="2370"> <caret line="45" column="2" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" /> <folding> - <element signature="e#0#19071#0" expanded="true" /> + <element signature="e#0#24417#0" expanded="true" /> <element signature="imports" expanded="true" /> - <element signature="e#2675#2676#0" expanded="true" /> - <element signature="e#2727#2728#0" expanded="true" /> - <element signature="e#3607#3608#0" expanded="true" /> - <element signature="e#3669#3670#0" expanded="true" /> - <element signature="e#18552#18568#0" expanded="true" /> + <element signature="e#3017#3018#0" expanded="true" /> + <element signature="e#3075#3076#0" expanded="true" /> + <element signature="e#15717#15733#0" expanded="true" /> </folding> </state> </provider> </entry> + <entry file="jar:///exlibris/dps/d4_1/system.dir/dps-sdk-4.0.0/lib/dps-sdk-4.0.0.jar!/com/exlibris/core/sdk/storage/containers/StoredEntityMetaData.class"> + <provider selected="true" editor-type-id="text-editor"> + <state vertical-scroll-proportion="-7.16" vertical-offset="466" max-vertical-offset="1290"> + <caret line="44" column="56" selection-start-line="44" selection-start-column="56" selection-end-line="44" selection-end-column="56" /> + <folding /> + </state> + </provider> + </entry> <entry file="jar:///exlibris/dps/d4_1/system.dir/dps-sdk-4.0.0/lib/dps-sdk-4.0.0.jar!/com/exlibris/core/sdk/storage/handler/AbstractStorageHandler.class"> <provider selected="true" editor-type-id="text-editor"> - <state vertical-scroll-proportion="0.14285715" vertical-offset="0" max-vertical-offset="720"> + <state vertical-scroll-proportion="-3.0" vertical-offset="0" max-vertical-offset="720"> <caret line="6" column="22" selection-start-line="6" selection-start-column="22" selection-end-line="6" selection-end-column="22" /> <folding /> </state> </provider> </entry> + <entry file="jar:///exlibris/dps/d4_1/system.dir/dps-sdk-4.0.0/lib/dps-sdk-4.0.0.jar!/com/exlibris/core/sdk/storage/handler/StorageUtil.class"> + <provider selected="true" editor-type-id="text-editor"> + <state vertical-scroll-proportion="-3.0" vertical-offset="0" max-vertical-offset="465"> + <caret line="6" column="13" selection-start-line="6" selection-start-column="13" selection-end-line="6" selection-end-column="13" /> + <folding /> + </state> + </provider> + </entry> <entry file="file://$PROJECT_DIR$/java/org/slub/rosetta/dps/repository/plugin/storage/nfs/NFSStoragePlugin.java"> <provider selected="true" editor-type-id="text-editor"> - <state vertical-scroll-proportion="-12.555555" vertical-offset="2586" max-vertical-offset="6885"> - <caret line="195" column="0" selection-start-line="185" selection-start-column="2" selection-end-line="195" selection-end-column="0" /> + <state vertical-scroll-proportion="102.85185" vertical-offset="6362" max-vertical-offset="6885"> + <caret line="239" column="38" selection-start-line="239" selection-start-column="38" selection-end-line="239" selection-end-column="38" /> <folding> <element signature="imports" expanded="true" /> <element signature="e#12505#12506#0" expanded="true" /> @@ -490,16 +530,14 @@ </entry> <entry file="file://$PROJECT_DIR$/java/org/slub/rosetta/dps/repository/plugin/storage/nfs/SLUBStoragePlugin.java"> <provider selected="true" editor-type-id="text-editor"> - <state vertical-scroll-proportion="0.6167883" vertical-offset="6457" max-vertical-offset="7005"> - <caret line="453" column="5" selection-start-line="453" selection-start-column="5" selection-end-line="453" selection-end-column="5" /> + <state vertical-scroll-proportion="0.33205375" vertical-offset="5302" max-vertical-offset="8025"> + <caret line="365" column="42" selection-start-line="365" selection-start-column="42" selection-end-line="365" selection-end-column="42" /> <folding> - <element signature="e#0#19071#0" expanded="true" /> + <element signature="e#0#24417#0" expanded="true" /> <element signature="imports" expanded="true" /> - <element signature="e#2675#2676#0" expanded="true" /> - <element signature="e#2727#2728#0" expanded="true" /> - <element signature="e#3607#3608#0" expanded="true" /> - <element signature="e#3669#3670#0" expanded="true" /> - <element signature="e#18552#18568#0" expanded="true" /> + <element signature="e#3017#3018#0" expanded="true" /> + <element signature="e#3075#3076#0" expanded="true" /> + <element signature="e#15717#15733#0" expanded="true" /> </folding> </state> </provider> diff --git a/PLUGIN-INF/metadata_SLUBStoragepPlugin.xml b/PLUGIN-INF/metadata_SLUBStoragepPlugin.xml index 0b4f817..21261c8 100644 --- a/PLUGIN-INF/metadata_SLUBStoragepPlugin.xml +++ b/PLUGIN-INF/metadata_SLUBStoragepPlugin.xml @@ -6,7 +6,7 @@ <fr:x_form xmlns:fr="http://com/exlibris/digitool/common/forms/xmlbeans"> <form_name>SLUBStoragePlugin_Params</form_name> <description>SLUBTreeStoragePlugin_parameters_form</description> - <version>0.1</version> + <version>0.2</version> <grid_x>1</grid_x> <md_format>1</md_format> <x_fields> @@ -70,7 +70,7 @@ </fr:x_form> </pl:initParameters> <pl:description>SLUB Storage Plugin</pl:description> - <pl:version>1.6</pl:version> + <pl:version>2.4</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 8a4a744..a12b77c 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 @@ -40,7 +40,7 @@ import java.util.*; /** * SLUBStoragePlugin * writes all IEs, files etc. into the same directory under yyyy/mm/dd/IEpid/ - * + * * HINT: this plugin is *only* useful to store AIPs (IEs + files) in * permanent storage. Otherwise (e.g in the case of SIPs) it can't * detect the IE-PID and will report an error. @@ -58,56 +58,28 @@ import java.util.*; * @ see com.exlibris.dps.repository.plugin.storage.nfs.NFSStoragePlugin */ public class SLUBStoragePlugin extends AbstractStorageHandler { - private static final String DIR_ROOT = "DIR_ROOT"; /** {@inheritDoc} */ - private static final ExLogger log = ExLogger.getExLogger(SLUBStoragePlugin.class); - - public SLUBStoragePlugin() { - log.info("SLUBStoragePlugin instantiated"); - } + private static final ExLogger log = ExLogger.getExLogger(SLUBStoragePlugin.class); + private static final String DIR_PREFIX = "DIR_PREFIX"; + private static final String DIR_ROOT = "DIR_ROOT"; /** {@inheritDoc} */ + private static final String FILE_PER_DIR = "FILE_PER_DIR"; + private static final String FILES_HANDLING_METHOD = "FILES_HANDLING_METHOD"; + private final String RELATIVE_DIRECTORY_PATH = "relativeDirectoryPath"; + private final String DEST_FILE_PATH = "destFilePath"; - public byte[] retrieveEntityByRange(String storedEntityIdentifier, long start, long end) - throws Exception - { - byte[] bytes = new byte[(int)(end - start + 1L)]; - RandomAccessFile file = null; - try - { - file = new RandomAccessFile((String)this.parameters.get("DIR_ROOT") + storedEntityIdentifier, "r"); - file.seek(start); - file.readFully(bytes, 0, (int)(end - start + 1L)); - return bytes; - } - finally - { - if (file != null) { - try - { - file.close(); - } - catch (Exception e) - { - log.warn("Failed closing file", e.getMessage()); - } - } - } + public SLUBStoragePlugin() { + log.info("SLUBStoragePlugin instantiated"); } - public String getLocalFilePath(String storedEntityIdentifier) - { - return getFullFilePath(storedEntityIdentifier); - } - public String getFullFilePath(String storedEntityIdentifier) - { - return (String)this.parameters.get("DIR_ROOT") + storedEntityIdentifier; - } public boolean checkFixity(List<Fixity> fixities, String storedEntityIdentifier) throws Exception { + log.info("SLUBStoragePlugin.checkFixity()"); return checkFixity(fixities, storedEntityIdentifier, true); } public boolean checkFixity(List<Fixity> fixities, String storedEntityIdentifier, boolean isRelativePath) throws Exception { + log.info("SLUBStoragePlugin.checkFixity() storedEntityIdentifier='" + storedEntityIdentifier + "' isRelativePath=" + isRelativePath); boolean result = true; if (fixities != null) { @@ -167,19 +139,10 @@ public class SLUBStoragePlugin extends AbstractStorageHandler { } return result; } - private int getChecksummerAlgorithmIndex(String algorithm) - { - try - { - Fixity.FixityAlgorithm fixityAlgorithm = Fixity.FixityAlgorithm.valueOf(algorithm); - return fixityAlgorithm.ordinal(); - } - catch (Exception e) {} - return -1; - } public boolean deleteEntity(String storedEntityIdentifier) { + log.info("SLUBStoragePlugin.deleteEntity()"); File file = new File((String)this.parameters.get("DIR_ROOT") + storedEntityIdentifier); try { @@ -187,25 +150,68 @@ public class SLUBStoragePlugin extends AbstractStorageHandler { } catch (Exception e) { - log.warn("failed to delete entity with path: " + file.getPath(), e.getMessage()); + log.warn("SLUBStoragePlugin failed to delete entity with path: " + file.getPath(), e.getMessage()); } return true; } + + + public String getLocalFilePath(String storedEntityIdentifier) + { + log.info("SLUBStoragePlugin.getLocalFilePath() with '" + storedEntityIdentifier + "'"); + return getFullFilePath(storedEntityIdentifier); + } + public String getFullFilePath(String storedEntityIdentifier) + { + log.info("SLUBStoragePlugin.getFullFilePath() with '" + storedEntityIdentifier + "'"); + return (String)this.parameters.get("DIR_ROOT") + storedEntityIdentifier; + } + public InputStream retrieveEntity(String storedEntityIdentifier) throws IOException { + log.info("SLUBStoragePlugin.retrieveEntity() with '" + storedEntityIdentifier + "'"); return retrieveEntity(storedEntityIdentifier, true); } public InputStream retrieveEntity(String storedEntityIdentifier, boolean isRelative) throws IOException { + log.info("SLUBStoragePlugin.retrieveEntity() with '" + storedEntityIdentifier + "' isrelative=" + isRelative); return new FileInputStream((isRelative ? (String)this.parameters.get("DIR_ROOT") : "") + storedEntityIdentifier); } + public byte[] retrieveEntityByRange(String storedEntityIdentifier, long start, long end) + throws Exception + { + log.info("SLUBStoragePlugin.retrieveEntitybyRange() with '" + storedEntityIdentifier + "' start=" + start + "end=" + end); + byte[] bytes = new byte[(int)(end - start + 1L)]; + RandomAccessFile file = null; + try + { + file = new RandomAccessFile((String)this.parameters.get("DIR_ROOT") + storedEntityIdentifier, "r"); + file.seek(start); + file.readFully(bytes, 0, (int)(end - start + 1L)); + return bytes; + } + finally + { + if (file != null) { + try + { + file.close(); + } + catch (Exception e) + { + log.warn("Failed closing file", e.getMessage()); + } + } + } + } public String storeEntity(InputStream is, StoredEntityMetaData storedEntityMetadata) throws Exception { + log.info("SLUBStoragePlugin.storeEntity()"); String existsDescPath = getFilePathInDescIfExists(storedEntityMetadata); - + log.info("SLUBStoragePlugin.storeEntity() existsDescPath='" + existsDescPath +"'"); String destFilePath = null; boolean isCopyFileNeeded = true; @@ -214,13 +220,18 @@ public class SLUBStoragePlugin extends AbstractStorageHandler { destFilePath = existsDescPath; isCopyFileNeeded = !checkFixity(storedEntityMetadata.getFixities(), destFilePath, false); } + log.info("SLUBStoragePlugin.storeEntity() destFilePath='" + destFilePath +"'"); Map<String, String> paths = getStoreEntityIdentifier(storedEntityMetadata, destFilePath); String storedEntityIdentifier = (String)paths.get("relativeDirectoryPath"); + log.info("SLUBStoragePlugin.storeEntity() storedEntityIdentifier='" + storedEntityIdentifier +"'"); destFilePath = (String)paths.get("destFilePath"); + log.info("SLUBStoragePlugin.storeEntity() destFilePath (2)='" + destFilePath +"'"); + log.info("SLUBStoragePlugin.storeEntity() isCopyFileNeeded='" + isCopyFileNeeded +"'"); if (isCopyFileNeeded) { if (canHandleSourcePath(storedEntityMetadata.getCurrentFilePath())) { + log.info("SLUBStoragePlugin.storeEntity() destFilePath canhandle sourcepath"); if (is != null) { is.close(); } @@ -228,10 +239,10 @@ public class SLUBStoragePlugin extends AbstractStorageHandler { } else { - log.info("Cannot handle source path: " + storedEntityMetadata.getCurrentFilePath()); + log.info("SLUBStoragePlugin.storeEntity() Cannot handle source path: " + storedEntityMetadata.getCurrentFilePath()); if (is == null) { - log.warn("InputStream is null"); + log.warn("SLUBStoragePlugin.storeEntity() InputStream is null"); return null; } FileOutputStream output = null; @@ -239,6 +250,7 @@ public class SLUBStoragePlugin extends AbstractStorageHandler { { output = new FileOutputStream(new File(destFilePath)); IOUtil.copy(is, output); + log.info("SLUBStoragePlugin.storeEntity() try copy was successfull"); } finally { @@ -246,19 +258,26 @@ public class SLUBStoragePlugin extends AbstractStorageHandler { } } if (!checkFixity(storedEntityMetadata.getFixities(), storedEntityIdentifier)) { + log.info("SLUBStoragePlugin.storeEntity() checkFixity failed"); return null; } } + log.info("SLUBStoragePlugin.storeEntity() storedEntityIdentifier (2)='" + storedEntityIdentifier +"'"); return storedEntityIdentifier; } protected void copyStream(StoredEntityMetaData storedEntityMetadata, String destPath) throws IOException { + log.info("SLUBStoragePlugin.copyStream()"); String filesHandlingMethod = (String)this.parameters.get("FILES_HANDLING_METHOD"); String srcPath = storedEntityMetadata.getCurrentFilePath(); - + log.info("SLUBStoragePlugin.copyStream() destPath='" + destPath + "'"); + log.info("SLUBStoragePlugin.copyStream() srcPath='" + srcPath + "'"); + log.info("SLUBStoragePlugin.copyStream() filesHandlingMethod='" + filesHandlingMethod + "'"); String pid = storedEntityMetadata.getEntityPid(); + log.info("SLUBStoragePlugin.copyStream() pid='" + pid + "'"); String iePid = storedEntityMetadata.getIePid(); + log.info("SLUBStoragePlugin.copyStream() iePid='" + iePid + "'"); if ("move".equalsIgnoreCase(filesHandlingMethod)) { File canonicalSrcFile = getCanonicalFile(srcPath); @@ -279,22 +298,49 @@ public class SLUBStoragePlugin extends AbstractStorageHandler { saveDestPathsTmpFile(iePid, pid, destPath); } } - private void saveDestPathsTmpFile(String folder, String key, String path) + protected String getFilePathInDescIfExists(StoredEntityMetaData storedEntityMetadata) { - if (folder == null) { - return; - } + log.info("SLUBStoragePlugin.getFilePathInDescIfExists()"); String tmpFilePath = getTempStorageDirectory(false) + "destPath"; + if (storedEntityMetadata.getIePid() == null) { + return null; + } + String existsDescPath = StorageUtil.readDestPathFromTmpFile(storedEntityMetadata.getIePid(), tmpFilePath, storedEntityMetadata.getEntityPid()); + return existsDescPath; + } + /** copied from NFS Storage Plugin, enhanced with debugging info, {@inheritDoc} */ + private boolean canHandleSourcePath(String srcPath) { + log.info("SLUBStoragePlugin.canHandleSourcePath path=" + srcPath); + try { + File file = new File(srcPath); + return file.canRead(); + } + catch (Exception e) { + log.warn("SLUBStoragePlugin.canHandleSourcePath exception=" + e.getMessage()); + return false; + } + } - File destPathDir = new File(getTempStorageDirectory(false) + "destPath" + File.separator); - if (!destPathDir.exists()) { - destPathDir.mkdirs(); + private int getChecksummerAlgorithmIndex(String algorithm) + { + log.info("SLUBStoragePlugin.getChecksummerAlgorithm() algorithm='" + algorithm + "'"); + try + { + Fixity.FixityAlgorithm fixityAlgorithm = Fixity.FixityAlgorithm.valueOf(algorithm); + return fixityAlgorithm.ordinal(); } - StorageUtil.saveDestPathToTmpFile(folder, tmpFilePath, key, path); + catch (Exception e) {} + return -1; } + + + + + private File getCanonicalFile(String srcPath) { + log.info("SLUBStoragePlugin.getCanonicalFile() srcPath='"+ srcPath + "'"); String fileName = srcPath.split("\\" + File.separator)[(srcPath.split("\\" + File.separator).length - 1)]; File canonicalSrcDir = null; try @@ -308,9 +354,121 @@ public class SLUBStoragePlugin extends AbstractStorageHandler { return null; } + private String getNextDir(String fullPath) + { + log.info("SLUBStoragePlugin.getNextDir() fullPath='"+ fullPath + "'"); + + String[] dirs = fullPath.split("\\" + File.separator); + String dir = dirs[(dirs.length - 2)]; + log.info("SLUBStoragePlugin.getNextDir() dir='" + dir + "'"); + return dir; + } + private Map<String, String> getStoreEntityIdentifier(StoredEntityMetaData storedEntityMetadata, String destFilePath) throws Exception + { + log.info("SLUBStoragePlugin.getStoreEntityIdentifier()"); + log.info("destFilePath='" + destFilePath +"'"); + Map<String, String> paths = new HashMap<String, String>(); + log.info( "(1) storedEntityMetadata is null?" + (null == storedEntityMetadata)); + String fileName = createFileName(storedEntityMetadata); + log.info("fileName='"+fileName +"'"); + log.info( "(2) storedEntityMetadata is null?" + (null == storedEntityMetadata)); + String relativeDirectoryPath = getStreamRelativePath(storedEntityMetadata); + log.info("relativeDirectoryPath='"+relativeDirectoryPath +"'"); + if (destFilePath == null) + { + File destFile = getStreamDirectory(relativeDirectoryPath, fileName); + destFilePath = destFile.getAbsolutePath(); + } + log.info("destFilePath (2)='" + destFilePath +"'"); + paths.put("destFilePath", destFilePath); + // paths.put("relativeDirectoryPath", (relativeDirectoryPath + getNextDir(destFilePath) + File.separator + fileName)); + paths.put("relativeDirectoryPath", (relativeDirectoryPath + File.separator + fileName)); + return paths; + + } + /** copied from NFS Storage Plugin, enhanced with debugging info, + * this combines full file path and creates parent directories if needed {@inheritDoc} + */ + private File getStreamDirectory(String path, String fileName) { + log.info("SLUBStoragePlugin.getStreamDirectory path='" + path + "' fileName='" + fileName + "'"); + File newDir = new File(parameters.get(DIR_ROOT) + File.separator + path); + log.info("SLUBStoragePlugin.getStreamDirectory newDir.getAbsolutePath()=" + newDir.getAbsolutePath()); + boolean arecreated = newDir.mkdirs(); + log.info("SLUBStoragePlugin.getStreamDirectory newDir.mkdirs(), directories are created:" + arecreated); + return new File(newDir.getAbsolutePath() + File.separator + fileName); + } + /** prepare right path + * path should be of form yyyy/MM/dd/IE-PID/ + * we need to findout the associated dnx document (IE), + * get the creation date of the IE/SIP + * and get the IE PID of the associated IE. + * @param storedEntityMetaData StoredEntityMetaData + * @return calculated relative path as String + * returns the path as string + */ + private String getStreamRelativePath(StoredEntityMetaData storedEntityMetaData ) throws Exception { + log.info("SLUBStoragePlugin.getStreamRelativePath()"); + if ((null == storedEntityMetaData)) throw new AssertionError(); + log.info("SLUBStoragePlugin.getStreamRelativePath() assert fine"); + String relativeDirectoryPath = File.separator; + // get IE PID by calling IE-DNX record and search for ""internalIdentifierType" == "PID" + DnxDocument iedoc = storedEntityMetaData.getIeDnx(); + log.info("SLUBStoragePlugin.getStreamRelativePath() getIeDnx fine"); + if (null == iedoc) { + log.error ("SLUBStoragePlugin.getStreamRelativePath no iedoc found, do you use plugin for others than permanent data? You should not!"); + throw new Exception("error, no iedoc found, do you use plugin for others than permanent data? You should not!"); + } + StoredEntityMetaData.EntityType entityType = storedEntityMetaData.getEntityType(); + log.info("SLUBStoragePlugin.getStreamRelativePath() getEntityType fine"); + String entitytype = entityType.name(); + log.info("entitytype='" + entitytype + "'"); + DnxSection iesec = iedoc.getSectionById("internalIdentifier"); + if (null == iesec) { + log.error ("SLUBStoragePlugin.getStreamRelativePath no section in entity of type "+entitytype +" with 'internalIdentfier' in associated iedoc found, do you use plugin for others than permanent data? You should not!"); + throw new Exception("error, no section in entity of type "+entitytype +" with 'internalIdentfier' in associated iedoc found, do you use plugin for others than permanent data? You should not!"); + } + String iepid = null; + log.info ("SLUBStoragePlugin.getStreamRelativePath iesec="+iesec.toString() ); + List<DnxSectionRecord> records = iesec.getRecordList(); + for (DnxSectionRecord element : records) { + if (element.getKeyById("internalIdentifierType").getValue().equals("PID")) { + iepid = element.getKeyById("internalIdentifierValue").getValue(); // found IEPID + break; + } + } + // raise Exception if IEPID is null + if (null == iepid) { + log.error ("SLUBStoragePlugin.getStreamRelativePath iesec="+iesec.toString() ); + throw new Exception("error, could not get IEPID for storedEntityMetaData:"+storedEntityMetaData.toString() +" of type " + entitytype); + } + log.info("SLUBStoragePlugin.getStreamRelativePath iepid=" + iepid + " (entitytype="+ entitytype +")"); + // get creationDate of "objectCharacteristics" + String datestring = iedoc.getSectionKeyValue("objectCharacteristics", "creationDate"); + Calendar date = Calendar.getInstance(); + // date ist there stored in format (example): 2014-01-15 14:28:01 + SimpleDateFormat sdf; + sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + sdf.setLenient(false); /* if parse errors, do not guess about */ + Date d = sdf.parse(datestring); + date.setTime(d); + log.info("SLUBStoragePlugin.getStreamRelativePath creation Date read=" + datestring + " parsed=" + date.toString()); + // now create path in format /yyyy/MM/dd/IEPID/ + relativeDirectoryPath = relativeDirectoryPath + new SimpleDateFormat("yyyy").format(d); + relativeDirectoryPath = relativeDirectoryPath + File.separator; + relativeDirectoryPath = relativeDirectoryPath + new SimpleDateFormat("MM").format(d); + relativeDirectoryPath = relativeDirectoryPath + File.separator; + relativeDirectoryPath = relativeDirectoryPath + new SimpleDateFormat("dd").format(d); + relativeDirectoryPath = relativeDirectoryPath + File.separator; + relativeDirectoryPath = relativeDirectoryPath + iepid; + relativeDirectoryPath = relativeDirectoryPath + File.separator; + log.info("SLUBStoragePlugin.getStreamRelativePath relativeDirectoryPath=" + relativeDirectoryPath); + return relativeDirectoryPath; + } + private void hardLink(String srcPath, String destPath) throws IOException { + log.info("SLUBStoragePlugin.hardLink srcPath='" + srcPath + "' destPath='" + destPath + "'"); String command = "ln"; ExecExternalProcess proc = new ExecExternalProcess(); List<String> args = new LinkedList(); @@ -321,10 +479,28 @@ public class SLUBStoragePlugin extends AbstractStorageHandler { throw new IOException("ln " + srcPath + " " + destPath + " failed " + proc.getErrorStream() + proc.getInputStream()); } } - + private void saveDestPathsTmpFile(String folder, String key, String path) + { + log.info("SLUBStoragePlugin.saveDestPathsTmpFile()"); + log.info("SLUBStoragePlugin.saveDestPathsTmpFile folder='" + folder + "'"); + log.info("SLUBStoragePlugin.saveDestPathsTmpFile key='" + key + "'"); + log.info("SLUBStoragePlugin.saveDestPathsTmpFile path='" + path + "'"); + if (folder == null) { + return; + } + String tmpFilePath = getTempStorageDirectory(false) + "destPath"; + log.info("SLUBStoragePlugin.saveDestPathsTmpFile tmpFilePath='" + tmpFilePath + "'"); + File destPathDir = new File(getTempStorageDirectory(false) + "destPath" + File.separator); + log.info("SLUBStoragePlugin.saveDestPathsTmpFile destPathDir='" + destPathDir + "'"); + if (!destPathDir.exists()) { + destPathDir.mkdirs(); + } + StorageUtil.saveDestPathToTmpFile(folder, tmpFilePath, key, path); + } private void softLink(String srcPath, String destPath) throws IOException { + log.info("SLUBStoragePlugin.softLink srcPath='" + srcPath + "' destPath='" + destPath + "'"); File source = new File(srcPath); if (!source.exists()) { throw new IOException("File " + source + " does not exist"); @@ -341,121 +517,13 @@ public class SLUBStoragePlugin extends AbstractStorageHandler { } } - protected String getFilePathInDescIfExists(StoredEntityMetaData storedEntityMetadata) - { - String tmpFilePath = getTempStorageDirectory(false) + "destPath"; - if (storedEntityMetadata.getIePid() == null) { - return null; - } - String existsDescPath = StorageUtil.readDestPathFromTmpFile(storedEntityMetadata.getIePid(), tmpFilePath, storedEntityMetadata.getEntityPid()); - return existsDescPath; - } - /** prepare right path - * path should be of form yyyy/MM/dd/IE-PID/ - * we need to findout the associated dnx document (IE), - * get the creation date of the IE/SIP - * and get the IE PID of the associated IE. - * @param storedEntityMetaData StoredEntityMetaData - * @return calculated relative path as String - * returns the path as string - */ - private String getStreamRelativePath(StoredEntityMetaData storedEntityMetaData ) throws Exception { - log.info("SLUBStoragePlugin AAB"); - String relativeDirectoryPath = File.separator; - // get IE PID by calling IE-DNX record and search for ""internalIdentifierType" == "PID" - DnxDocument iedoc = storedEntityMetaData.getIeDnx(); - String entitytype = storedEntityMetaData.getEntityType().name(); - DnxSection iesec = iedoc.getSectionById("internalIdentifier"); - if (null == iesec) { - log.error ("SLUBStoragePlugin.getStreamRelativePath no section in entity of type "+entitytype +" with 'internalIdentfier' in associated iedoc found, do you use plugin for others than permanent data? You should not!"); - throw new Exception("error, no section in entity of type "+entitytype +" with 'internalIdentfier' in associated iedoc found, do you use plugin for others than permanent data? You should not!"); - } - String iepid = null; - log.info ("SLUBStoragePlugin.getStreamRelativePath iesec="+iesec.toString() ); - List<DnxSectionRecord> records = iesec.getRecordList(); - for (DnxSectionRecord element : records) { - if (element.getKeyById("internalIdentifierType").getValue().equals("PID")) { - iepid = element.getKeyById("internalIdentifierValue").getValue(); // found IEPID - break; - } - } - // raise Exception if IEPID is null - if (null == iepid) { - log.error ("SLUBStoragePlugin.getStreamRelativePath iesec="+iesec.toString() ); - throw new Exception("error, could not get IEPID for storedEntityMetaData:"+storedEntityMetaData.toString() +" of type " + entitytype); - } - log.info("SLUBStoragePlugin.getStreamRelativePath iepid=" + iepid + " (entitytype="+ entitytype +")"); - // get creationDate of "objectCharacteristics" - String datestring = iedoc.getSectionKeyValue("objectCharacteristics", "creationDate"); - Calendar date = Calendar.getInstance(); - // date ist there stored in format (example): 2014-01-15 14:28:01 - SimpleDateFormat sdf; - sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - sdf.setLenient(false); /* if parse errors, do not guess about */ - Date d = sdf.parse(datestring); - date.setTime(d); - log.info("SLUBStoragePlugin.getStreamRelativePath creation Date read=" + datestring + " parsed=" + date.toString()); - // now create path in format /yyyy/MM/dd/IEPID/ - relativeDirectoryPath = relativeDirectoryPath + new SimpleDateFormat("yyyy").format(d); - relativeDirectoryPath = relativeDirectoryPath + File.separator; - relativeDirectoryPath = relativeDirectoryPath + new SimpleDateFormat("MM").format(d); - relativeDirectoryPath = relativeDirectoryPath + File.separator; - relativeDirectoryPath = relativeDirectoryPath + new SimpleDateFormat("dd").format(d); - relativeDirectoryPath = relativeDirectoryPath + File.separator; - relativeDirectoryPath = relativeDirectoryPath + iepid; - relativeDirectoryPath = relativeDirectoryPath + File.separator; - log.info("SLUBStoragePlugin.getStreamRelativePath relativeDirectoryPath=" + relativeDirectoryPath); - return relativeDirectoryPath; - } - - /** copied from NFS Storage Plugin, enhanced with debugging info, - * this combines full file path and creates parent directories if needed {@inheritDoc} - */ - private File getStreamDirectory(String path, String fileName) { - File newDir = new File(parameters.get(DIR_ROOT) + File.separator + path); - log.info("SLUBStoragePlugin.getStreamDirectory path=" + path); - log.info("SLUBStoragePlugin.getStreamDirectory fileName=" + fileName); - log.info("SLUBStoragePlugin.getStreamDirectory newDir.getAbsolutePath()=" + newDir.getAbsolutePath()); - boolean arecreated = newDir.mkdirs(); - log.info("SLUBStoragePlugin.getStreamDirectory newDir.mkdirs(), directories are created:" + arecreated); - return new File(newDir.getAbsolutePath() + File.separator + fileName); - } - - /** copied from NFS Storage Plugin, enhanced with debugging info, {@inheritDoc} */ - private boolean canHandleSourcePath(String srcPath) { - log.info("SLUBStoragePlugin.canHandleSourcePath path=" + srcPath); - try { - File file = new File(srcPath); - return file.canRead(); - } - catch (Exception e) { - log.warn("SLUBStoragePlugin.canHandleSourcePath exception=" + e.getMessage()); - return false; - } - } -private String getNextDir(String fullPath) - { - String[] dirs = fullPath.split("\\" + File.separator); - return dirs[(dirs.length - 2)]; - } -private Map<String, String> getStoreEntityIdentifier(StoredEntityMetaData storedEntityMetadata, String destFilePath) throws Exception - { - Map<String, String> paths = new HashMap<String, String>(); - String fileName = createFileName(storedEntityMetadata); - String relativeDirectoryPath = getStreamRelativePath(storedEntityMetadata); - if (destFilePath == null) - { - File destFile = getStreamDirectory(relativeDirectoryPath, fileName); - destFilePath = destFile.getAbsolutePath(); - } - paths.put("destFilePath", destFilePath); - paths.put("relativeDirectoryPath", (relativeDirectoryPath + getNextDir(destFilePath) + File.separator + fileName)); - return paths; - } + + + } -- GitLab