Search in sources :

Example 1 with InlinePictureEntity

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

the class CategoryServiceImpl method getBackground.

@Override
public InlinePictureEntity getBackground(String categoryId) {
    CategoryEntity categoryEntity = findById(categoryId);
    InlinePictureEntity imageEntity = new InlinePictureEntity();
    if (categoryEntity.getBackground() != null) {
        String[] parts = categoryEntity.getBackground().split(";", 2);
        imageEntity.setType(parts[0].split(":")[1]);
        String base64Content = categoryEntity.getBackground().split(",", 2)[1];
        imageEntity.setContent(DatatypeConverter.parseBase64Binary(base64Content));
    }
    return imageEntity;
}
Also used : UuidString(io.gravitee.rest.api.service.common.UuidString) NewCategoryEntity(io.gravitee.rest.api.model.NewCategoryEntity) CategoryEntity(io.gravitee.rest.api.model.CategoryEntity) UpdateCategoryEntity(io.gravitee.rest.api.model.UpdateCategoryEntity) InlinePictureEntity(io.gravitee.rest.api.model.InlinePictureEntity)

Example 2 with InlinePictureEntity

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

the class CategoryServiceImpl method getPicture.

@Override
public InlinePictureEntity getPicture(String categoryId) {
    CategoryEntity categoryEntity = findById(categoryId);
    InlinePictureEntity imageEntity = new InlinePictureEntity();
    if (categoryEntity.getPicture() != null) {
        String[] parts = categoryEntity.getPicture().split(";", 2);
        imageEntity.setType(parts[0].split(":")[1]);
        String base64Content = categoryEntity.getPicture().split(",", 2)[1];
        imageEntity.setContent(DatatypeConverter.parseBase64Binary(base64Content));
    }
    return imageEntity;
}
Also used : UuidString(io.gravitee.rest.api.service.common.UuidString) NewCategoryEntity(io.gravitee.rest.api.model.NewCategoryEntity) CategoryEntity(io.gravitee.rest.api.model.CategoryEntity) UpdateCategoryEntity(io.gravitee.rest.api.model.UpdateCategoryEntity) InlinePictureEntity(io.gravitee.rest.api.model.InlinePictureEntity)

Example 3 with InlinePictureEntity

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

the class CategoryResource method background.

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

Example 4 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 5 with InlinePictureEntity

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

the class ThemeServiceImpl method convertToPicture.

private PictureEntity convertToPicture(String picture) {
    if (picture.matches("^(http|https)://.*$")) {
        return new UrlPictureEntity(picture);
    } else {
        InlinePictureEntity imageEntity = new InlinePictureEntity();
        String[] parts = picture.split(";", 2);
        imageEntity.setType(parts[0].split(":")[1]);
        String base64Content = picture.split(",", 2)[1];
        imageEntity.setContent(DatatypeConverter.parseBase64Binary(base64Content));
        return imageEntity;
    }
}
Also used : UrlPictureEntity(io.gravitee.rest.api.model.UrlPictureEntity) InlinePictureEntity(io.gravitee.rest.api.model.InlinePictureEntity)

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