Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,11 @@ public static void create(final MCRDerivate mcrDerivate) throws MCRPersistenceEx

setDerivateMetadata(mcrDerivate);

Path sourcePath = removeSourcePathFromInternals(mcrDerivate);

fireEvent(mcrDerivate, null, MCREvent.EventType.CREATE);

createDataInIFS(mcrDerivate, derivateId, objectId, objectBackup);
createDataInIFS(mcrDerivate, derivateId, objectId, objectBackup, sourcePath);

addLinkToMetadata(mcrDerivate, objectId, objectBackup);
}
Expand Down Expand Up @@ -270,9 +272,9 @@ private static void setDerivateMetadata(MCRDerivate mcrDerivate) {
}

private static void createDataInIFS(MCRDerivate mcrDerivate, MCRObjectID derivateId, MCRObjectID objectId,
byte[] objectBackup) throws MCRPersistenceException {
byte[] objectBackup, Path sourcePath) throws MCRPersistenceException {
try {
processDerivate(mcrDerivate, derivateId, objectBackup);
processDerivate(mcrDerivate, derivateId, objectBackup, sourcePath);
} catch (Exception e) {
restore(mcrDerivate, objectId, objectBackup);
throw new MCRPersistenceException("Error during data creation in IFS.", e);
Expand All @@ -294,26 +296,24 @@ private static void addLinkToMetadata(MCRDerivate mcrDerivate, MCRObjectID objec
}

private static void processDerivate(MCRDerivate mcrDerivate, MCRObjectID objectId,
byte[] objectBackup) {
byte[] objectBackup, final Path sourcePath) {
MCRObjectID derivateId = mcrDerivate.getId();
if (mcrDerivate.getDerivate().getInternals() != null) {
MCRPath rootPath = MCRPath.getPath(derivateId.toString(), "/");
if (mcrDerivate.getDerivate().getInternals().getSourcePath() == null) {
if (sourcePath == null) {
try {
rootPath.getFileSystem().createRoot(rootPath.getOwner());
} catch (IOException ioExc) {
throw new MCRPersistenceException(
"Cannot create root of '" + rootPath.getOwner() + "'.", ioExc);
}
} else {
final String sourcepath = mcrDerivate.getDerivate().getInternals().getSourcePath();
final Path f = Paths.get(sourcepath);
if (Files.exists(f)) {
if (Files.exists(sourcePath)) {
try {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Starting File-Import");
}
importDerivate(derivateId.toString(), f);
importDerivate(derivateId.toString(), sourcePath);
} catch (final Exception e) {
if (Files.exists(rootPath)) {
deleteDerivate(derivateId.toString());
Expand All @@ -322,7 +322,7 @@ private static void processDerivate(MCRDerivate mcrDerivate, MCRObjectID objectI
throw new MCRPersistenceException("Can't add derivate to the IFS", e);
}
} else {
LOGGER.warn("Empty derivate, the File or Directory -->{}<-- was not found.", sourcepath);
LOGGER.warn("Empty derivate, the File or Directory -->{}<-- was not found.", sourcePath);
}
}
}
Expand Down Expand Up @@ -853,7 +853,7 @@ public static void update(final MCRDerivate mcrDerivate) throws MCRPersistenceEx

checkUpdatePermission(derivateId);

Path fileSourceDirectory = handleFileSourceDirectory(mcrDerivate);
Path fileSourceDirectory = removeSourcePathFromInternals(mcrDerivate);

MCRDerivate old = retrieveMCRDerivate(derivateId);

Expand All @@ -866,7 +866,7 @@ public static void update(final MCRDerivate mcrDerivate) throws MCRPersistenceEx
addLinkToMetadata(mcrDerivate);
}

private static Path handleFileSourceDirectory(MCRDerivate mcrDerivate) {
private static Path removeSourcePathFromInternals(MCRDerivate mcrDerivate) {
MCRMetaIFS internals = mcrDerivate.getDerivate().getInternals();
if (internals != null && internals.getSourcePath() != null) {
Path fileSourceDirectory = Paths.get(internals.getSourcePath());
Expand Down
Loading