Search in sources :

Example 16 with ProjectConfigDto

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;
        }
    });
}
Also used : Optional(com.google.common.base.Optional) NewProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) Resource(org.eclipse.che.ide.api.resources.Resource) ProblemProjectMarker(org.eclipse.che.ide.api.resources.Project.ProblemProjectMarker) FunctionException(org.eclipse.che.api.promises.client.FunctionException) TreeElement(org.eclipse.che.api.project.shared.dto.TreeElement) Function(org.eclipse.che.api.promises.client.Function) ResourceChangedEvent(org.eclipse.che.ide.api.resources.ResourceChangedEvent)

Example 17 with ProjectConfigDto

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()));
                }
            }
        }
    });
}
Also used : Path(org.eclipse.che.ide.resource.Path) DeleteProjectEvent(org.eclipse.che.ide.api.event.project.DeleteProjectEvent) EditorOpenedEvent(org.eclipse.che.ide.api.editor.EditorOpenedEvent) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) Resource(org.eclipse.che.ide.api.resources.Resource) DeleteProjectHandler(org.eclipse.che.ide.api.event.project.DeleteProjectHandler) EditorOpenedEventHandler(org.eclipse.che.ide.api.editor.EditorOpenedEventHandler) WorkspaceReadyEvent(org.eclipse.che.ide.api.workspace.WorkspaceReadyEvent) ResourceChangedEvent(org.eclipse.che.ide.api.resources.ResourceChangedEvent)

Example 18 with ProjectConfigDto

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);
    }
}
Also used : Breakpoint(org.eclipse.che.ide.api.debug.Breakpoint) Project(org.eclipse.che.ide.api.resources.Project) Storage(com.google.gwt.storage.client.Storage) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) Resource(org.eclipse.che.ide.api.resources.Resource) StorableBreakpointDto(org.eclipse.che.ide.api.debug.dto.StorableBreakpointDto) LinkedList(java.util.LinkedList)

Example 19 with ProjectConfigDto

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));
            }
        }
    }
}
Also used : ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) BadRequestException(org.eclipse.che.api.core.BadRequestException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 20 with ProjectConfigDto

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());
}
Also used : ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) Link(org.eclipse.che.api.core.rest.shared.dto.Link) Test(org.testng.annotations.Test)

Aggregations

ProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto)30 Test (org.testng.annotations.Test)14 List (java.util.List)13 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)10 LinkedList (java.util.LinkedList)10 ContainerResponse (org.everrest.core.impl.ContainerResponse)10 Collections.singletonList (java.util.Collections.singletonList)9 LinkedHashMap (java.util.LinkedHashMap)7 Resource (org.eclipse.che.ide.api.resources.Resource)6 NewProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto)5 SourceStorageDto (org.eclipse.che.api.workspace.shared.dto.SourceStorageDto)5 WorkspaceConfigDto (org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto)5 ResourceChangedEvent (org.eclipse.che.ide.api.resources.ResourceChangedEvent)5 Optional (com.google.common.base.Optional)4 WorkspaceDto (org.eclipse.che.api.workspace.shared.dto.WorkspaceDto)4 ApiOperation (io.swagger.annotations.ApiOperation)3 ApiResponses (io.swagger.annotations.ApiResponses)3 Function (org.eclipse.che.api.promises.client.Function)3 FunctionException (org.eclipse.che.api.promises.client.FunctionException)3