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;
}
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");
}
});
}
});
}
});
}
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;
}
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"));
}
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));
}
}
Aggregations