Search in sources :

Example 1 with ZipStreamingOutput

use of com.thinkbiganalytics.spark.io.ZipStreamingOutput in project kylo by Teradata.

the class AbstractTransformController method download.

/**
 * Downloads the saved results as a ZIP file.
 *
 * @param id the save id
 * @return the zip file response
 */
@GET
@Path("{table}/save/{save}/zip")
@ApiOperation("Downloads the saved results in a ZIP file")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the saved file."), @ApiResponse(code = 404, message = "The save does not exist."), @ApiResponse(code = 500, message = "There was a problem accessing the data.") })
@Nonnull
public Response download(@Nonnull @PathParam("save") final String id) {
    // Find job
    SaveJob job;
    try {
        job = transformService.getSaveJob(id, true);
    } catch (final IllegalArgumentException e) {
        job = null;
    }
    // Get result
    final SaveResult result;
    if (job != null && job.isDone()) {
        try {
            result = job.get();
        } catch (final Exception e) {
            return error(Response.Status.INTERNAL_SERVER_ERROR, e);
        }
    } else {
        result = null;
    }
    // Return response
    if (result != null && result.getPath() != null) {
        return Response.ok(new ZipStreamingOutput(result.getPath(), fileSystem)).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM).header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + id + ".zip\"").build();
    } else {
        return error(Response.Status.NOT_FOUND, "download.notFound");
    }
}
Also used : ZipStreamingOutput(com.thinkbiganalytics.spark.io.ZipStreamingOutput) SaveJob(com.thinkbiganalytics.spark.metadata.SaveJob) SaveResult(com.thinkbiganalytics.spark.model.SaveResult) MissingResourceException(java.util.MissingResourceException) Path(javax.ws.rs.Path) Nonnull(javax.annotation.Nonnull) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

ZipStreamingOutput (com.thinkbiganalytics.spark.io.ZipStreamingOutput)1 SaveJob (com.thinkbiganalytics.spark.metadata.SaveJob)1 SaveResult (com.thinkbiganalytics.spark.model.SaveResult)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 MissingResourceException (java.util.MissingResourceException)1 Nonnull (javax.annotation.Nonnull)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1