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

- because checkFixity() will be called with relative paths, we should add dirroot explicitely

- added some assertions
parent a56aa48b
Branches
Tags
No related merge requests found
Pipeline #3398 passed
......@@ -70,7 +70,7 @@
</fr:x_form>
</pl:initParameters>
<pl:description>SLUB Storage Plugin</pl:description>
<pl:version>2.821</pl:version>
<pl:version>2.822</pl:version>
<pl:materialType>DIGITAL</pl:materialType>
<pl:module>Repository</pl:module>
<pl:generalType>TASK</pl:generalType>
......
......@@ -109,7 +109,15 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
return "(unknown) Bytes/s";
}
public boolean checkFixity(List<Fixity> fixities, String absolute_storedEntityIdentifier) throws Exception {
/**
* checkFixity
* @param fixities
* @param storedEntityIdentifier (relative filepath)
* @return true if valid, otherwise false
* @throws Exception
*/
public boolean checkFixity(List<Fixity> fixities, String storedEntityIdentifier) throws Exception {
String absolute_storedEntityIdentifier = getFullFilePath(storedEntityIdentifier);
log.info("SLUBStoragePlugin.checkFixity() storedEntityIdentifier='" + absolute_storedEntityIdentifier + "'");
// log.info("SLUBStoragePlugin.checkFixity() all fixities=" + fixities);
if (fixities == null) {
......@@ -124,6 +132,13 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
return result;
}
/**
* checkSpecificFixity
* @param absolute_storedEntityIdentifier absolute file path
* @param fixity
* @return true if valid otherwise false
* @throws Exception
*/
private boolean checkSpecificFixity(String absolute_storedEntityIdentifier, Fixity fixity) throws Exception {
String algorithm = fixity.getAlgorithm();
/* HINT: in past versions of Rosetta was a workaround for fixity.getAlgorithm() required,
......@@ -163,9 +178,9 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
/** uses a checksummer object and check if fixity of given builtin algorithm is correct
*
* @param fixity concrete fixity object
* @param absolute_storedEntityIdentifier ROsetta identifier
* @param absolute_storedEntityIdentifier absolute filepath
* @param algorithm which algorithm should be used
* @return result
* @return true if valid, otherwise false
* @throws NoSuchAlgorithmException if algorithm is unknown
* @throws IOException if I/O error
*/
......@@ -190,11 +205,12 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
/** check fixity by calling its registered plugin
*
* @param fixity concrete fixity object
* @param absolute_storedEntityIdentifier path to file which should be checked
* @return result
* @param absolute_storedEntityIdentifier absolute filepath to file which should be checked
* @return true if valid, otherwise false
* @throws Exception to inform rosetta
*/
private boolean checkFixityByPlugin(Fixity fixity, String absolute_storedEntityIdentifier) throws Exception {
assert( absolute_storedEntityIdentifier.startsWith( getDirRoot() ) );
log.info("SLUBStoragePlugin.checkFixityByPlugin() another fixity");
String pluginname = fixity.getPluginName();
log.info("SLUBStoragePlugin.checkFixityByPlugin() pluginname=" + pluginname);
......@@ -227,6 +243,11 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
return result;
}
/**
* deleteEntity
* @param relative_storedEntityIdentifier
* @return true if successful
*/
public boolean deleteEntity(String relative_storedEntityIdentifier)
{
log.info("SLUBStoragePlugin.deleteEntity() storedEntityIdentifier='" + relative_storedEntityIdentifier + "'");
......@@ -249,12 +270,25 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
log.info("SLUBStoragePlugin.getLocalFilePath() with '" + storedEntityIdentifier + "'");
return getFullFilePath(storedEntityIdentifier);
}
/**
* getFullFilePath
* @param storedEntityIdentifier - relative filepath
* @return absolute filepath
*/
public String getFullFilePath(String storedEntityIdentifier)
{
assert(! storedEntityIdentifier.startsWith( getDirRoot() ) );
log.info("SLUBStoragePlugin.getFullFilePath() with '" + storedEntityIdentifier + "'");
return getDirRoot() + storedEntityIdentifier;
}
/**
* retrieveEntity
* @param storedEntityIdentifier as relative filepath
* @return Buffered InputStream
* @throws IOException
*/
public InputStream retrieveEntity(String storedEntityIdentifier)
throws IOException
{
......@@ -266,6 +300,15 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
var is = java.nio.file.Files.newInputStream( absolute_path );
return new BufferedInputStream( is , getBlockSize());
}
/**
* retrieveEntityByRange
* @param storedEntityIdentifier as relative filepath
* @param start offset to begin
* @param end offset to end
* @return byte array of size end-begin
* @throws Exception
*/
public byte[] retrieveEntityByRange(String storedEntityIdentifier, long start, long end) throws Exception
{
log.info("SLUBStoragePlugin.retrieveEntitybyRange() with '" + storedEntityIdentifier + "' start=" + start + " end=" + end);
......@@ -295,6 +338,13 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
}
}
/**
* storeEntity
* @param is - InputStream
* @param storedEntityMetadata
* @return relative path to storedEntity
* @throws Exception
*/
public String storeEntity(InputStream is, StoredEntityMetaData storedEntityMetadata)
throws Exception
{
......@@ -308,7 +358,7 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
{
destFilePath = existsDescPath;
/* destFilePath is relative, checkfixity expects absolute */
isCopyFileNeeded = !checkFixity(storedEntityMetadata.getFixities(), getFullFilePath(destFilePath));
isCopyFileNeeded = !checkFixity(storedEntityMetadata.getFixities(), destFilePath);
}
log.debug("SLUBStoragePlugin.storeEntity() destFilePath='" + destFilePath + "'");
Map<String, String> paths = getStoreEntityIdentifier(storedEntityMetadata, destFilePath);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment