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();
}
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);
}
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);
}
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);
}
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());
}
Aggregations