Search in sources :

Example 6 with NewProjectConfigDto

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

the class ProjectManagerWriteTest method testCreateBatchProjectsWithInnerProject.

@Test
public void testCreateBatchProjectsWithInnerProject() throws Exception {
    final String rootProjectPath = "/testProject1";
    final String innerProjectPath = "/testProject1/innerProject";
    final String importType = "importType1";
    final String innerProjectType = "pt2";
    Map<String, List<String>> attributes = new HashMap<>();
    attributes.put("pt2-var2", new AttributeValue("test").getList());
    final String[] paths1 = { "folder1/", "folder1/file1.txt" };
    final String[] paths2 = { "innerProject/", "innerProject/folder2/", "innerProject/folder2/file2.txt" };
    final List<String> children1 = Arrays.asList(paths1);
    final List<String> children2 = Arrays.asList(paths2);
    final List<String> children = new ArrayList<>(children1);
    children.addAll(children2);
    registerImporter(importType, prepareZipArchiveBasedOn(children));
    SourceStorageDto source = DtoFactory.newDto(SourceStorageDto.class).withLocation("someLocation").withType(importType);
    NewProjectConfigDto config1 = createProjectConfigObject("testProject1", rootProjectPath, BaseProjectType.ID, source);
    NewProjectConfigDto config2 = createProjectConfigObject("innerProject", innerProjectPath, innerProjectType, null);
    config2.setAttributes(attributes);
    List<NewProjectConfig> configs = new ArrayList<>(2);
    configs.add(config1);
    configs.add(config2);
    pm.createBatchProjects(configs, false, new ProjectOutputLineConsumerFactory("ws", 300));
    RegisteredProject rootProject = projectRegistry.getProject(rootProjectPath);
    FolderEntry rootProjectFolder = rootProject.getBaseFolder();
    RegisteredProject innerProject = projectRegistry.getProject(innerProjectPath);
    FolderEntry innerProjectFolder = innerProject.getBaseFolder();
    assertNotNull(rootProject);
    assertTrue(rootProjectFolder.getVirtualFile().exists());
    assertEquals(rootProjectPath, rootProject.getPath());
    checkChildrenFor(rootProjectFolder, children1);
    assertNotNull(innerProject);
    assertTrue(innerProjectFolder.getVirtualFile().exists());
    assertEquals(innerProjectPath, innerProject.getPath());
    assertEquals(innerProjectType, innerProject.getType());
    checkChildrenFor(rootProjectFolder, children2);
}
Also used : AttributeValue(org.eclipse.che.api.project.server.type.AttributeValue) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SourceStorageDto(org.eclipse.che.api.workspace.shared.dto.SourceStorageDto) NewProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto) ArrayList(java.util.ArrayList) List(java.util.List) NewProjectConfig(org.eclipse.che.api.core.model.project.NewProjectConfig) Test(org.junit.Test)

Example 7 with NewProjectConfigDto

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

the class ProjectManagerWriteTest method testCreateBatchProjectsWithInnerProjectWhenInnerProjectContainsSource.

@Test
public void testCreateBatchProjectsWithInnerProjectWhenInnerProjectContainsSource() throws Exception {
    final String rootProjectPath = "/rootProject";
    final String innerProjectPath = "/rootProject/innerProject";
    final String rootImportType = "rootImportType";
    final String innerImportType = "innerImportType";
    final String innerProjectType = "pt2";
    Map<String, List<String>> attributes = new HashMap<>();
    attributes.put("pt2-var2", new AttributeValue("test").getList());
    final String[] paths1 = { "folder1/", "folder1/file1.txt" };
    final List<String> children1 = new ArrayList<>(Arrays.asList(paths1));
    registerImporter(rootImportType, prepareZipArchiveBasedOn(children1));
    final String[] paths2 = { "folder2/", "folder2/file2.txt" };
    final List<String> children2 = new ArrayList<>(Arrays.asList(paths2));
    registerImporter(innerImportType, prepareZipArchiveBasedOn(children2));
    final SourceStorageDto source1 = DtoFactory.newDto(SourceStorageDto.class).withLocation("someLocation").withType(rootImportType);
    final NewProjectConfigDto config1 = createProjectConfigObject("testProject1", rootProjectPath, BaseProjectType.ID, source1);
    final SourceStorageDto source2 = DtoFactory.newDto(SourceStorageDto.class).withLocation("someLocation").withType(innerImportType);
    final NewProjectConfigDto config2 = createProjectConfigObject("testProject2", innerProjectPath, innerProjectType, source2);
    config2.setAttributes(attributes);
    final List<NewProjectConfig> configs = new ArrayList<>(2);
    configs.add(config2);
    configs.add(config1);
    pm.createBatchProjects(configs, false, new ProjectOutputLineConsumerFactory("ws", 300));
    RegisteredProject rootProject = projectRegistry.getProject(rootProjectPath);
    FolderEntry rootProjectFolder = rootProject.getBaseFolder();
    checkProjectExist(rootProjectPath);
    checkChildrenFor(rootProjectFolder, children1);
    RegisteredProject innerProject = projectRegistry.getProject(innerProjectPath);
    FolderEntry innerProjectFolder = innerProject.getBaseFolder();
    assertNotNull(innerProject);
    assertTrue(innerProjectFolder.getVirtualFile().exists());
    assertEquals(innerProjectPath, innerProject.getPath());
    assertEquals(innerProjectType, innerProject.getType());
    checkChildrenFor(innerProjectFolder, children2);
}
Also used : AttributeValue(org.eclipse.che.api.project.server.type.AttributeValue) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SourceStorageDto(org.eclipse.che.api.workspace.shared.dto.SourceStorageDto) NewProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto) ArrayList(java.util.ArrayList) List(java.util.List) NewProjectConfig(org.eclipse.che.api.core.model.project.NewProjectConfig) Test(org.junit.Test)

