Search in sources :

Example 1 with IGenerator

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);
    }
}
Also used : GeneratedDownload(com.willshex.blogwt.shared.api.datatype.GeneratedDownload) ServiceException(com.willshex.gson.web.service.server.ServiceException) Filter(com.willshex.blogwt.shared.page.search.Filter) IGenerator(com.willshex.blogwt.server.background.generatedownload.generator.IGenerator) Stack(com.willshex.blogwt.shared.page.Stack)

Aggregations

IGenerator (com.willshex.blogwt.server.background.generatedownload.generator.IGenerator)1 GeneratedDownload (com.willshex.blogwt.shared.api.datatype.GeneratedDownload)1 Stack (com.willshex.blogwt.shared.page.Stack)1 Filter (com.willshex.blogwt.shared.page.search.Filter)1 ServiceException (com.willshex.gson.web.service.server.ServiceException)1