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();
}
}
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 + "]");
}
}
}
}
}
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);
}
});
}
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);
}
}
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());
}
}
}
Aggregations