Skip to content

Commit

Permalink
CHE-5718 Progress of the importing project is not displayed (eclipse-…
Browse files Browse the repository at this point in the history
…che#5934)

* CHE-5718 Progress of the importing project is not displayed

* CHE-5718 Progress of the importing project is not displayed

* CHE-5718 Progress of the importing project is not displayed

* CHE-5718 Progress of the importing project is not displayed

* Remove batch project creation from dashboard

Signed-off-by: Anna Shumilova <ashumilo@redhat.com>

* CHE-5718 Progress of the importing project is not displayed
  • Loading branch information
Vitaliy Guliy committed Aug 8, 2017
1 parent 96599f0 commit 37d8cb0
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export class CreateWorkspaceSvc {
createWorkspace(workspaceConfig: che.IWorkspaceConfig, attributes?: any): ng.IPromise<any> {
const namespaceId = this.namespaceSelectorSvc.getNamespaceId(),
projectTemplates = this.projectSourceSelectorService.getProjectTemplates();

workspaceConfig.projects = projectTemplates;
return this.checkEditingProgress().then(() => {
return this.cheWorkspace.createWorkspaceFromConfig(namespaceId, workspaceConfig, attributes).then((workspace: che.IWorkspace) => {

Expand All @@ -177,13 +177,9 @@ export class CreateWorkspaceSvc {
}).then(() => {
return this.cheWorkspace.fetchWorkspaceDetails(workspace.id);
}).then(() => {
return this.createProjects(workspace.id, projectTemplates);
}).then(() => {
this.getIDE().ProjectExplorer.refresh();
return this.importProjects(workspace.id, projectTemplates);
return this.addProjectCommands(workspace.id, projectTemplates);
}).then(() => {
let IDE = this.getIDE();
IDE.ProjectExplorer.refresh();
IDE.CommandManager.refresh();
});
}, (error: any) => {
Expand Down Expand Up @@ -242,29 +238,25 @@ export class CreateWorkspaceSvc {
}

/**
* Imports bunch of projects in row.
* Returns resolved promise if all project are imported properly, otherwise returns rejected promise with list of names of failed projects.
* Adds commands from the bunch of projects in row.
* Returns resolved promise if all commands are aded properly, otherwise returns rejected promise with list of names of failed projects.
*
* @param {string} workspaceId the workspace ID
* @param {Array<che.IProjectTemplate>} projectTemplates the list of project templates to import
* @param {Array<che.IProjectTemplate>} projectTemplates the list of project templates
* @return {IPromise<any>}
*/
importProjects(workspaceId: string, projectTemplates: Array<che.IProjectTemplate>): ng.IPromise<any> {
addProjectCommands(workspaceId: string, projectTemplates: Array<che.IProjectTemplate>): ng.IPromise<any> {
const defer = this.$q.defer();
defer.resolve();
let accumulatorPromise = defer.promise;

const projectTypeResolverService = this.cheWorkspace.getWorkspaceAgent(workspaceId).getProjectTypeResolver();

const failedProjects = [];

accumulatorPromise = projectTemplates.reduce((_accumulatorPromise: ng.IPromise<any>, project: che.IProjectTemplate) => {
return _accumulatorPromise.then(() => {
return this.addCommands(workspaceId, project.name, project.commands).catch(() => {
// adding commands errors, ignore them here
return this.$q.when();
}).then(() => {
return projectTypeResolverService.resolveProjectType(project as any);
}).catch((error: any) => {
failedProjects.push(project.name);
if (error && error.message) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*******************************************************************************
* Copyright (c) 2012-2017 Codenvy, S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.ide.factory.utils;

import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.eclipse.che.api.promises.client.*;
import org.eclipse.che.api.promises.client.js.Promises;
import org.eclipse.che.ide.CoreLocalizationConstant;
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.ide.api.notification.NotificationManager;
import org.eclipse.che.ide.api.notification.StatusNotification;
import org.eclipse.che.ide.api.oauth.OAuth2AuthenticatorRegistry;
import org.eclipse.che.ide.api.project.wizard.ImportProjectNotificationSubscriberFactory;
import org.eclipse.che.ide.api.resources.Project;
import org.eclipse.che.ide.api.user.AskCredentialsDialog;
import org.eclipse.che.ide.part.explorer.project.ProjectExplorerPresenter;
import org.eclipse.che.ide.projectimport.wizard.ProjectImportOutputJsonRpcNotifier;
import org.eclipse.che.ide.projectimport.wizard.ProjectImporter;
import org.eclipse.che.ide.projectimport.wizard.ProjectResolver;
import java.util.*;

import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.FLOAT_MODE;
import static org.eclipse.che.ide.api.notification.StatusNotification.Status.FAIL;
import static org.eclipse.che.ide.api.notification.StatusNotification.Status.PROGRESS;

/**
* Imports projects on file system.
*/
@Singleton
public class InitialProjectImporter extends ProjectImporter {

private final ProjectImportOutputJsonRpcNotifier subscriber;
private final NotificationManager notificationManager;
private final CoreLocalizationConstant locale;

@Inject
public InitialProjectImporter(CoreLocalizationConstant localizationConstant,
ImportProjectNotificationSubscriberFactory subscriberFactory,
AppContext appContext,
ProjectResolver projectResolver,
AskCredentialsDialog credentialsDialog,
OAuth2AuthenticatorRegistry oAuth2AuthenticatorRegistry,
ProjectImportOutputJsonRpcNotifier subscriber,
NotificationManager notificationManager,
CoreLocalizationConstant locale,
ProjectExplorerPresenter projectExplorerPresenter) {

super(localizationConstant, subscriberFactory, appContext, projectResolver, credentialsDialog, oAuth2AuthenticatorRegistry);

this.subscriber = subscriber;
this.notificationManager = notificationManager;
this.locale = locale;
}

/**
* Import source projects and if it's already exist in workspace
* then show warning notification
*
* @param projects
* list of projects that already exist in workspace and will be imported on file system
*/
public void importProjects(final List<Project> projects) {
if (projects.isEmpty()) {
return;
}

final Project importProject = projects.remove(0);
final StatusNotification notification = notificationManager.notify(locale.cloningSource(importProject.getName()), null, PROGRESS, FLOAT_MODE);
subscriber.subscribe(importProject.getName(), notification);

appContext.getWorkspaceRoot()
.importProject()
.withBody(importProject)
.send()
.then(new Operation<Project>() {
@Override
public void apply(Project project) throws OperationException {
subscriber.onSuccess();

appContext.getWorkspaceRoot().synchronize();

importProjects(projects);
}
}).catchErrorPromise(
new Function<PromiseError, Promise<Project>>() {
@Override
public Promise<Project> apply(PromiseError err) throws FunctionException {
subscriber.onFailure(err.getMessage());
notification.setTitle(locale.cloningSourceFailedTitle(importProject.getName()));
notification.setStatus(FAIL);

return Promises.resolve(null);
}
}
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package org.eclipse.che.ide.workspace;

import com.google.gwt.core.client.Callback;
import com.google.gwt.core.client.Scheduler;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.google.web.bindery.event.shared.EventBus;
Expand All @@ -20,16 +21,22 @@
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.ide.api.component.Component;
import org.eclipse.che.ide.api.dialogs.DialogFactory;
import org.eclipse.che.ide.api.machine.events.WsAgentStateEvent;
import org.eclipse.che.ide.api.notification.NotificationManager;
import org.eclipse.che.ide.api.preferences.PreferencesManager;
import org.eclipse.che.ide.api.resources.Project;
import org.eclipse.che.ide.api.workspace.WorkspaceServiceClient;
import org.eclipse.che.ide.context.BrowserAddress;
import org.eclipse.che.ide.dto.DtoFactory;
import org.eclipse.che.ide.factory.utils.InitialProjectImporter;
import org.eclipse.che.ide.rest.DtoUnmarshallerFactory;
import org.eclipse.che.ide.ui.loaders.LoaderPresenter;
import org.eclipse.che.ide.workspace.create.CreateWorkspacePresenter;
import org.eclipse.che.ide.workspace.start.StartWorkspacePresenter;

import java.util.ArrayList;
import java.util.List;

/**
* Performs default start of IDE - creates new or starts latest workspace.
* Used when no {@code factory} specified.
Expand All @@ -39,6 +46,8 @@
@Singleton
public class DefaultWorkspaceComponent extends WorkspaceComponent {

private InitialProjectImporter initialProjectImporter;

@Inject
public DefaultWorkspaceComponent(WorkspaceServiceClient workspaceServiceClient,
CreateWorkspacePresenter createWorkspacePresenter,
Expand All @@ -54,6 +63,7 @@ public DefaultWorkspaceComponent(WorkspaceServiceClient workspaceServiceClient,
DtoFactory dtoFactory,
LoaderPresenter loader,
RequestTransmitter transmitter,
InitialProjectImporter initialProjectImporter,
WorkspaceEventsHandler handler) {
super(workspaceServiceClient,
createWorkspacePresenter,
Expand All @@ -69,6 +79,8 @@ public DefaultWorkspaceComponent(WorkspaceServiceClient workspaceServiceClient,
dtoFactory,
loader,
transmitter);

this.initialProjectImporter = initialProjectImporter;
}

/** {@inheritDoc} */
Expand All @@ -88,6 +100,30 @@ public void start(final Callback<Component, Exception> callback) {
}

@Override
public void tryStartWorkspace() {
public void onWsAgentStarted(WsAgentStateEvent event) {
super.onWsAgentStarted(event);

Scheduler.get().scheduleDeferred(() -> {
importProjects();
});
}

/**
* Imports all projects described in workspace configuration but not existed on file system.
*/
private void importProjects() {
final Project[] projects = appContext.getProjects();

List<Project> importProjects = new ArrayList<>();
for (Project project : projects) {
if (project.getSource() == null || project.getSource().getLocation() == null || project.exists()) {
continue;
}

importProjects.add(project);
}

initialProjectImporter.importProjects(importProjects);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ public void start(final Callback<Component, Exception> callback) {

}

@Override
public void tryStartWorkspace() {
if (this.workspaceId == null) {
notificationManager.notify(locale.failedToLoadFactory(), locale.workspaceIdUndefined(), FAIL, FLOAT_MODE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,6 @@ public void apply(WorkspaceDto workspaceToStart) throws OperationException {
};
}

abstract void tryStartWorkspace();

private void startWorkspaceById(String workspaceId, String defaultEnvironment, Boolean restoreFromSnapshot) {
loader.show(STARTING_WORKSPACE_RUNTIME);
workspaceServiceClient.startById(workspaceId, defaultEnvironment, restoreFromSnapshot).catchError(new Operation<PromiseError>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
@Singleton
public class WorkspaceComponentProvider implements Provider<WorkspaceComponent> {

private final Provider<DefaultWorkspaceComponent> workspaceComponentProvider;
private final Provider<FactoryWorkspaceComponent> factoryComponentProvider;
private final QueryParameters queryParameters;
private final Provider<DefaultWorkspaceComponent> workspaceComponentProvider;
private final Provider<FactoryWorkspaceComponent> factoryComponentProvider;
private final QueryParameters queryParameters;

@Inject
public WorkspaceComponentProvider(Provider<DefaultWorkspaceComponent> workspaceComponentProvider,
Expand All @@ -40,7 +40,11 @@ public WorkspaceComponentProvider(Provider<DefaultWorkspaceComponent> workspaceC

@Override
public WorkspaceComponent get() {
final String factoryParams = queryParameters.getByName("factory");
return factoryParams.isEmpty() ? workspaceComponentProvider.get() : factoryComponentProvider.get();
if (!queryParameters.getByName("factory").isEmpty()) {
return factoryComponentProvider.get();
}

return workspaceComponentProvider.get();
}

}

0 comments on commit 37d8cb0

Please sign in to comment.