Search in sources :

Example 26 with PromiseError

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

the class PullPresenter method updateBranches.

/**
     * Update the list of branches.
     *
     * @param remoteMode
     *         is a remote mode
     */
private void updateBranches(@NotNull final BranchListMode remoteMode) {
    service.branchList(appContext.getDevMachine(), project.getLocation(), remoteMode).then(new Operation<List<Branch>>() {

        @Override
        public void apply(List<Branch> branches) throws OperationException {
            if (LIST_REMOTE.equals(remoteMode)) {
                view.setRemoteBranches(branchSearcher.getRemoteBranchesToDisplay(view.getRepositoryName(), branches));
                updateBranches(LIST_LOCAL);
            } else {
                view.setLocalBranches(branchSearcher.getLocalBranchesToDisplay(branches));
                for (Branch branch : branches) {
                    if (branch.isActive()) {
                        view.selectRemoteBranch(branch.getDisplayName());
                        break;
                    }
                }
            }
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError error) throws OperationException {
            handleError(error.getCause(), BRANCH_LIST_COMMAND_NAME);
            view.setEnablePullButton(false);
        }
    });
}
Also used : PromiseError(org.eclipse.che.api.promises.client.PromiseError) Branch(org.eclipse.che.api.git.shared.Branch) List(java.util.List) Operation(org.eclipse.che.api.promises.client.Operation) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 27 with PromiseError

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

the class PushToRemotePresenter method onPushClicked.

/** {@inheritDoc} */
@Override
public void onPushClicked() {
    final StatusNotification notification = notificationManager.notify(constant.pushProcess(), PROGRESS, FLOAT_MODE);
    final String repository = view.getRepository();
    final GitOutputConsole console = gitOutputConsoleFactory.create(PUSH_COMMAND_NAME);
    service.push(appContext.getDevMachine(), project.getLocation(), getRefs(), repository, false).then(new Operation<PushResponse>() {

        @Override
        public void apply(PushResponse response) throws OperationException {
            console.print(response.getCommandOutput());
            processesPanelPresenter.addCommandOutput(appContext.getDevMachine().getId(), console);
            notification.setStatus(SUCCESS);
            if (response.getCommandOutput().contains("Everything up-to-date")) {
                notification.setTitle(constant.pushUpToDate());
            } else {
                notification.setTitle(constant.pushSuccess(repository));
            }
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError error) throws OperationException {
            handleError(error.getCause(), notification, console);
            processesPanelPresenter.addCommandOutput(appContext.getDevMachine().getId(), console);
        }
    });
    view.close();
}
Also used : PromiseError(org.eclipse.che.api.promises.client.PromiseError) GitOutputConsole(org.eclipse.che.ide.ext.git.client.outputconsole.GitOutputConsole) StatusNotification(org.eclipse.che.ide.api.notification.StatusNotification) Operation(org.eclipse.che.api.promises.client.Operation) PushResponse(org.eclipse.che.api.git.shared.PushResponse) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 28 with PromiseError

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

the class PushToRemotePresenter method getUpstreamBranch.

/**
     * Get upstream branch for selected local branch. Can invoke {@code onSuccess(null)} if upstream branch isn't set
     */
private void getUpstreamBranch(final AsyncCallback<Branch> result) {
    final String configBranchRemote = "branch." + view.getLocalBranch() + ".remote";
    final String configUpstreamBranch = "branch." + view.getLocalBranch() + ".merge";
    service.config(appContext.getDevMachine(), project.getLocation(), Arrays.asList(configUpstreamBranch, configBranchRemote)).then(new Operation<Map<String, String>>() {

        @Override
        public void apply(Map<String, String> configs) throws OperationException {
            if (configs.containsKey(configBranchRemote) && configs.containsKey(configUpstreamBranch)) {
                String displayName = configs.get(configBranchRemote) + "/" + configs.get(configUpstreamBranch);
                Branch upstream = dtoFactory.createDto(Branch.class).withActive(false).withRemote(true).withDisplayName(displayName).withName("refs/remotes/" + displayName);
                result.onSuccess(upstream);
            } else {
                result.onSuccess(null);
            }
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError error) throws OperationException {
            result.onFailure(error.getCause());
        }
    });
}
Also used : PromiseError(org.eclipse.che.api.promises.client.PromiseError) Branch(org.eclipse.che.api.git.shared.Branch) Operation(org.eclipse.che.api.promises.client.Operation) Map(java.util.Map) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 29 with PromiseError

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

the class HistoryPresenterTest method shouldShowDialogOnInitCommitError.

@Test
public void shouldShowDialogOnInitCommitError() throws Exception {
    PromiseError error = mock(PromiseError.class);
    ServerException exception = mock(ServerException.class);
    when(exception.getErrorCode()).thenReturn(ErrorCodes.INIT_COMMIT_WAS_NOT_PERFORMED);
    when(error.getCause()).thenReturn(exception);
    when(constant.initCommitWasNotPerformed()).thenReturn("error message");
    MessageDialog dialog = mock(MessageDialog.class);
    when(dialogFactory.createMessageDialog(eq("title"), eq("error message"), any(ConfirmCallback.class))).thenReturn(dialog);
    presenter.show();
    verify(logPromise).catchError(promiseErrorCaptor.capture());
    promiseErrorCaptor.getValue().apply(error);
    verify(dialog).show();
}
Also used : ConfirmCallback(org.eclipse.che.ide.api.dialogs.ConfirmCallback) ServerException(org.eclipse.che.ide.commons.exception.ServerException) PromiseError(org.eclipse.che.api.promises.client.PromiseError) MessageDialog(org.eclipse.che.ide.api.dialogs.MessageDialog) BaseTest(org.eclipse.che.ide.ext.git.client.BaseTest) Test(org.junit.Test)

Example 30 with PromiseError

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

the class CreateWorkspacePresenterTest method errorShouldBeCaughtWhenCreatesWorkSpace.

@Test
public void errorShouldBeCaughtWhenCreatesWorkSpace() throws Exception {
    final PromiseError promiseError = mock(PromiseError.class);
    clickOnCreateButton();
    verify(userWsPromise).catchError(errorOperation.capture());
    errorOperation.getValue().apply(promiseError);
    //noinspection ThrowableResultOfMethodCallIgnored
    verify(promiseError).getCause();
    verify(componentCallback).onFailure(Matchers.<Exception>anyObject());
}
Also used : PromiseError(org.eclipse.che.api.promises.client.PromiseError) Test(org.junit.Test)

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