Search in sources :

Example 16 with Project

use of org.eclipse.che.ide.api.resources.Project 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();
                }
            });
        }
    });
}
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) FunctionException(org.eclipse.che.api.promises.client.FunctionException) Resource(org.eclipse.che.ide.api.resources.Resource) Folder(org.eclipse.che.ide.api.resources.Folder) ProjectConfig(org.eclipse.che.api.core.model.project.ProjectConfig) MutableProjectConfig(org.eclipse.che.ide.api.project.MutableProjectConfig) NewProjectConfig(org.eclipse.che.api.core.model.project.NewProjectConfig) Promise(org.eclipse.che.api.promises.client.Promise) Function(org.eclipse.che.api.promises.client.Function) Project(org.eclipse.che.ide.api.resources.Project) SourceStorage(org.eclipse.che.api.core.model.project.SourceStorage) Container(org.eclipse.che.ide.api.resources.Container) SourceStorageDto(org.eclipse.che.api.workspace.shared.dto.SourceStorageDto) ResourceChangedEvent(org.eclipse.che.ide.api.resources.ResourceChangedEvent)

Example 17 with Project

use of org.eclipse.che.ide.api.resources.Project 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");
                        }
                    });
                }
            });
        }
    });
}
Also used : Path(org.eclipse.che.ide.resource.Path) MutableProjectConfig(org.eclipse.che.ide.api.project.MutableProjectConfig) 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) FunctionException(org.eclipse.che.api.promises.client.FunctionException) Promise(org.eclipse.che.api.promises.client.Promise) Function(org.eclipse.che.api.promises.client.Function) Project(org.eclipse.che.ide.api.resources.Project) List(java.util.List) ArrayList(java.util.ArrayList) ResourceChangedEvent(org.eclipse.che.ide.api.resources.ResourceChangedEvent)

Example 18 with Project

use of org.eclipse.che.ide.api.resources.Project in project che by eclipse.

the class ProjectImporter method importProject.

public void importProject(final CompleteCallback callback, MutableProjectConfig projectConfig) {
    final Path path = !isNullOrEmpty(projectConfig.getPath()) ? Path.valueOf(projectConfig.getPath()) : !isNullOrEmpty(projectConfig.getName()) ? Path.valueOf(projectConfig.getName()).makeAbsolute() : null;
    checkState(path != null, "Import path is undefined");
    startImport(path, projectConfig.getSource()).then(new Operation<Project>() {

        @Override
        public void apply(Project arg) throws OperationException {
            if (callback != null) {
                callback.onCompleted();
            }
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError arg) throws OperationException {
            if (callback != null) {
                callback.onFailure(arg.getCause());
            }
        }
    });
}
Also used : Path(org.eclipse.che.ide.resource.Path) Project(org.eclipse.che.ide.api.resources.Project) PromiseError(org.eclipse.che.api.promises.client.PromiseError) Operation(org.eclipse.che.api.promises.client.Operation) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 19 with Project

use of org.eclipse.che.ide.api.resources.Project in project che by eclipse.

the class ProjectImporter method doImport.

private Promise<Project> doImport(final Path path, final SourceStorage sourceStorage) {
    final ProjectNotificationSubscriber subscriber = subscriberFactory.createSubscriber();
    subscriber.subscribe(path.lastSegment());
    MutableProjectConfig importConfig = new MutableProjectConfig();
    importConfig.setPath(path.toString());
    importConfig.setSource(sourceStorage);
    return appContext.getWorkspaceRoot().importProject().withBody(importConfig).send().thenPromise(new Function<Project, Promise<Project>>() {

        @Override
        public Promise<Project> apply(Project project) throws FunctionException {
            subscriber.onSuccess();
            return projectResolver.resolve(project);
        }
    }).catchErrorPromise(new Function<PromiseError, Promise<Project>>() {

        @Override
        public Promise<Project> apply(PromiseError exception) throws FunctionException {
            subscriber.onFailure(exception.getCause().getMessage());
            switch(getErrorCode(exception.getCause())) {
                case UNABLE_GET_PRIVATE_SSH_KEY:
                    throw new IllegalStateException(localizationConstant.importProjectMessageUnableGetSshKey());
                case UNAUTHORIZED_SVN_OPERATION:
                    return recallImportWithCredentials(sourceStorage, path);
                case UNAUTHORIZED_GIT_OPERATION:
                    final Map<String, String> attributes = ExceptionUtils.getAttributes(exception.getCause());
                    final String providerName = attributes.get(PROVIDER_NAME);
                    final String authenticateUrl = attributes.get(AUTHENTICATE_URL);
                    if (!Strings.isNullOrEmpty(providerName) && !Strings.isNullOrEmpty(authenticateUrl)) {
                        return authUserAndRecallImport(providerName, authenticateUrl, path, sourceStorage, subscriber);
                    } else {
                        throw new IllegalStateException(localizationConstant.oauthFailedToGetAuthenticatorText());
                    }
                default:
                    throw new IllegalStateException(exception.getCause());
            }
        }
    });
}
Also used : Function(org.eclipse.che.api.promises.client.Function) Project(org.eclipse.che.ide.api.resources.Project) Promise(org.eclipse.che.api.promises.client.Promise) MutableProjectConfig(org.eclipse.che.ide.api.project.MutableProjectConfig) ProjectNotificationSubscriber(org.eclipse.che.ide.api.project.wizard.ProjectNotificationSubscriber) PromiseError(org.eclipse.che.api.promises.client.PromiseError) FunctionException(org.eclipse.che.api.promises.client.FunctionException) Map(java.util.Map)

