Search in sources :

Example 1 with GenerateLink

use of org.eclipse.che.api.core.rest.annotations.GenerateLink in project che by eclipse.

the class ProjectService method createBatchProjects.

@POST
@Path("/batch")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Creates batch of projects according to their configurations", notes = "A project will be created by importing when project configuration contains source object. " + "For creating a project by generator options should be specified.", response = ProjectConfigDto.class)
@ApiResponses({ @ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 400, message = "Path for new project should be defined"), @ApiResponse(code = 403, message = "Operation is forbidden"), @ApiResponse(code = 409, message = "Project with specified name already exist in workspace"), @ApiResponse(code = 500, message = "Server error") })
@GenerateLink(rel = LINK_REL_CREATE_BATCH_PROJECTS)
public List<ProjectConfigDto> createBatchProjects(@Description("list of descriptors for projects") List<NewProjectConfigDto> projectConfigList, @ApiParam(value = "Force rewrite existing project", allowableValues = "true,false") @QueryParam("force") boolean rewrite) throws ConflictException, ForbiddenException, ServerException, NotFoundException, IOException, UnauthorizedException, BadRequestException {
    List<ProjectConfigDto> result = new ArrayList<>(projectConfigList.size());
    final ProjectOutputLineConsumerFactory outputOutputConsumerFactory = new ProjectOutputLineConsumerFactory(workspace, 300);
    for (RegisteredProject registeredProject : projectManager.createBatchProjects(projectConfigList, rewrite, outputOutputConsumerFactory)) {
        ProjectConfigDto projectConfig = injectProjectLinks(asDto(registeredProject));
        result.add(projectConfig);
        eventService.publish(new ProjectCreatedEvent(workspace, registeredProject.getPath()));
    }
    return result;
}
Also used : NewProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) ArrayList(java.util.ArrayList) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) GenerateLink(org.eclipse.che.api.core.rest.annotations.GenerateLink) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with GenerateLink

use of org.eclipse.che.api.core.rest.annotations.GenerateLink in project che by eclipse.

the class ProjectService method createProject.

@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Creates new project", response = ProjectConfigDto.class)
@ApiResponses({ @ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 403, message = "Operation is forbidden"), @ApiResponse(code = 409, message = "Project with specified name already exist in workspace"), @ApiResponse(code = 500, message = "Server error") })
@GenerateLink(rel = LINK_REL_CREATE_PROJECT)
public /**
     * NOTE: parentPath is added to make a module
     */
ProjectConfigDto createProject(@ApiParam(value = "Add to this project as module", required = false) @Context UriInfo uriInfo, @Description("descriptor of project") ProjectConfigDto projectConfig) throws ConflictException, ForbiddenException, ServerException, NotFoundException {
    Map<String, String> options = new HashMap<>();
    MultivaluedMap<String, String> map = uriInfo.getQueryParameters();
    for (String key : map.keySet()) {
        options.put(key, map.get(key).get(0));
    }
    String pathToProject = projectConfig.getPath();
    String pathToParent = pathToProject.substring(0, pathToProject.lastIndexOf("/"));
    if (!pathToParent.equals("/")) {
        VirtualFileEntry parentFileEntry = projectManager.getProjectsRoot().getChild(pathToParent);
        if (parentFileEntry == null) {
            throw new NotFoundException("The parent folder with path " + pathToParent + " does not exist.");
        }
    }
    final RegisteredProject project = projectManager.createProject(projectConfig, options);
    final ProjectConfigDto configDto = asDto(project);
    eventService.publish(new ProjectCreatedEvent(workspace, project.getPath()));
    return injectProjectLinks(configDto);
}
Also used : HashMap(java.util.HashMap) NewProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) NotFoundException(org.eclipse.che.api.core.NotFoundException) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) GenerateLink(org.eclipse.che.api.core.rest.annotations.GenerateLink) ApiResponses(io.swagger.annotations.ApiResponses)

Example 3 with GenerateLink

use of org.eclipse.che.api.core.rest.annotations.GenerateLink in project che by eclipse.

the class WorkspaceService method create.

@POST
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@GenerateLink(rel = LINK_REL_CREATE_WORKSPACE)
@ApiOperation(value = "Create a new workspace based on the configuration", notes = "This operation can be performed only by authorized user," + "this user will be the owner of the created workspace", response = WorkspaceConfigDto.class)
@ApiResponses({ @ApiResponse(code = 201, message = "The workspace successfully created"), @ApiResponse(code = 400, message = "Missed required parameters, parameters are not valid"), @ApiResponse(code = 403, message = "The user does not have access to create a new workspace"), @ApiResponse(code = 409, message = "Conflict error occurred during the workspace creation" + "(e.g. The workspace with such name already exists)"), @ApiResponse(code = 500, message = "Internal server error occurred") })
public Response create(@ApiParam(value = "The configuration to create the new workspace", required = true) WorkspaceConfigDto config, @ApiParam(value = "Workspace attribute defined in 'attrName:attrValue' format. " + "The first ':' is considered as attribute name and value separator", examples = @Example({ @ExampleProperty("stackId:stack123"), @ExampleProperty("attrName:value-with:colon") })) @QueryParam("attribute") List<String> attrsList, @ApiParam("If true then the workspace will be immediately " + "started after it is successfully created") @QueryParam("start-after-create") @DefaultValue("false") Boolean startAfterCreate, @ApiParam("Namespace where workspace should be created") @QueryParam("namespace") String namespace) throws ConflictException, ServerException, BadRequestException, ForbiddenException, NotFoundException {
    requiredNotNull(config, "Workspace configuration");
    final Map<String, String> attributes = parseAttrs(attrsList);
    validator.validateAttributes(attributes);
    validator.validateConfig(config);
    relativizeRecipeLinks(config);
    if (namespace == null) {
        namespace = EnvironmentContext.getCurrent().getSubject().getUserName();
    }
    final WorkspaceImpl workspace = workspaceManager.createWorkspace(config, namespace, attributes);
    if (startAfterCreate) {
        workspaceManager.startWorkspace(workspace.getId(), null, false);
    }
    return Response.status(201).entity(linksInjector.injectLinks(asDto(workspace), getServiceContext())).build();
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) GenerateLink(org.eclipse.che.api.core.rest.annotations.GenerateLink) ApiResponses(io.swagger.annotations.ApiResponses)

Example 4 with GenerateLink

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

Example 5 with GenerateLink

use of org.eclipse.che.api.core.rest.annotations.GenerateLink in project che by eclipse.

the class StackService method createStack.

@POST
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@GenerateLink(rel = LINK_REL_CREATE_STACK)
@ApiOperation(value = "Create a new stack", notes = "This operation can be performed only by authorized user", response = StackDto.class)
@ApiResponses({ @ApiResponse(code = 201, message = "The stack successfully created"), @ApiResponse(code = 400, message = "Missed required parameters, parameters are not valid"), @ApiResponse(code = 403, message = "The user does not have access to create a new stack"), @ApiResponse(code = 409, message = "Conflict error occurred during the stack creation" + "(e.g. The stack with such name already exists)"), @ApiResponse(code = 500, message = "Internal server error occurred") })
public Response createStack(@ApiParam("The new stack") final StackDto stackDto) throws ApiException {
    stackValidator.check(stackDto);
    final String userId = EnvironmentContext.getCurrent().getSubject().getUserId();
    final StackImpl newStack = StackImpl.builder().generateId().setName(stackDto.getName()).setDescription(stackDto.getDescription()).setScope(stackDto.getScope()).setCreator(userId).setTags(stackDto.getTags()).setWorkspaceConfig(stackDto.getWorkspaceConfig()).setSource(stackDto.getSource()).setComponents(stackDto.getComponents()).build();
    stackDao.create(newStack);
    return Response.status(CREATED).entity(asStackDto(newStack)).build();
}
Also used : StackImpl(org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) 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