Search in sources :

Example 1 with NewProjectConfigDto

use of org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto 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 NewProjectConfigDto

use of org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto in project che by eclipse.

the class ResourceManager method createProject.

Promise<Project> createProject(final Project.ProjectRequest createRequest) {
    checkArgument(checkProjectName(createRequest.getBody().getName()), "Invalid project name");
    checkArgument(typeRegistry.getProjectType(createRequest.getBody().getType()) != null, "Invalid project type");
    final Path path = Path.valueOf(createRequest.getBody().getPath());
    return findResource(path, true).thenPromise(new Function<Optional<Resource>, Promise<Project>>() {

        @Override
        public Promise<Project> apply(Optional<Resource> resource) throws FunctionException {
            if (resource.isPresent()) {
                if (resource.get().isProject()) {
                    throw new IllegalStateException("Project already exists");
                } else if (resource.get().isFile()) {
                    throw new IllegalStateException("File can not be converted to project");
                }
                return update(path, createRequest);
            }
            final MutableProjectConfig projectConfig = (MutableProjectConfig) createRequest.getBody();
            final List<NewProjectConfig> projectConfigList = projectConfig.getProjects();
            projectConfigList.add(asDto(projectConfig));
            final List<NewProjectConfigDto> configDtoList = asDto(projectConfigList);
            return ps.createBatchProjects(configDtoList).thenPromise(new Function<List<ProjectConfigDto>, Promise<Project>>() {

                @Override
                public Promise<Project> apply(final List<ProjectConfigDto> configList) throws FunctionException {
                    return ps.getProjects().then(new Function<List<ProjectConfigDto>, Project>() {

                        @Override
                        public Project apply(List<ProjectConfigDto> updatedConfiguration) throws FunctionException {
                            //cache new configs
                            cachedConfigs = updatedConfiguration.toArray(new ProjectConfigDto[updatedConfiguration.size()]);
                            for (ProjectConfigDto projectConfigDto : configList) {
                                if (projectConfigDto.getPath().equals(path.toString())) {
                                    final Project newResource = resourceFactory.newProjectImpl(projectConfigDto, ResourceManager.this);
                                    store.register(newResource);
                                    eventBus.fireEvent(new ResourceChangedEvent(new ResourceDeltaImpl(newResource, ADDED | DERIVED)));
                                    return newResource;
                                }
                            }
                            throw new IllegalStateException("Created project is not found");
                        }
                    });
                }
            });
        }
    });
}
Also used : Path(org.eclipse.che.ide.resource.Path) MutableProjectConfig(org.eclipse.che.ide.api.project.MutableProjectConfig) Optional(com.google.common.base.Optional) NewProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) Resource(org.eclipse.che.ide.api.resources.Resource) FunctionException(org.eclipse.che.api.promises.client.FunctionException) Promise(org.eclipse.che.api.promises.client.Promise) Function(org.eclipse.che.api.promises.client.Function) Project(org.eclipse.che.ide.api.resources.Project) List(java.util.List) ArrayList(java.util.ArrayList) ResourceChangedEvent(org.eclipse.che.ide.api.resources.ResourceChangedEvent)

Example 3 with NewProjectConfigDto

use of org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto in project che by eclipse.

the class ResourceManager method asDto.

private List<NewProjectConfigDto> asDto(List<NewProjectConfig> configList) {
    List<NewProjectConfigDto> result = new ArrayList<>(configList.size());
    for (NewProjectConfig config : configList) {
        final SourceStorage source = config.getSource();
        final SourceStorageDto sourceStorageDto = dtoFactory.createDto(SourceStorageDto.class).withType(source.getType()).withLocation(source.getLocation()).withParameters(source.getParameters());
        result.add(dtoFactory.createDto(NewProjectConfigDto.class).withName(config.getName()).withPath(config.getPath()).withDescription(config.getDescription()).withSource(sourceStorageDto).withType(config.getType()).withMixins(config.getMixins()).withAttributes(config.getAttributes()).withOptions(config.getOptions()));
    }
    return result;
}
Also used : SourceStorage(org.eclipse.che.api.core.model.project.SourceStorage) SourceStorageDto(org.eclipse.che.api.workspace.shared.dto.SourceStorageDto) NewProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto) ArrayList(java.util.ArrayList) NewProjectConfig(org.eclipse.che.api.core.model.project.NewProjectConfig)

Example 4 with NewProjectConfigDto

use of org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto in project che by eclipse.

the class ProjectManagerWriteTest method shouldRewriteProjectAtCreatingBatchProjectsWhenProjectAlreadyExist.

