io.automatiko.addon.files.s3.web.FileDownloadResource Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of automatiko-files-azure-blob-addon Show documentation
Show all versions of automatiko-files-azure-blob-addon Show documentation
Files based on Azure BlobStore AddOn for Automatiko Engine
package io.automatiko.addon.files.s3.web;
import java.io.FileNotFoundException;
import io.automatiko.addon.files.s3.AzureBlobStoreStore;
import io.automatiko.engine.api.workflow.files.File;
import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.Response.ResponseBuilder;
@Path("/management/files")
public class FileDownloadResource {
private AzureBlobStoreStore store;
@Inject
public FileDownloadResource(AzureBlobStoreStore store) {
this.store = store;
}
@GET
@Path("download/{processId}/{processInstanceId}/{variable}/{filename}")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response downloadFile(@PathParam("processId") String processId,
@PathParam("processInstanceId") String processInstanceId,
@PathParam("variable") String variable,
@PathParam("filename") String filename) {
try {
byte[] content = store.content(processId, processInstanceId, variable, filename);
ResponseBuilder response = Response.ok().entity(content);
response.header("Content-Disposition", "attachment;filename=" + filename);
response.header("Content-Type", File.discoverType(filename));
return response.build();
} catch (FileNotFoundException e) {
return Response.status(Response.Status.NOT_FOUND.getStatusCode(), "File with name " + filename + " not found")
.build();
} catch (Exception e) {
return Response.serverError().build();
}
}
@GET
@Path("download/{processId}/{processVersion}/{processInstanceId}/{variable}/{filename}")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response downloadVersionedFile(@PathParam("processId") String processId,
@PathParam("processVersion") String processVersion,
@PathParam("processInstanceId") String processInstanceId,
@PathParam("variable") String variable,
@PathParam("filename") String filename) {
try {
byte[] content = store.content(processId, processVersion, processInstanceId, variable, filename);
ResponseBuilder response = Response.ok().entity(content);
response.header("Content-Disposition", "attachment;filename=" + filename);
response.header("Content-Type", File.discoverType(filename));
return response.build();
} catch (FileNotFoundException e) {
return Response.status(Response.Status.NOT_FOUND.getStatusCode(), "File with name " + filename + " not found")
.build();
} catch (Exception e) {
return Response.serverError().build();
}
}
}