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

- added exLogger support

- getStreamRelativePath() rewritten using IEPID and Date (needs further tests)
parent 8557435f
No related branches found
No related tags found
No related merge requests found
...@@ -4,30 +4,35 @@ package org.slub.rosetta.dps.repository.plugin.storage.nfs; ...@@ -4,30 +4,35 @@ package org.slub.rosetta.dps.repository.plugin.storage.nfs;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.InputStream; import java.io.InputStream;
import java.util.Calendar;
import java.text.SimpleDateFormat;
import com.exlibris.core.infra.common.exceptions.logging.ExLogger;
import com.exlibris.digitool.common.dnx.DnxDocument;
import com.exlibris.dps.repository.plugin.storage.nfs.NFSStoragePlugin; import com.exlibris.dps.repository.plugin.storage.nfs.NFSStoragePlugin;
import com.exlibris.core.infra.common.util.IOUtil; import com.exlibris.core.infra.common.util.IOUtil;
import com.exlibris.core.sdk.storage.containers.StoredEntityMetaData; import com.exlibris.core.sdk.storage.containers.StoredEntityMetaData;
import com.exlibris.digitool.common.storage.Fixity; import com.exlibris.digitool.common.storage.Fixity;
import com.exlibris.digitool.infrastructure.utils.Checksummer; import com.exlibris.digitool.infrastructure.utils.Checksummer;
/**
* SLUBStoragePlugin
* writes all IEs, files and so on into the same dir under yyyy/mm/dd/IEpid/
*
* @author andreas.romeyke@slub-dresden.de (Andreas Romeyke)
*/
public class SLUBStoragePlugin extends NFSStoragePlugin { public class SLUBStoragePlugin extends NFSStoragePlugin {
private static final String DIR_ROOT = "DIR_ROOT"; private static final String DIR_ROOT = "DIR_ROOT";
private static final ExLogger log = ExLogger.getExLogger(NFSStoragePlugin.class);
public SLUBStoragePlugin() { public SLUBStoragePlugin() {
super(); super();
} }
@Override @Override
public String storeEntity(InputStream is, StoredEntityMetaData storedEntityMetadata) throws Exception { public String storeEntity(InputStream is, StoredEntityMetaData storedEntityMetadata) throws Exception {
String fileName = createFileName(storedEntityMetadata); String fileName = createFileName(storedEntityMetadata);
String relativeDirectoryPath = getStreamRelativePath(storedEntityMetadata); String relativeDirectoryPath = getStreamRelativePath(storedEntityMetadata);
File destFile = getStreamDirectory(relativeDirectoryPath, fileName); File destFile = getStreamDirectory(relativeDirectoryPath, fileName);
// better move/link // better move/link
if (canHandleSourcePath(storedEntityMetadata.getCurrentFilePath())) { if (canHandleSourcePath(storedEntityMetadata.getCurrentFilePath())) {
is.close(); // close input stream so that 'move' can work, we don't use it anyway is.close(); // close input stream so that 'move' can work, we don't use it anyway
...@@ -38,42 +43,40 @@ public class SLUBStoragePlugin extends NFSStoragePlugin { ...@@ -38,42 +43,40 @@ public class SLUBStoragePlugin extends NFSStoragePlugin {
IOUtil.copy(is, new FileOutputStream(destFile)); IOUtil.copy(is, new FileOutputStream(destFile));
} }
String storedEntityIdentifier = relativeDirectoryPath + File.separator + fileName; String storedEntityIdentifier = relativeDirectoryPath + File.separator + fileName;
if(!checkFixity(storedEntityMetadata.getFixities(), storedEntityIdentifier)) { if(!checkFixity(storedEntityMetadata.getFixities(), storedEntityIdentifier)) {
deleteEntity(storedEntityIdentifier); // delete corrupt files deleteEntity(storedEntityIdentifier); // delete corrupt files
return null; return null;
} }
// return only relative (not absolute) path // return only relative (not absolute) path
return storedEntityIdentifier; return storedEntityIdentifier;
} }
// path should be of form yyyy/mm/dd/IE-PID/
private String getStreamRelativePath(StoredEntityMetaData storedEntityMetaData ) throws Exception { protected String getStreamRelativePath(StoredEntityMetaData storedEntityMetaData ) throws Exception {
String relativeDirectoryPath = File.separator; String relativeDirectoryPath = File.separator;
String pid = storedEntityMetaData.getEntityPid(); // get IE PID by calling IE-DNX record and search for ""internalIdentifierType" == "PID"
Checksummer checksummer = new Checksummer(pid, true, false, false); DnxDocument iedoc = storedEntityMetaData.getIeDnx();
Fixity fixity = new Fixity(Fixity.FixityAlgorithm.MD5.toString(), checksummer.getMD5()); String iepid = iedoc.getSectionKeyValue("internalIdentifierType", "PID");
String value = fixity.getValue(); log.debug("SLUBStoragePlugin iepid=" + iepid);
String datestring = iedoc.getSectionKeyValue("objectCharacteristics", "creationDate");
for(int i=0 ; i<value.length() && i<32 ; i= i+2) { Calendar date = Calendar.getInstance();
if(i+1 < value.length()) { // date: 2014-01-15 14:28:01
relativeDirectoryPath += value.substring(i, i+2) + File.separator; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd HH:mm:ss");
} else { date.setTime(sdf.parse(datestring));
relativeDirectoryPath += value.substring(i, i+1) + File.separator; log.debug("SLUBStoragePlugin creation Date read=" + datestring + " parsed=" + date.toString());
} relativeDirectoryPath = relativeDirectoryPath + new SimpleDateFormat("yyyy").format(date);
} relativeDirectoryPath = relativeDirectoryPath + File.separator;
relativeDirectoryPath = relativeDirectoryPath + new SimpleDateFormat("MM").format(date);
if(32 < value.length()) { relativeDirectoryPath = relativeDirectoryPath + File.separator;
relativeDirectoryPath += value.substring(32); relativeDirectoryPath = relativeDirectoryPath + new SimpleDateFormat("dd").format(date);
} relativeDirectoryPath = relativeDirectoryPath + File.separator;
relativeDirectoryPath = relativeDirectoryPath + iepid;
relativeDirectoryPath = relativeDirectoryPath + File.separator;
log.debug("SLUBStoragePlugin relativeDirectoryPath=" + relativeDirectoryPath);
return relativeDirectoryPath; return relativeDirectoryPath;
} }
protected File getStreamDirectory(String path, String fileName) { protected 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);
newDir.mkdirs(); newDir.mkdirs();
return new File(newDir.getAbsolutePath() + File.separator + fileName); return new File(newDir.getAbsolutePath() + File.separator + fileName);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment