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