@GET @Path("/{id}/icon") @Produces("image/*") @GenerateLink(rel = LINK_REL_GET_ICON) @ApiOperation( value = "Get icon by stack id", notes = "This operation can be performed only by authorized user", response = byte[].class) @ApiResponses({ @ApiResponse(code = 200, message = "The response contains requested image entity"), @ApiResponse(code = 403, message = "The user does not have access to get image entity"), @ApiResponse(code = 500, message = "Internal server error occurred") }) public Response getIcon(@ApiParam("The stack id") @PathParam("id") final String id) throws NotFoundException, ServerException, BadRequestException { StackImpl stack = stackDao.getById(id); if (stack == null) { throw new NotFoundException("Stack with id '" + id + "' was not found."); } StackIcon image = stack.getStackIcon(); if (image == null) { throw new NotFoundException("Image for stack with id '" + id + "' was not found."); } return Response.ok(image.getData(), image.getMediaType()).build(); }
links.add(getLink); StackIcon stackIcon = stack.getStackIcon(); if (stackIcon != null) { Link deleteIcon =
/** * Searches for stack icon and set image data into given stack. * * @param stack stack for icon setup * @param stackIconFolderPath path to icon folder */ protected void setIconData(StackImpl stack, Path stackIconFolderPath) { StackIcon stackIcon = stack.getStackIcon(); if (stackIcon == null) { return; } if (stackIconFolderPath == null) { stack.setStackIcon(null); LOG.warn("No configured image found for stack {}", stack.getId()); return; } try { final Path stackIconPath = stackIconFolderPath.resolve(stackIcon.getName()); final byte[] imageData = IOUtils.toByteArray(IoUtil.getResource(stackIconPath.toString())); stackIcon = new StackIcon(stackIcon.getName(), stackIcon.getMediaType(), imageData); stack.setStackIcon(stackIcon); } catch (IOException ex) { stack.setStackIcon(null); LOG.error( format("Failed to load stack icon data for the stack with id '%s'", stack.getId()), ex); } } }
public StackImpl(StackImpl stack) { this( stack.getId(), stack.getName(), stack.getDescription(), stack.getScope(), stack.getCreator(), stack.getTags(), stack.getWorkspaceConfig(), stack.getComponents(), stack.getStackIcon()); }