use of com.hortonworks.streamline.streams.catalog.File in project streamline by hortonworks.
the class FileCatalogResource method downloadFile.
/**
* Downloads a given {@link File} resource for given {@code fileId}
*
* @param fileId
*/
@Timed
@GET
@Produces({ "application/octet-stream", "application/json" })
@Path("/files/download/{fileId}")
public Response downloadFile(@PathParam("fileId") Long fileId, @Context SecurityContext securityContext) throws IOException {
SecurityUtil.checkPermissions(authorizer, securityContext, File.NAMESPACE, fileId, READ, EXECUTE);
File file = catalogService.getFile(fileId);
if (file != null) {
StreamingOutput streamOutput = WSUtils.wrapWithStreamingOutput(catalogService.downloadFileFromStorage(file.getStoredFileName()));
return Response.ok(streamOutput).build();
}
throw EntityNotFoundException.byId(fileId.toString());
}
use of com.hortonworks.streamline.streams.catalog.File in project streamline by hortonworks.
the class FileCatalogResource method updateFile.
/**
* @param inputStream
* @param contentDispositionHeader
* @param file
*/
@Timed
@PUT
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("/files/{id}")
public Response updateFile(@PathParam("id") Long fileId, @FormDataParam("file") final InputStream inputStream, @FormDataParam("file") final FormDataContentDisposition contentDispositionHeader, @FormDataParam("fileInfo") final File file, @Context SecurityContext securityContext) throws IOException {
SecurityUtil.checkPermissions(authorizer, securityContext, File.NAMESPACE, fileId, WRITE);
log.info("Received fileInfo: [{}]", file);
String oldFileStorageName = null;
final File existingFile = catalogService.getFile(fileId);
if (existingFile != null) {
oldFileStorageName = existingFile.getStoredFileName();
}
final File updatedFile = addOrUpdateFile(fileId, inputStream, file);
if (oldFileStorageName != null) {
final boolean deleted = catalogService.deleteFileFromStorage(oldFileStorageName);
logDeletionMessage(oldFileStorageName, deleted);
}
return WSUtils.respondEntity(updatedFile, CREATED);
}
use of com.hortonworks.streamline.streams.catalog.File in project streamline by hortonworks.
the class FileCatalogResource method getFile.
@GET
@Path("/files/{id}")
@Timed
public Response getFile(@PathParam("id") Long fileId, @Context SecurityContext securityContext) {
SecurityUtil.checkPermissions(authorizer, securityContext, File.NAMESPACE, fileId, READ);
File result = catalogService.getFile(fileId);
if (result != null) {
return WSUtils.respondEntity(result, OK);
}
throw EntityNotFoundException.byId(fileId.toString());
}
Aggregations