use of org.eclipse.che.api.workspace.server.stack.image.StackIcon in project che by eclipse.
the class StackLoader method setIconData.
private void setIconData(StackImpl stack, Path stackIconFolderPath) {
StackIcon stackIcon = stack.getStackIcon();
if (stackIcon == null) {
return;
}
try {
Path stackIconPath = stackIconFolderPath.resolve(stackIcon.getName());
if (Files.exists(stackIconPath) && Files.isRegularFile(stackIconPath)) {
stackIcon = new StackIcon(stackIcon.getName(), stackIcon.getMediaType(), Files.readAllBytes(stackIconPath));
stack.setStackIcon(stackIcon);
} else {
throw new IOException("Stack icon is not a file or doesn't exist by path: " + stackIconPath);
}
} catch (IOException e) {
stack.setStackIcon(null);
LOG.error(format("Failed to load stack icon data for the stack with id '%s'", stack.getId()), e);
}
}
use of org.eclipse.che.api.workspace.server.stack.image.StackIcon in project che by eclipse.
the class StackService method uploadIcon.
@POST
@Path("/{id}/icon")
@Consumes(MULTIPART_FORM_DATA)
@Produces(TEXT_PLAIN)
@GenerateLink(rel = LINK_REL_UPLOAD_ICON)
@ApiOperation(value = "Upload icon for required stack", notes = "This operation can be performed only by authorized stack owner")
@ApiResponses({ @ApiResponse(code = 200, message = "Image was successfully uploaded"), @ApiResponse(code = 400, message = "Missed required parameters, parameters are not valid"), @ApiResponse(code = 403, message = "The user does not have access upload image for stack with required id"), @ApiResponse(code = 404, message = "The stack doesn't exist"), @ApiResponse(code = 500, message = "Internal server error occurred") })
public Response uploadIcon(@ApiParam("The image for stack") final Iterator<FileItem> formData, @ApiParam("The stack id") @PathParam("id") final String id) throws NotFoundException, ServerException, BadRequestException, ForbiddenException, ConflictException {
if (formData.hasNext()) {
FileItem fileItem = formData.next();
StackIcon stackIcon = new StackIcon(fileItem.getName(), fileItem.getContentType(), fileItem.get());
StackImpl stack = stackDao.getById(id);
stack.setStackIcon(stackIcon);
stackDao.update(stack);
}
return Response.ok().build();
}
use of org.eclipse.che.api.workspace.server.stack.image.StackIcon in project che by eclipse.
the class StackService method asStackDto.
private StackDto asStackDto(StackImpl stack) {
final UriBuilder builder = getServiceContext().getServiceUriBuilder();
List<Link> links = new ArrayList<>();
final Link removeLink = LinksHelper.createLink("DELETE", builder.clone().path(getClass(), "removeStack").build(stack.getId()).toString(), LINK_REL_REMOVE_STACK);
final Link getLink = LinksHelper.createLink("GET", builder.clone().path(getClass(), "getStack").build(stack.getId()).toString(), APPLICATION_JSON, LINK_REL_GET_STACK_BY_ID);
links.add(removeLink);
links.add(getLink);
StackIcon stackIcon = stack.getStackIcon();
if (stackIcon != null) {
Link deleteIcon = LinksHelper.createLink("DELETE", builder.clone().path(getClass(), "removeIcon").build(stack.getId()).toString(), stackIcon.getMediaType(), LINK_REL_DELETE_ICON);
Link getIconLink = LinksHelper.createLink("GET", builder.clone().path(getClass(), "getIcon").build(stack.getId()).toString(), stackIcon.getMediaType(), LINK_REL_GET_ICON);
links.add(deleteIcon);
links.add(getIconLink);
}
return asDto(stack).withLinks(links);
}
use of org.eclipse.che.api.workspace.server.stack.image.StackIcon in project che by eclipse.
the class StackService method getIcon.
@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();
}
use of org.eclipse.che.api.workspace.server.stack.image.StackIcon in project che by eclipse.
the class StackServiceTest method setUp.
@BeforeMethod
public void setUp() throws NoSuchFieldException, IllegalAccessException {
byte[] fileContent = STACK_ID.getBytes();
stackIcon = new StackIcon(ICON_MEDIA_TYPE, "image/svg+xml", fileContent);
componentsImpl = singletonList(new StackComponentImpl(COMPONENT_NAME, COMPONENT_VERSION));
stackSourceImpl = new StackSourceImpl(SOURCE_TYPE, SOURCE_ORIGIN);
CommandImpl command = new CommandImpl(COMMAND_NAME, COMMAND_LINE, COMMAND_TYPE);
EnvironmentImpl environment = new EnvironmentImpl(null, null);
WorkspaceConfigImpl workspaceConfig = WorkspaceConfigImpl.builder().setName(WORKSPACE_CONFIG_NAME).setDefaultEnv(DEF_ENVIRONMENT_NAME).setCommands(singletonList(command)).setEnvironments(singletonMap(ENVIRONMENT_NAME, environment)).build();
stackSourceDto = newDto(StackSourceDto.class).withType(SOURCE_TYPE).withOrigin(SOURCE_ORIGIN);
StackComponentDto stackComponentDto = newDto(StackComponentDto.class).withName(COMPONENT_NAME).withVersion(COMPONENT_VERSION);
componentsDto = singletonList(stackComponentDto);
stackDto = DtoFactory.getInstance().createDto(StackDto.class).withId(STACK_ID).withName(NAME).withDescription(DESCRIPTION).withScope(SCOPE).withCreator(CREATOR).withTags(tags).withSource(stackSourceDto).withComponents(componentsDto);
stackImpl = StackImpl.builder().setId(STACK_ID).setName(NAME).setDescription(DESCRIPTION).setScope(SCOPE).setCreator(CREATOR).setTags(tags).setSource(stackSourceImpl).setComponents(componentsImpl).setWorkspaceConfig(workspaceConfig).setStackIcon(stackIcon).build();
foreignStack = StackImpl.builder().setId(STACK_ID).setName(NAME).setDescription(DESCRIPTION).setScope(SCOPE).setCreator(FOREIGN_CREATOR).setTags(tags).setSource(stackSourceImpl).setComponents(componentsImpl).setWorkspaceConfig(workspaceConfig).setStackIcon(stackIcon).build();
when(uriInfo.getBaseUriBuilder()).thenReturn(new UriBuilderImpl());
final Field uriField = service.getClass().getSuperclass().getDeclaredField("uriInfo");
uriField.setAccessible(true);
uriField.set(service, uriInfo);
}
Aggregations