Search in sources :

Example 11 with MediaEntity

use of io.gravitee.rest.api.model.MediaEntity in project gravitee-management-rest-api by gravitee-io.

the class PortalMediaResource method getPortalMedia.

@GET
@Path("/{hash}")
@ApiOperation(value = "Retrieve a media")
@ApiResponses({ @ApiResponse(code = 200, message = "A media"), @ApiResponse(code = 500, message = "Internal server error") })
public Response getPortalMedia(@Context Request request, @PathParam("hash") String hash) {
    MediaEntity mediaEntity = mediaService.findByHash(hash);
    if (mediaEntity == null) {
        return Response.status(Response.Status.NOT_FOUND).build();
    }
    CacheControl cc = new CacheControl();
    cc.setNoTransform(true);
    cc.setMustRevalidate(false);
    cc.setNoCache(false);
    cc.setMaxAge(86400);
    EntityTag etag = new EntityTag(hash);
    Response.ResponseBuilder builder = request.evaluatePreconditions(etag);
    if (builder != null) {
        // Preconditions are not met, returning HTTP 304 'not-modified'
        return builder.cacheControl(cc).build();
    }
    return Response.ok(mediaEntity.getData()).type(mediaEntity.getMimeType()).cacheControl(cc).tag(etag).build();
}
Also used : ApiResponse(io.swagger.annotations.ApiResponse) MediaEntity(io.gravitee.rest.api.model.MediaEntity) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

MediaEntity (io.gravitee.rest.api.model.MediaEntity)11 Permissions (io.gravitee.rest.api.management.rest.security.Permissions)6 UploadUnauthorized (io.gravitee.rest.api.service.exceptions.UploadUnauthorized)4 InvalidImageException (io.gravitee.rest.api.exception.InvalidImageException)2 PageEntity (io.gravitee.rest.api.model.PageEntity)2 PageMediaEntity (io.gravitee.rest.api.model.PageMediaEntity)2 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 Media (io.gravitee.repository.media.model.Media)1 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)1 ApiQuery (io.gravitee.rest.api.model.api.ApiQuery)1 ApiNotFoundException (io.gravitee.rest.api.service.exceptions.ApiNotFoundException)1 ApiResponse (io.swagger.annotations.ApiResponse)1 ArrayList (java.util.ArrayList)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1