@Test
public void shouldRewriteProjectAtCreatingBatchProjectsWhenProjectAlreadyExist() throws Exception {
    final String projectPath = "/testProject";
    final String importType1 = "importType1";
    final String importType2 = "importType2";
    final String[] paths1 = { "folder1/", "folder1/file1.txt" };
    final List<String> children1 = new ArrayList<>(Arrays.asList(paths1));
    registerImporter(importType1, prepareZipArchiveBasedOn(children1));
    final String[] paths2 = { "folder2/", "folder2/file2.txt" };
    final List<String> children2 = new ArrayList<>(Arrays.asList(paths2));
    registerImporter(importType2, prepareZipArchiveBasedOn(children2));
    final SourceStorageDto source1 = DtoFactory.newDto(SourceStorageDto.class).withLocation("someLocation").withType(importType1);
    final NewProjectConfigDto config1 = createProjectConfigObject("testProject1", projectPath, "blank", source1);
    final SourceStorageDto source2 = DtoFactory.newDto(SourceStorageDto.class).withLocation("someLocation").withType(importType2);
    final NewProjectConfigDto config2 = createProjectConfigObject("testProject2", projectPath, "blank", source2);
    final List<NewProjectConfig> configs = new ArrayList<>(1);
    configs.add(config1);
    pm.createBatchProjects(configs, false, new ProjectOutputLineConsumerFactory("ws", 300));
    final FolderEntry projectFolder1 = projectRegistry.getProject(projectPath).getBaseFolder();
    checkProjectExist(projectPath);
    checkChildrenFor(projectFolder1, children1);
    assertEquals(1, projectRegistry.getProjects().size());
    configs.clear();
    configs.add(config2);
    pm.createBatchProjects(configs, true, new ProjectOutputLineConsumerFactory("ws", 300));
    final FolderEntry projectFolder2 = projectRegistry.getProject(projectPath).getBaseFolder();
    checkProjectExist(projectPath);
    checkChildrenFor(projectFolder2, children2);
    assertEquals(1, projectRegistry.getProjects().size());
    assertNull(projectFolder2.getChild("folder1/"));
    assertNull(projectFolder2.getChild("folder1/file1.txt"));
}
Also used : SourceStorageDto(org.eclipse.che.api.workspace.shared.dto.SourceStorageDto) NewProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto) ArrayList(java.util.ArrayList) NewProjectConfig(org.eclipse.che.api.core.model.project.NewProjectConfig) Test(org.junit.Test)

Example 5 with NewProjectConfigDto

use of org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto in project che by eclipse.

the class ProjectManagerWriteTest method testCreateProjectWhenSourceCodeIsNotReachable.

@Test
public void testCreateProjectWhenSourceCodeIsNotReachable() throws Exception {
    final String projectPath = "/testProject";
    final SourceStorageDto source = DtoFactory.newDto(SourceStorageDto.class).withLocation("someLocation").withType("importType");
    final NewProjectConfigDto config = createProjectConfigObject("testProject1", projectPath, BaseProjectType.ID, source);
    final List<NewProjectConfig> configs = new ArrayList<>(1);
    configs.add(config);
    try {
        pm.createBatchProjects(configs, false, new ProjectOutputLineConsumerFactory("ws", 300));
        fail("Exception should be thrown when source code is not reachable");
    } catch (Exception e) {
        assertEquals(0, projectRegistry.getProjects().size());
        assertNull(projectRegistry.getProject(projectPath));
        assertNull(pm.getProjectsRoot().getChild(projectPath));
    }
}
Also used : SourceStorageDto(org.eclipse.che.api.workspace.shared.dto.SourceStorageDto) NewProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto) ArrayList(java.util.ArrayList) NewProjectConfig(org.eclipse.che.api.core.model.project.NewProjectConfig) ConflictException(org.eclipse.che.api.core.ConflictException) IOException(java.io.IOException) NotFoundException(org.eclipse.che.api.core.NotFoundException) BadRequestException(org.eclipse.che.api.core.BadRequestException) ServerException(org.eclipse.che.api.core.ServerException) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)10 NewProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto)10 NewProjectConfig (org.eclipse.che.api.core.model.project.NewProjectConfig)8 SourceStorageDto (org.eclipse.che.api.workspace.shared.dto.SourceStorageDto)7 Test (org.junit.Test)6 List (java.util.List)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 BadRequestException (org.eclipse.che.api.core.BadRequestException)2 ConflictException (org.eclipse.che.api.core.ConflictException)2 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)2 NotFoundException (org.eclipse.che.api.core.NotFoundException)2 ServerException (org.eclipse.che.api.core.ServerException)2 AttributeValue (org.eclipse.che.api.project.server.type.AttributeValue)2 ProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto)2 Optional (com.google.common.base.Optional)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1