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

- because Rosetta4.0 comes with massive changes on NFSStoragePlugin, we decided

to remove dependencies to this plugin, but use them as source for our variant.
parent ad6ee4f5
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="UTF-8"?>
<project version="4" />
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
<processorPath useClasspath="true" /> <processorPath useClasspath="true" />
</profile> </profile>
</annotationProcessing> </annotationProcessing>
<bytecodeTargetLevel target="1.6" />
</component> </component>
</project> </project>
<component name="CopyrightManager"> <component name="CopyrightManager">
<settings default=""> <settings default="" />
<module2copyright />
</settings>
</component> </component>
\ No newline at end of file
<component name="libraryTable">
<library name="NFSStoragePlugin">
<CLASSES>
<root url="jar:///exlibris/dps/d4_1/system.dir/bundled_plugins/NFSStoragePlugin.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="dps-sdk-3.2.2">
<CLASSES>
<root url="jar:///exlibris/dps/d4_1/system.dir/dps-sdk-3.2.2/lib/dps-sdk-3.2.2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="dps-sdk-4.0.0">
<CLASSES>
<root url="jar:///exlibris/dps/d4_1/system.dir/dps-sdk-4.0.0/lib/dps-sdk-4.0.0.jar!/" />
<root url="jar:///exlibris/dps/d4_1/system.dir/dps-sdk-4.0.0/dps-sdk-projects/dps-sdk-plugins/resources/lib/axis.jar!/" />
<root url="jar:///exlibris/dps/d4_1/system.dir/dps-sdk-4.0.0/dps-sdk-projects/dps-sdk-plugins/resources/lib/commons-httpclient-3.1.jar!/" />
<root url="jar:///exlibris/dps/d4_1/system.dir/dps-sdk-4.0.0/dps-sdk-projects/dps-sdk-plugins/resources/lib/commons-io-2.0.1.jar!/" />
<root url="jar:///exlibris/dps/d4_1/system.dir/dps-sdk-4.0.0/dps-sdk-projects/dps-sdk-plugins/resources/lib/commons-lang-2.6.jar!/" />
<root url="jar:///exlibris/dps/d4_1/system.dir/dps-sdk-4.0.0/dps-sdk-projects/dps-sdk-plugins/resources/lib/httpclient-4.1.2.jar!/" />
<root url="jar:///exlibris/dps/d4_1/system.dir/dps-sdk-4.0.0/dps-sdk-projects/dps-sdk-plugins/resources/lib/httpcore-4.1.2.jar!/" />
<root url="jar:///exlibris/dps/d4_1/system.dir/dps-sdk-4.0.0/dps-sdk-projects/dps-sdk-plugins/resources/lib/jackson-core-asl-1.5.2.jar!/" />
<root url="jar:///exlibris/dps/d4_1/system.dir/dps-sdk-4.0.0/dps-sdk-projects/dps-sdk-plugins/resources/lib/jhove-1.10.jar!/" />
<root url="jar:///exlibris/dps/d4_1/system.dir/dps-sdk-4.0.0/dps-sdk-projects/dps-sdk-plugins/resources/lib/jhove-handler-1.10.jar!/" />
<root url="jar:///exlibris/dps/d4_1/system.dir/dps-sdk-4.0.0/dps-sdk-projects/dps-sdk-plugins/resources/lib/jhove-module-1.10.jar!/" />
<root url="jar:///exlibris/dps/d4_1/system.dir/dps-sdk-4.0.0/dps-sdk-projects/dps-sdk-plugins/resources/lib/json-simple-1.1.jar!/" />
<root url="jar:///exlibris/dps/d4_1/system.dir/dps-sdk-4.0.0/dps-sdk-projects/dps-sdk-plugins/resources/lib/xmlbeans-2.3.0.jar!/" />
<root url="jar:///exlibris/dps/d4_1/system.dir/dps-sdk-4.0.0/dps-sdk-projects/dps-sdk-plugins/resources/lib/zip4j-1.3.2.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar:///exlibris/dps/d4_1/system.dir/dps-sdk-4.0.0/lib/dps-sdk-4.0.0-javadoc.jar!/" />
</JAVADOC>
<SOURCES />
</library>
</component>
\ No newline at end of file
This diff is collapsed.
...@@ -58,7 +58,7 @@ SLUBStoragePlugin.jar: $(OBJS) ...@@ -58,7 +58,7 @@ SLUBStoragePlugin.jar: $(OBJS)
@cp -r PLUGIN-INF/ build/ @cp -r PLUGIN-INF/ build/
@cp -r META-INF/ build/ @cp -r META-INF/ build/
@cd java; find ./ -name "*.class" -print -exec cp --parents -r \{\} $(PWD)/build \; ; cd .. @cd java; find ./ -name "*.class" -print -exec cp --parents -r \{\} $(PWD)/build \; ; cd ..
@cp /exlibris/dps/d4_1/system.dir/bundled_plugins/NFSStoragePlugin.jar build/ #@cp /exlibris/dps/d4_1/system.dir/bundled_plugins/NFSStoragePlugin.jar build/
#cd build; ${JAVAPATH}/jar xfz /exlibris/dps/d4_1/system.dir/bundled_plugins/NFSStoragePlugin.jar #cd build; ${JAVAPATH}/jar xfz /exlibris/dps/d4_1/system.dir/bundled_plugins/NFSStoragePlugin.jar
@cd build; ${JAVAPATH}/jar cfvM ../$@ ./* ; cd .. @cd build; ${JAVAPATH}/jar cfvM ../$@ ./* ; cd ..
......
...@@ -70,7 +70,7 @@ ...@@ -70,7 +70,7 @@
</fr:x_form> </fr:x_form>
</pl:initParameters> </pl:initParameters>
<pl:description>SLUB Storage Plugin</pl:description> <pl:description>SLUB Storage Plugin</pl:description>
<pl:version>1.2</pl:version> <pl:version>1.6</pl:version>
<pl:materialType>DIGITAL</pl:materialType> <pl:materialType>DIGITAL</pl:materialType>
<pl:module>Repository</pl:module> <pl:module>Repository</pl:module>
<pl:generalType>TASK</pl:generalType> <pl:generalType>TASK</pl:generalType>
......
...@@ -22,19 +22,20 @@ package org.slub.rosetta.dps.repository.plugin.storage.nfs; ...@@ -22,19 +22,20 @@ package org.slub.rosetta.dps.repository.plugin.storage.nfs;
import com.exlibris.core.infra.common.exceptions.logging.ExLogger; import com.exlibris.core.infra.common.exceptions.logging.ExLogger;
import com.exlibris.core.infra.common.util.IOUtil; import com.exlibris.core.infra.common.util.IOUtil;
import com.exlibris.core.infra.svc.api.scriptRunner.ExecExternalProcess;
import com.exlibris.core.sdk.storage.containers.StoredEntityMetaData; import com.exlibris.core.sdk.storage.containers.StoredEntityMetaData;
import com.exlibris.core.sdk.storage.handler.AbstractStorageHandler;
import com.exlibris.core.sdk.storage.handler.StorageUtil;
import com.exlibris.core.sdk.utils.FileUtil;
import com.exlibris.digitool.common.dnx.DnxDocument; import com.exlibris.digitool.common.dnx.DnxDocument;
import com.exlibris.digitool.common.dnx.DnxSection; import com.exlibris.digitool.common.dnx.DnxSection;
import com.exlibris.digitool.common.dnx.DnxSectionRecord; import com.exlibris.digitool.common.dnx.DnxSectionRecord;
import com.exlibris.dps.repository.plugin.storage.nfs.NFSStoragePlugin; import com.exlibris.digitool.common.storage.Fixity;
import com.exlibris.digitool.infrastructure.utils.Checksummer;
import java.io.File; import java.io.*;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Calendar; import java.util.*;
import java.util.Date;
import java.util.List;
/** /**
* SLUBStoragePlugin * SLUBStoragePlugin
...@@ -54,18 +55,303 @@ import java.util.List; ...@@ -54,18 +55,303 @@ import java.util.List;
* unable to find full documentation. * unable to find full documentation.
* *
* @author andreas.romeyke@slub-dresden.de (Andreas Romeyke) * @author andreas.romeyke@slub-dresden.de (Andreas Romeyke)
* @see com.exlibris.dps.repository.plugin.storage.nfs.NFSStoragePlugin * @ see com.exlibris.dps.repository.plugin.storage.nfs.NFSStoragePlugin
*/ */
public class SLUBStoragePlugin extends NFSStoragePlugin { public class SLUBStoragePlugin extends AbstractStorageHandler {
private static final String DIR_ROOT = "DIR_ROOT"; /** {@inheritDoc} */ private static final String DIR_ROOT = "DIR_ROOT"; /** {@inheritDoc} */
private static final ExLogger log = ExLogger.getExLogger(SLUBStoragePlugin.class); private static final ExLogger log = ExLogger.getExLogger(SLUBStoragePlugin.class);
public SLUBStoragePlugin() { public SLUBStoragePlugin() {
super();
log.info("SLUBStoragePlugin instantiated"); log.info("SLUBStoragePlugin instantiated");
} }
/** prepare right path 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 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
{
return checkFixity(fixities, storedEntityIdentifier, true);
}
public boolean checkFixity(List<Fixity> fixities, String storedEntityIdentifier, boolean isRelativePath)
throws Exception
{
boolean result = true;
if (fixities != null)
{
boolean calcMD5 = false;
boolean calcSHA1 = false;
boolean calcCRC32 = false;
for (Fixity fixity : fixities)
{
fixity.setResult(null);
if (Fixity.FixityAlgorithm.MD5.toString().equals(fixity.getAlgorithm()))
{
calcMD5 = true;
}
else if (Fixity.FixityAlgorithm.SHA1.toString().equals(fixity.getAlgorithm()))
{
calcSHA1 = true;
}
else if (Fixity.FixityAlgorithm.CRC32.toString().equals(fixity.getAlgorithm()))
{
calcCRC32 = true;
}
else
{
String oldValue = fixity.getValue();
fixity.setValue(getChecksumUsingPlugin(isRelativePath ? getLocalFilePath(storedEntityIdentifier) : storedEntityIdentifier, fixity.getPluginName(), oldValue));
fixity.setResult(Boolean.valueOf((oldValue == null) || (oldValue.equals(fixity.getValue()))));
result &= fixity.getResult().booleanValue();
}
}
if ((calcMD5) || (calcSHA1) || (calcCRC32))
{
InputStream is = null;
try
{
is = retrieveEntity(storedEntityIdentifier, isRelativePath);
Checksummer checksummer = new Checksummer(is, calcMD5, calcSHA1, calcCRC32);
for (Fixity fixity : fixities)
{
int checksummerAlgorithmIndex = getChecksummerAlgorithmIndex(fixity.getAlgorithm());
if (checksummerAlgorithmIndex != -1)
{
String oldValue = fixity.getValue();
fixity.setValue(checksummer.getChecksum(fixity.getAlgorithm()));
fixity.setResult(Boolean.valueOf((oldValue == null) || (oldValue.equalsIgnoreCase(fixity.getValue()))));
result &= fixity.getResult().booleanValue();
}
}
}
finally
{
Checksummer checksummer;
if (is != null) {
is.close();
}
}
}
}
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)
{
File file = new File((String)this.parameters.get("DIR_ROOT") + storedEntityIdentifier);
try
{
return file.delete();
}
catch (Exception e)
{
log.warn("failed to delete entity with path: " + file.getPath(), e.getMessage());
}
return true;
}
public InputStream retrieveEntity(String storedEntityIdentifier)
throws IOException
{
return retrieveEntity(storedEntityIdentifier, true);
}
public InputStream retrieveEntity(String storedEntityIdentifier, boolean isRelative)
throws IOException
{
return new FileInputStream((isRelative ? (String)this.parameters.get("DIR_ROOT") : "") + storedEntityIdentifier);
}
public String storeEntity(InputStream is, StoredEntityMetaData storedEntityMetadata)
throws Exception
{
String existsDescPath = getFilePathInDescIfExists(storedEntityMetadata);
String destFilePath = null;
boolean isCopyFileNeeded = true;
if (existsDescPath != null)
{
destFilePath = existsDescPath;
isCopyFileNeeded = !checkFixity(storedEntityMetadata.getFixities(), destFilePath, false);
}
Map<String, String> paths = getStoreEntityIdentifier(storedEntityMetadata, destFilePath);
String storedEntityIdentifier = (String)paths.get("relativeDirectoryPath");
destFilePath = (String)paths.get("destFilePath");
if (isCopyFileNeeded)
{
if (canHandleSourcePath(storedEntityMetadata.getCurrentFilePath()))
{
if (is != null) {
is.close();
}
copyStream(storedEntityMetadata, destFilePath);
}
else
{
log.info("Cannot handle source path: " + storedEntityMetadata.getCurrentFilePath());
if (is == null)
{
log.warn("InputStream is null");
return null;
}
FileOutputStream output = null;
try
{
output = new FileOutputStream(new File(destFilePath));
IOUtil.copy(is, output);
}
finally
{
IOUtil.closeQuietly(output);
}
}
if (!checkFixity(storedEntityMetadata.getFixities(), storedEntityIdentifier)) {
return null;
}
}
return storedEntityIdentifier;
}
protected void copyStream(StoredEntityMetaData storedEntityMetadata, String destPath)
throws IOException
{
String filesHandlingMethod = (String)this.parameters.get("FILES_HANDLING_METHOD");
String srcPath = storedEntityMetadata.getCurrentFilePath();
String pid = storedEntityMetadata.getEntityPid();
String iePid = storedEntityMetadata.getIePid();
if ("move".equalsIgnoreCase(filesHandlingMethod))
{
File canonicalSrcFile = getCanonicalFile(srcPath);
FileUtil.moveFile(canonicalSrcFile, new File(destPath));
saveDestPathsTmpFile(iePid, pid, destPath);
}
else if ("soft_link".equalsIgnoreCase(filesHandlingMethod))
{
softLink(srcPath, destPath);
}
else if ("hard_link".equalsIgnoreCase(filesHandlingMethod))
{
hardLink(srcPath, destPath);
}
else
{
FileUtil.copyFile(srcPath, destPath);
saveDestPathsTmpFile(iePid, pid, destPath);
}
}
private void saveDestPathsTmpFile(String folder, String key, String path)
{
if (folder == null) {
return;
}
String tmpFilePath = getTempStorageDirectory(false) + "destPath";
File destPathDir = new File(getTempStorageDirectory(false) + "destPath" + File.separator);
if (!destPathDir.exists()) {
destPathDir.mkdirs();
}
StorageUtil.saveDestPathToTmpFile(folder, tmpFilePath, key, path);
}
private File getCanonicalFile(String srcPath)
{
String fileName = srcPath.split("\\" + File.separator)[(srcPath.split("\\" + File.separator).length - 1)];
File canonicalSrcDir = null;
try
{
canonicalSrcDir = new File(srcPath).getParentFile().getCanonicalFile();
return new File(canonicalSrcDir, fileName).getCanonicalFile();
}
catch (IOException e) {
log.warn("getCanonicalFile of '" + srcPath + "':" + e.getMessage());
}
return null;
}
private void hardLink(String srcPath, String destPath)
throws IOException
{
String command = "ln";
ExecExternalProcess proc = new ExecExternalProcess();
List<String> args = new LinkedList();
args.add(srcPath);
args.add(destPath);
int retValue = proc.execExternalProcess(command, args);
if (retValue != 0) {
throw new IOException("ln " + srcPath + " " + destPath + " failed " + proc.getErrorStream() + proc.getInputStream());
}
}
private void softLink(String srcPath, String destPath)
throws IOException
{
File source = new File(srcPath);
if (!source.exists()) {
throw new IOException("File " + source + " does not exist");
}
String command = "ln";
ExecExternalProcess proc = new ExecExternalProcess();
List<String> args = new ArrayList();
args.add("-s");
args.add(srcPath);
args.add(destPath);
int retValue = proc.execExternalProcess(command, args);
if (retValue != 0) {
throw new IOException("ln -s " + srcPath + " " + destPath + " failed " + proc.getErrorStream() + proc.getInputStream());
}
}
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/ * path should be of form yyyy/MM/dd/IE-PID/
* we need to findout the associated dnx document (IE), * we need to findout the associated dnx document (IE),
* get the creation date of the IE/SIP * get the creation date of the IE/SIP
...@@ -74,7 +360,7 @@ public class SLUBStoragePlugin extends NFSStoragePlugin { ...@@ -74,7 +360,7 @@ public class SLUBStoragePlugin extends NFSStoragePlugin {
* @return calculated relative path as String * @return calculated relative path as String
* returns the path as string * returns the path as string
*/ */
protected String getStreamRelativePath(StoredEntityMetaData storedEntityMetaData ) throws Exception { private String getStreamRelativePath(StoredEntityMetaData storedEntityMetaData ) throws Exception {
log.info("SLUBStoragePlugin AAB"); log.info("SLUBStoragePlugin AAB");
String relativeDirectoryPath = File.separator; String relativeDirectoryPath = File.separator;
// get IE PID by calling IE-DNX record and search for ""internalIdentifierType" == "PID" // get IE PID by calling IE-DNX record and search for ""internalIdentifierType" == "PID"
...@@ -126,7 +412,7 @@ public class SLUBStoragePlugin extends NFSStoragePlugin { ...@@ -126,7 +412,7 @@ public class SLUBStoragePlugin extends NFSStoragePlugin {
/** copied from NFS Storage Plugin, enhanced with debugging info, /** copied from NFS Storage Plugin, enhanced with debugging info,
* this combines full file path and creates parent directories if needed {@inheritDoc} * this combines full file path and creates parent directories if needed {@inheritDoc}
*/ */
protected File getStreamDirectory(String path, String fileName) { private File getStreamDirectory(String path, String fileName) {
File newDir = new File(parameters.get(DIR_ROOT) + File.separator + path); File newDir = new File(parameters.get(DIR_ROOT) + File.separator + path);
log.info("SLUBStoragePlugin.getStreamDirectory path=" + path); log.info("SLUBStoragePlugin.getStreamDirectory path=" + path);
log.info("SLUBStoragePlugin.getStreamDirectory fileName=" + fileName); log.info("SLUBStoragePlugin.getStreamDirectory fileName=" + fileName);
...@@ -148,4 +434,28 @@ public class SLUBStoragePlugin extends NFSStoragePlugin { ...@@ -148,4 +434,28 @@ public class SLUBStoragePlugin extends NFSStoragePlugin {
return false; 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;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment