Search in sources :

Example 6 with InlinePictureEntity

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

the class ThemeResource method buildPictureResponse.

private Response buildPictureResponse(PictureEntity picture, @Context Request request) {
    if (picture == null) {
        return Response.ok().build();
    }
    if (picture instanceof UrlPictureEntity) {
        return Response.temporaryRedirect(URI.create(((UrlPictureEntity) picture).getUrl())).build();
    }
    CacheControl cc = new CacheControl();
    cc.setNoTransform(true);
    cc.setMustRevalidate(false);
    cc.setNoCache(false);
    cc.setMaxAge(86400);
    InlinePictureEntity image = (InlinePictureEntity) picture;
    EntityTag etag = new EntityTag(Integer.toString(new String(image.getContent()).hashCode()));
    Response.ResponseBuilder builder = request.evaluatePreconditions(etag);
    if (builder != null) {
        // Preconditions are not met, returning HTTP 304 'not-modified'
        return builder.cacheControl(cc).build();
    }
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    baos.write(image.getContent(), 0, image.getContent().length);
    return Response.ok().entity(baos).cacheControl(cc).tag(etag).type(image.getType()).build();
}
Also used : UrlPictureEntity(io.gravitee.rest.api.model.UrlPictureEntity) ByteArrayOutputStream(java.io.ByteArrayOutputStream) InlinePictureEntity(io.gravitee.rest.api.model.InlinePictureEntity)

Example 7 with InlinePictureEntity

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

the class CategoryResource method picture.

@GET
@Path("picture")
@RequirePortalAuth
public Response picture(@Context Request request, @PathParam("categoryId") String categoryId) {
    categoryService.findNotHiddenById(categoryId);
    InlinePictureEntity image = categoryService.getPicture(categoryId);
    return createPictureResponse(request, image);
}
Also used : InlinePictureEntity(io.gravitee.rest.api.model.InlinePictureEntity) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) RequirePortalAuth(io.gravitee.rest.api.portal.rest.security.RequirePortalAuth)

Example 8 with InlinePictureEntity

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

the class ApplicationResource method getPictureByApplicationId.

@GET
@Path("picture")
@Produces({ MediaType.WILDCARD, MediaType.APPLICATION_JSON })
@Permissions({ @Permission(value = RolePermission.APPLICATION_DEFINITION, acls = RolePermissionAction.READ) })
public Response getPictureByApplicationId(@Context Request request, @PathParam("applicationId") String applicationId) {
    applicationService.findById(applicationId);
    InlinePictureEntity image = applicationService.getPicture(applicationId);
    return createPictureResponse(request, image);
}
Also used : InlinePictureEntity(io.gravitee.rest.api.model.InlinePictureEntity) Permissions(io.gravitee.rest.api.portal.rest.security.Permissions)

Example 9 with InlinePictureEntity

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

the class ApplicationResource method getBackgroundByApplicationId.

@GET
@Path("background")
@Produces({ MediaType.WILDCARD, MediaType.APPLICATION_JSON })
@Permissions({ @Permission(value = RolePermission.APPLICATION_DEFINITION, acls = RolePermissionAction.READ) })
public Response getBackgroundByApplicationId(@Context Request request, @PathParam("applicationId") String applicationId) {
    applicationService.findById(applicationId);
    InlinePictureEntity image = applicationService.getBackground(applicationId);
    return createPictureResponse(request, image);
}
Also used : InlinePictureEntity(io.gravitee.rest.api.model.InlinePictureEntity) Permissions(io.gravitee.rest.api.portal.rest.security.Permissions)

Example 10 with InlinePictureEntity

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

the class UserResourceTest method init.

@Before
public void init() throws IOException, URISyntaxException {
    resetAllMocks();
    doReturn(new User()).when(userMapper).convert(nullable(UserEntity.class));
    doReturn(new UserLinks()).when(userMapper).computeUserLinks(any(), any());
    InlinePictureEntity mockImage = new InlinePictureEntity();
    byte[] apiLogoContent = Files.readAllBytes(Paths.get(this.getClass().getClassLoader().getResource("media/logo.svg").toURI()));
    mockImage.setContent(apiLogoContent);
    mockImage.setType("image/svg");
    doReturn(mockImage).when(userService).getPicture(any());
}
Also used : UserLinks(io.gravitee.rest.api.portal.rest.model.UserLinks) User(io.gravitee.rest.api.portal.rest.model.User) UpdateUserEntity(io.gravitee.rest.api.model.UpdateUserEntity) UserEntity(io.gravitee.rest.api.model.UserEntity) InlinePictureEntity(io.gravitee.rest.api.model.InlinePictureEntity) Before(org.junit.Before)

Aggregations

InlinePictureEntity (io.gravitee.rest.api.model.InlinePictureEntity)15 UrlPictureEntity (io.gravitee.rest.api.model.UrlPictureEntity)4 Test (org.junit.Test)4 CategoryEntity (io.gravitee.rest.api.model.CategoryEntity)3 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 NewCategoryEntity (io.gravitee.rest.api.model.NewCategoryEntity)2 UpdateCategoryEntity (io.gravitee.rest.api.model.UpdateCategoryEntity)2 Permissions (io.gravitee.rest.api.portal.rest.security.Permissions)2 UuidString (io.gravitee.rest.api.service.common.UuidString)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Before (org.junit.Before)2 Theme (io.gravitee.repository.management.model.Theme)1 PictureEntity (io.gravitee.rest.api.model.PictureEntity)1 UpdateUserEntity (io.gravitee.rest.api.model.UpdateUserEntity)1 UserEntity (io.gravitee.rest.api.model.UserEntity)1 User (io.gravitee.rest.api.portal.rest.model.User)1 UserLinks (io.gravitee.rest.api.portal.rest.model.UserLinks)1 RequirePortalAuth (io.gravitee.rest.api.portal.rest.security.RequirePortalAuth)1