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

- reindented with gvim, to enable better compare with new version

parent 1cd023d2
Branches
Tags
No related merge requests found
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
JAVAPATH=$(wildcard /usr/lib/jvm/java-1.6.0-openjdk-*/bin/) JAVAPATH=$(wildcard /usr/lib/jvm/java-1.6.0-openjdk-*/bin/)
# Verwendete Rosetta-Version # Verwendete Rosetta-Version
ROSETTAVERSION=3.2.2 ROSETTAVERSION=4.0.0
# Pfad zum Rosetta-SDK # Pfad zum Rosetta-SDK
ROSETTASDK=/exlibris/dps/d4_1/system.dir/dps-sdk-${ROSETTAVERSION}/lib/ ROSETTASDK=/exlibris/dps/d4_1/system.dir/dps-sdk-${ROSETTAVERSION}/lib/
......
...@@ -25,14 +25,14 @@ import java.util.Map; ...@@ -25,14 +25,14 @@ import java.util.Map;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
public class NFSStoragePlugin public class NFSStoragePlugin
extends AbstractStorageHandler extends AbstractStorageHandler
{ {
private static final String DIR_PREFIX = "DIR_PREFIX"; private static final String DIR_PREFIX = "DIR_PREFIX";
private static final String FILE_PER_DIR = "FILE_PER_DIR"; private static final String FILE_PER_DIR = "FILE_PER_DIR";
private static final String DIR_ROOT = "DIR_ROOT"; private static final String DIR_ROOT = "DIR_ROOT";
private static final String FILES_HANDLING_METHOD = "FILES_HANDLING_METHOD"; private static final String FILES_HANDLING_METHOD = "FILES_HANDLING_METHOD";
private static final ExLogger log = ExLogger.getExLogger(NFSStoragePlugin.class); private static final ExLogger log = ExLogger.getExLogger(NFSStoragePlugin.class);
public boolean deleteEntity(String storedEntityIdentifier) public boolean deleteEntity(String storedEntityIdentifier)
{ {
File file = new File((String)parameters.get("DIR_ROOT") + storedEntityIdentifier); File file = new File((String)parameters.get("DIR_ROOT") + storedEntityIdentifier);
...@@ -46,101 +46,101 @@ public class NFSStoragePlugin ...@@ -46,101 +46,101 @@ public class NFSStoragePlugin
} }
return true; return true;
} }
public InputStream retrieveEntity(String storedEntityIdentifier) public InputStream retrieveEntity(String storedEntityIdentifier)
throws IOException throws IOException
{
return new FileInputStream((String)parameters.get("DIR_ROOT") + storedEntityIdentifier);
}
public String storeEntity(InputStream is, StoredEntityMetaData storedEntityMetadata)
throws Exception
{
String fileName = createFileName(storedEntityMetadata);
String relativeDirectoryPath = getStreamRelativePath();
File destFile = getStreamDirectory(relativeDirectoryPath, fileName);
if (canHandleSourcePath(storedEntityMetadata.getCurrentFilePath()))
{ {
is.close(); return new FileInputStream((String)parameters.get("DIR_ROOT") + storedEntityIdentifier);
copyStream(storedEntityMetadata.getCurrentFilePath(), destFile.getAbsolutePath());
} }
else
{ public String storeEntity(InputStream is, StoredEntityMetaData storedEntityMetadata)
IOUtil.copy(is, new FileOutputStream(destFile)); throws Exception
}
String storedEntityIdentifier = relativeDirectoryPath + getNextDir(destFile.getAbsolutePath()) + File.separator + fileName;
if (!checkFixity(storedEntityMetadata.getFixities(), storedEntityIdentifier))
{ {
deleteEntity(storedEntityIdentifier); String fileName = createFileName(storedEntityMetadata);
return null;
String relativeDirectoryPath = getStreamRelativePath();
File destFile = getStreamDirectory(relativeDirectoryPath, fileName);
if (canHandleSourcePath(storedEntityMetadata.getCurrentFilePath()))
{
is.close();
copyStream(storedEntityMetadata.getCurrentFilePath(), destFile.getAbsolutePath());
}
else
{
IOUtil.copy(is, new FileOutputStream(destFile));
}
String storedEntityIdentifier = relativeDirectoryPath + getNextDir(destFile.getAbsolutePath()) + File.separator + fileName;
if (!checkFixity(storedEntityMetadata.getFixities(), storedEntityIdentifier))
{
deleteEntity(storedEntityIdentifier);
return null;
}
return storedEntityIdentifier;
} }
return storedEntityIdentifier;
}
public boolean checkFixity(List<Fixity> fixities, String storedEntityIdentifier) public boolean checkFixity(List<Fixity> fixities, String storedEntityIdentifier)
throws Exception throws Exception
{
boolean result = true;
if (fixities != null)
{ {
boolean calcMD5 = false; boolean result = true;
boolean calcSHA1 = false; if (fixities != null)
boolean calcCRC32 = false;
for (Fixity fixity : fixities)
{ {
fixity.setResult(null); boolean calcMD5 = false;
if (Fixity.FixityAlgorithm.MD5.toString().equals(fixity.getAlgorithm())) boolean calcSHA1 = false;
{ boolean calcCRC32 = false;
calcMD5 = true; for (Fixity fixity : fixities)
}
else if (Fixity.FixityAlgorithm.SHA1.toString().equals(fixity.getAlgorithm()))
{ {
calcSHA1 = true; fixity.setResult(null);
} if (Fixity.FixityAlgorithm.MD5.toString().equals(fixity.getAlgorithm()))
else if (Fixity.FixityAlgorithm.CRC32.toString().equals(fixity.getAlgorithm())) {
{ calcMD5 = true;
calcCRC32 = true; }
} else if (Fixity.FixityAlgorithm.SHA1.toString().equals(fixity.getAlgorithm()))
else {
{ calcSHA1 = true;
String oldValue = fixity.getValue(); }
fixity.setValue(getChecksumUsingPlugin(getLocalFilePath(storedEntityIdentifier), fixity.getPluginName(), oldValue)); else if (Fixity.FixityAlgorithm.CRC32.toString().equals(fixity.getAlgorithm()))
fixity.setResult(Boolean.valueOf((oldValue == null) || (oldValue.equals(fixity.getValue())))); {
result &= fixity.getResult().booleanValue(); calcCRC32 = true;
}
else
{
String oldValue = fixity.getValue();
fixity.setValue(getChecksumUsingPlugin(getLocalFilePath(storedEntityIdentifier), fixity.getPluginName(), oldValue));
fixity.setResult(Boolean.valueOf((oldValue == null) || (oldValue.equals(fixity.getValue()))));
result &= fixity.getResult().booleanValue();
}
} }
} if ((calcMD5) || (calcSHA1) || (calcCRC32))
if ((calcMD5) || (calcSHA1) || (calcCRC32))
{
InputStream is = null;
try
{ {
is = retrieveEntity(storedEntityIdentifier); InputStream is = null;
checksummer = new Checksummer(is, calcMD5, calcSHA1, calcCRC32); try
for (Fixity fixity : fixities)
{ {
int checksummerAlgorithmIndex = getChecksummerAlgorithmIndex(fixity.getAlgorithm()); is = retrieveEntity(storedEntityIdentifier);
if (checksummerAlgorithmIndex != -1) checksummer = new Checksummer(is, calcMD5, calcSHA1, calcCRC32);
for (Fixity fixity : fixities)
{ {
String oldValue = fixity.getValue(); int checksummerAlgorithmIndex = getChecksummerAlgorithmIndex(fixity.getAlgorithm());
fixity.setValue(checksummer.getChecksum(fixity.getAlgorithm())); if (checksummerAlgorithmIndex != -1)
fixity.setResult(Boolean.valueOf((oldValue == null) || (oldValue.equals(fixity.getValue())))); {
result &= fixity.getResult().booleanValue(); String oldValue = fixity.getValue();
fixity.setValue(checksummer.getChecksum(fixity.getAlgorithm()));
fixity.setResult(Boolean.valueOf((oldValue == null) || (oldValue.equals(fixity.getValue()))));
result &= fixity.getResult().booleanValue();
}
} }
} }
} finally
finally {
{ Checksummer checksummer;
Checksummer checksummer; if (is != null) {
if (is != null) { is.close();
is.close(); }
} }
} }
} }
return result;
} }
return result;
}
private int getChecksummerAlgorithmIndex(String algorithm) private int getChecksummerAlgorithmIndex(String algorithm)
{ {
try try
...@@ -151,12 +151,12 @@ public class NFSStoragePlugin ...@@ -151,12 +151,12 @@ public class NFSStoragePlugin
catch (Exception e) {} catch (Exception e) {}
return -1; return -1;
} }
private String getStreamRelativePath() private String getStreamRelativePath()
{ {
String relativeDirectoryPath = ""; String relativeDirectoryPath = "";
Date date = new Date(); Date date = new Date();
relativeDirectoryPath = relativeDirectoryPath + File.separator; relativeDirectoryPath = relativeDirectoryPath + File.separator;
relativeDirectoryPath = relativeDirectoryPath + new SimpleDateFormat("yyyy").format(date); relativeDirectoryPath = relativeDirectoryPath + new SimpleDateFormat("yyyy").format(date);
relativeDirectoryPath = relativeDirectoryPath + File.separator; relativeDirectoryPath = relativeDirectoryPath + File.separator;
...@@ -164,10 +164,10 @@ public class NFSStoragePlugin ...@@ -164,10 +164,10 @@ public class NFSStoragePlugin
relativeDirectoryPath = relativeDirectoryPath + File.separator; relativeDirectoryPath = relativeDirectoryPath + File.separator;
relativeDirectoryPath = relativeDirectoryPath + new SimpleDateFormat("dd").format(date); relativeDirectoryPath = relativeDirectoryPath + new SimpleDateFormat("dd").format(date);
relativeDirectoryPath = relativeDirectoryPath + File.separator; relativeDirectoryPath = relativeDirectoryPath + File.separator;
return relativeDirectoryPath; return relativeDirectoryPath;
} }
private File getStreamDirectory(String path, String fileName) private File getStreamDirectory(String path, String fileName)
{ {
String directoryPrefix = "fileset_"; String directoryPrefix = "fileset_";
...@@ -181,16 +181,16 @@ public class NFSStoragePlugin ...@@ -181,16 +181,16 @@ public class NFSStoragePlugin
File newDir = new File((String)parameters.get("DIR_ROOT") + File.separator + path); File newDir = new File((String)parameters.get("DIR_ROOT") + File.separator + path);
newDir.mkdirs(); newDir.mkdirs();
File destDir = FileUtil.getNextDirectory(newDir, directoryPrefix, maxFilesPerDir); File destDir = FileUtil.getNextDirectory(newDir, directoryPrefix, maxFilesPerDir);
return new File(destDir.getAbsolutePath() + File.separator + fileName); return new File(destDir.getAbsolutePath() + File.separator + fileName);
} }
private String getNextDir(String fullPath) private String getNextDir(String fullPath)
{ {
String[] dirs = fullPath.split("\\" + File.separator); String[] dirs = fullPath.split("\\" + File.separator);
return dirs[(dirs.length - 2)]; return dirs[(dirs.length - 2)];
} }
private boolean canHandleSourcePath(String srcPath) private boolean canHandleSourcePath(String srcPath)
{ {
try try
...@@ -201,89 +201,89 @@ public class NFSStoragePlugin ...@@ -201,89 +201,89 @@ public class NFSStoragePlugin
catch (Exception e) {} catch (Exception e) {}
return false; return false;
} }
protected void copyStream(String srcPath, String destPath) protected void copyStream(String srcPath, String destPath)
throws IOException throws IOException
{
String filesHandlingMethod = (String)parameters.get("FILES_HANDLING_METHOD");
if ("move".equalsIgnoreCase(filesHandlingMethod))
{ {
File canonicalSrcFile = getCanonicalFile(srcPath); String filesHandlingMethod = (String)parameters.get("FILES_HANDLING_METHOD");
FileUtil.moveFile(canonicalSrcFile, new File(destPath)); if ("move".equalsIgnoreCase(filesHandlingMethod))
} {
else if ("soft_link".equalsIgnoreCase(filesHandlingMethod)) File canonicalSrcFile = getCanonicalFile(srcPath);
{ FileUtil.moveFile(canonicalSrcFile, new File(destPath));
softLink(srcPath, destPath); }
} else if ("soft_link".equalsIgnoreCase(filesHandlingMethod))
else if ("hard_link".equalsIgnoreCase(filesHandlingMethod)) {
{ softLink(srcPath, destPath);
hardLink(srcPath, destPath); }
} else if ("hard_link".equalsIgnoreCase(filesHandlingMethod))
else {
{ hardLink(srcPath, destPath);
FileUtil.copyFile(srcPath, destPath); }
else
{
FileUtil.copyFile(srcPath, destPath);
}
} }
}
private File getCanonicalFile(String srcPath) private File getCanonicalFile(String srcPath)
throws IOException throws IOException
{ {
String fileName = srcPath.split("\\" + File.separator)[(srcPath.split("\\" + File.separator).length - 1)]; String fileName = srcPath.split("\\" + File.separator)[(srcPath.split("\\" + File.separator).length - 1)];
File canonicalSrcDir = new File(srcPath).getParentFile().getCanonicalFile(); File canonicalSrcDir = new File(srcPath).getParentFile().getCanonicalFile();
File canonicalSrcFile = new File(canonicalSrcDir, fileName).getCanonicalFile(); File canonicalSrcFile = new File(canonicalSrcDir, fileName).getCanonicalFile();
return canonicalSrcFile; return canonicalSrcFile;
} }
private void hardLink(String srcPath, String destPath) private void hardLink(String srcPath, String destPath)
throws IOException throws IOException
{ {
String command = "ln"; String command = "ln";
ExecExternalProcess proc = new ExecExternalProcess(); ExecExternalProcess proc = new ExecExternalProcess();
List<String> args = new LinkedList(); List<String> args = new LinkedList();
args.add(srcPath); args.add(srcPath);
args.add(destPath); args.add(destPath);
int retValue = proc.execExternalProcess(command, args); int retValue = proc.execExternalProcess(command, args);
if (retValue != 0) { if (retValue != 0) {
throw new IOException("ln " + srcPath + " " + destPath + " failed " + proc.getErrorStream() + proc.getInputStream()); throw new IOException("ln " + srcPath + " " + destPath + " failed " + proc.getErrorStream() + proc.getInputStream());
}
} }
}
private void softLink(String srcPath, String destPath) private void softLink(String srcPath, String destPath)
throws IOException throws IOException
{ {
File source = new File(srcPath); File source = new File(srcPath);
if (!source.exists()) { if (!source.exists()) {
throw new IOException("File " + source + " does not exist"); throw new IOException("File " + source + " does not exist");
} }
String command = "ln"; String command = "ln";
ExecExternalProcess proc = new ExecExternalProcess(); ExecExternalProcess proc = new ExecExternalProcess();
List<String> args = new ArrayList(); List<String> args = new ArrayList();
args.add("-s"); args.add("-s");
args.add(srcPath); args.add(srcPath);
args.add(destPath); args.add(destPath);
int retValue = proc.execExternalProcess(command, args); int retValue = proc.execExternalProcess(command, args);
if (retValue != 0) { if (retValue != 0) {
throw new IOException("ln -s " + srcPath + " " + destPath + " failed " + proc.getErrorStream() + proc.getInputStream()); throw new IOException("ln -s " + srcPath + " " + destPath + " failed " + proc.getErrorStream() + proc.getInputStream());
}
} }
}
public String getFullFilePath(String storedEntityIdentifier) public String getFullFilePath(String storedEntityIdentifier)
{ {
return (String)parameters.get("DIR_ROOT") + storedEntityIdentifier; return (String)parameters.get("DIR_ROOT") + storedEntityIdentifier;
} }
public String getLocalFilePath(String storedEntityIdentifier) public String getLocalFilePath(String storedEntityIdentifier)
{ {
return getFullFilePath(storedEntityIdentifier); return getFullFilePath(storedEntityIdentifier);
} }
public boolean isAvailable() public boolean isAvailable()
{ {
try try
{ {
File file = new File((String)parameters.get("DIR_ROOT")); File file = new File((String)parameters.get("DIR_ROOT"));
if ((!file.exists()) && if ((!file.exists()) &&
(!file.mkdirs())) (!file.mkdirs()))
{ {
log.error("No access to folder" + (String)parameters.get("DIR_ROOT"), new String[0]); log.error("No access to folder" + (String)parameters.get("DIR_ROOT"), new String[0]);
return false; return false;
...@@ -306,18 +306,17 @@ public class NFSStoragePlugin ...@@ -306,18 +306,17 @@ public class NFSStoragePlugin
} }
return true; return true;
} }
public byte[] retrieveEntityByRange(String storedEntityIdentifier, long start, long end) public byte[] retrieveEntityByRange(String storedEntityIdentifier, long start, long end)
throws Exception throws Exception
{
bytes = new byte[(int)(end - start + 1L)];
RandomAccessFile file = null;
try
{ {
file = new RandomAccessFile((String)parameters.get("DIR_ROOT") + storedEntityIdentifier, "r"); bytes = new byte[(int)(end - start + 1L)];
file.seek(start); RandomAccessFile file = null;
file.readFully(bytes, 0, (int)(end - start + 1L)); try
{
file = new RandomAccessFile((String)parameters.get("DIR_ROOT") + storedEntityIdentifier, "r");
file.seek(start);
file.readFully(bytes, 0, (int)(end - start + 1L));
...@@ -326,21 +325,22 @@ public class NFSStoragePlugin ...@@ -326,21 +325,22 @@ public class NFSStoragePlugin
return bytes;
} return bytes;
finally }
{ finally
if (file != null) { {
try if (file != null) {
{ try
file.close(); {
} file.close();
catch (Exception e) }
{ catch (Exception e)
log.warn("Failed closing file", new String[0]); {
log.warn("Failed closing file", new String[0]);
}
} }
} }
} }
}
} }
...@@ -65,47 +65,6 @@ public class SLUBStoragePlugin extends NFSStoragePlugin { ...@@ -65,47 +65,6 @@ public class SLUBStoragePlugin extends NFSStoragePlugin {
log.info("SLUBStoragePlugin instantiated"); log.info("SLUBStoragePlugin instantiated");
} }
/** copied from NFS Storage Plugin, enhanced with debugging info,
* stores InputStream on Storage in given format and does fixity check
* to see if written sucessfully
* @param is InputStream
* @param storedEntityMetadata storedEntityMetaData
* @return relative path to file
*/
@Override
public String storeEntity(InputStream is, StoredEntityMetaData storedEntityMetadata) throws Exception {
log.info("SLUBStoragePlugin.storeEntity() called");
String fileName = createFileName(storedEntityMetadata);
log.info("SLUBStoragePlugin.storeEntity() fileName="+fileName);
String relativeDirectoryPath = getStreamRelativePath(storedEntityMetadata);
log.info("SLUBStoragePlugin.storeEntity() relativeDirectoryPath="+relativeDirectoryPath);
File destFile = getStreamDirectory(relativeDirectoryPath, fileName);
log.info("SLUBStoragePlugin.storeEntity() destfile.getAbsolutePath()="+destFile.getAbsolutePath());
// debug
// List<Fixity> fixities = getAvailableFixities( storedEntityMetadata );
// better move/link
if (canHandleSourcePath(storedEntityMetadata.getCurrentFilePath())) {
is.close(); // close input stream so that 'move' can work, we don't use it anyway
copyStream(storedEntityMetadata.getCurrentFilePath(), destFile.getAbsolutePath());
}
// default way - copy from input stream
else {
IOUtil.copy(is, new FileOutputStream(destFile));
}
String storedEntityIdentifier = relativeDirectoryPath + File.separator + fileName;
log.info("SLUBStoragePlugin.storeEntity() storedEntityIdentifier="+storedEntityIdentifier);
// check if stored correctly
if(!checkFixity(storedEntityMetadata.getFixities(), storedEntityIdentifier)) {
log.error("error, SLUBStoragePlugin.storeEntity() has written corrupted files (checked via checkFixity()), storedEntityIdentifier="+storedEntityIdentifier);
deleteEntity(storedEntityIdentifier); // delete corrupt files
return null;
}
// return only relative (not absolute) path
return storedEntityIdentifier;
}
/** prepare right path /** 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),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment