use of org.eclipse.che.api.core.model.project.NewProjectConfig 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;
}
use of org.eclipse.che.api.core.model.project.NewProjectConfig in project che by eclipse.
the class ProjectManagerWriteTest method shouldSetBlankTypeAtCreatingBatchProjectsWhenConfigContainsUnregisteredProjectType.
@Test
public void shouldSetBlankTypeAtCreatingBatchProjectsWhenConfigContainsUnregisteredProjectType() throws Exception {
// If declared primary PT is not registered, project is created as Blank, with Problem 12
final String projectPath = "/testProject";
final String projectType = "unregisteredProjectType";
final NewProjectConfig config = createProjectConfigObject("projectName", projectPath, projectType, null);
final List<NewProjectConfig> configs = new ArrayList<>(1);
configs.add(config);
pm.createBatchProjects(configs, false, new ProjectOutputLineConsumerFactory("ws", 300));
final RegisteredProject project = projectRegistry.getProject(projectPath);
final List<Problem> problems = project.getProblems();
checkProjectExist(projectPath);
assertNotEquals(projectType, project.getType());
assertEquals(1, problems.size());
assertEquals(12, problems.get(0).code);
assertEquals(1, projectRegistry.getProjects().size());
}
use of org.eclipse.che.api.core.model.project.NewProjectConfig 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"));
}
use of org.eclipse.che.api.core.model.project.NewProjectConfig in project che by eclipse.
the class ProjectManagerWriteTest method testCreateBatchProjectsByConfigs.
@Test
public void testCreateBatchProjectsByConfigs() throws Exception {
final String projectPath1 = "/testProject1";
final String projectPath2 = "/testProject2";
final NewProjectConfig config1 = createProjectConfigObject("testProject1", projectPath1, BaseProjectType.ID, null);
final NewProjectConfig config2 = createProjectConfigObject("testProject2", projectPath2, BaseProjectType.ID, null);
final List<NewProjectConfig> configs = new ArrayList<>(2);
configs.add(config1);
configs.add(config2);
pm.createBatchProjects(configs, false, new ProjectOutputLineConsumerFactory("ws", 300));
checkProjectExist(projectPath1);
checkProjectExist(projectPath2);
assertEquals(2, projectRegistry.getProjects().size());
}
use of org.eclipse.che.api.core.model.project.NewProjectConfig in project che by eclipse.
the class ProjectManager method createBatchProjects.
/**
* Create batch of projects according to their configurations.
* <p/>
* Notes: - a project will be created by importing when project configuration contains {@link SourceStorage} object,
* otherwise this one will be created corresponding its {@link NewProjectConfig}:
* <li> - {@link NewProjectConfig} object contains only one mandatory {@link NewProjectConfig#setPath(String)} field.
* In this case Project will be created as project of {@link BaseProjectType} type </li>
* <li> - a project will be created as project of {@link BaseProjectType} type with {@link Problem#code} = 12
* when declared primary project type is not registered, </li>
* <li> - a project will be created with {@link Problem#code} = 12 and without mixin project type
* when declared mixin project type is not registered</li>
* <li> - for creating a project by generator {@link NewProjectConfig#getOptions()} should be specified.</li>
*
* @param projectConfigList
* the list of configurations to create projects
* @param rewrite
* whether rewrite or not (throw exception otherwise) if such a project exists
* @return the list of new projects
* @throws BadRequestException
* when {@link NewProjectConfig} object not contains mandatory {@link NewProjectConfig#setPath(String)} field.
* @throws ConflictException
* when the same path project exists and {@code rewrite} is {@code false}
* @throws ForbiddenException
* when trying to overwrite the project and this one contains at least one locked file
* @throws NotFoundException
* when parent folder does not exist
* @throws UnauthorizedException
* if user isn't authorized to access to location at importing source code
* @throws ServerException
* if other error occurs
*/
public List<RegisteredProject> createBatchProjects(List<? extends NewProjectConfig> projectConfigList, boolean rewrite, ProjectOutputLineConsumerFactory lineConsumerFactory) throws BadRequestException, ConflictException, ForbiddenException, NotFoundException, ServerException, UnauthorizedException, IOException {
fileWatcherManager.suspend();
try {
final List<RegisteredProject> projects = new ArrayList<>(projectConfigList.size());
validateProjectConfigurations(projectConfigList, rewrite);
final List<NewProjectConfig> sortedConfigList = projectConfigList.stream().sorted((config1, config2) -> config1.getPath().compareTo(config2.getPath())).collect(Collectors.toList());
for (NewProjectConfig projectConfig : sortedConfigList) {
RegisteredProject registeredProject;
final String pathToProject = projectConfig.getPath();
//creating project(by config or by importing source code)
try {
final SourceStorage sourceStorage = projectConfig.getSource();
if (sourceStorage != null && !isNullOrEmpty(sourceStorage.getLocation())) {
doImportProject(pathToProject, sourceStorage, rewrite, lineConsumerFactory.setProjectName(projectConfig.getPath()));
} else if (!isVirtualFileExist(pathToProject)) {
registeredProject = doCreateProject(projectConfig, projectConfig.getOptions());
projects.add(registeredProject);
continue;
}
} catch (Exception e) {
if (!isVirtualFileExist(pathToProject)) {
//project folder is absent
rollbackCreatingBatchProjects(projects);
throw e;
}
}
//update project
if (isVirtualFileExist(pathToProject)) {
try {
registeredProject = updateProject(projectConfig);
} catch (Exception e) {
registeredProject = projectRegistry.putProject(projectConfig, asFolder(pathToProject), true, false);
final Problem problem = new Problem(NOT_UPDATED_PROJECT, "The project is not updated, caused by " + e.getLocalizedMessage());
registeredProject.getProblems().add(problem);
}
} else {
registeredProject = projectRegistry.putProject(projectConfig, null, true, false);
}
projects.add(registeredProject);
}
return projects;
} finally {
fileWatcherManager.resume();
}
}
Aggregations