use of com.openmeap.cluster.ClusterHandlingException in project OpenMEAP by OpenMEAP.
the class ArchiveFileUploadHandler method handle.
@Override
public <E extends Event<Map>> void handle(E event) throws ClusterHandlingException {
Map parms = event.getPayload();
ApplicationArchive arch = (ApplicationArchive) parms.get("archive");
String hashId = String.format("{%s}%s", arch.getHashAlgorithm(), arch.getHash());
logger.debug("ArchiveUploadEvent for file {}", hashId);
File file = arch.getFile(getFileSystemStoragePathPrefix());
if (file.exists()) {
logger.warn("ApplicationArchive with {} hash already exists, ignoring ArchiveUploadEvent.", hashId);
return;
}
if (parms.get("file") == null || !(parms.get("file") instanceof FileItem)) {
logger.error("Expected a FileItem under the \"file\" parameter. Got " + parms.get("file") + " instead.");
throw new ClusterHandlingException("Expected a FileItem under the \"file\" parameter. Got " + parms.get("file") + " instead.");
}
FileItem item = (FileItem) parms.get("file");
try {
item.write(file);
} catch (Exception ioe) {
logger.error("An error occurred writing {}: {}", item.getName(), ioe);
throw new ClusterHandlingException(ioe);
}
item.delete();
}
Aggregations