Search in sources :

Example 6 with File

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());
}
Also used : StreamingOutput(javax.ws.rs.core.StreamingOutput) File(com.hortonworks.streamline.streams.catalog.File) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Example 7 with File

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);
}
Also used : File(com.hortonworks.streamline.streams.catalog.File) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Timed(com.codahale.metrics.annotation.Timed) PUT(javax.ws.rs.PUT)

Example 8 with File

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());
}
Also used : File(com.hortonworks.streamline.streams.catalog.File) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Aggregations

File (com.hortonworks.streamline.streams.catalog.File)8 Timed (com.codahale.metrics.annotation.Timed)5 Path (javax.ws.rs.Path)5 StorableKey (com.hortonworks.registries.storage.StorableKey)2 Consumes (javax.ws.rs.Consumes)2 GET (javax.ws.rs.GET)2 IntegrationTest (com.hortonworks.streamline.common.test.IntegrationTest)1 Permission (com.hortonworks.streamline.streams.security.Permission)1 DELETE (com.hortonworks.streamline.streams.security.Permission.DELETE)1 IOException (java.io.IOException)1 DELETE (javax.ws.rs.DELETE)1 POST (javax.ws.rs.POST)1 PUT (javax.ws.rs.PUT)1 Produces (javax.ws.rs.Produces)1 Client (javax.ws.rs.client.Client)1 StreamingOutput (javax.ws.rs.core.StreamingOutput)1 FormDataBodyPart (org.glassfish.jersey.media.multipart.FormDataBodyPart)1 MultiPart (org.glassfish.jersey.media.multipart.MultiPart)1 MultiPartFeature (org.glassfish.jersey.media.multipart.MultiPartFeature)1 StreamDataBodyPart (org.glassfish.jersey.media.multipart.file.StreamDataBodyPart)1