Search in sources :

Example 1 with ProjectNotificationSubscriber

use of org.eclipse.che.ide.api.project.wizard.ProjectNotificationSubscriber 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)

Aggregations

Map (java.util.Map)1 Function (org.eclipse.che.api.promises.client.Function)1 FunctionException (org.eclipse.che.api.promises.client.FunctionException)1 Promise (org.eclipse.che.api.promises.client.Promise)1 PromiseError (org.eclipse.che.api.promises.client.PromiseError)1 MutableProjectConfig (org.eclipse.che.ide.api.project.MutableProjectConfig)1 ProjectNotificationSubscriber (org.eclipse.che.ide.api.project.wizard.ProjectNotificationSubscriber)1 Project (org.eclipse.che.ide.api.resources.Project)1