private void handleGetFileRequest(GetFileRequest fileRequest) { try { FileHistoryId fileHistoryId = FileHistoryId.parseFileId(fileRequest.getFileHistoryId()); long version = fileRequest.getVersion(); FileVersion fileVersion = localDatabase.getFileVersion(fileHistoryId, version); FileContent fileContent = localDatabase.getFileContent(fileVersion.getChecksum(), true); Map<ChunkChecksum, MultiChunkId> multiChunks = localDatabase.getMultiChunkIdsByChecksums(fileContent.getChunks()); TransferManager transferManager = config.getTransferPlugin().createTransferManager(config.getConnection()); Downloader downloader = new Downloader(config, transferManager); Assembler assembler = new Assembler(config, localDatabase); downloader.downloadAndDecryptMultiChunks(new HashSet<MultiChunkId>(multiChunks.values())); File tempFile = assembler.assembleToCache(fileVersion); String tempFileToken = StringUtil.toHex(ObjectId.secureRandomBytes(40)); GetFileResponse fileResponse = new GetFileResponse(fileRequest.getId(), fileRequest.getRoot(), tempFileToken); GetFileResponseInternal fileResponseInternal = new GetFileResponseInternal(fileResponse, tempFile); eventBus.post(fileResponseInternal); } catch (Exception e) { logger.log(Level.WARNING, "Cannot reassemble file.", e); eventBus.post(new BadRequestResponse(fileRequest.getId(), "Cannot reassemble file.")); } }
@Override public OperationResult execute() throws Exception { logger.log(Level.INFO, "Determine file system actions ..."); FileSystemActionReconciliator actionReconciliator = new FileSystemActionReconciliator(config, result.getChangeSet()); List<FileSystemAction> actions; if (cleanupOccurred) { actions = actionReconciliator.determineFileSystemActions( winnersDatabase, true, preDeleteFileHistoriesWithLastVersion); } else { actions = actionReconciliator.determineFileSystemActions(winnersDatabase); } Set<MultiChunkId> unknownMultiChunks = determineRequiredMultiChunks(actions, winnersDatabase); downloader.downloadAndDecryptMultiChunks(unknownMultiChunks); result.getDownloadedMultiChunks().addAll(unknownMultiChunks); applyFileSystemActions(actions); return null; }