use of org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto in project che by eclipse.
the class ResourceManager method getRemoteResources.
Promise<Resource[]> getRemoteResources(final Container container, final int depth, boolean includeFiles) {
checkArgument(depth > -2, "Invalid depth");
if (depth == DEPTH_ZERO) {
return promises.resolve(NO_RESOURCES);
}
int depthToReload = depth;
final Optional<Resource[]> descendants = store.getAll(container.getLocation());
if (depthToReload != -1 && descendants.isPresent()) {
for (Resource resource : descendants.get()) {
if (resource.getLocation().segmentCount() - container.getLocation().segmentCount() > depth) {
depthToReload = resource.getLocation().segmentCount() - container.getLocation().segmentCount();
}
}
}
return ps.getTree(container.getLocation(), depthToReload, includeFiles).then(new Function<TreeElement, Resource[]>() {
@Override
public Resource[] apply(TreeElement tree) throws FunctionException {
class Visitor implements ResourceVisitor {
Resource[] resources;
//size of total items
private int size = 0;
//step to increase resource array
private int incStep = 50;
private Visitor() {
this.resources = NO_RESOURCES;
}
@Override
public void visit(Resource resource) {
if (resource.getResourceType() == PROJECT) {
final Optional<ProjectConfigDto> optionalConfig = findProjectConfigDto(resource.getLocation());
if (optionalConfig.isPresent()) {
final Optional<ProblemProjectMarker> optionalMarker = getProblemMarker(optionalConfig.get());
if (optionalMarker.isPresent()) {
resource.addMarker(optionalMarker.get());
}
}
}
if (size > resources.length - 1) {
//check load factor and increase resource array
resources = copyOf(resources, resources.length + incStep);
}
resources[size++] = resource;
}
}
final Visitor visitor = new Visitor();
traverse(tree, visitor);
return copyOf(visitor.resources, visitor.size);
}
}).then(new Function<Resource[], Resource[]>() {
@Override
public Resource[] apply(Resource[] reloaded) throws FunctionException {
Resource[] result = new Resource[0];
if (descendants.isPresent()) {
Resource[] outdated = descendants.get();
final Resource[] removed = removeAll(outdated, reloaded, false);
for (Resource resource : removed) {
store.dispose(resource.getLocation(), false);
eventBus.fireEvent(new ResourceChangedEvent(new ResourceDeltaImpl(resource, REMOVED)));
}
final Resource[] updated = removeAll(outdated, reloaded, true);
for (Resource resource : updated) {
store.register(resource);
eventBus.fireEvent(new ResourceChangedEvent(new ResourceDeltaImpl(resource, UPDATED)));
final Optional<Resource> registered = store.getResource(resource.getLocation());
if (registered.isPresent()) {
result = Arrays.add(result, registered.get());
}
}
final Resource[] added = removeAll(reloaded, outdated, false);
for (Resource resource : added) {
store.register(resource);
eventBus.fireEvent(new ResourceChangedEvent(new ResourceDeltaImpl(resource, ADDED)));
final Optional<Resource> registered = store.getResource(resource.getLocation());
if (registered.isPresent()) {
result = Arrays.add(result, registered.get());
}
}
} else {
for (Resource resource : reloaded) {
store.register(resource);
eventBus.fireEvent(new ResourceChangedEvent(new ResourceDeltaImpl(resource, ADDED)));
final Optional<Resource> registered = store.getResource(resource.getLocation());
if (registered.isPresent()) {
result = Arrays.add(result, registered.get());
}
}
}
return result;
}
});
}
use of org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto in project che by eclipse.
the class BreakpointManagerImpl method registerEventHandlers.
/**
* Registers events handlers.
*/
private void registerEventHandlers(EventBus eventBus) {
eventBus.addHandler(WorkspaceReadyEvent.getType(), new WorkspaceReadyEvent.WorkspaceReadyHandler() {
@Override
public void onWorkspaceReady(WorkspaceReadyEvent event) {
restoreBreakpoints();
}
});
eventBus.addHandler(EditorOpenedEvent.TYPE, new EditorOpenedEventHandler() {
@Override
public void onEditorOpened(EditorOpenedEvent event) {
onOpenEditor(event.getFile().getLocation().toString(), event.getEditor());
}
});
eventBus.addHandler(DeleteProjectEvent.TYPE, new DeleteProjectHandler() {
@Override
public void onProjectDeleted(DeleteProjectEvent event) {
if (breakpoints.isEmpty()) {
return;
}
ProjectConfigDto config = event.getProjectConfig();
String path = config.getPath() + "/";
deleteBreakpoints(getBreakpointPaths(path));
}
});
eventBus.addHandler(ResourceChangedEvent.getType(), new ResourceChangedEvent.ResourceChangedHandler() {
@Override
public void onResourceChanged(ResourceChangedEvent event) {
if (event.getDelta().getKind() == ResourceDelta.REMOVED) {
if (breakpoints.isEmpty()) {
return;
}
final Resource resource = event.getDelta().getResource();
Path path = resource.getLocation();
if (resource.isFolder()) {
path.addTrailingSeparator();
deleteBreakpoints(getBreakpointPaths(path.toString()));
} else if (resource.isFile()) {
deleteBreakpoints(Collections.singleton(path.toString()));
}
}
}
});
}
use of org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto in project che by eclipse.
the class BreakpointManagerImpl method preserveBreakpoints.
private void preserveBreakpoints() {
Storage localStorage = Storage.getLocalStorageIfSupported();
if (localStorage != null) {
List<StorableBreakpointDto> allDtoBreakpoints = new LinkedList<StorableBreakpointDto>();
List<Breakpoint> allBreakpoints = getBreakpointList();
if (currentBreakpoint != null) {
allBreakpoints.add(currentBreakpoint);
}
for (Breakpoint breakpoint : allBreakpoints) {
StorableBreakpointDto dto = dtoFactory.createDto(StorableBreakpointDto.class);
dto.setType(breakpoint.getType());
dto.setPath(breakpoint.getPath());
dto.setLineNumber(breakpoint.getLineNumber());
if (breakpoint.getFile() instanceof Resource) {
final Optional<Project> project = ((Resource) breakpoint.getFile()).getRelatedProject();
if (project.isPresent()) {
final ProjectConfigDto projectDto = dtoFactory.createDto(ProjectConfigDto.class).withName(project.get().getName()).withPath(project.get().getPath()).withType(project.get().getType()).withDescription(project.get().getDescription()).withAttributes(project.get().getAttributes()).withMixins(project.get().getMixins());
//TODO need to think to change argument type from dto to model interface
dto.setFileProjectConfig(projectDto);
}
}
dto.setActive(breakpoint.isActive());
allDtoBreakpoints.add(dto);
}
String data = dtoFactory.toJson(allDtoBreakpoints);
localStorage.setItem(LOCAL_STORAGE_BREAKPOINTS_KEY, data);
}
}
use of org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto in project che by eclipse.
the class FactoryBaseValidator method validateProjects.
/**
* Validates source parameter of factory.
*
* @param factory
* factory to validate
* @throws BadRequestException
* when source projects in the factory is invalid
*/
protected void validateProjects(FactoryDto factory) throws BadRequestException {
for (ProjectConfigDto project : factory.getWorkspace().getProjects()) {
final String projectName = project.getName();
if (null != projectName && !PROJECT_NAME_VALIDATOR.matcher(projectName).matches()) {
throw new BadRequestException("Project name must contain only Latin letters, " + "digits or these following special characters -._.");
}
if (project.getPath().indexOf('/', 1) == -1) {
final String location = project.getSource().getLocation();
final String parameterLocationName = "project.source.location";
if (isNullOrEmpty(location)) {
throw new BadRequestException(format(FactoryConstants.PARAMETRIZED_ILLEGAL_PARAMETER_VALUE_MESSAGE, parameterLocationName, location));
}
try {
URLDecoder.decode(location, "UTF-8");
} catch (IllegalArgumentException | UnsupportedEncodingException e) {
throw new BadRequestException(format(FactoryConstants.PARAMETRIZED_ILLEGAL_PARAMETER_VALUE_MESSAGE, parameterLocationName, location));
}
}
}
}
use of org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto in project che by eclipse.
the class ProjectServiceLinksInjectorTest method verifyProjectLinks.
@Test
public void verifyProjectLinks() throws Exception {
ProjectConfigDto projectConfigDto = DtoFactory.newDto(ProjectConfigDto.class);
projectConfigDto.withPath(PROJECT_PATH);
ProjectConfigDto result = projectServiceLinksInjector.injectProjectLinks(projectConfigDto, serviceContext);
final List<Link> links = result.getLinks();
assertEquals(4, links.size());
final Link updateProjectLink = links.get(0);
assertNotNull(updateProjectLink);
assertEquals("localhost:8080/project/project_path", updateProjectLink.getHref());
assertEquals(HttpMethod.PUT, updateProjectLink.getMethod());
assertEquals(LINK_REL_UPDATE_PROJECT, updateProjectLink.getRel());
assertEquals(APPLICATION_JSON, updateProjectLink.getConsumes());
assertEquals(APPLICATION_JSON, updateProjectLink.getProduces());
final Link childrenProjectLink = links.get(1);
assertNotNull(childrenProjectLink);
assertEquals("localhost:8080/project/children/project_path", childrenProjectLink.getHref());
assertEquals(HttpMethod.GET, childrenProjectLink.getMethod());
assertEquals(LINK_REL_CHILDREN, childrenProjectLink.getRel());
assertEquals(APPLICATION_JSON, childrenProjectLink.getProduces());
final Link treeProjectLink = links.get(2);
assertNotNull(treeProjectLink);
assertEquals("localhost:8080/project/tree/project_path", treeProjectLink.getHref());
assertEquals(HttpMethod.GET, treeProjectLink.getMethod());
assertEquals(LINK_REL_TREE, treeProjectLink.getRel());
assertEquals(APPLICATION_JSON, treeProjectLink.getProduces());
final Link deleteProjectLink = links.get(3);
assertNotNull(deleteProjectLink);
assertEquals("localhost:8080/project/project_path", deleteProjectLink.getHref());
assertEquals(HttpMethod.DELETE, deleteProjectLink.getMethod());
assertEquals(LINK_REL_DELETE, deleteProjectLink.getRel());
}
Aggregations