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);
}
});
}
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();
}
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());
}
});
}
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();
}
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());
}
Aggregations