Search in sources :

Example 51 with PromiseError

use of org.eclipse.che.api.promises.client.PromiseError in project che by eclipse.

the class CleanupPresenter method cleanup.

public void cleanup() {
    final Project project = appContext.getRootProject();
    checkState(project != null);
    final Resource[] resources = appContext.getResources();
    checkState(!Arrays.isNullOrEmpty(resources));
    service.cleanup(project.getLocation(), toRelative(project, resources)).then(new Operation<CLIOutputResponse>() {

        @Override
        public void apply(CLIOutputResponse result) throws OperationException {
            printResponse(result.getCommand(), result.getOutput(), result.getErrOutput(), constants.commandCleanup());
            notificationManager.notify(constants.cleanupSuccessful());
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError error) throws OperationException {
            notificationManager.notify(constants.cleanupFailed() + ": " + error.getMessage(), FAIL, FLOAT_MODE);
        }
    });
}
Also used : Project(org.eclipse.che.ide.api.resources.Project) PromiseError(org.eclipse.che.api.promises.client.PromiseError) Resource(org.eclipse.che.ide.api.resources.Resource) Operation(org.eclipse.che.api.promises.client.Operation) CLIOutputResponse(org.eclipse.che.plugin.svn.shared.CLIOutputResponse) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 52 with PromiseError

use of org.eclipse.che.api.promises.client.PromiseError in project che by eclipse.

the class CommitPresenter method loadAllChanges.

private void loadAllChanges() {
    final Project project = appContext.getRootProject();
    checkState(project != null);
    service.status(project.getLocation(), new Path[0], null, false, false, false, true, false, null).then(new Operation<CLIOutputResponse>() {

        @Override
        public void apply(CLIOutputResponse response) throws OperationException {
            List<StatusItem> statusItems = parseChangesList(response);
            view.setChangesList(statusItems);
            view.onShow();
            cache.put(Changes.ALL, statusItems);
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError error) throws OperationException {
            Log.error(CommitPresenter.class, error.getMessage());
        }
    });
}
Also used : StatusItem(org.eclipse.che.plugin.svn.shared.StatusItem) Project(org.eclipse.che.ide.api.resources.Project) PromiseError(org.eclipse.che.api.promises.client.PromiseError) Operation(org.eclipse.che.api.promises.client.Operation) CLIOutputResponse(org.eclipse.che.plugin.svn.shared.CLIOutputResponse) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 53 with PromiseError

use of org.eclipse.che.api.promises.client.PromiseError in project che by eclipse.

the class CommitPresenter method showDiff.

/** {@inheritDoc} */
@Override
public void showDiff(final String path) {
    final Project project = appContext.getRootProject();
    checkState(project != null);
    performOperationWithCredentialsRequestIfNeeded(new RemoteSubversionOperation<CLIOutputResponse>() {

        @Override
        public Promise<CLIOutputResponse> perform(Credentials credentials) {
            return service.showDiff(project.getLocation(), new Path[] { valueOf(path) }, "HEAD", credentials);
        }
    }, null).then(new Operation<CLIOutputResponse>() {

        @Override
        public void apply(CLIOutputResponse response) throws OperationException {
            String content = Joiner.on('\n').join(response.getOutput());
            diffViewerPresenter.showDiff(content);
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError error) throws OperationException {
            notificationManager.notify(error.getMessage(), FAIL, FLOAT_MODE);
        }
    });
}
Also used : Path(org.eclipse.che.ide.resource.Path) Project(org.eclipse.che.ide.api.resources.Project) Promise(org.eclipse.che.api.promises.client.Promise) PromiseError(org.eclipse.che.api.promises.client.PromiseError) CLIOutputResponse(org.eclipse.che.plugin.svn.shared.CLIOutputResponse) Operation(org.eclipse.che.api.promises.client.Operation) Credentials(org.eclipse.che.ide.api.subversion.Credentials) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 54 with PromiseError

use of org.eclipse.che.api.promises.client.PromiseError 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 55 with PromiseError

use of org.eclipse.che.api.promises.client.PromiseError 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

PromiseError (org.eclipse.che.api.promises.client.PromiseError)137 OperationException (org.eclipse.che.api.promises.client.OperationException)123 Operation (org.eclipse.che.api.promises.client.Operation)109 Project (org.eclipse.che.ide.api.resources.Project)48 Resource (org.eclipse.che.ide.api.resources.Resource)40 CLIOutputResponse (org.eclipse.che.plugin.svn.shared.CLIOutputResponse)21 StatusNotification (org.eclipse.che.ide.api.notification.StatusNotification)20 Promise (org.eclipse.che.api.promises.client.Promise)19 List (java.util.List)15 JsPromiseError (org.eclipse.che.api.promises.client.js.JsPromiseError)13 GitOutputConsole (org.eclipse.che.ide.ext.git.client.outputconsole.GitOutputConsole)13 Path (org.eclipse.che.ide.resource.Path)13 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)11 DebuggerObserver (org.eclipse.che.ide.debug.DebuggerObserver)11 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)10 Credentials (org.eclipse.che.ide.api.subversion.Credentials)10 HashMap (java.util.HashMap)9 Function (org.eclipse.che.api.promises.client.Function)8 FunctionException (org.eclipse.che.api.promises.client.FunctionException)8