Search in sources :

Example 1 with GeneratedDownload

use of com.willshex.blogwt.shared.api.datatype.GeneratedDownload in project blogwt by billy1380.

the class DownloadJsonServlet method doGet.

/* (non-Javadoc)
	 * 
	 * @see com.willshex.gson.web.service.server.JsonServlet#doGet() */
@Override
protected void doGet() throws IOException {
    String action = REQUEST.get().getParameter("action");
    String request = REQUEST.get().getParameter("request");
    if (request == null && "download".equals(action)) {
        Session userSession = ServletHelper.session(REQUEST.get());
        if (userSession != null) {
            String idParam = REQUEST.get().getParameter(ENTITY_ID_KEY);
            if (idParam != null) {
                Long id = Long.valueOf(idParam);
                GeneratedDownload generatedDownload = GeneratedDownloadServiceProvider.provide().getGeneratedDownload(id);
                if (generatedDownload.userKey.getId() == userSession.userKey.getId()) {
                    Filter filter = Filter.fromStack(Stack.parse(generatedDownload.parameters));
                    String fileName = StringUtils.urldecode(generatedDownload.parameters).replace(Filter.QUERY + "/", "").replace("/", "_").replace("&", "_").replace(" ", "_") + "." + DownloadGeneratorProvider.extension(filter.type).get();
                    RESPONSE.get().setContentType(DownloadGeneratorProvider.contentType(filter.type).get());
                    RESPONSE.get().setHeader("content-disposition", "inline; filename=\"" + fileName + "\"");
                    RESPONSE.get().getOutputStream().write(GcsHelper.load(GeneratedDownloadHelper.path(generatedDownload, filter)));
                } else {
                    RESPONSE.get().sendError(403, "Access denied, cannot download other user's file");
                }
            }
        } else {
            RESPONSE.get().sendError(403, "Access denied, cannot download file without logging in");
        }
    } else {
        super.doGet();
    }
}
Also used : GeneratedDownload(com.willshex.blogwt.shared.api.datatype.GeneratedDownload) Filter(com.willshex.blogwt.shared.page.search.Filter) Session(com.willshex.blogwt.shared.api.datatype.Session)

Example 2 with GeneratedDownload

use of com.willshex.blogwt.shared.api.datatype.GeneratedDownload in project blogwt by billy1380.

the class DeleteGeneratedDownloadsActionHandler method handle.

@Override
public void handle(DeleteGeneratedDownloadsRequest input, DeleteGeneratedDownloadsResponse output) throws Exception {
    ApiValidator.notNull(input, DeleteGeneratedDownloadsRequest.class, "input");
    ApiValidator.accessCode(input.accessCode, "input.accessCode");
    output.session = input.session = SessionValidator.lookupCheckAndExtend(input.session, "input.session");
    PropertyValidator.ensureTrue(PropertyHelper.DOWNLOAD_ENABLED);
    input.downloads = GeneratedDownloadValidator.lookupAll(input.downloads, "input.downloads");
    for (GeneratedDownload download : input.downloads) {
        if (download.status == GeneratedDownloadStatusType.GeneratedDownloadStatusTypeGenerating) {
            if (LOG.isLoggable(Level.WARNING)) {
                LOG.log(Level.WARNING, "Attempting to delete generated download [" + download.id + "] while it is generating. Skipping deletion.");
            }
        } else {
            if (DataTypeHelper.<User>same(download.userKey, input.session.user)) {
                GeneratedDownloadServiceProvider.provide().deleteGeneratedDownload(download);
            } else {
                if (LOG.isLoggable(Level.INFO)) {
                    LOG.log(Level.INFO, "Attempting to delete generated download [" + download.id + "] for user with id [" + download.userKey.getId() + "] out of session, current session belongs to user with id [" + input.session.user.id + "]");
                }
            }
        }
    }
}
Also used : GeneratedDownload(com.willshex.blogwt.shared.api.datatype.GeneratedDownload) User(com.willshex.blogwt.shared.api.datatype.User)

Example 3 with GeneratedDownload

use of com.willshex.blogwt.shared.api.datatype.GeneratedDownload in project blogwt by billy1380.

the class GeneratedDownloadController method generateDownload.

public void generateDownload(Filter filter) {
    final GenerateDownloadRequest input = ApiHelper.setAccessCode(new GenerateDownloadRequest()).download(new GeneratedDownload().parameters(filter.url()));
    input.session = SessionController.get().sessionForApiCall();
    ApiHelper.createDownloadClient().generateDownload(input, new AsyncCallback<GenerateDownloadResponse>() {

        @Override
        public void onSuccess(GenerateDownloadResponse output) {
            DefaultEventBus.get().fireEventFromSource(new GenerateDownloadEventHandler.GenerateDownloadSuccess(input, output), GeneratedDownloadController.this);
        }

        @Override
        public void onFailure(Throwable caught) {
            DefaultEventBus.get().fireEventFromSource(new GenerateDownloadEventHandler.GenerateDownloadFailure(input, caught), GeneratedDownloadController.this);
        }
    });
}
Also used : GenerateDownloadRequest(com.willshex.blogwt.shared.api.download.call.GenerateDownloadRequest) GeneratedDownload(com.willshex.blogwt.shared.api.datatype.GeneratedDownload) GenerateDownloadResponse(com.willshex.blogwt.shared.api.download.call.GenerateDownloadResponse)

Example 4 with GeneratedDownload

use of com.willshex.blogwt.shared.api.datatype.GeneratedDownload 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)

Example 5 with GeneratedDownload

use of com.willshex.blogwt.shared.api.datatype.GeneratedDownload in project blogwt by billy1380.

the class GenerateDownloadAction method fromJson.

@Override
public void fromJson(JsonObject jsonObject) {
    super.fromJson(jsonObject);
    if (jsonObject.has("download")) {
        JsonElement jsonDownload = jsonObject.get("download");
        if (jsonDownload != null) {
            download = new GeneratedDownload();
            download.fromJson(jsonDownload.getAsJsonObject());
        }
    }
}
Also used : GeneratedDownload(com.willshex.blogwt.shared.api.datatype.GeneratedDownload) JsonElement(com.google.gson.JsonElement)

Aggregations

GeneratedDownload (com.willshex.blogwt.shared.api.datatype.GeneratedDownload)13 JsonElement (com.google.gson.JsonElement)5 Filter (com.willshex.blogwt.shared.page.search.Filter)3 User (com.willshex.blogwt.shared.api.datatype.User)2 Stack (com.willshex.blogwt.shared.page.Stack)2 Date (java.util.Date)2 BlobKey (com.google.appengine.api.blobstore.BlobKey)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)1 Column (com.google.gwt.user.cellview.client.Column)1 TextColumn (com.google.gwt.user.cellview.client.TextColumn)1 GetPostsActionHandler (com.willshex.blogwt.server.api.blog.action.GetPostsActionHandler)1 IGenerator (com.willshex.blogwt.server.background.generatedownload.generator.IGenerator)1 Pager (com.willshex.blogwt.shared.api.Pager)1 GetPostsRequest (com.willshex.blogwt.shared.api.blog.call.GetPostsRequest)1 MetaNotification (com.willshex.blogwt.shared.api.datatype.MetaNotification)1 Permission (com.willshex.blogwt.shared.api.datatype.Permission)1 Resource (com.willshex.blogwt.shared.api.datatype.Resource)1 Role (com.willshex.blogwt.shared.api.datatype.Role)1