use of com.willshex.blogwt.server.background.generatedownload.generator.IGenerator in project blogwt by billy1380.
the class GenerateDownloadServlet method processGenerateDownload.
/**
* @param input
* @throws InputValidationException
*/
private void processGenerateDownload(GenerateDownloadAction input) throws ServiceException {
GeneratedDownload generatedDownload = GeneratedDownloadValidator.lookup(input.download, "input.download");
try {
generatedDownload.status = GeneratedDownloadStatusType.GeneratedDownloadStatusTypeGenerating;
GeneratedDownloadServiceProvider.provide().updateGeneratedDownload(generatedDownload);
Stack stack = Stack.parse(generatedDownload.parameters);
Filter filter = Filter.fromStack(stack);
IGenerator generator = DownloadGeneratorProvider.generator(filter.type);
if (generator == null)
ApiValidator.throwServiceError(ServiceException.class, ApiError.NoGeneratorFound, filter.type);
byte[] bytes = generator.generate(generatedDownload, filter);
if (bytes != null && generatedDownload.parameters.endsWith("send")) {
GeneratedDownloadHelper.sendEmail(generatedDownload, filter, bytes);
}
generatedDownload.status = GeneratedDownloadStatusType.GeneratedDownloadStatusTypeReady;
generatedDownload.url = "/download?action=download&id=" + generatedDownload.id;
GeneratedDownloadServiceProvider.provide().updateGeneratedDownload(generatedDownload);
} catch (Throwable t) {
generatedDownload.status = GeneratedDownloadStatusType.GeneratedDownloadStatusTypeError;
GeneratedDownloadServiceProvider.provide().updateGeneratedDownload(generatedDownload);
throw new RuntimeException(t);
}
}
Aggregations