use of org.eclipse.che.api.workspace.shared.dto.SourceStorageDto in project che by eclipse.
the class ResourceManager method importProject.
protected Promise<Project> importProject(final Project.ProjectRequest importRequest) {
checkArgument(checkProjectName(importRequest.getBody().getName()), "Invalid project name");
checkNotNull(importRequest.getBody().getSource(), "Null source configuration occurred");
final Path path = Path.valueOf(importRequest.getBody().getPath());
return findResource(path, true).thenPromise(new Function<Optional<Resource>, Promise<Project>>() {
@Override
public Promise<Project> apply(final Optional<Resource> resource) throws FunctionException {
final SourceStorage sourceStorage = importRequest.getBody().getSource();
final SourceStorageDto sourceStorageDto = dtoFactory.createDto(SourceStorageDto.class).withType(sourceStorage.getType()).withLocation(sourceStorage.getLocation()).withParameters(sourceStorage.getParameters());
return ps.importProject(path, sourceStorageDto).thenPromise(new Function<Void, Promise<Project>>() {
@Override
public Promise<Project> apply(Void ignored) throws FunctionException {
return ps.getProject(path).then(new Function<ProjectConfigDto, Project>() {
@Override
public Project apply(ProjectConfigDto config) throws FunctionException {
cachedConfigs = add(cachedConfigs, config);
Resource project = resourceFactory.newProjectImpl(config, ResourceManager.this);
checkState(project != null, "Failed to locate imported project's configuration");
store.register(project);
eventBus.fireEvent(new ResourceChangedEvent(new ResourceDeltaImpl(project, (resource.isPresent() ? UPDATED : ADDED) | DERIVED)));
return (Project) project;
}
});
}
});
}
});
}
use of org.eclipse.che.api.workspace.shared.dto.SourceStorageDto in project che by eclipse.
the class ResourceManager method update.
/**
* Update state of specific properties in project and save this state on the server.
* As the result method should return the {@link Promise} with new {@link Project} object.
* <p/>
* During the update method have to iterate on children of updated resource and if any of
* them has changed own type, e.g. folder -> project, project -> folder, specific event
* has to be fired.
* <p/>
* Method is not intended to be called in third party components. It is the service method
* for {@link Project}.
*
* @param path
* the path to project which should be updated
* @param request
* the update request
* @return the {@link Promise} with new {@link Project} object.
* @see ResourceChangedEvent
* @see ProjectRequest
* @see Project#update()
* @since 4.4.0
*/
protected Promise<Project> update(final Path path, final ProjectRequest request) {
final ProjectConfig projectConfig = request.getBody();
final SourceStorage source = projectConfig.getSource();
final SourceStorageDto sourceDto = dtoFactory.createDto(SourceStorageDto.class);
if (source != null) {
sourceDto.setLocation(source.getLocation());
sourceDto.setType(source.getType());
sourceDto.setParameters(source.getParameters());
}
final ProjectConfigDto dto = dtoFactory.createDto(ProjectConfigDto.class).withName(projectConfig.getName()).withPath(path.toString()).withDescription(projectConfig.getDescription()).withType(projectConfig.getType()).withMixins(projectConfig.getMixins()).withAttributes(projectConfig.getAttributes()).withSource(sourceDto);
return ps.updateProject(dto).thenPromise(new Function<ProjectConfigDto, Promise<Project>>() {
@Override
public Promise<Project> apply(ProjectConfigDto reference) throws FunctionException {
/* Note: After update, project may become to be other type,
e.g. blank -> java or maven, or ant, or etc. And this may
cause sub-project creations. Simultaneously on the client
side there is outdated information about sub-projects, so
we need to get updated project list. */
//dispose outdated resource
final Optional<Resource> outdatedResource = store.getResource(path);
checkState(outdatedResource.isPresent(), "Outdated resource wasn't found");
final Resource resource = outdatedResource.get();
checkState(resource instanceof Container, "Outdated resource is not a container");
Container container = (Container) resource;
if (resource instanceof Folder) {
Container parent = resource.getParent();
checkState(parent != null, "Parent of the resource wasn't found");
container = parent;
}
return synchronize(container).then(new Function<Resource[], Project>() {
@Override
public Project apply(Resource[] synced) throws FunctionException {
final Optional<Resource> updatedProject = store.getResource(path);
checkState(updatedProject.isPresent(), "Updated resource is not present");
checkState(updatedProject.get().isProject(), "Updated resource is not a project");
eventBus.fireEvent(new ResourceChangedEvent(new ResourceDeltaImpl(updatedProject.get(), UPDATED)));
return (Project) updatedProject.get();
}
});
}
});
}
use of org.eclipse.che.api.workspace.shared.dto.SourceStorageDto 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.SourceStorageDto 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.SourceStorageDto in project che by eclipse.
the class StackLoaderTest method dtoShouldBeSerialized.
@Test
public void dtoShouldBeSerialized() {
StackDto stackDtoDescriptor = newDto(StackDto.class).withName("nameWorkspaceConfig");
StackComponentDto stackComponentDto = newDto(StackComponentDto.class).withName("java").withVersion("1.8");
stackDtoDescriptor.setComponents(Collections.singletonList(stackComponentDto));
stackDtoDescriptor.setTags(Arrays.asList("some teg1", "some teg2"));
stackDtoDescriptor.setDescription("description");
stackDtoDescriptor.setId("someId");
stackDtoDescriptor.setScope("scope");
stackDtoDescriptor.setCreator("Created in Codenvy");
Map<String, String> attributes = new HashMap<>();
attributes.put("attribute1", "valute attribute1");
Link link = newDto(Link.class).withHref("some url").withMethod("get").withRel("someRel").withConsumes("consumes").withProduces("produces");
HashMap<String, List<String>> projectMap = new HashMap<>();
projectMap.put("test", Arrays.asList("test", "test2"));
ProjectProblemDto projectProblem = newDto(ProjectProblemDto.class).withCode(100).withMessage("message");
SourceStorageDto sourceStorageDto = newDto(SourceStorageDto.class).withType("some type").withParameters(attributes).withLocation("location");
ProjectConfigDto projectConfigDto = newDto(ProjectConfigDto.class).withName("project").withPath("somePath").withAttributes(projectMap).withType("maven type").withDescription("some project description").withLinks(Collections.singletonList(link)).withMixins(Collections.singletonList("mixin time")).withProblems(Collections.singletonList(projectProblem)).withSource(sourceStorageDto);
EnvironmentRecipeDto environmentRecipe = newDto(EnvironmentRecipeDto.class).withContent("some content").withContentType("some content type").withType("someType");
Map<String, ServerConf2Dto> servers = new HashMap<>();
servers.put("server1Ref", newDto(ServerConf2Dto.class).withPort("8080/tcp").withProtocol("http").withProperties(singletonMap("key", "value")));
Map<String, ExtendedMachineDto> machines = new HashMap<>();
machines.put("someMachineName", newDto(ExtendedMachineDto.class).withAgents(Arrays.asList("agent1", "agent2")).withServers(servers).withAttributes(singletonMap("memoryLimitBytes", "" + 512L * 1024L * 1024L)));
EnvironmentDto environmentDto = newDto(EnvironmentDto.class).withRecipe(environmentRecipe).withMachines(machines);
CommandDto commandDto = newDto(CommandDto.class).withType("command type").withName("command name").withCommandLine("command line");
WorkspaceConfigDto workspaceConfigDto = newDto(WorkspaceConfigDto.class).withName("SomeWorkspaceConfig").withDescription("some workspace").withLinks(Collections.singletonList(link)).withDefaultEnv("some Default Env name").withProjects(Collections.singletonList(projectConfigDto)).withEnvironments(singletonMap("name", environmentDto)).withCommands(Collections.singletonList(commandDto));
stackDtoDescriptor.setWorkspaceConfig(workspaceConfigDto);
Gson GSON = new GsonBuilder().create();
GSON.fromJson(stackDtoDescriptor.toString(), StackImpl.class);
}
Aggregations