Example 20 with Project

use of org.eclipse.che.ide.api.resources.Project in project che by eclipse.

the class ProjectResolver method resolve.

public Promise<Project> resolve(final Project project) {
    return project.resolve().thenPromise(new Function<List<SourceEstimation>, Promise<Project>>() {

        @Override
        public Promise<Project> apply(List<SourceEstimation> estimations) throws FunctionException {
            if (estimations == null || estimations.isEmpty()) {
                return promiseProvider.resolve(project);
            }
            final List<String> primeTypes = newArrayList();
            for (SourceEstimation estimation : estimations) {
                if (projectTypeRegistry.getProjectType(estimation.getType()).isPrimaryable()) {
                    primeTypes.add(estimation.getType());
                }
            }
            final MutableProjectConfig config = new MutableProjectConfig(project);
            final SourceStorage source = project.getSource();
            if (source != null && source.getParameters() != null && source.getParameters().containsKey("keepDir")) {
                config.setType(Constants.BLANK_ID);
            } else if (primeTypes.isEmpty()) {
                return promiseProvider.resolve(project);
            } else if (primeTypes.size() == 1) {
                config.setType(primeTypes.get(0));
            } else {
                config.setType(Constants.BLANK_ID);
                projectWizard.show(config);
                return promiseProvider.resolve(project);
            }
            return project.update().withBody(config).send();
        }
    }).catchErrorPromise(new Function<PromiseError, Promise<Project>>() {

        @Override
        public Promise<Project> apply(PromiseError error) throws FunctionException {
            Log.warn(ProjectResolver.class, error.getMessage());
            return promiseProvider.resolve(project);
        }
    });
}
Also used : MutableProjectConfig(org.eclipse.che.ide.api.project.MutableProjectConfig) FunctionException(org.eclipse.che.api.promises.client.FunctionException) Function(org.eclipse.che.api.promises.client.Function) Project(org.eclipse.che.ide.api.resources.Project) Promise(org.eclipse.che.api.promises.client.Promise) SourceStorage(org.eclipse.che.api.core.model.project.SourceStorage) PromiseError(org.eclipse.che.api.promises.client.PromiseError) SourceEstimation(org.eclipse.che.api.project.shared.dto.SourceEstimation) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList)

Aggregations

Project (org.eclipse.che.ide.api.resources.Project)127 Resource (org.eclipse.che.ide.api.resources.Resource)74 OperationException (org.eclipse.che.api.promises.client.OperationException)53 Operation (org.eclipse.che.api.promises.client.Operation)51 PromiseError (org.eclipse.che.api.promises.client.PromiseError)48 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)24 CLIOutputResponse (org.eclipse.che.plugin.svn.shared.CLIOutputResponse)18 Promise (org.eclipse.che.api.promises.client.Promise)16 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)14 Container (org.eclipse.che.ide.api.resources.Container)14 List (java.util.List)12 StatusNotification (org.eclipse.che.ide.api.notification.StatusNotification)12 Path (org.eclipse.che.ide.resource.Path)12 Optional (com.google.common.base.Optional)11 ArrayList (java.util.ArrayList)10 File (org.eclipse.che.ide.api.resources.File)10 Credentials (org.eclipse.che.ide.api.subversion.Credentials)10 FunctionException (org.eclipse.che.api.promises.client.FunctionException)9 JavaUtil.isJavaProject (org.eclipse.che.ide.ext.java.client.util.JavaUtil.isJavaProject)9 TextEditor (org.eclipse.che.ide.api.editor.texteditor.TextEditor)8