Skip to content

Commit

Permalink
Fix callback
Browse files Browse the repository at this point in the history
  • Loading branch information
mshaposhnik committed Feb 19, 2016
1 parent f6c5730 commit d32e4c1
Showing 1 changed file with 8 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.eclipse.che.api.promises.client.OperationException;
import org.eclipse.che.api.promises.client.Promise;
import org.eclipse.che.api.promises.client.PromiseError;
import org.eclipse.che.api.promises.client.callback.AsyncPromiseHelper;
import org.eclipse.che.api.vfs.gwt.client.VfsServiceClient;
import org.eclipse.che.api.vfs.shared.dto.Item;
import org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto;
Expand Down Expand Up @@ -112,19 +111,13 @@ protected void onFailure(Throwable exception) {
protected Promise<Void> importProject(@NotNull final String pathToProject,
@NotNull final String projectName,
@NotNull final SourceStorageDto sourceStorage) {
return AsyncPromiseHelper.createFromAsyncRequest(new AsyncPromiseHelper.RequestCall<Void>() {
@Override
public void makeCall(AsyncCallback<Void> internalCallback) {
doImport(pathToProject, projectName, sourceStorage, internalCallback);
}
});
return doImport(pathToProject, projectName, sourceStorage);
}


private void doImport(@NotNull final String pathToProject,
private Promise<Void> doImport(@NotNull final String pathToProject,
@NotNull final String projectName,
@NotNull final SourceStorageDto sourceStorage,
final AsyncCallback<Void> internalCallback) {
@NotNull final SourceStorageDto sourceStorage) {
final ProjectNotificationSubscriber subscriber = subscriberFactory.createSubscriber();
subscriber.subscribe(projectName);
Promise<Void> importPromise = projectService.importProject(workspaceId, pathToProject, false, sourceStorage);
Expand All @@ -135,7 +128,6 @@ public void apply(Void arg) throws OperationException {
eventBus.fireEvent(new CreateProjectEvent(projectConfig));
projectResolver.resolveProject(callback, projectConfig);
subscriber.onSuccess();
internalCallback.onSuccess(null);
}
}).catchError(new Operation<PromiseError>() {
@Override
Expand All @@ -158,28 +150,27 @@ public void apply(PromiseError exception) throws OperationException {
pathToProject,
projectName,
sourceStorage,
subscriber,
internalCallback);
subscriber);
} else {
dialogFactory.createMessageDialog(localizationConstant.oauthFailedToGetAuthenticatorTitle(),
localizationConstant.oauthFailedToGetAuthenticatorText(), null).show();
}
} else {
subscriber.onFailure(exception.getMessage());
internalCallback.onFailure(exception.getCause());
callback.onFailure(new Exception(exception.getCause().getMessage()));
}
}
});

return importPromise;
}

private void tryAuthenticateRepeatImport(@NotNull final String providerName,
@NotNull final String authenticateUrl,
@NotNull final String pathToProject,
@NotNull final String projectName,
@NotNull final SourceStorageDto sourceStorage,
@NotNull final ProjectNotificationSubscriber subscriber,
final AsyncCallback<Void> internalCallback) {
@NotNull final ProjectNotificationSubscriber subscriber) {
OAuth2Authenticator authenticator = oAuth2AuthenticatorRegistry.getAuthenticator(providerName);
if(authenticator == null) {
authenticator = oAuth2AuthenticatorRegistry.getAuthenticator("default");
Expand All @@ -194,7 +185,7 @@ public void onFailure(Throwable caught) {
@Override
public void onSuccess(OAuthStatus result) {
if (!result.equals(OAuthStatus.NOT_PERFORMED)) {
doImport(pathToProject, projectName, sourceStorage, internalCallback);
doImport(pathToProject, projectName, sourceStorage);
} else {
subscriber.onFailure("Authentication cancelled");
callback.onCompleted();
Expand Down

0 comments on commit d32e4c1

Please sign in to comment.