Search in sources :

Example 6 with GenerateLink

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));
}
Also used : StackImpl(org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) GenerateLink(org.eclipse.che.api.core.rest.annotations.GenerateLink) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 7 with GenerateLink

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();
}
Also used : FileItem(org.apache.commons.fileupload.FileItem) SshPairImpl(org.eclipse.che.api.ssh.server.model.impl.SshPairImpl) BadRequestException(org.eclipse.che.api.core.BadRequestException) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GenerateLink(org.eclipse.che.api.core.rest.annotations.GenerateLink)

Example 8 with GenerateLink

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;
}
Also used : Description(org.eclipse.che.api.core.rest.annotations.Description) ServiceDescriptor(org.eclipse.che.api.core.rest.shared.dto.ServiceDescriptor) ArrayList(java.util.ArrayList) GenerateLink(org.eclipse.che.api.core.rest.annotations.GenerateLink) HttpMethod(javax.ws.rs.HttpMethod) Method(java.lang.reflect.Method) Link(org.eclipse.che.api.core.rest.shared.dto.Link) GenerateLink(org.eclipse.che.api.core.rest.annotations.GenerateLink)

Example 9 with GenerateLink

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);
}
Also used : StackImpl(org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) ApiOperation(io.swagger.annotations.ApiOperation) GenerateLink(org.eclipse.che.api.core.rest.annotations.GenerateLink) ApiResponses(io.swagger.annotations.ApiResponses)

Example 10 with GenerateLink

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();
}
Also used : StackImpl(org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl) NotFoundException(org.eclipse.che.api.core.NotFoundException) StackIcon(org.eclipse.che.api.workspace.server.stack.image.StackIcon) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) GenerateLink(org.eclipse.che.api.core.rest.annotations.GenerateLink) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

GenerateLink (org.eclipse.che.api.core.rest.annotations.GenerateLink)16 ApiOperation (io.swagger.annotations.ApiOperation)14 ApiResponses (io.swagger.annotations.ApiResponses)13 Consumes (javax.ws.rs.Consumes)13 Produces (javax.ws.rs.Produces)11 POST (javax.ws.rs.POST)10 Path (javax.ws.rs.Path)9 StackImpl (org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl)5 SshPairImpl (org.eclipse.che.api.ssh.server.model.impl.SshPairImpl)3 ArrayList (java.util.ArrayList)2 DELETE (javax.ws.rs.DELETE)2 PUT (javax.ws.rs.PUT)2 FileItem (org.apache.commons.fileupload.FileItem)2 BadRequestException (org.eclipse.che.api.core.BadRequestException)2 NotFoundException (org.eclipse.che.api.core.NotFoundException)2 StackIcon (org.eclipse.che.api.workspace.server.stack.image.StackIcon)2 NewProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto)2 ProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto)2 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1