Search in sources :

Example 1 with ClusterHandlingException

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();
}
Also used : FileItem(org.apache.commons.fileupload.FileItem) ClusterHandlingException(com.openmeap.cluster.ClusterHandlingException) Map(java.util.Map) ApplicationArchive(com.openmeap.model.dto.ApplicationArchive) File(java.io.File) InvalidPropertiesException(com.openmeap.model.InvalidPropertiesException) ClusterHandlingException(com.openmeap.cluster.ClusterHandlingException)

Aggregations

ClusterHandlingException (com.openmeap.cluster.ClusterHandlingException)1 InvalidPropertiesException (com.openmeap.model.InvalidPropertiesException)1 ApplicationArchive (com.openmeap.model.dto.ApplicationArchive)1 File (java.io.File)1 Map (java.util.Map)1 FileItem (org.apache.commons.fileupload.FileItem)1