use of org.eclipse.che.api.core.rest.annotations.GenerateLink in project che by eclipse.
the class StackService method updateStack.
@PUT
@Path("/{id}")
@Produces(APPLICATION_JSON)
@Consumes(APPLICATION_JSON)
@GenerateLink(rel = LINK_REL_UPDATE_STACK)
@ApiOperation(value = "Update the stack by replacing all the existing data (exclude field \"creator\") with update")
@ApiResponses({ @ApiResponse(code = 200, message = "The stack successfully updated"), @ApiResponse(code = 400, message = "Missed required parameters, parameters are not valid"), @ApiResponse(code = 403, message = "The user does not have access to update the stack"), @ApiResponse(code = 409, message = "Conflict error occurred during stack update" + "(e.g. Stack with such name already exists)"), @ApiResponse(code = 500, message = "Internal server error occurred") })
public StackDto updateStack(@ApiParam(value = "The stack update", required = true) final StackDto updateDto, @ApiParam(value = "The stack id", required = true) @PathParam("id") final String id) throws ApiException {
stackValidator.check(updateDto);
final StackImpl stack = stackDao.getById(id);
StackImpl stackForUpdate = StackImpl.builder().setId(id).setName(updateDto.getName()).setDescription(updateDto.getDescription()).setScope(updateDto.getScope()).setCreator(stack.getCreator()).setTags(updateDto.getTags()).setWorkspaceConfig(updateDto.getWorkspaceConfig()).setSource(updateDto.getSource()).setComponents(updateDto.getComponents()).build();
return asStackDto(stackDao.update(stackForUpdate));
}
use of org.eclipse.che.api.core.rest.annotations.GenerateLink in project che by eclipse.
the class SshService method createPair.
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.TEXT_HTML)
@GenerateLink(rel = Constants.LINK_REL_CREATE_PAIR)
public Response createPair(Iterator<FileItem> formData) throws BadRequestException, ServerException, ConflictException {
String service = null;
String name = null;
String privateKey = null;
String publicKey = null;
while (formData.hasNext()) {
FileItem item = formData.next();
String fieldName = item.getFieldName();
switch(fieldName) {
case "service":
service = item.getString();
break;
case "name":
name = item.getString();
break;
case "privateKey":
privateKey = item.getString();
break;
case "publicKey":
publicKey = item.getString();
break;
default:
}
}
requiredNotNull(service, "Service name required");
requiredNotNull(name, "Name required");
if (privateKey == null && publicKey == null) {
throw new BadRequestException("Key content was not provided.");
}
sshManager.createPair(new SshPairImpl(getCurrentUserId(), service, name, publicKey, privateKey));
// through specific of html form that doesn't invoke complete submit handler
return Response.ok("", MediaType.TEXT_HTML).build();
}
use of org.eclipse.che.api.core.rest.annotations.GenerateLink in project che by eclipse.
the class Service method generateServiceDescriptor.
private ServiceDescriptor generateServiceDescriptor(UriInfo uriInfo, Class<? extends Service> service) {
final List<Link> links = new ArrayList<>();
for (Method method : service.getMethods()) {
final GenerateLink generateLink = method.getAnnotation(GenerateLink.class);
if (generateLink != null) {
try {
links.add(generateLinkForMethod(uriInfo, generateLink.rel(), method));
} catch (RuntimeException ignored) {
}
}
}
final Description description = service.getAnnotation(Description.class);
final ServiceDescriptor dto = createServiceDescriptor().withHref(uriInfo.getRequestUriBuilder().replaceQuery(null).build().toString()).withLinks(links).withVersion(Constants.API_VERSION);
if (description != null) {
dto.setDescription(description.value());
}
return dto;
}
use of org.eclipse.che.api.core.rest.annotations.GenerateLink in project che by eclipse.
the class StackService method removeIcon.
@DELETE
@Path("/{id}/icon")
@GenerateLink(rel = LINK_REL_DELETE_ICON)
@ApiOperation(value = "Delete icon for required stack", notes = "This operation can be performed only by authorized stack owner")
@ApiResponses({ @ApiResponse(code = 204, message = "Icon was successfully removed"), @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 or icon doesn't exist"), @ApiResponse(code = 409, message = "Conflict error occurred during stack update" + "(e.g. Stack with such name already exists)"), @ApiResponse(code = 500, message = "Internal server error occurred") })
public void removeIcon(@ApiParam("The stack Id") @PathParam("id") final String id) throws NotFoundException, ServerException, ConflictException, ForbiddenException, BadRequestException {
StackImpl stack = stackDao.getById(id);
stack.setStackIcon(null);
stackDao.update(stack);
}
use of org.eclipse.che.api.core.rest.annotations.GenerateLink 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();
}
Aggregations