Example 8 with NewProjectConfigDto

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

the class ProjectManagerWriteTest method testCreateBatchProjectsByImportingSourceCode.

@Test
public void testCreateBatchProjectsByImportingSourceCode() throws Exception {
    final String projectPath1 = "/testProject1";
    final String projectPath2 = "/testProject2";
    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", projectPath1, BaseProjectType.ID, source1);
    final SourceStorageDto source2 = DtoFactory.newDto(SourceStorageDto.class).withLocation("someLocation").withType(importType2);
    final NewProjectConfigDto config2 = createProjectConfigObject("testProject2", projectPath2, BaseProjectType.ID, source2);
    final List<NewProjectConfig> configs = new ArrayList<>(2);
    configs.add(config1);
    configs.add(config2);
    pm.createBatchProjects(configs, false, new ProjectOutputLineConsumerFactory("ws", 300));
    final RegisteredProject project1 = projectRegistry.getProject(projectPath1);
    final FolderEntry projectFolder1 = project1.getBaseFolder();
    checkProjectExist(projectPath1);
    checkChildrenFor(projectFolder1, children1);
    final RegisteredProject project2 = projectRegistry.getProject(projectPath2);
    final FolderEntry projectFolder2 = project2.getBaseFolder();
    checkProjectExist(projectPath2);
    checkChildrenFor(projectFolder2, children2);
}
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 9 with NewProjectConfigDto

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

the class ProjectManagerWriteTest method shouldRollbackCreatingBatchProjects.

@Test
public void shouldRollbackCreatingBatchProjects() throws Exception {
    // we should rollback operation of creating batch projects when we have not source code for at least one project
    // For example: two projects were success created, but we could not get source code for third configuration
    // At this use case we should rollback the operation and clean up all created projects
    final String projectPath1 = "/testProject1";
    final String projectPath2 = "/testProject2";
    final String projectPath3 = "/testProject3";
    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", projectPath1, BaseProjectType.ID, source1);
    final SourceStorageDto source2 = DtoFactory.newDto(SourceStorageDto.class).withLocation("someLocation").withType(importType2);
    final NewProjectConfigDto config2 = createProjectConfigObject("testProject2", projectPath2, BaseProjectType.ID, source2);
    final SourceStorageDto source = DtoFactory.newDto(SourceStorageDto.class).withLocation("someLocation").withType("importType");
    final NewProjectConfigDto config3 = createProjectConfigObject("testProject3", projectPath3, BaseProjectType.ID, source);
    final List<NewProjectConfig> configs = new ArrayList<>(2);
    //will be success created
    configs.add(config1);
    //will be success created
    configs.add(config2);
    //we be failed - we have not registered importer - source code will not be imported
    configs.add(config3);
    try {
        pm.createBatchProjects(configs, false, new ProjectOutputLineConsumerFactory("ws", 300));
        fail("We should rollback operation of creating batch projects when we could not get source code for at least one project");
    } catch (Exception e) {
        assertEquals(0, projectRegistry.getProjects().size());
        assertNull(projectRegistry.getProject(projectPath1));
        assertNull(pm.getProjectsRoot().getChild(projectPath1));
        assertNull(projectRegistry.getProject(projectPath2));
        assertNull(pm.getProjectsRoot().getChild(projectPath2));
        assertNull(projectRegistry.getProject(projectPath3));
        assertNull(pm.getProjectsRoot().getChild(projectPath3));
    }
}
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)

Example 10 with NewProjectConfigDto

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

the class CategoriesPagePresenter method updateProjectConfigs.

private void updateProjectConfigs(String newProjectPath, ProjectTemplateDescriptor projectTemplate) {
    final List<NewProjectConfigDto> configDtoList = projectTemplate.getProjects();
    if (newProjectPath.equals("/")) {
        return;
    }
    final String templatePath = projectTemplate.getPath();
    final List<NewProjectConfig> updatedConfigs = new ArrayList<>(configDtoList.size());
    for (NewProjectConfigDto configDto : configDtoList) {
        final NewProjectConfig newConfig = new NewProjectConfigImpl(configDto);
        final String projectPath = configDto.getPath();
        if (projectPath.startsWith(templatePath)) {
            final String path = projectPath.replaceFirst(templatePath, newProjectPath);
            newConfig.setPath(path);
        }
        updatedConfigs.add(newConfig);
    }
    dataObject.setProjects(updatedConfigs);
}
Also used : NewProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto) NewProjectConfigImpl(org.eclipse.che.ide.api.project.NewProjectConfigImpl) ArrayList(java.util.ArrayList) NewProjectConfig(org.eclipse.che.api.core.model.project.NewProjectConfig)

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